BaseAgent
conatus.agents.base
¶
Base abstract agent class.
Ps
module-attribute
¶
Type variable for the task parameters (or inputs).
R
module-attribute
¶
Type variable for the task result.
Ps2
module-attribute
¶
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.
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.
BaseAgent
¶
BaseAgent(
func_or_description: Callable[Ps, R] | None = None,
/,
*,
actions: (
Sequence[RawAction] | ActionStarterPack | None
) = None,
config: TaskConfig | None = None,
model_config: ModelConfig | SimpleDict | None = None,
mock_responses: None = None,
description: None = None,
inputs: None = None,
outputs: None = None,
starting_variables: None = None,
task: None = None,
previous_runs: None = None,
cost: None = None,
)
BaseAgent(
func_or_description: str,
/,
*,
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,
mock_responses: list[AIResponse] | None = None,
description: None = None,
previous_runs: None = None,
task: None = None,
cost: None = None,
)
BaseAgent(
func_or_description: None = None,
/,
*,
description: str,
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,
mock_responses: list[AIResponse] | None = None,
previous_runs: None = None,
task: None = None,
cost: None = None,
)
BaseAgent(
func_or_description: None = None,
/,
*,
task: BaseTask[R, Ps],
mock_responses: list[AIResponse] | None = None,
previous_runs: list[RunData] | None = None,
cost: float | None = None,
actions: None = None,
inputs: None = None,
outputs: None = None,
description: None = None,
starting_variables: None = None,
config: None = None,
model_config: None = None,
)
BaseAgent(
func_or_description: (
str | Callable[Ps, R] | None
) = None,
/,
*,
task: BaseTask[R, Ps] | None = None,
description: str | None = None,
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,
mock_responses: list[AIResponse] | None = None,
previous_runs: list[RunData] | None = None,
cost: float | None = None,
)
Abstract agent class.
| PARAMETER | DESCRIPTION |
|---|---|
func_or_description
|
The function or description of the agent. |
task
|
The task to use for the agent. This argument is required if
|
description
|
The description of the agent. To be used only if
neither
TYPE:
|
actions
|
The actions to use for the agent. To be used only if
TYPE:
|
inputs
|
The inputs to use for the agent. 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 outputs to use for the agent. 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 configuration to use for the agent. To be used only if
TYPE:
|
model_config
|
The model configuration to use for the agent. To be
used only if
TYPE:
|
mock_responses
|
The mock responses to use for the agent.
TYPE:
|
previous_runs
|
The previous runs to use for the agent. To be used
only if
TYPE:
|
cost
|
The cost of the agent. To be used only if
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If the arguments are invalid. |
Source code in conatus/agents/base.py
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 | |
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.
__call__
¶
__call__(*args: args, **kwargs: kwargs) -> R
__call__(
func: Callable[Ps2, R2] | None = None,
*args: args,
**kwargs: kwargs
) -> BaseAgent[R2, Ps2] | R
Run the task.
This is a convenience method to run the task.
| PARAMETER | DESCRIPTION |
|---|---|
func
|
The function to use as the task. |
*args
|
The arguments to pass to the task.
TYPE:
|
**kwargs
|
The keyword arguments to pass to the task.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
BaseAgent[R2, Ps2] | R
|
The result of the task. |
Source code in conatus/agents/base.py
from_function
classmethod
¶
from_function(
*,
actions: (
Sequence[RawAction] | ActionStarterPack | None
) = None,
config: TaskConfig | None = None,
model_config: ModelConfig | SimpleDict | None = None
) -> Callable[[Callable[Ps2, R2]], BaseAgent[R2, Ps2]]
from_function(
fn: Callable[Ps2, R2],
/,
*,
actions: (
Sequence[RawAction] | ActionStarterPack | None
) = None,
config: TaskConfig | None = None,
model_config: ModelConfig | SimpleDict | None = None,
) -> BaseAgent[R2, Ps2]
from_function(
fn: Callable[Ps2, R2] | None = None,
/,
*,
actions: (
Sequence[RawAction] | ActionStarterPack | None
) = None,
config: TaskConfig | None = None,
model_config: ModelConfig | SimpleDict | None = None,
) -> (
BaseAgent[R2, Ps2]
| Callable[[Callable[Ps2, R2]], BaseAgent[R2, Ps2]]
)
Create a Agent from a function.
| PARAMETER | DESCRIPTION |
|---|---|
fn
|
The function to wrap in an agent. |
actions
|
The actions to add to the agent.
TYPE:
|
config
|
The configuration for the agent.
TYPE:
|
model_config
|
The model configuration for the agent.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
BaseAgent[R2, Ps2] | Callable[[Callable[Ps2, R2]], BaseAgent[R2, Ps2]]
|
Source code in conatus/agents/base.py
filter_output_variables
¶
filter_output_variables(
state: RuntimeState,
) -> dict[str, RuntimeVariable]
Filter the output variables.
At the end of a run, the state should contain the output variables. This method allows to return a dictionary with only the output variables.
| PARAMETER | DESCRIPTION |
|---|---|
state
|
The state of the agent.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
dict[str, RuntimeVariable]
|
The filtered output variables. |
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If the state does not contain one of the output variables. |
Source code in conatus/agents/base.py
run
abstractmethod
¶
run(
runtime: Runtime, run_writer: FileWriter | None
) -> CompleteRunData
Run the agent.
| PARAMETER | DESCRIPTION |
|---|---|
runtime
|
The runtime of the agent.
TYPE:
|
run_writer
|
The writer to use for the run. This writer will be used to write down logs related to the run.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
CompleteRunData
|
The data of the run. |
Source code in conatus/agents/base.py
Agent
¶
Agent(
func_or_description: Callable[Ps, R] | None = None,
/,
*,
actions: (
Sequence[RawAction] | ActionStarterPack | None
) = None,
config: TaskConfig | None = None,
model_config: ModelConfig | SimpleDict | None = None,
mock_responses: None = None,
description: None = None,
inputs: None = None,
outputs: None = None,
starting_variables: None = None,
task: None = None,
previous_runs: None = None,
cost: None = None,
)
Agent(
func_or_description: str,
/,
*,
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,
mock_responses: list[AIResponse] | None = None,
description: None = None,
previous_runs: None = None,
task: None = None,
cost: None = None,
)
Agent(
func_or_description: None = None,
/,
*,
description: str,
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,
mock_responses: list[AIResponse] | None = None,
previous_runs: None = None,
task: None = None,
cost: None = None,
)
Agent(
func_or_description: None = None,
/,
*,
task: BaseTask[R, Ps],
mock_responses: list[AIResponse] | None = None,
previous_runs: list[RunData] | None = None,
cost: float | None = None,
actions: None = None,
inputs: None = None,
outputs: None = None,
description: None = None,
starting_variables: None = None,
config: None = None,
model_config: None = None,
)
Agent(
func_or_description: (
str | Callable[Ps, R] | None
) = None,
/,
*,
task: BaseTask[R, Ps] | None = None,
description: str | None = None,
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,
mock_responses: list[AIResponse] | None = None,
previous_runs: list[RunData] | None = None,
cost: float | None = None,
)
Default agent.
Source code in conatus/agents/base.py
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 | |
run
¶
run(
runtime: Runtime, run_writer: FileWriter | None
) -> CompleteRunData
Run the agent.
| PARAMETER | DESCRIPTION |
|---|---|
runtime
|
The runtime of the agent.
TYPE:
|
run_writer
|
The writer to use for the run. This writer will be used to write down logs related to the run.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
CompleteRunData
|
The data of the run. |
Source code in conatus/agents/base.py
CUAgent
¶
CUAgent(
func_or_description: Callable[Ps, R] | None = None,
/,
*,
actions: (
Sequence[RawAction] | ActionStarterPack | None
) = None,
config: TaskConfig | None = None,
model_config: ModelConfig | SimpleDict | None = None,
mock_responses: None = None,
description: None = None,
inputs: None = None,
outputs: None = None,
starting_variables: None = None,
task: None = None,
previous_runs: None = None,
cost: None = None,
)
CUAgent(
func_or_description: str,
/,
*,
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,
mock_responses: list[AIResponse] | None = None,
description: None = None,
previous_runs: None = None,
task: None = None,
cost: None = None,
)
CUAgent(
func_or_description: None = None,
/,
*,
description: str,
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,
mock_responses: list[AIResponse] | None = None,
previous_runs: None = None,
task: None = None,
cost: None = None,
)
CUAgent(
func_or_description: None = None,
/,
*,
task: BaseTask[R, Ps],
mock_responses: list[AIResponse] | None = None,
previous_runs: list[RunData] | None = None,
cost: float | None = None,
actions: None = None,
inputs: None = None,
outputs: None = None,
description: None = None,
starting_variables: None = None,
config: None = None,
model_config: None = None,
)
CUAgent(
func_or_description: (
str | Callable[Ps, R] | None
) = None,
/,
*,
task: BaseTask[R, Ps] | None = None,
description: str | None = None,
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,
mock_responses: list[AIResponse] | None = None,
previous_runs: list[RunData] | None = None,
cost: float | None = None,
)
Computer use agent.
Source code in conatus/agents/base.py
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 | |
run
¶
run(
runtime: Runtime, run_writer: FileWriter | None
) -> CompleteRunData
Run the agent.
| PARAMETER | DESCRIPTION |
|---|---|
runtime
|
The runtime of the agent.
TYPE:
|
run_writer
|
The writer to use for the run. This writer will be used to write down logs related to the run.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
CompleteRunData
|
The data of the run. |
Source code in conatus/agents/base.py
MockAgent
¶
MockAgent(
func_or_description: Callable[Ps, R] | None = None,
/,
*,
actions: (
Sequence[RawAction] | ActionStarterPack | None
) = None,
config: TaskConfig | None = None,
model_config: ModelConfig | SimpleDict | None = None,
mock_responses: None = None,
description: None = None,
inputs: None = None,
outputs: None = None,
starting_variables: None = None,
task: None = None,
previous_runs: None = None,
cost: None = None,
)
MockAgent(
func_or_description: str,
/,
*,
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,
mock_responses: list[AIResponse] | None = None,
description: None = None,
previous_runs: None = None,
task: None = None,
cost: None = None,
)
MockAgent(
func_or_description: None = None,
/,
*,
description: str,
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,
mock_responses: list[AIResponse] | None = None,
previous_runs: None = None,
task: None = None,
cost: None = None,
)
MockAgent(
func_or_description: None = None,
/,
*,
task: BaseTask[R, Ps],
mock_responses: list[AIResponse] | None = None,
previous_runs: list[RunData] | None = None,
cost: float | None = None,
actions: None = None,
inputs: None = None,
outputs: None = None,
description: None = None,
starting_variables: None = None,
config: None = None,
model_config: None = None,
)
MockAgent(
func_or_description: (
str | Callable[Ps, R] | None
) = None,
/,
*,
task: BaseTask[R, Ps] | None = None,
description: str | None = None,
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,
mock_responses: list[AIResponse] | None = None,
previous_runs: list[RunData] | None = None,
cost: float | None = None,
)
Mock agent.
Source code in conatus/agents/base.py
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 | |
run
¶
run(
runtime: Runtime, run_writer: FileWriter | None
) -> CompleteRunData
Run the agent.
| PARAMETER | DESCRIPTION |
|---|---|
runtime
|
The runtime of the agent.
TYPE:
|
run_writer
|
The writer to use for the run. This writer will be used to write down logs related to the run.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
CompleteRunData
|
The data of the run. |
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If the mock responses are not set. |
Source code in conatus/agents/base.py
initialize_ai_interfaces_dictionary
¶
initialize_ai_interfaces_dictionary(
default: dict[str, type[BaseAIInterface]] | None = None,
) -> dict[str, type[BaseAIInterface]]
Get the AI interfaces.
This is a helper function to make the ai_interfaces field of the
BaseAgent class compatible with
the default_factory argument of the field function.
Feel free to use this function in your own classes; that way, you ensure
that the ai_interfaces attribute of your class is always a dictionary,
and that the underlying dictionary is not shared across instances of
the same class.
XXXX Example
| PARAMETER | DESCRIPTION |
|---|---|
default
|
The default AI interfaces.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
dict[str, type[BaseAIInterface]]
|
The AI interfaces. |