fix: capture text from intermediate tool_use iterations#989
Open
letzdoo-js wants to merge 1 commit intoRightNow-AI:mainfrom
Open
fix: capture text from intermediate tool_use iterations#989letzdoo-js wants to merge 1 commit intoRightNow-AI:mainfrom
letzdoo-js wants to merge 1 commit intoRightNow-AI:mainfrom
Conversation
When an LLM produces text alongside tool_use blocks (e.g., a chat message followed by memory_store calls), the text was lost if the final EndTurn iteration returned empty text. The empty-response guard would activate and return "[Task completed — the agent executed tools but did not produce a text summary.]" even though the agent DID produce text in an earlier iteration. This is a common pattern when agents are instructed to respond to users AND persist state via memory_store in the same turn. Fix: accumulate text content from all ToolUse iterations. When the final EndTurn has empty text, use accumulated text as fallback before triggering the empty-response guard. Applied to both sync and streaming agent loop paths.
lc-soft
pushed a commit
to lc-soft/openfang
that referenced
this pull request
Apr 8, 2026
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.
Summary
Fix lost text responses when LLM produces text alongside tool_use blocks in the agent loop.
When an agent responds to a user AND calls tools (e.g., memory_store) in the same turn, the text is produced in an intermediate ToolUse iteration. If the final EndTurn iteration returns empty text, the empty-response guard activates and replaces the actual response with "[Task completed — the agent executed tools but did not produce a text summary.]"
This is a common pattern with Claude when agents are instructed to chat with users and persist state in the same conversation turn.
Changes
accumulated_textbuffer inagent_loop.rsthat captures text content from ToolUse iterationsaccumulated_textas fallback before triggering the guardTesting
cargo clippy --workspace --all-targets -- -D warningspassescargo test --workspacepassescorrectly.
Security