Agent( )





Pattern
Call Options: prepareCall
Dynamically configure one ToolLoopAgent per request with callOptionsSchema and prepareCall. A customer-support agent rewrites instructions, gates tools, tunes reasoning effort, and injects RAG context based on account tier and urgency.
IntermediateJun 2026View the full pattern on desktop


Problems solved
- Configure one ToolLoopAgent per request with prepareCall
- Inject per-user RAG context into instructions at runtime
- Gate tools by account tier with activeTools
- Tune reasoning effort from request urgency
Use cases
- Multi-tier customer support agents
- Per-user RAG injection
- Role-based tool access
- Runtime provider option selection
AI SDK APIs
ToolLoopAgentcallOptionsSchemaprepareCallactiveToolsproviderOptionstoolgateway
Tags
aiagentscall-optionsprepare-calldynamic-configragtool-loop-agentai-sdkagent-api
Requirements
- Node.js
- 24+
- Memory
- 512MB
- Other
- OpenAI API key
Environment variables
OPENAI_API_KEYGet key
External services
openai
Ready to use?
View the full interactive pattern with live preview and copy the source code.
View the pattern on desktopRelated patterns


Loop Control: stopWhen
Demonstrate ToolLoopAgent loop control with stopWhen. Covers stepCountIs, hasToolCall, combined conditions, and a custom StopCondition with step timeline visualization.
aiagents+7
View pattern β


PrepareStep: Trim Message History
Demonstrate ToolLoopAgent prepareStep for trimming long message history. Pre-seeded 24-message conversation shows context compression on the first run with per-step trim telemetry.
aiagents+6
View pattern β



