fix(langchain): make write_todos calls tool-only to stop duplicated plan text#38132
Draft
Mason Daugherty (mdrxy) wants to merge 1 commit into
Draft
fix(langchain): make write_todos calls tool-only to stop duplicated plan text#38132Mason Daugherty (mdrxy) wants to merge 1 commit into
write_todos calls tool-only to stop duplicated plan text#38132Mason Daugherty (mdrxy) wants to merge 1 commit into
Conversation
… plan text Add a boundary rule to the `TodoListMiddleware` default prompt and tool description: when calling `write_todos`, the assistant message must be tool-only. User-facing plan text, status updates, approval questions, and final answers should not appear in the same message as the call — they are sent once, after the tool result returns. This stops streaming consumers from showing the same plan/question twice (before and after the call) while preserving #37643's contract that the final answer lands after the call. Co-authored-by: open-swe[bot] <open-swe@users.noreply.github.com>
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.
When
TodoListMiddlewaredrives an agent, some models (notably Claude Sonnet) emit user-facing plan text — e.g.Plan: ... Does this plan look good?— before/alongside awrite_todostool call, and then emit nearly the same plan/question again after the tool result. Streaming consumers (like dcode) render both, so the user sees the same planning message twice.This is a side effect of the contract added in #37643: that change told the model to land its substantive/user-facing answer after the final
write_todosresult (so the loop-terminatingAIMessageisn't empty), but it never said not to also put that same plan/status/question before or in the same assistant message as the call. This PR closes that gap.The default
WRITE_TODOS_SYSTEM_PROMPTandWRITE_TODOS_TOOL_DESCRIPTIONnow spell out a boundary rule: awrite_todoscall updates todo state only — the assistant message containing the call must be tool-only, with no user-facing plan text, status updates, approval questions, or final answers. That content is sent once, after the tool result returns. The #37643 contract is preserved: substantive/final answers still land after the relevantwrite_todosresult, not before it.Before: model narrates the plan, calls
write_todos, then repeats the plan after the result → duplicate. After: model callswrite_todostool-only, then sends the plan/question/answer once after the result.Unit tests assert both default prompts contain the tool-only boundary language and still preserve the "answer after the call" contract.
Related: #37643
A note for transparency: this contribution was prepared with the help of an AI agent.
Made by Open SWE