nemoguardrails.colang.runtime

View as Markdown

Module Contents

Classes

NameDescription
RuntimeBase Colang Runtime implementation.

Data

log

API

class nemoguardrails.colang.runtime.Runtime(
config: nemoguardrails.rails.llm.config.RailsConfig,
verbose: bool = False
)

Base Colang Runtime implementation.

action_dispatcher
llm_task_manager
= LLMTaskManager(config)
max_events
= 500
registered_action_params
dict = {}
registered_actions
dict

Return registered actions.

watchers
= []
nemoguardrails.colang.runtime.Runtime._init_flow_configs() -> None
abstract
nemoguardrails.colang.runtime.Runtime.generate_events(
events: typing.List[dict],
processing_log: typing.Optional[typing.List[dict]] = None
) -> typing.List[dict]
async

Generates the next events based on the provided history.

This is a wrapper around the process_events method, that will keep processing the events until the listen event is produced.

:return: The list of events.

Parameters:

events
List[dict]

The list of events.

processing_log
Optional[List[dict]]Defaults to None

The processing log so far. This will be mutated.

nemoguardrails.colang.runtime.Runtime.process_events(
events: typing.List[dict],
state: typing.Optional[typing.Any] = None,
blocking: bool = False
) -> typing.Tuple[typing.List[dict], typing.Any]
async

Process a sequence of events in a given state.

The events will be processed one by one, in the input order.

Parameters:

events
List[dict]

A sequence of events that needs to be processed.

state
Optional[Any]Defaults to None

The state that should be used as the starting point. If not provided, a clean state will be used.

blocking
boolDefaults to False

In blocking mode, the event processing will also wait for all local async actions.

Returns: Tuple[List[dict], Any]

(output_events, output_state) Returns a sequence of output events and an output state.

nemoguardrails.colang.runtime.Runtime.register_action(
action: typing.Callable,
name: typing.Optional[str] = None,
override: bool = True
) -> None

Registers an action with the given name.

:param name: The name of the action. :param action: The action function. :param override: If an action already exists, whether it should be overriden or not.

nemoguardrails.colang.runtime.Runtime.register_action_param(
name: str,
value: typing.Any
) -> None

Registers an additional parameter that can be passed to the actions.

:param name: The name of the parameter. :param value: The value of the parameter.

nemoguardrails.colang.runtime.Runtime.register_actions(
actions_obj: typing.Any,
override: bool = True
) -> None

Registers all the actions from the given object.

nemoguardrails.colang.runtime.log = logging.getLogger(__name__)