- 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
The language model to use.
The tools that the agent can use.
System instructions for the agent. This is the system prompt that will be used for all calls.
Optional ID for the agent.
The tool choice strategy. Default:
'auto'.Maximum number of tokens to generate.
Temperature setting.
Nucleus sampling.
Only sample from the top K options for each subsequent token.
Presence penalty setting.
Frequency penalty setting.
Stop sequences.
The seed (integer) to use for random sampling.
Condition for stopping the agent when there are tool results in the last step.
Optional specification for parsing structured outputs from the LLM response.
Limits the tools that are available for the model to call.
Optional function that you can use to provide different settings for a step.
Optional function that is called before each agent invocation to prepare the call arguments.
A function that attempts to repair a tool call that failed to parse.
Custom download function to use for URLs.
Context that is passed into tool execution.
Optional telemetry configuration (experimental).
Additional provider-specific options.
Callback invoked when generation begins, before any LLM calls.
Callback invoked when each step begins, before the provider is called.
Callback invoked before each tool execution begins.
Callback invoked after each tool execution completes.
Callback that is called when each step (LLM call) is finished.
Callback that is called when all steps are finished.
Properties
The ID of the agent.
The tools that the agent can use.
The version of the agent API.
Methods
generate()
Generates an output from the agent (non-streaming).Parameters
The prompt for the agent.
Alternative to
prompt: provide a list of messages directly.Call-specific options (if configured in
prepareCall).An optional abort signal that can be used to cancel the call.
An optional timeout in milliseconds.
Callback invoked when generation begins. Merges with the agent’s callback.
Callback invoked when each step begins. Merges with the agent’s callback.
Callback invoked before each tool execution. Merges with the agent’s callback.
Callback invoked after each tool execution. Merges with the agent’s callback.
Callback when each step finishes. Merges with the agent’s callback.
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:
Optional stream transformations.
Returns
Returns aPromise<StreamTextResult> with the same properties as streamText.