Skip to content

Docs agent loops on grep/search variations within a single turn, exceeding its own 2-round cap#593

Draft
langsmith-engine[bot] wants to merge 1 commit into
masterfrom
issues-agent/03ffef18-2454-4e10-a62d-e35b6c022251
Draft

Docs agent loops on grep/search variations within a single turn, exceeding its own 2-round cap#593
langsmith-engine[bot] wants to merge 1 commit into
masterfrom
issues-agent/03ffef18-2454-4e10-a62d-e35b6c022251

Conversation

@langsmith-engine
Copy link
Copy Markdown

The docs agent repeatedly violates the system prompt's hard cap of 2 search/read rounds per turn by retrying query_docs_filesystem_docs_by_lang_chain with alternate shell-syntax variations (rggrepheadcat) on the same .mdx file when the first command returns no matches, and by firing search_docs_by_lang_chain with synonym/case-only restatements of the same concept after ambiguous results. In one trace (trace 1) the agent fired the exact same search_docs_by_lang_chain({"query":"command"}) + search_support_articles({...}) pair twice within one turn separated only by a single fs-read round; in another (trace 2) it ran 9 tool rounds in one turn cycling through tracingcallbacksconsole loggingstdout callbackConsoleCallbackHandler. Final answers are typically still correct, but each looping turn burns 5–10× the intended token budget and inflates latency well above the p99 of 35s.

Adds a pre-flight checklist to the docs agent prompt and a new
DedupeToolCallsMiddleware that short-circuits any (tool_name, args)
signature already issued since the latest HumanMessage. Together this
enforces the prompt's 2-round cap that was previously advisory only.

- src/prompts/docs_agent_prompt.py: new mandatory pre-flight check
  step covering identical-args repeats, shell-syntax-variation retries
  on the same .mdx file, and synonym/case/plural restatements.
- src/middleware/dedupe_tool_calls_middleware.py: new middleware that
  tracks (tool_name, canonical_json(args)) per turn (keyed on the last
  HumanMessage index) and returns a synthetic ToolMessage on dupes.
- src/agent/docs_graph.py: register dedupe middleware before
  tool_retry_middleware so duplicate signatures are skipped before
  retries run.
- src/middleware/__init__.py: export DedupeToolCallsMiddleware.
- tests/unit/test_dedupe_tool_calls_middleware.py: cover the four
  contract points (dupe short-circuit, different args not deduped,
  arg key ordering, new HumanMessage resets the window).
@vercel
Copy link
Copy Markdown

vercel Bot commented May 20, 2026

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

Project Deployment Actions Updated (UTC)
chat-langchain Ready Ready Preview, Comment May 20, 2026 2:32am

Request Review

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.

0 participants