spawn
A function to spawn an agent.
An optional premise for the agent. This will be attached to the system prompt of all invocations of this agent.
An optional default set of resources which the agent will have access to indefinitely.
Resources in scope may be arbitrary Python functions, methods, objects, iterators, types or any other Python value.
These resources may additionally be specified per invocation later on.
An optional system prompt for the agent. This will be the system prompt of all invocations of this agent.
The string of a path to a
.json file representing an MCP configuration. Any servers and/or tools of servers outlined in the config can be used during the agent’s run.MCP Configuration Fields
MCP Configuration Fields
The executable command to run the MCP server. This should be an absolute path or a command available in the system
PATH.Example:An array of command-line arguments passed to the server executable. Arguments are passed in order.Example:
An object containing environment variables to set when launching the server. All values must be strings.Example:
The model which backs your agent.One of:
'openai:gpt-3.5-turbo''openai:gpt-4o''openai:gpt-4.1''openai:gpt-5''anthropic:claude-sonnet-4''anthropic:claude-opus-4.1''anthropic:claude-sonnet-4.5''anthropic:claude-opus-4.5'
The default model is
openai:gpt-4.1.Either
- the maximum number of output tokens generated in a single round of inference in a single invocation, or
- an instance of
MaxTokensfor more fine-grained control.
MaxTokens for information on default values.Optional listener constructor for logging the agentic function’s activity and chat history.
The default agent listener is the
StandardListener, but can be changed for all agents and agentic functions in the current scope with set_default_agent_listener.
If a context-specific logger is used in the current scope, the logger will be added to the listener: if the listener is None, then the listener will be set to:- the default agent listener, if it is not
None, or - the
StandardListener, if the default agent listener isNone
StandardListener and the listener heirarchy, see here.The agent that was spawned.
Agent.__init__
A method to directly instantiate an agent.
Agent.__init__ arguments.
Agent.call
A method to invoke an agent.
Provide a return type for the agent to have it return an instance of a specific type
T.- Providing a return type is optional; *if you do not provide a
return_type, thereturn_typewill default tostr. - You may specify a return type of
Noneif you do not care about the result, only the side effects.
The agent’s task (or objective) for this invocation of the agent.
If the
system argument is provided when spawning the agent, task will be provided as a raw user prompt.The string of a path to a
.json file representing an MCP configuration. Any servers and/or tools of servers outlined in the config can be used during the agent’s run.MCP Configuration Fields
MCP Configuration Fields
The executable command to run the MCP server. This should be an absolute path or a command available in the system
PATH.Example:An array of command-line arguments passed to the server executable. Arguments are passed in order.Example:
An object containing environment variables to set when launching the server. All values must be strings.Example:
Any additional resources added to the agent’s scope for this invocation.
The result the agent returns must be awaited.
Agent.total_usage
A method to obtain the token usage of an agent for accross all invocations.
The token usage accross all invocations of the agent.
Agent.last_usage
A method to obtain the token usage of an agent for the last invocation.
The token usage of the last invocation of the agent.