spawn function creates a new agent instance.
spawn
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 system prompt for the agent. This is for providing completely custom behaviour.
The model which backs your agent.One of:
openai:gpt-3.5-turboopenai:gpt-4oopenai:gpt-4.1openai:gpt-5anthropic:claude-sonnet-4anthropic:claude-opus-4.1anthropic:claude-sonnet-4.5
openai:gpt-4.1.The maximum number of tokens that the agent can generate during one round of inference.Defaults to
2048.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
The Agent class represents a stateful agent that maintains conversation history.Methods
call
Invoke the agent with a task.
The agent’s task (or objective) for this invocation of the agent.
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.close
Manually close the agent and clean up resources.
AsyncDisposable for use with await using syntax: