The Context7Agent class is a pre-configured AI agent that handles the complete documentation lookup workflow automatically. It combines both resolveLibraryId and queryDocs tools with an optimized system prompt.
Usage#
Configuration#
Parameters#
Configuration options for the agent.
Show propertiesHide properties
Language model to use. Must be a LanguageModel instance from an AI SDK provider.
Examples:
anthropic('claude-sonnet-4-20250514')openai('gpt-5.2')google('gemini-1.5-pro')
Context7 API key. If not provided, uses the CONTEXT7_API_KEY environment variable.
Custom system prompt. Overrides the default AGENT_PROMPT.
Condition for when the agent should stop. Defaults to stopping after 5 steps.
Default: "stepCountIs(5)"
Returns#
Context7Agent extends the AI SDK Agent class and provides generate() and stream() methods.
Agent Workflow#
The agent follows a structured multi-step workflow:
Step-by-Step#
- Extract library name - Identifies the library/framework from the user's query
- Resolve library - Calls
resolveLibraryIdto find the Context7 library ID - Select best match - Analyzes results based on reputation, coverage, and relevance
- Fetch documentation - Calls
queryDocswith the selected library ID and user's query - Query if needed - Makes additional queries if initial context is insufficient
- Generate response - Provides an answer with code examples from the documentation
Examples#
Basic Usage#
With OpenAI#
Streaming Responses#
Custom Configuration#
Custom System Prompt#
Comparison: Agent vs Tools#
| Feature | Context7Agent | Individual Tools |
|---|---|---|
| Setup | Single configuration | Configure each tool |
| Workflow | Automatic multi-step | Manual orchestration |
| System prompt | Optimized default | You provide |
| Customization | Limited | Full control |
| Best for | Quick integration | Custom workflows |
When to Use the Agent#
- Rapid prototyping
- Standard documentation lookup use cases
- When you want sensible defaults
When to Use Individual Tools#
- Custom agentic workflows
- Integration with other tools
- Fine-grained control over the process
- Custom system prompts with specific behavior
Related#
- resolveLibraryId - The library search tool used by the agent
- queryDocs - The documentation fetch tool used by the agent
- Getting Started - Overview of the AI SDK integration