ctx7-2685: Add Context7 SDK agent examples - #3143
Conversation
enesgules
left a comment
There was a problem hiding this comment.
Thanks for this. Three blocking items, then smaller ones inline.
Blocking
- The AI SDK example re-implements the tools that
@upstash/context7-tools-ai-sdkalready publishes (Context7Agent,resolveLibraryId,queryDocs). The example should use the package. pnpm buildispnpm -r run build, so release and canary now runnext buildandeve buildand install Next/React/LangChain/Eve on every publish. Filter examples out of release builds.- The Node 24 bump on release/canary is only needed by Eve. Published packages declare
node >=20.18.1; CI should keep building them on 20.
Also
- Root
package.jsonstill has"workspaces": ["packages/*"]. pnpm ignores it, but it is now wrong. Update or remove.
Verified OK: SDK call signatures, deploy button URLs and env keys, npm (not workspace) dependency on the SDK so the clone installs standalone.
| }); | ||
|
|
||
| export const agent = new ToolLoopAgent({ | ||
| model: openai("gpt-5-mini"), |
There was a problem hiding this comment.
This file duplicates packages/tools-ai-sdk. Replace with:
import { openai } from "@ai-sdk/openai";
import { Context7Agent } from "@upstash/context7-tools-ai-sdk";
export const agent = new Context7Agent({ model: openai("gpt-5-mini") });An example that bypasses the official package signals that the package is not the recommended path.
| uses: actions/setup-node@v6 | ||
| with: | ||
| node-version: "20" | ||
| node-version: "24" |
There was a problem hiding this comment.
Keep 20 here. Published packages declare engines.node >=20.18.1; release CI should build on the minimum supported version. Node 24 is only required by the Eve example, which should not be part of the release build (see comment on examples/ai-sdk/package.json).
| uses: actions/setup-node@v6 | ||
| with: | ||
| node-version: "20" | ||
| node-version: "24" |
There was a problem hiding this comment.
Same as release.yml: keep 20.
| uses: actions/setup-node@v6 | ||
| with: | ||
| node-version: "20" | ||
| node-version: "24" |
There was a problem hiding this comment.
Bumping the single test job to 24 means packages are no longer tested on 20. Use a matrix ([20, 24]) or run the Eve typecheck in a separate job on 24.
| "type": "module", | ||
| "scripts": { | ||
| "agent": "tsx agent.ts", | ||
| "build": "next build", |
There was a problem hiding this comment.
With examples/* in the workspace, root pnpm build (pnpm -r run build) now runs next build and eve build on every release and canary, and pnpm install --frozen-lockfile pulls Next, React, LangChain, and Eve (+1700 lockfile lines) into the publish pipeline. Either change the release workflows to pnpm --filter "./packages/*" build, or drop build scripts from the examples and keep only typecheck/lint.
| import { never } from "eve/tools/approval"; | ||
| import { z } from "zod"; | ||
|
|
||
| const context7 = () => new Context7(); |
There was a problem hiding this comment.
A new client per tool call is unnecessary. const context7 = new Context7(); at module level is enough (same in resolve_library.ts), as the LangChain example already does.
| @@ -0,0 +1,2 @@ | |||
| CONTEXT7_API_KEY=your-context7-api-key | |||
There was a problem hiding this comment.
Use ctx7sk-... like the other two examples. The SDK warns when the key does not start with ctx7sk.
| From the repository root: | ||
|
|
||
| ```bash | ||
| cp examples/langchain/.env.example examples/langchain/.env |
There was a problem hiding this comment.
This example uses .env, the other two use .env.local. Pick one for all three.
| @@ -0,0 +1,25 @@ | |||
| { | |||
There was a problem hiding this comment.
No .gitignore here or in examples/ai-sdk. examples/eve has one. The Vercel deploy button clones the folder into a fresh repo with no root .gitignore, so .env.local and .next can end up committed. Add the same .gitignore to both.
| @@ -0,0 +1,33 @@ | |||
| # Context7 Agent Examples | |||
|
|
|||
| These examples show how to expose the Context7 SDK as native tools in popular TypeScript agent frameworks. | |||
There was a problem hiding this comment.
Worth one line noting that the Eve example is on ai@7 / @ai-sdk/openai@4 (Eve peer requirement) while the AI SDK example is on ai@6 / @ai-sdk/openai@3, so readers do not assume a mistake.
Summary
ToolLoopAgentbacked by Context7 toolsValidation
pnpm --dir examples/ai-sdk agent -- "How do I revalidate a Next.js page on demand?"pnpm --dir examples/eve invoke "How do I revalidate a Next.js page on demand?"pnpm --dir examples/eve build.vercel/outputwith thenodejs24.xruntimepnpm typecheckpnpm lint:checkpnpm format:checkpnpm buildgit diff --check