nemoguardrails.colang.v1_0.runtime.flows
nemoguardrails.colang.v1_0.runtime.flows
A simplified modeling of the CoFlows engine.
Module Contents
Classes
Functions
API
The configuration of a flow.
The state of a flow.
Bases: enum.Enum
The status of a flow.
A state of a flow-driven system.
Helper to call a subflow.
The head for flow_state is expected to be on a “flow” element.
Parameters:
State — The current state of the system.
FlowState — The state of the current flow.
Returns: Optional[ FlowState ]
Optional[FlowState]: The state of the subflow, if applicable.
Check if a flow ID contains arguments.
A flow ID is considered to contain arguments if it contains both ”(” and ”)”.
Parameters:
The flow ID to check.
Returns: bool
True if the flow ID contains arguments, False otherwise.
Checks if the given element is actionable.
Parameters:
The element to be checked.
Returns: bool
True if the element is actionable, False otherwise.
Checks if the given element matches the given event.
Parameters:
The element to be checked for a match.
The event to compare against.
Returns: bool
True if the element matches the event, False otherwise.
Helper to record the next step.
Parameters:
State — The current state to update.
FlowState — The state of the current flow.
FlowConfig — The configuration of the current flow.
Priority modifier. Defaults to 1.0.
Slides the provided flow and also calls subflows, if applicable.
Parameters:
State — The current state of the system.
FlowState — The state of the current flow.
Returns: Optional[int]
Optional[int]: The new head position of the flow, if applicable.
Converts a next step from a flow element into an actual event.
Parameters:
The next step from a flow element.
Returns: dict
The corresponding event.
Computes the context given a history of events.
Special context variables:
- $last_user_message: the last message sent by the user.
- $last_bot_message: the last message sent by the bot.
Parameters:
The history of events.
Returns:
The computed context.
Computes the next state of the flow-driven system.
Currently, this is a very simplified implementation, with the following assumptions:
- All flows are singleton i.e. you can’t have multiple instances of the same flow.
- Flows can be interrupted by one flow at a time.
- Flows are resumed when the interruption flow completes.
- No prioritization between flows, the first one that can decide something will be used.
Parameters:
State — The current state of the system.
The event triggering the computation.
Returns: State
The updated state of the system.
Computes the next step in a flow-driven system given a history of events.
Parameters:
The history of events.
Dict[str, FlowConfig ] — Flow configurations.
RailsConfig — Rails configuration.
The processing log so far. This will be mutated.
Returns: List[dict]
List[dict]: The list of computed next steps.