Overview
BuiltInAgent is a ready-to-use agent implementation that integrates with OpenAI, Anthropic, and Google models through the Vercel AI SDK. It handles message formatting, tool execution, state management, and streaming responses with minimal configuration.
Constructor
Configuration
The language model to use. Can be a string identifier or a LanguageModel instance.Supported models:
- OpenAI:
"openai/gpt-5","openai/gpt-4o","openai/gpt-4o-mini","openai/o3-mini" - Anthropic:
"anthropic/claude-sonnet-4.5","anthropic/claude-opus-4","anthropic/claude-3.5-haiku" - Google:
"google/gemini-2.5-pro","google/gemini-2.5-flash"
API key for the model provider. If not provided, falls back to environment variables:
OPENAI_API_KEYfor OpenAI modelsANTHROPIC_API_KEYfor Anthropic modelsGOOGLE_API_KEYfor Google models
System prompt for the agent. Defines the agent’s behavior and personality.
Maximum number of tool-calling iterations. Controls how many times the agent can call tools in a single run.
How tools are selected for execution:
"auto": Model decides when to use tools"required": Model must use a tool"none": Model cannot use tools{ type: "tool", toolName: "..." }: Force specific tool
Maximum number of tokens to generate.
Sampling temperature (range depends on provider). Higher values make output more random.
Nucleus sampling parameter. Alternative to temperature.
Top-K sampling parameter.
Penalty for token presence. Reduces repetition.
Penalty for token frequency. Reduces repetition.
Sequences that will stop generation.
Seed for deterministic results (where supported by the provider).
Maximum number of retries for failed requests.
Provider-specific options passed to the model.
List of properties that can be overridden by
forwardedProps from the client.MCP (Model Context Protocol) server configurations.
Server-side tools available to the agent. These tools execute on the server.
Whether to forward system-role messages from input to the LLM.
Whether to forward developer-role messages from input to the LLM (as system messages).
Methods
run()
Execute the agent with given input. Inherited fromAbstractAgent.
abortRun()
Abort the currently running agent execution.clone()
Create a copy of the agent with the same configuration.canOverride()
Check if a property can be overridden by forwardedProps.Usage Examples
Basic Agent
With Tools
With Multiple Steps
With Custom Temperature
With Overridable Properties
With MCP Servers
Multi-Model Configuration
With Reasoning Models
Custom LanguageModel
State Management
BuiltInAgent automatically handles application state updates through special tools:State Snapshot
Replace the entire application state:State Delta
Apply incremental updates using JSON Patch operations:Runtime Integration
Use with CopilotRuntime:Model Resolution
TheresolveModel() helper function converts string identifiers to LanguageModel instances:
Error Handling
BuiltInAgent emits error events through the Observable:Performance Considerations
- maxSteps: Higher values allow more tool interactions but increase latency
- temperature: Lower values (0.1-0.3) are faster and more deterministic
- maxOutputTokens: Limit token generation for faster responses
- Streaming: Events are streamed as generated (real-time feedback)
See Also
- defineTool - Tool definition helper
- AbstractAgent - Agent interface
- CopilotRuntime - Runtime configuration
