fix(agents): swap edge order in singleRunStrategy for nodeSendToolResult#2175
Open
rainbow7 wants to merge 1 commit into
Open
fix(agents): swap edge order in singleRunStrategy for nodeSendToolResult#2175rainbow7 wants to merge 1 commit into
rainbow7 wants to merge 1 commit into
Conversation
The edge order for nodeSendToolResult was: onTextMessage (first) → nodeFinish onToolCalls (second) → nodeExecuteTool When an LLM returns both Text and ToolCall simultaneously (common with DeepSeek and other models), the onTextMessage edge matched first, causing the agent to return the intermediate text as the final answer instead of executing the tool calls. This fix swaps the order so onToolCalls is evaluated first, matching the same pattern already used for nodeCallLLM edges above. Added test: test_SingleRunStrategy_SecondRoundMixedResponse_ExecutesAllTools
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.
Problem
When an LLM returns both Text and ToolCall simultaneously in the same response (common behavior with DeepSeek, and some other models), the
singleRunStrategyfails to execute the tool calls after receiving tool results. Instead, it treats the intermediate text as the final answer.Root Cause
The edge order for
nodeSendToolResultwas:edge(nodeSendToolResult forwardTo nodeFinish onTextMessage { true }) // first — matches Text edge(nodeSendToolResult forwardTo nodeExecuteTool onToolCalls { true }) // second — never reachedSince
resolveEdgeevaluates edges in definition order (FIFO) and returns the first match,onTextMessagealways wins when both Text and ToolCall are present.Notably, the edges for
nodeCallLLM(lines 35-36) already have the correct order withonToolCallsfirst. This inconsistency suggests thenodeSendToolResultorder was unintentional.Fix
Swap the two edges so
onToolCallsis evaluated first (matching thenodeCallLLMpattern):edge(nodeSendToolResult forwardTo nodeExecuteTool onToolCalls { true }) // first — execute tools edge(nodeSendToolResult forwardTo nodeFinish onTextMessage { true }) // second — finish on pure textTest
Added
test_SingleRunStrategy_SecondRoundMixedResponse_ExecutesAllToolswhich reproduces the bug:This test fails without the fix and passes with it.