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.
Returns#
Context7Agent extends the AI SDK ToolLoopAgent 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