Skip to content
Open
Show file tree
Hide file tree
Changes from 34 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
e6332a8
feat: context7 vercel ai sdk tools package
fahreddinozcan Nov 30, 2025
6156060
ci: remove master target condition on test action
fahreddinozcan Nov 30, 2025
ff65e5d
ci: manual actions trigger for test
fahreddinozcan Nov 30, 2025
dd01697
ci: always run all tests
fahreddinozcan Nov 30, 2025
1bf82d9
update tests and imports
fahreddinozcan Nov 30, 2025
b6b5d3c
ci: typecheck command
fahreddinozcan Nov 30, 2025
28efd60
fix: tests
fahreddinozcan Nov 30, 2025
c30d8aa
Merge branch 'master' of https://github.com/upstash/context7 into CTX…
fahreddinozcan Dec 2, 2025
677c173
docs: add readme
fahreddinozcan Dec 2, 2025
908d522
update folder structure and tool descriptions
fahreddinozcan Dec 3, 2025
d99cba0
docs: context7-ai-sdk
fahreddinozcan Dec 3, 2025
47b719f
tests: fix test env vars
fahreddinozcan Dec 3, 2025
12b7eaf
ci: bump pnpm version
fahreddinozcan Dec 4, 2025
62c0e15
update ai sdk step count api
fahreddinozcan Dec 4, 2025
5fcfa21
Add stopWhen to docstring examples
fahreddinozcan Dec 4, 2025
f4229a6
update tests
fahreddinozcan Dec 4, 2025
19bd3a5
update prompt name
fahreddinozcan Dec 4, 2025
f56da4d
update context7 agent name
fahreddinozcan Dec 4, 2025
7b7c94e
update tool description var to description
fahreddinozcan Dec 4, 2025
8d0d394
make context7agent config optional
fahreddinozcan Dec 4, 2025
410098e
ci: add changeset
fahreddinozcan Dec 4, 2025
6ebfdce
make context7-sdk peer deps
fahreddinozcan Dec 4, 2025
6f77788
update pnpm-lock.yaml
fahreddinozcan Dec 4, 2025
600f7e7
update package name to @upstash/context7-tools-ai-sdk
fahreddinozcan Dec 4, 2025
7657e9b
remove check workflow
fahreddinozcan Dec 4, 2025
6b92769
Merge branch 'CTX7-879' of https://github.com/upstash/context7 into C…
fahreddinozcan Dec 4, 2025
a7aa3ab
update pnpm lock
fahreddinozcan Dec 4, 2025
935c0c2
make the agent a class instead of function
fahreddinozcan Dec 4, 2025
6b690e7
replace all name instances
fahreddinozcan Dec 4, 2025
50273ba
add agent generate test
fahreddinozcan Dec 4, 2025
72606a8
Merge branch 'CTX7-879' of https://github.com/upstash/context7 into C…
fahreddinozcan Dec 4, 2025
e904a85
update docs with latest changes and updated veai sdk examples
fahreddinozcan Dec 4, 2025
62bba8b
finalize docs
fahreddinozcan Dec 4, 2025
3f6db0c
docs: remove duplicate H1 headers from AI SDK documentation pages
enesgules Dec 4, 2025
e5c88fb
simplify agent config
fahreddinozcan Dec 4, 2025
a3ced6d
fix refs
fahreddinozcan Dec 4, 2025
5f14fde
Merge branch 'CTX7-879' of https://github.com/upstash/context7 into C…
fahreddinozcan Dec 4, 2025
4efa8dc
Merge branch 'CTX7-879-docs' of https://github.com/upstash/context7 i…
fahreddinozcan Dec 4, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .changeset/slimy-dancers-wait.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
"@upstash/context7-tools-ai-sdk": minor
---

Initial release of `@upstash/context7-tools-ai-sdk` - Vercel AI SDK integration for Context7.

### Features

- **Tools**: `resolveLibrary()` and `getLibraryDocs()` tools compatible with AI SDK's `generateText` and `streamText`
- **Agent**: Pre-configured `Context7Agent` that handles the multi-step documentation retrieval workflow automatically

2 changes: 1 addition & 1 deletion .github/workflows/canary-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
- name: Setup pnpm
uses: pnpm/action-setup@v4
with:
version: 9
version: 10

- name: Configure npm authentication
run: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
- name: Setup pnpm
uses: pnpm/action-setup@v4
with:
version: 9
version: 10

- name: Configure npm authentication
run: |
Expand Down
40 changes: 24 additions & 16 deletions .github/workflows/check.yaml → .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,32 +1,30 @@
name: Build Check
name: Test

on:
push:
branches: [master]
pull_request:
push:
branches: [master]
workflow_dispatch:

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
build:
name: Build
test:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v6
- uses: actions/checkout@v4

- name: Setup Node.js
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: "20"

- name: Setup pnpm
uses: pnpm/action-setup@v4
with:
version: 9
version: 10

- name: Get pnpm store directory
id: pnpm-cache
Expand All @@ -42,14 +40,24 @@ jobs:
restore-keys: |
${{ runner.os }}-pnpm-store-

- name: Install dependencies
- name: Install Dependencies
run: pnpm install --frozen-lockfile

- name: Run linter
run: pnpm run lint:check
- name: Lint
run: pnpm lint:check

- name: Format
run: pnpm format:check

- name: Build
run: pnpm build

- name: Check formatting
run: pnpm run format:check
- name: Typecheck
run: pnpm typecheck

