Configuring Call Options
Call options allow you to pass type-safe structured inputs to your agent. Use them to dynamically modify any agent setting based on the specific request.Why Use Call Options?
When you need agent behavior to change based on runtime context:- Add dynamic context - Inject retrieved documents, user preferences, or session data into prompts
- Select models dynamically - Choose faster or more capable models based on request complexity
- Configure tools per request - Pass user location to search tools or adjust tool behavior
- Customize provider options - Set reasoning effort, temperature, or other provider-specific settings
How It Works
Define call options in three steps:- Define the schema - Specify what inputs you accept using
callOptionsSchema - Configure with
prepareCall- Use those inputs to modify agent settings - Pass options at runtime - Provide the options when calling
generate()orstream()
Basic Example
Add user context to your agent’s prompt at runtime:options parameter is now required and type-checked. If you don’t provide it or pass incorrect types, TypeScript will error.
Modifying Agent Settings
UseprepareCall to modify any agent setting. Return only the settings you want to change.
Dynamic Model Selection
Choose models based on request characteristics:Dynamic Tool Configuration
Configure tools based on runtime context:Provider-Specific Options
Configure provider settings dynamically:Advanced Patterns
Retrieval Augmented Generation (RAG)
Fetch relevant context and inject it into your prompt:prepareCall function can be async, enabling you to fetch data before configuring the agent.
Combining Multiple Modifications
Modify multiple settings together:Using with createAgentUIStreamResponse
Pass call options through API routes to your agent:Next Steps
- Learn about loop control for execution management
- Explore workflow patterns for complex multi-step processes