conatus.tasks.base.BaseTask
¶
BaseTask(func_or_description: Callable[Ps, R])
BaseTask(
func_or_description: Callable[Ps, R] | None = None,
/,
*,
actions: (
Sequence[RawAction] | ActionStarterPack | None
) = None,
config: TaskConfig | None = None,
model_config: ModelConfig | SimpleDict | None = None,
agent_cls: type[BaseAgent[R, Ps]] | None = None,
starting_variables: None = None,
mock_responses: None = None,
description: None = None,
name: None = None,
inputs: None = None,
outputs: None = None,
)
BaseTask(
func_or_description: str,
/,
actions: (
Sequence[RawAction] | ActionStarterPack | None
) = None,
*,
name: str,
description: None = None,
inputs: TypeCollection | TypeOfType | None = None,
outputs: TypeCollection | type[R] | None = None,
starting_variables: (
list[ParamType] | dict[str, ParamType] | None
) = None,
config: TaskConfig | None = None,
model_config: ModelConfig | SimpleDict | None = None,
agent_cls: type[BaseAgent[R, Ps]] | None = None,
mock_responses: list[AIResponse] | None = None,
)
BaseTask(
func_or_description: None = None,
/,
actions: (
Sequence[RawAction] | ActionStarterPack | None
) = None,
*,
name: str,
description: str,
inputs: TypeCollection | TypeOfType | None = None,
outputs: (
TypeCollection | TypeOfType | type[R] | None
) = None,
starting_variables: (
list[ParamType] | dict[str, ParamType] | None
) = None,
config: TaskConfig | None = None,
model_config: ModelConfig | SimpleDict | None = None,
agent_cls: type[BaseAgent[R, Ps]] | None = None,
mock_responses: list[AIResponse] | None = None,
)
BaseTask(
func_or_description: (
str | Callable[Ps, R] | None
) = None,
/,
actions: (
Sequence[RawAction] | ActionStarterPack | None
) = None,
*,
description: str | None = None,
name: str | None = None,
inputs: TypeCollection | TypeOfType | None = None,
outputs: (
TypeCollection | TypeOfType | type[R] | None
) = None,
starting_variables: (
list[ParamType] | dict[str, ParamType] | None
) = None,
config: TaskConfig | None = None,
model_config: ModelConfig | SimpleDict | None = None,
agent_cls: type[BaseAgent[R, Ps]] | None = None,
mock_responses: list[AIResponse] | None = None,
)
Base class for Task implementations.
Not meant to be used directly
If you are an end-user, you should use the Task
class instead. This class is
meant for developers who want to create their own task classes.
The BaseTask 'contract'¶
If we use the design-by-contract approach, we can define the contract of
the BaseTask class as follows:
Using generic parameters¶
If you want to benefit from the generic parameters, you just need to
specific a specific type in the outputs parameter.
from conatus import Task
write_generics_poem = Task(
description="Write me a poem about generics",
name="write_generics_poem",
outputs=str
)
# Type-checkers will infer 'result' to be of type 'str'
# result = write_generics_poem()
| PARAMETER | DESCRIPTION |
|---|---|
|
The function to use as the task, or the
description of the task. |
|
The actions that are available to the task.
TYPE:
|
|
The description of the task.
TYPE:
|
|
The name of the task. Even though it is optional in type, it is required in practice and we will throw an error if you don't provide it.
TYPE:
|
|
The inputs to the task. Can be a list of type hints, a
dictionary of type hints, a single type hint,
or None. If you don't provide any inputs, or pass None,
you will not be able to pass any variables to the task,
or the recipe that you will generate from it.
If you want to specify specific variables instead of type
hints, you can use the
TYPE:
|
|
The expected output of the task. It should either be a
dictionary of format {output_name: output_type}, a list of
output types, a single output type, or None. If None,
it will be up to the LLM to determine the expected output.
If you want the task to return
TYPE:
|
|
The variables to start with. Can be a list of
variables, or a dictionary of variables, or None. This
parameter is mutually exclusive with the
TYPE:
|
|
The task configuration, as a dictionary. Many other
values can also be set in the keyword arguments, and will
override the values set in the
TYPE:
|
|
The model configuration, as a dictionary. This will override any model configuration set in the classes that will be used to generate the task.
TYPE:
|
|
The class of the agent to use for the task. |
|
The mock responses to use for the task. Useful for testing.
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
TypeError
|
If the |
ValueError
|
If the |
ValueError
|
If the |
| METHOD | DESCRIPTION |
|---|---|
run |
Run the task. |
additional_actions |
The additional actions to add to the task. |
prepare_state_and_runtime |
Prepare the state and runtime for the task. |
postprocess_run_data |
Postprocess the run data. |
write_recipe |
Write the recipe to the run writer. |
__call__ |
Run the task. |
from_function |
Create a |
| ATTRIBUTE | DESCRIPTION |
|---|---|
definition |
The task definition.
TYPE:
|
accepts_empty_actions_parameter |
Whether the task accepts an empty list of actions.
TYPE:
|
running |
Whether the task is currently running.
TYPE:
|
config |
The task configuration.
TYPE:
|
agent_cls |
The class of the agent to use for the task. |
agent |
The agent to use for the task. |
task_runs |
The runs of the task.
TYPE:
|
actions |
The actions to perform the task. |
inputs |
The inputs of the task.
TYPE:
|
inputs_form |
The form of the inputs of the task.
TYPE:
|
outputs |
The outputs of the task.
TYPE:
|
outputs_form |
The form of the outputs of the task.
TYPE:
|
starting_variables |
The starting variables of the task.
TYPE:
|
description |
The description of the task.
TYPE:
|
Source code in conatus/tasks/base.py
263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 | |
definition
instance-attribute
¶
definition: TaskDefinition
The task definition.
It contains information about the task, such as the user prompt,
the actions that can be used to perform the task, and the expected
inputs and outputs of the task. It should be set by the constructor
of the BaseTask subclass.
TaskDefinition can be
subclassed to add additional information to the task; the downside, of
course, is that lower classes such as BaseAgent
will have to be updated to support the new
information.
accepts_empty_actions_parameter
class-attribute
instance-attribute
¶
accepts_empty_actions_parameter: bool = True
Whether the task accepts an empty list of actions.
Set this to True if you're already providing some pre-defined
actions in the constructor.
running
class-attribute
instance-attribute
¶
running: bool = False
Whether the task is currently running.
config
instance-attribute
¶
config: ConsolidatedTaskConfig = ConsolidatedTaskConfig(
user_provided_config
)
The task configuration.
The user can provide a TaskConfig
dictionary when instantiating a Task.
The config attribute is a
ConsolidatedTaskConfig
instance, which contains the user-provided values, as well as the default
values.
For more information, see ConsolidatedTaskConfig
.
agent_cls
instance-attribute
¶
The class of the agent to use for the task.
agent
instance-attribute
¶
agent: BaseAgent[R, Ps] = agent_cls(
task=self, mock_responses=mock_responses
)
The agent to use for the task.
actions
property
writable
¶
The actions to perform the task.
Note that you cannot modify this attribute while the task is running.
inputs
property
writable
¶
inputs: OrderedDict[str, TypeOfType]
The inputs of the task.
Note that you cannot modify this attribute.
inputs_form
property
writable
¶
inputs_form: ExpectedInputForm | None
The form of the inputs of the task.
Note that you cannot modify this attribute.
outputs
property
writable
¶
outputs: OrderedDict[str, TypeOfType]
The outputs of the task.
Note that you cannot modify this attribute while the task is running.
outputs_form
property
writable
¶
outputs_form: ExpectedOutputForm | None
The form of the outputs of the task.
Note that you cannot modify this attribute.
starting_variables
property
¶
starting_variables: dict[str, RuntimeVariable] | None
The starting variables of the task.
If the inputs are not predefined, this is set to None.
Note that you cannot modify this attribute.
run
¶
Run the task.
Just treat this is a normal function call.
| PARAMETER | DESCRIPTION |
|---|---|
|
The arguments to pass to the task.
TYPE:
|
|
The keyword arguments to pass to the task.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
R
|
The result of the task. |
Source code in conatus/tasks/base.py
additional_actions
¶
additional_actions() -> list[RawAction] | ActionStarterPack
The additional actions to add to the task.
This method can be overridden by the user in the task class.
| RETURNS | DESCRIPTION |
|---|---|
list[RawAction] | ActionStarterPack
|
The additional actions to add to the task. |
Source code in conatus/tasks/base.py
prepare_state_and_runtime
¶
prepare_state_and_runtime(
state: RuntimeState, runtime: Runtime
) -> tuple[RuntimeState, Runtime]
Prepare the state and runtime for the task.
This method can be overridden by the user in the task class.
| PARAMETER | DESCRIPTION |
|---|---|
|
The state of the agent.
TYPE:
|
|
The runtime of the agent.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
tuple[RuntimeState, Runtime]
|
The state and runtime of the agent. |
Source code in conatus/tasks/base.py
postprocess_run_data
¶
postprocess_run_data(
run_data: CompleteRunData,
) -> CompleteRunData
Postprocess the run data.
This method can be overridden by the user in the task class.
| PARAMETER | DESCRIPTION |
|---|---|
|
The run data to postprocess.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
CompleteRunData
|
The postprocessed run data. |
Source code in conatus/tasks/base.py
write_recipe
¶
write_recipe(
run_data: CompleteRunData, run_writer: FileWriter
) -> None
Write the recipe to the run writer.
This method can be overridden by the user in the task class.
| PARAMETER | DESCRIPTION |
|---|---|
|
The run data to write the recipe to.
TYPE:
|
|
The run writer to write the recipe to.
TYPE:
|
Source code in conatus/tasks/base.py
__call__
¶
__call__(
func: Callable[Ps2, R2] | None = None,
*args: args,
**kwargs: kwargs
) -> BaseTask[R2, Ps2] | R
Run the task.
This is a convenience method to run the task.
| PARAMETER | DESCRIPTION |
|---|---|
|
The function to use as the task. |
|
The arguments to pass to the task.
TYPE:
|
|
The keyword arguments to pass to the task.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
BaseTask[R2, Ps2] | R
|
The result of the task. |
Source code in conatus/tasks/base.py
from_function
classmethod
¶
from_function(
*,
actions: (
Sequence[RawAction] | ActionStarterPack | None
) = None,
agent_cls: type[BaseAgent[R2, Ps2]] | None = None,
config: TaskConfig | None = None,
model_config: ModelConfig | SimpleDict | None = None
) -> Callable[[Callable[Ps2, R2]], BaseTask[R2, Ps2]]
from_function(
fn: Callable[Ps2, R2],
/,
*,
actions: (
Sequence[RawAction] | ActionStarterPack | None
) = None,
agent_cls: type[BaseAgent[R2, Ps2]] | None = None,
config: TaskConfig | None = None,
model_config: ModelConfig | SimpleDict | None = None,
) -> BaseTask[R2, Ps2]
from_function(
fn: Callable[Ps2, R2] | None = None,
/,
*,
actions: (
Sequence[RawAction] | ActionStarterPack | None
) = None,
agent_cls: type[BaseAgent[R2, Ps2]] | None = None,
config: TaskConfig | None = None,
model_config: ModelConfig | SimpleDict | None = None,
) -> (
BaseTask[R2, Ps2]
| Callable[[Callable[Ps2, R2]], BaseTask[R2, Ps2]]
)
Create a Task from a function.
| PARAMETER | DESCRIPTION |
|---|---|
|
The function to wrap in a task. |
|
The actions to add to the task.
TYPE:
|
|
The class of the agent to use for the task. |
|
The configuration for the task.
TYPE:
|
|
The model configuration for the task.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
BaseTask[R2, Ps2] | Callable[[Callable[Ps2, R2]], BaseTask[R2, Ps2]]
|
Source code in conatus/tasks/base.py
Utilities¶
conatus.tasks.base.Ps
module-attribute
¶
Ps = ParamSpec('Ps')
Type variable for the task parameters (or inputs).
conatus.tasks.base.R
module-attribute
¶
R = TypeVar('R', bound=ParamType)
Type variable for the task result.
conatus.tasks.base.Ps2
module-attribute
¶
Ps2 = ParamSpec('Ps2')
Type variable for the task parameters (or inputs).
This type variable is used when the user creates a task with from_function
, while Ps
is used when the user creates a task with the
constructor.
conatus.tasks.base.R2
module-attribute
¶
R2 = TypeVar('R2', bound=ParamType)
Type variable for the task result.
This type variable is used when the user creates a task with from_function
, while R
is used when the user creates a task with the constructor.
conatus.tasks.base.RawAction
module-attribute
¶
RawAction: TypeAlias = (
"Action | ActionBlueprint | ActionStarterPack | FunctionType"
)
A raw action that can be converted to an action.
Can be either:
- An instance of
Action - An instance of
ActionBlueprint - An instance of
ActionStarterPack - A function, as defined by the
FunctionTypetype.
conatus.tasks.base.StrictlyTypedBaseTask
¶
StrictlyTypedBaseTask(
description: str,
name: str = "my_task",
actions: (
Sequence[RawAction] | ActionStarterPack | None
) = None,
*,
inputs: TypeCollection | TypeOfType | None = None,
outputs: TypeCollection | type[R] | None = None,
starting_variables: (
list[ParamType] | dict[str, ParamType] | None
) = None,
config: TaskConfig | None = None,
model_config: ModelConfig | SimpleDict | None = None,
agent_cls: type[BaseAgent[R, Ps]] | None = None,
mock_responses: list[AIResponse] | None = None
)
A task that is strictly typed.
This is a convenience class to make type-checkers happy, but it is
equivalent in functionality to the non-generic BaseTask
.
The difference between this class and the BaseTask
class is purely for type-checking
purposes: it expects the actions to be instances or class instances
of the Action class. It will
not raise an error if that happens, though.
| PARAMETER | DESCRIPTION |
|---|---|
description
|
The description of the task.
TYPE:
|
name
|
The name of the task.
TYPE:
|
actions
|
The actions to perform.
TYPE:
|
inputs
|
The inputs to the task. Can be a list of type hints, a
dictionary of type hints, a single type hint,
or None. If you don't provide any inputs, or pass None,
you will not be able to pass any variables to the task,
or the recipe that you will generate from it.
If you want to specify specific variables instead of type
hints, you can use the
TYPE:
|
outputs
|
The expected output of the task. It should either be a
dictionary of format {output_name: output_type}, a list of
output types, a single output type, or None. If None,
it will be up to the LLM to determine the expected output.
If you want the task to return
TYPE:
|
starting_variables
|
The variables to start with. Can be a list of
variables, or a dictionary of variables, or None. This
parameter is mutually exclusive with the
TYPE:
|
config
|
The task configuration, as a dictionary. Many other
values can also be set in the keyword arguments, and will
override the values set in the
TYPE:
|
model_config
|
The model configuration, as a dictionary. This will override any model configuration set in the classes that will be used to generate the task.
TYPE:
|
agent_cls
|
The class of the agent to use for the task. |
mock_responses
|
The mock responses to use for the task. Useful for testing.
TYPE:
|