Skip to content

Simplify system instructions and align prompt + tools with AI SDK docs#187

Merged
chloeilabs merged 1 commit into
mainfrom
chore/simplify-system-prompt
Jun 16, 2026
Merged

Simplify system instructions and align prompt + tools with AI SDK docs#187
chloeilabs merged 1 commit into
mainfrom
chore/simplify-system-prompt

Conversation

@chloeilabs

Copy link
Copy Markdown
Owner

What

Two related improvements to the agent prompt layer, grounded in the AI SDK v6 bundled docs (node_modules/ai/docs/):

  1. Simplify the system instructions — the DEFAULT_OPERATING_INSTRUCTION had grown to 141 lines (~10.6 KB) of dense, overlapping guidance.
  2. Align the prompt and tools with documented best practices.

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 — simplification

  • 141 → ~25 lines (~77% smaller), folding 10 overlapping sections into 4: trust_and_safety, how_to_work, voice (+ a one-line intro).
  • Removed guidance redundant with always-appended runtime blocks: inline-citation rules (added unconditionally by withAiSdkInlineCitationInstruction in agent-route.ts) and date handling (the always-present RUNTIME DATE CONTEXT block), plus content already in the identity/tone soul block and generic boilerplate strong models follow.
  • Dropped "repository/patch work" guidance — this product's only tools are tavily_search / tavily_extract, not file/repo tools.
  • Preserved verbatim: all 5 test-pinned safety contracts, prompt-injection defense, PII protection, refusals, high-stakes handling, no-fabrication. The soul/identity block is unchanged.

Best-practice alignment (per docs)

  • ai-sdk-tavily-tools.ts: added .describe() to all 11 tavily_search / tavily_extract schema 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.ts was 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 manual streamText loop for this kind of custom streaming, so no rewrite was warranted.

Not included (flagged for follow-up)

  • temperature: 0 for 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 test157/157 ✅ (incl. "default operating instruction preserves prompt safety contracts").

🤖 Generated with Claude Code

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>
@vercel

vercel Bot commented Jun 16, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
chloei Ready Ready Preview, Comment Jun 16, 2026 4:35am

@chloeilabs chloeilabs merged commit 6c8df7a into main Jun 16, 2026
6 checks passed
@chloeilabs chloeilabs deleted the chore/simplify-system-prompt branch June 16, 2026 04:38
@chloeilabs chloeilabs mentioned this pull request Jun 16, 2026
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.

1 participant