spawn
A function to spawn an agent.
An initial premise for the agent. This will be attached to the system prompt of this agent.
An optional default set of resources which the agent will have access to indefinitely.
Resources in scope may be arbitrary functions, methods, objects, iterators, types or any other 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.
Either
- a
string, or - or an instance of
Template.
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.A callback for streaming any invocations of the agent’s responses.
Each streamed text chunk for each agent invocation, determined by a unique invocation ID, will route to this callback.
A promise that resolves to an
Agent instance.Agent.call
A method to invoke an agent.
The agent’s task (or objective) for this invocation of the agent.
Either
- a
string, or - or an instance of
Template.
If the
system argument is provided when spawning the agent, prompt will be provided as a raw user prompt.Optional. Any additional resources added to the agent’s scope for this invocation.
Optional configuration for this invocation.
Optional. Override the agent’s streaming listener for this specific call.
Returns a promise that resolves to the result of specified or inferred return type
T.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.
Agent.close
A method to manually close an agent and clean up resources.
AsyncDisposable for use with await using syntax: