AI & Agent Dev Bug Sandbox logo
AI & Agent Dev Bug Sandbox
Back to Radar

CodeActAgent Drops Assistant Tool-Call Metadata During Handoff, Leaving An Orphan Tool Response

When CodeActAgent hands off to another agent, it rebuilds the assistant message using only text content, discarding ToolCallBlock entries and additional_kwargs tool_calls. The receiving agent sees a tool result with a tool_call_id but no matching assistant tool call, causing providers that validate tool-call/result pairs to reject the conversation.

highConfidence 95%Llama_indexVectorStoreIndexRetrievalDocument ProcessingAffected V0.14.25

Origin Analysis

In CodeActAgent.take_step(), after obtaining the LLM response, the assistant message is reconstructed from the response's text content alone (e.g., ChatMessage.from_str(chat_response.message.content)), which drops all non-text blocks and metadata. The original response already contains the tool call information in message.blocks and/or message.additional_kwargs['tool_calls'], but it is lost before being stored in the scratchpad and shared memory.
Install llama-index-core 0.14.25 from source commit 6dd2f3cdd9ce7ff927ea8d46ccee08875bb00f95. Create an AgentWorkflow with a CodeActAgent that can hand off to a FunctionAgent. Configure the CodeActAgent's MockFunctionCallingLLM to return an assistant ChatMessage containing only a ToolCallBlock for the handoff tool. Configure the FunctionAgent's MockFunctionCallingLLM to validate that each tool message has a preceding assistant tool call with the same tool_call_id. Run the workflow. The validation fails with 'Provider rejects orphan tool response: handoff-1'. Inspect the shared memory: the assistant message has only an empty text block and no tool_call block.

Fixing Code Block

Edge Case Audit

The patch is minimal and should not affect normal code execution, but it changes the stored assistant message to include tool call blocks that were previously discarded. If downstream code expects the assistant message to contain only simple text content or manually reconstructs tool calls, it may inadvertently duplicate or mishandle the blocks. Ensure that any consumer of the scratchpad or memory gracefully handles both block-based and additional_kwargs-based tool calls. Rollback is straightforward: revert the one-line change. No database migrations or external dependencies are involved.

Ecosystem Topology

Agent Frameworks

LangChain, LlamaIndex, and Pydantic

  1. highProperty graph relation keys collide when entity IDs or labels contain underscores
  2. highCodeActAgent drops assistant tool-call metadata during handoff, leaving an orphan tool response
  3. high[Bug]: HierarchicalNodeParser async methods return the documents unsplit
  4. highLLM.predict_and_call fails with ValidationError for non-function-calling models when react_chat_formatter is omitted
  5. highAnthropic streaming server-tool input_json_delta overwrites completed client tool_use arguments due to stale cur_tool_call state