Simplify system instructions and align prompt + tools with AI SDK docs#187
Merged
Conversation
Trim the agent system prompt and bring the prompt and tool definitions in line with the AI SDK v6 documented best practices (node_modules/ai/docs). System instructions (system-instructions.ts): - Shrink DEFAULT_OPERATING_INSTRUCTION from 141 lines (~10.6 KB) to ~25 lines (~77% smaller), folding 10 overlapping sections into 4: trust_and_safety, how_to_work, voice (+ a one-line intro). - Remove guidance that is redundant with always-appended runtime blocks (the citation augmentation in agent-route, and the RUNTIME DATE CONTEXT block) and with the identity/tone soul block, plus generic boilerplate strong models already follow. - Drop "repository/patch work" guidance: this product's only tools are tavily_search/tavily_extract, not file/repo tools. - Preserve all five test-pinned safety contracts verbatim, plus prompt-injection defense, PII protection, refusals, high-stakes handling, and no-fabrication. The soul/identity block is unchanged. Tool definitions (ai-sdk-tavily-tools.ts): - Add .describe() to every tavily_search/tavily_extract schema property, per the AI SDK "Prompts for Tools" guidance, to improve tool-calling accuracy. Validation rules are unchanged. System prompt also gains concise, search-specific tool-usage guidance per the "Tool Usage Instructions" best practice. Agent workflow (agent-runtime.ts) reviewed against the loop-control docs and already follows documented patterns (streamText + stopWhen/stepCountIs + prepareStep + telemetry + manual synthesis fallback); left unchanged. Verified: pnpm lint, pnpm format:check, pnpm typecheck, and pnpm test (157/157) all pass, including "preserves prompt safety contracts". Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Two related improvements to the agent prompt layer, grounded in the AI SDK v6 bundled docs (
node_modules/ai/docs/):DEFAULT_OPERATING_INSTRUCTIONhad grown to 141 lines (~10.6 KB) of dense, overlapping guidance.Why
The operating instruction repeated itself across ~10 XML sections and duplicated guidance that is already injected elsewhere at runtime, while the Tavily tool schemas lacked the property descriptions the docs recommend for reliable tool calling.
Changes
system-instructions.ts— simplificationtrust_and_safety,how_to_work,voice(+ a one-line intro).withAiSdkInlineCitationInstructioninagent-route.ts) and date handling (the always-presentRUNTIME DATE CONTEXTblock), plus content already in the identity/tone soul block and generic boilerplate strong models follow.tavily_search/tavily_extract, not file/repo tools.Best-practice alignment (per docs)
ai-sdk-tavily-tools.ts: added.describe()to all 11tavily_search/tavily_extractschema properties — [prompt-engineering "Prompts for Tools"]. Validation rules unchanged; purely additive metadata to improve tool-calling accuracy.system-instructions.ts: added concise, search-specific tool-usage guidance — [building-agents "Tool Usage Instructions"].Agent workflow — reviewed, no change
agent-runtime.tswas checked against the [loop-control] docs and already follows documented patterns:streamText+stopWhen: stepCountIs(12)+prepareStep(forced final synthesis + mid-budget nudge) +experimental_telemetry+ a manual no-text synthesis fallback. The docs explicitly bless the manualstreamTextloop for this kind of custom streaming, so no rewrite was warranted.Not included (flagged for follow-up)
temperature: 0for tool calls (docs recommend it; trades prose warmth for determinism in a chat product)..optional()→.nullable()on tool params (only matters for strict-schema providers like OpenAI; Qwen/Kimi via the Gateway work today).Verification
pnpm lint(--max-warnings=0) ✅ ·pnpm format:check✅ ·pnpm typecheck✅ ·pnpm test→ 157/157 ✅ (incl. "default operating instruction preserves prompt safety contracts").🤖 Generated with Claude Code