Overview
TheContext7Agent is a pre-configured Vercel AI SDK agent that automatically handles the multi-step workflow for documentation lookup.
It extends ToolLoopAgent and comes pre-configured with:
resolveLibraryIdandqueryDocstools- Optimized system prompt for documentation retrieval
- Sensible defaults for step count and workflow
Class Signature
Configuration
Inherited Settings from ToolLoopAgentSettings
model- The AI model to use (required)instructions- Custom system prompt (optional, defaults to optimized prompt)stopWhen- Condition to stop agent execution (optional, defaults tostepCountIs(5))tools- Additional tools to include alongside Context7 tools (optional)maxSteps- Maximum number of steps (deprecated, usestopWheninstead)onStepFinish- Callback after each step
Basic Usage
Simple Query
With Custom API Key
Advanced Configuration
Custom Stop Condition
Custom Instructions
Adding Custom Tools
Agent Workflow
The agent follows this multi-step workflow:Streaming Responses
Text Streaming
Full Stream with Tool Calls
Default System Prompt
The agent uses this optimized prompt by default:Step Tracking
Step Callbacks
Error Handling
Complete Example
Comparison with Direct Tool Usage
Using Tools Directly
Using Context7Agent
- You want optimized documentation retrieval out-of-the-box
- You need consistent behavior across multiple queries
- You want to extend with additional tools while keeping Context7 workflow
- You need full control over the system prompt
- You’re integrating into an existing agent architecture
- You want to customize the tool selection logic
Type Exports
Best Practices
- Set reasonable step limits: Use
stopWhen: stepCountIs(5)to prevent excessive API calls - Use streaming for better UX: Stream responses to show progress to users
- Add custom tools carefully: Don’t overwhelm the agent with too many tools
- Monitor steps: Use
onStepFinishto track agent behavior and debug issues - Handle errors gracefully: Wrap
generate()calls in try-catch blocks - Reuse agent instances: Create one agent and use it for multiple queries
Next Steps
Tools Reference
Learn more about resolveLibraryId and queryDocs tools