Skip to main content
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

Context7AgentConfig
Configuration options for the agent.

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

  1. Extract library name - Identifies the library/framework from the user’s query
  2. Resolve library - Calls resolveLibraryId to find the Context7 library ID
  3. Select best match - Analyzes results based on reputation, coverage, and relevance
  4. Fetch documentation - Calls queryDocs with the selected library ID and user’s query
  5. Query if needed - Makes additional queries if initial context is insufficient
  6. 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

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