Skip to content

ctx7-2685: Add Context7 SDK agent examples - #3143

Open
fahreddinozcan wants to merge 4 commits into
masterfrom
ctx7-2685-sdk-agent-examples
Open

ctx7-2685: Add Context7 SDK agent examples#3143
fahreddinozcan wants to merge 4 commits into
masterfrom
ctx7-2685-sdk-agent-examples

Conversation

@fahreddinozcan

@fahreddinozcan fahreddinozcan commented Sep 4, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • add a standalone Vercel AI SDK 6 ToolLoopAgent backed by Context7 tools
  • reuse the same agent in a deployable Next.js app
  • add a filesystem-first Vercel Eve agent with native Context7 tools
  • add one-click Vercel deploy buttons with required Context7 and OpenAI environment variables
  • add a LangChain agent backed by Context7 SDK tools
  • keep each example independently runnable with the published Context7 SDK
  • run repository build and release workflows on Node 24, as required by Eve
  • include example changes in workspace typecheck, lint, formatting, build, and CI checks

Validation

  • 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-mode Eve build generated .vercel/output with the nodejs24.x runtime
  • pnpm typecheck
  • pnpm lint:check
  • pnpm format:check
  • pnpm build
  • git diff --check

@linear-code

linear-code Bot commented Sep 4, 2026

Copy link
Copy Markdown

CTX7-2685

@enesgules enesgules left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this. Three blocking items, then smaller ones inline.

Blocking

  1. The AI SDK example re-implements the tools that @upstash/context7-tools-ai-sdk already publishes (Context7Agent, resolveLibraryId, queryDocs). The example should use the package.
  2. pnpm build is pnpm -r run build, so release and canary now run next build and eve build and install Next/React/LangChain/Eve on every publish. Filter examples out of release builds.
  3. 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.json still 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"),

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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"

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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"

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as release.yml: keep 20.

uses: actions/setup-node@v6
with:
node-version: "20"
node-version: "24"

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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",

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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();

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread examples/eve/.env.example
@@ -0,0 +1,2 @@
CONTEXT7_API_KEY=your-context7-api-key

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This example uses .env, the other two use .env.local. Pick one for all three.

@@ -0,0 +1,25 @@
{

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread examples/README.md
@@ -0,0 +1,33 @@
# Context7 Agent Examples

These examples show how to expose the Context7 SDK as native tools in popular TypeScript agent frameworks.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants