Skip to content

fix(agentspan): MCP/API agents lose every tool result — set _agent_tool_name in enrichToolsScriptDynamic - #1533

Closed
ling-senpeng13 wants to merge 2 commits into
conductor-oss:mainfrom
ling-senpeng13:fix/1532-mcp-tool-results-lost-in-join
Closed

fix(agentspan): MCP/API agents lose every tool result — set _agent_tool_name in enrichToolsScriptDynamic#1533
ling-senpeng13 wants to merge 2 commits into
conductor-oss:mainfrom
ling-senpeng13:fix/1532-mcp-tool-results-lost-in-join

Conversation

@ling-senpeng13

@ling-senpeng13 ling-senpeng13 commented Aug 13, 2026

Copy link
Copy Markdown
Contributor

Fixes #1532.

Any agent whose toolset includes an MCP or API tool never receives its own tool results. Every LLM turn is dispatched with the identical bare [system, user] message list, so the model reissues the same call until the ReAct loop hits its iteration cap.

The fix

One line in enrichToolsScriptDynamic, which enrichToolsScript already had:

t.inputParameters._agent_tool_name = n;

Why it fixes it

Join.compactAgentOutput decides whether a fork branch is an agent tool call by reading that marker from the branch's input:

Object agentToolName = forkedTask.getInputData().get("_agent_tool_name");
if (agentToolName != null) {
    compact.put("_agent_tool_name", agentToolName);
    compact.put("_agent_tool_output", output);   // the full payload rides along here
    return compact;
}
// otherwise: only AGENT_PROPAGATED_KEYS = {"_state_updates", "state"}

and the caller only records non-empty results:

if (!compact.isEmpty()) task.addOutput(joinOnRef, compact);

Setting the marker makes compact non-empty and attaches _agent_tool_output, so the whole chain refills.

Verification

Reproduced and fixed with the python-sdk examples 04_mcp_weather.py and 04_http_and_mcp_tools.py

Join.compactAgentOutput identifies an agent tool call by reading
_agent_tool_name from the forked task's input. enrichToolsScript sets it;
enrichToolsScriptDynamic — selected whenever an agent has MCP or API tools —
never did, so branch outputs were dropped from the JOIN, the state merge saw
toolResults=[], and every LLM turn was dispatched with no record of the call.
The model reissued the same call until the loop hit its iteration cap.

The line goes after the type-specific branch chain because each branch replaces
inputParameters wholesale, so it applies to MCP, HTTP, media, rag and plain
worker tools alike.

Fixes conductor-oss#1532
@ling-senpeng13
ling-senpeng13 force-pushed the fix/1532-mcp-tool-results-lost-in-join branch from ffe3470 to d0035e7 Compare August 13, 2026 01:16
@ling-senpeng13 ling-senpeng13 self-assigned this Aug 13, 2026
@ling-senpeng13
ling-senpeng13 marked this pull request as ready for review August 13, 2026 16:19
@ling-senpeng13
ling-senpeng13 marked this pull request as draft August 13, 2026 19:34
@ling-senpeng13

Copy link
Copy Markdown
Contributor Author

#1532 is not reproducible now

@ling-senpeng13
ling-senpeng13 deleted the fix/1532-mcp-tool-results-lost-in-join branch August 13, 2026 19:59
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.

bug(agentspan): agents with MCP tools loop to the iteration cap — tool results never reach the LLM

1 participant