- name: Build project
run: pnpm run build
- name: Test
run: pnpm test
env:
AWS_REGION: ${{ secrets.AWS_REGION }}
AWS_BEARER_TOKEN_BEDROCK: ${{ secrets.AWS_BEARER_TOKEN_BEDROCK }}
CONTEXT7_API_KEY: ${{ secrets.CONTEXT7_API_KEY }}
206 changes: 206 additions & 0 deletions docs/agentic-tools/ai-sdk/agents/context7-agent.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,206 @@
---
title: "Context7Agent"
sidebarTitle: "Context7Agent"
description: "Pre-built AI agent for documentation lookup workflows"
---

The `Context7Agent` class is a pre-configured AI agent that handles the complete documentation lookup workflow automatically. It combines both `resolveLibrary` and `getLibraryDocs` tools with an optimized system prompt.

## Usage

```typescript
import { Context7Agent } from "@upstash/context7-tools-ai-sdk";
import { anthropic } from "@ai-sdk/anthropic";

const agent = new Context7Agent({
model: anthropic("claude-sonnet-4-20250514"),
});

const { text } = await agent.generate({
prompt: "How do I use React Server Components?",
});

console.log(text);
```

## Configuration

```typescript
new Context7Agent(config?: Context7AgentConfig)
```

### Parameters

<ParamField path="config" type="Context7AgentConfig" optional>
Configuration options for the agent.

<Expandable title="properties">
<ParamField path="model" type="LanguageModel" optional>
Language model to use. Must be a LanguageModel instance from an AI SDK provider.

Examples:
- `anthropic('claude-sonnet-4-20250514')`
- `openai('gpt-4o')`
- `google('gemini-1.5-pro')`
</ParamField>
<ParamField path="apiKey" type="string" optional>
Context7 API key. If not provided, uses the `CONTEXT7_API_KEY` environment variable.
</ParamField>
<ParamField path="defaultMaxResults" type="number" optional default="10">
Default maximum number of documentation results per request.
</ParamField>
<ParamField path="system" type="string" optional>
Custom system prompt. Overrides the default `AGENT_PROMPT`.
</ParamField>
<ParamField path="stopWhen" type="StopCondition" optional default="stepCountIs(5)">
Condition for when the agent should stop. Defaults to stopping after 5 steps.
</ParamField>

</Expandable>
</ParamField>

### Returns

`Context7Agent` extends the AI SDK `Agent` class and provides `generate()` and `stream()` methods.

## Agent Workflow

The agent follows a structured multi-step workflow:

```mermaid
flowchart TD
A[User Query] --> B[Extract Library Name]
B --> C[Call resolveLibrary]
C --> D{Results Found?}
D -->|Yes| E[Select Best Match]
D -->|No| F[Report No Results]
E --> G[Call getLibraryDocs]
G --> H{Sufficient Context?}
H -->|Yes| I[Generate Response]
H -->|No| J[Fetch More Pages]
J --> H
I --> K[Return Answer with Examples]
```

### Step-by-Step

1. **Extract library name** - Identifies the library/framework from the user's query
2. **Resolve library** - Calls `resolveLibrary` to find the Context7 library ID
3. **Select best match** - Analyzes results based on reputation, coverage, and relevance
4. **Fetch documentation** - Calls `getLibraryDocs` with the selected library ID and relevant topic
5. **Paginate if needed** - Fetches additional pages if initial context is insufficient
6. **Generate response** - Provides an answer with code examples from the documentation

## Examples

### Basic Usage

```typescript
import { Context7Agent } from "@upstash/context7-tools-ai-sdk";
import { anthropic } from "@ai-sdk/anthropic";

const agent = new Context7Agent({
model: anthropic("claude-sonnet-4-20250514"),
});

const { text } = await agent.generate({
prompt: "How do I set up authentication in Next.js?",
});

console.log(text);
```

### With OpenAI

```typescript
import { Context7Agent } from "@upstash/context7-tools-ai-sdk";
import { openai } from "@ai-sdk/openai";

const agent = new Context7Agent({
model: openai("gpt-4o"),
});

const { text } = await agent.generate({
prompt: "Explain Tanstack Query's useQuery hook",
});
```

### Streaming Responses

```typescript
import { Context7Agent } from "@upstash/context7-tools-ai-sdk";
import { anthropic } from "@ai-sdk/anthropic";

const agent = new Context7Agent({
model: anthropic("claude-sonnet-4-20250514"),
});

const { textStream } = await agent.stream({
prompt: "How do I create a Supabase Edge Function?",
});

for await (const chunk of textStream) {
process.stdout.write(chunk);
}
```

### Custom Configuration

```typescript
import { Context7Agent } from "@upstash/context7-tools-ai-sdk";
import { anthropic } from "@ai-sdk/anthropic";
import { stepCountIs } from "ai";

const agent = new Context7Agent({
model: anthropic("claude-sonnet-4-20250514"),
apiKey: process.env.CONTEXT7_API_KEY,
defaultMaxResults: 5,
stopWhen: stepCountIs(8), // Allow more steps for complex queries
});
```

### Custom System Prompt

```typescript
import { Context7Agent, AGENT_PROMPT } from "@upstash/context7-tools-ai-sdk";
import { openai } from "@ai-sdk/openai";

const agent = new Context7Agent({
model: openai("gpt-4o"),
system: `${AGENT_PROMPT}

Additional instructions:
- Always include TypeScript examples
- Mention version compatibility when relevant
- Suggest related documentation topics`,
});
```

## 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

- [resolveLibrary](/agentic-tools/ai-sdk/tools/resolve-library) - The library search tool used by the agent
- [getLibraryDocs](/agentic-tools/ai-sdk/tools/get-library-docs) - The documentation fetch tool used by the agent
- [Getting Started](/agentic-tools/ai-sdk/getting-started) - Overview of the AI SDK integration
Loading