- A finish reason other than tool-calls is returned, or
- A tool that is invoked does not have an execute function, or
- A tool call needs approval, or
- A stop condition is met (default stop condition is
stepCountIs(20))
Constructor
Parameters
LanguageModel
required
The language model to use.
ToolSet
The tools that the agent can use.
string
System instructions for the agent. This is the system prompt that will be used for all calls.
string
Optional ID for the agent.
ToolChoice
The tool choice strategy. Default:
'auto'.number
Maximum number of tokens to generate.
number
Temperature setting.
number
Nucleus sampling.
number
Only sample from the top K options for each subsequent token.
number
Presence penalty setting.
number
Frequency penalty setting.
Array<string>
Stop sequences.
number
The seed (integer) to use for random sampling.
StopCondition | Array<StopCondition>
default:"stepCountIs(20)"
Condition for stopping the agent when there are tool results in the last step.
Output
Optional specification for parsing structured outputs from the LLM response.
Array<keyof TOOLS>
Limits the tools that are available for the model to call.
PrepareStepFunction
Optional function that you can use to provide different settings for a step.
PrepareCallFunction
Optional function that is called before each agent invocation to prepare the call arguments.
ToolCallRepairFunction
A function that attempts to repair a tool call that failed to parse.
DownloadFunction
Custom download function to use for URLs.
unknown
Context that is passed into tool execution.
TelemetrySettings
Optional telemetry configuration (experimental).
ProviderOptions
Additional provider-specific options.
(event: OnStartEvent) => void
Callback invoked when generation begins, before any LLM calls.
(event: OnStepStartEvent) => void
Callback invoked when each step begins, before the provider is called.
(event: OnToolCallStartEvent) => void
Callback invoked before each tool execution begins.
(event: OnToolCallFinishEvent) => void
Callback invoked after each tool execution completes.
(event: OnStepFinishEvent) => void
Callback that is called when each step (LLM call) is finished.
(event: OnFinishEvent) => void
Callback that is called when all steps are finished.
Properties
string | undefined
The ID of the agent.
TOOLS
The tools that the agent can use.
'agent-v1'
The version of the agent API.
Methods
generate()
Generates an output from the agent (non-streaming).Parameters
string | Array<ModelMessage>
The prompt for the agent.
Array<ModelMessage>
Alternative to
prompt: provide a list of messages directly.CALL_OPTIONS
Call-specific options (if configured in
prepareCall).AbortSignal
An optional abort signal that can be used to cancel the call.
number
An optional timeout in milliseconds.
(event: OnStartEvent) => void
Callback invoked when generation begins. Merges with the agent’s callback.
(event: OnStepStartEvent) => void
Callback invoked when each step begins. Merges with the agent’s callback.
(event: OnToolCallStartEvent) => void
Callback invoked before each tool execution. Merges with the agent’s callback.
(event: OnToolCallFinishEvent) => void
Callback invoked after each tool execution. Merges with the agent’s callback.
(event: OnStepFinishEvent) => void
Callback when each step finishes. Merges with the agent’s callback.
(event: OnFinishEvent) => void
Callback when all steps finish. Merges with the agent’s callback.
Returns
Returns aPromise<GenerateTextResult> with the same properties as generateText.
stream()
Streams an output from the agent.Parameters
Same parameters asgenerate(), plus:
StreamTextTransform | Array<StreamTextTransform>
Optional stream transformations.
Returns
Returns aPromise<StreamTextResult> with the same properties as streamText.