From 0cec32e1efac7ba58bcecf9f2a83829f4ca7530b Mon Sep 17 00:00:00 2001 From: barry <91018388+barry166@users.noreply.github.com> Date: Fri, 3 Jul 2026 21:35:52 +0800 Subject: [PATCH] Clarify source selection for duplicate docs entries Context7 can expose both repository and docs-site sources for the same project, but the AI SDK tool description did not tell agents how to handle that common shape. Add a narrow prompt hint so agents pick the source that fits the user's question and retry the sibling source before declaring documentation missing. Constraint: Issue #2069 notes multi-source libraries are currently offered separately Rejected: Implement source unification | broader product work than the issue-comment workaround Confidence: medium Scope-risk: narrow Directive: Keep this as selection guidance unless Context7 gains first-class multi-source library records Tested: pnpm --filter @upstash/context7-sdk build Tested: pnpm --filter @upstash/context7-tools-ai-sdk typecheck Tested: pnpm --filter @upstash/context7-tools-ai-sdk build Tested: pnpm --filter @upstash/context7-tools-ai-sdk exec vitest run src/index.test.ts -t 'should export RESOLVE_LIBRARY_ID_DESCRIPTION' Tested: pnpm --filter @upstash/context7-tools-ai-sdk exec prettier --check src/prompts/system.ts src/index.test.ts Tested: git diff --check Not-tested: Full tools-ai-sdk test suite requires AWS_REGION/AWS_BEARER_TOKEN_BEDROCK for Bedrock-backed tests Related: https://github.com/upstash/context7/issues/2069 --- packages/tools-ai-sdk/src/index.test.ts | 1 + packages/tools-ai-sdk/src/prompts/system.ts | 2 ++ 2 files changed, 3 insertions(+) diff --git a/packages/tools-ai-sdk/src/index.test.ts b/packages/tools-ai-sdk/src/index.test.ts index 6302f54f3..dc916a2b7 100644 --- a/packages/tools-ai-sdk/src/index.test.ts +++ b/packages/tools-ai-sdk/src/index.test.ts @@ -223,6 +223,7 @@ describe("@upstash/context7-tools-ai-sdk", () => { expect(RESOLVE_LIBRARY_ID_DESCRIPTION).toBeDefined(); expect(typeof RESOLVE_LIBRARY_ID_DESCRIPTION).toBe("string"); expect(RESOLVE_LIBRARY_ID_DESCRIPTION).toContain("library"); + expect(RESOLVE_LIBRARY_ID_DESCRIPTION).toContain("docs site"); }); }); }); diff --git a/packages/tools-ai-sdk/src/prompts/system.ts b/packages/tools-ai-sdk/src/prompts/system.ts index bd0458c54..e9e245a1e 100644 --- a/packages/tools-ai-sdk/src/prompts/system.ts +++ b/packages/tools-ai-sdk/src/prompts/system.ts @@ -61,6 +61,8 @@ Selection Process: - Documentation coverage (prioritize libraries with higher Code Snippet counts) - Source reputation (consider libraries with High or Medium reputation more authoritative) - Benchmark Score: Quality indicator (100 is the highest score) +- Source type fit: some projects have separate repo and docs site entries; choose the source that best matches the user's question +- If one source lacks the needed API reference, examples, or guide content, try the other available source before concluding the docs are missing Response Format: - Return the selected library ID in a clearly marked section