Skip to content

TaskDefinition

conatus.tasks.definition

BaseTask information.

TaskDefinition dataclass

TaskDefinition(
    name: str,
    user_prompt: str,
    actions: OrderedDict[str, Action],
    user_provided_actions_keys: list[str],
    inputs_with_positions: OrderedDict[
        str, tuple[TypeOfType, ParamKind, bool, str]
    ],
    inputs_form: ExpectedInputForm | None,
    inputs_are_predefined: bool,
    predefined_inputs: (
        OrderedDict[str, RuntimeVariable] | None
    ),
    outputs_with_positions: OrderedDict[
        str, tuple[TypeOfType, str]
    ],
    outputs_form: ExpectedOutputForm | None,
    flatten_output_to_string: bool = False,
)

Definition of a BaseTask.

Note that this information is invariant across runs. This means, in practice, that inputs and outputs are types, not values, because they describe the expected inputs and outputs of the task, not the actual inputs and outputs of the task.

name instance-attribute

name: str

The name of the task.

user_prompt instance-attribute

user_prompt: str

The user prompt of the task, as passed in the constructor.

actions instance-attribute

actions: OrderedDict[str, Action]

The actions that can be used to perform the task.

user_provided_actions_keys instance-attribute

user_provided_actions_keys: list[str]

The keys of the actions provided by the user in the constructor.

This is essentially actions.keys(), minus: * any actions already included by the Task subclass, or * any standard library actions such as terminate .

Use the user_provided_actions property to get the actions as an OrderedDict.

inputs_with_positions instance-attribute

inputs_with_positions: OrderedDict[
    str, tuple[TypeOfType, ParamKind, bool, str]
]

The input specifications of the task.

We say "with positions" because the inputs are stored in an OrderedDict.

The structure of the dictionary is as follows:

{
    "input_name": (input_type, ParamKind, is_required),
}
Where ParamKind is the kind of the input, input_type is the type of the input, and is_required is a boolean indicating whether the input is required.

inputs_form instance-attribute

inputs_form: ExpectedInputForm | None

The form of the inputs of the agent.

Users can define the expected inputs in four ways:

  • "none": no inputs are expected.
  • "singleton": a single input is expected.
  • "list": a list of inputs is expected.
  • "dict": a dictionary of inputs is expected.

Internally, we use this parameter to see how we parse inputs when they are given by the user during a run.

Note that in the case where the task comes from a decorator, this parameter is set to None, since we can have both positional and keyword inputs.

inputs_are_predefined instance-attribute

inputs_are_predefined: bool

Whether the inputs are predefined or not.

Set to True if starting_variables is provided in the constructor of the BaseTask subclass.

Set to False if inputs is provided in the constructor of the BaseTask subclass.

predefined_inputs instance-attribute

predefined_inputs: OrderedDict[str, RuntimeVariable] | None

The predefined inputs (a.k.a. starting variables) of the agent.

These are the inputs that are provided in the starting_variables parameter of the constructor of the BaseTask subclass.

If the inputs are not predefined, this is set to None.

outputs_with_positions instance-attribute

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

The outputs of the task.

We say "with positions" because the outputs are stored in an OrderedDict.

These are the outputs that are expected by the task, as passed in the constructor. We store the type of the output and the description of the output.

outputs_form instance-attribute

outputs_form: ExpectedOutputForm | None

The form of the outputs of the agent.

Users can define the expected outputs in four ways:

  • "none": no outputs are expected, the agent should decide what to return.
  • "singleton": a single output is expected.
  • "list": a list of outputs is expected.
  • "dict": a dictionary of outputs is expected.

Internally, we use this parameter to see how we parse outputs when they are given by the agent during a run.

Note that in the case where the task comes from a decorator, this parameter is set to None, since we can have both positional and keyword outputs.

flatten_output_to_string class-attribute instance-attribute

flatten_output_to_string: bool = False

Whether to flatten the output to a string.

This is set to True if the user initializes an agent without decorating a function, and does not specify the outputs parameter in the constructor.

inputs property

The inputs of the task.

outputs property writable

The outputs of the task.

actions_list property

actions_list: list[Action]

The actions as a list.

user_provided_actions property

user_provided_actions: OrderedDict[str, Action]

The actions provided by the user.

task_provided_actions property

task_provided_actions: OrderedDict[str, Action]

The actions provided by the task or the standard library.

UninitializedTaskArguments dataclass

UninitializedTaskArguments(
    actions: (
        Sequence[RawAction] | ActionStarterPack | None
    ) = None,
    config: TaskConfig | None = None,
    model_config: ModelConfig | SimpleDict | None = None,
    agent_cls: type[BaseAgent] | None = None,
)

A data structure to store task decorator arguments.

If a function is decorated with @Task(actions=...), two operations needs to happen:

  1. We create an instance of BaseTask.
  2. Immediately afterwards, that instance is called with the decorated function as the argument.

We need to be able to store the arguments passed to the decorator so that we can use them to initialize the task.

conatus.tasks._types.ExpectedInputForm module-attribute

ExpectedInputForm: TypeAlias = Literal[
    "none", "singleton", "list", "dict"
]

The form of the inputs of the agent.

Can be "none", "singleton", "list", or "dict".

conatus.tasks._types.ExpectedOutputForm module-attribute

ExpectedOutputForm: TypeAlias = ExpectedInputForm

The form of the outputs of the agent.

Can be "none", "singleton", "list", or "dict".