Skip to content

Standard actions

conatus.actions.preloaded.standard_actions

Built-in Actions that are always available.

Print

Bases: Action

Print a message.

limited_print conatus-action

limited_print(obj: ParamType, offset: int = 0) -> str
This function is an Action

You can call limited_print just like a regular function, but note that it is actually a Action object.

This means that:

  • limited_print has additional properties and methods that you can use (see the Action documentation for more information);
  • but it also means that operations like issubclass and isinstance will not work as expected.

Print a message.

PARAMETER DESCRIPTION
obj

The object to print.

TYPE: ParamType

offset

The offset to start printing from.

TYPE: int DEFAULT: 0

RETURNS DESCRIPTION
str

The printed message.

TYPE: str

Source code in conatus/actions/preloaded/standard_actions.py
@Action.function
def limited_print(self, obj: ParamType, offset: int = 0) -> str:
    """Print a message.

    Args:
        obj: The object to print.
        offset: The offset to start printing from.

    Returns:
        str: The printed message.
    """
    _ = self
    return str(obj)[offset : offset + 500]

Terminate

Bases: TypedAction[[tuple[ParamType]], None]

Terminate the program.

terminate conatus-action

terminate(*args: ParamType, **kwargs: ParamType) -> None
This function is an Action

You can call terminate just like a regular function, but note that it is actually a Action object.

This means that:

  • terminate has additional properties and methods that you can use (see the Action documentation for more information);
  • but it also means that operations like issubclass and isinstance will not work as expected.

Terminate the program.

PARAMETER DESCRIPTION
args

The variables to terminate the program with.

TYPE: ParamType DEFAULT: ()

kwargs

The keyword arguments to terminate the program with.

TYPE: ParamType DEFAULT: {}

Source code in conatus/actions/preloaded/standard_actions.py
@Action.function
def terminate(self, *args: ParamType, **kwargs: ParamType) -> None:
    """Terminate the program.

    Args:
        args: The variables to terminate the program with.
        kwargs: The keyword arguments to terminate the program with.
    """
    _ = args
    if self.runtime_state is not None:
        for k, v in kwargs.items():
            _ = self.runtime_state.add_result(v, variable_name=k)
        self.runtime_state.termination_sentinel = True

terminate_ conatus-action

terminate_(*args: ParamType, **kwargs: ParamType) -> None
This function is an Action

You can call terminate_ just like a regular function, but note that it is actually a Action object.

This means that:

  • terminate_ has additional properties and methods that you can use (see the Action documentation for more information);
  • but it also means that operations like issubclass and isinstance will not work as expected.

Terminate the program.

PARAMETER DESCRIPTION
args

The variables to terminate the program with.

TYPE: ParamType DEFAULT: ()

kwargs

The keyword arguments to terminate the program with.

TYPE: ParamType DEFAULT: {}

Source code in conatus/actions/preloaded/standard_actions.py
@_privileged_action(suppress_strict_mode_warning=True)
def terminate_(*args: ParamType, **kwargs: ParamType) -> None:
    """Terminate the program.

    Args:
        args: The variables to terminate the program with.
        kwargs: The keyword arguments to terminate the program with.
    """
    _ = args, kwargs

terminate

terminate(
    expected_outputs: OrderedDict[
        str, tuple[TypeOfType, str]
    ],
) -> Action

Get an 'terminate' action that expects specific outputs.

This function enables an Agent to have a function that can terminate a run. That function (a wrapped version of terminate_ ) expects its inputs to be the outputs of the run. Think of this as a return statement.

PARAMETER DESCRIPTION
expected_outputs

The expected outputs of the program. The keys are the names of the outputs, and the values are a tuple containing the type of the output and its description.

TYPE: OrderedDict[str, tuple[TypeOfType, str]]

RETURNS DESCRIPTION
Action

the Action

Source code in conatus/actions/preloaded/standard_actions.py
def terminate(
    expected_outputs: OrderedDict[str, tuple[TypeOfType, str]],
) -> Action:
    """Get an 'terminate' action that expects specific outputs.

    This function enables an [`Agent`][conatus.agents.Agent] to
    have a function that can terminate a run. That function (a
    wrapped version of [`terminate_`
    ][conatus.actions.preloaded.standard_actions.terminate_]) expects its
    inputs to be the outputs of the run. Think of this as a `return`
    statement.

    Args:
        expected_outputs: The expected outputs of the program. The keys are
            the names of the outputs, and the values are a tuple containing
            the type of the output and its description.

    Returns:
        (Action): the Action
    """
    terminate_action_instance = Terminate(direct_execute=False)
    return termination_action(terminate_action_instance, expected_outputs)

print_to_console conatus-action

print_to_console(message: str) -> None
This function is an Action

You can call print_to_console just like a regular function, but note that it is actually a Action object.

This means that:

  • print_to_console has additional properties and methods that you can use (see the Action documentation for more information);
  • but it also means that operations like issubclass and isinstance will not work as expected.

Print a message to the console.

Warning: Your console is limited in terms of space, so be careful with the length of the message.

PARAMETER DESCRIPTION
message

The message to print.

TYPE: str

Source code in conatus/actions/preloaded/standard_actions.py
@_privileged_action
def print_to_console(message: str) -> None:
    """Print a message to the console.

    Warning: Your console is limited in terms of space, so be careful with
    the length of the message.

    Args:
        message: The message to print.
    """
    print_body(message)