fix(agents): date an inline task's tool call with its result - #6981
Conversation
The call that awaited an AgentTask was created before the task's whole sub-conversation, so once that conversation is merged into the parent the call sorts ahead of it and the result follows the call. The parent model then reads result -> dialogue and, with the dialogue ending on a bare confirmation, starts the capture over. Dating the call at completion puts dialogue -> call -> result in front of the parent's reply.
|
can you share the full chat context before and after the fix?
by default the function tool inside the AgentTask won't be merged back to the parent agent, so something like |
You're right, Here is the actual main this branch The problem is the same without the inner calls: on main, the |
What
After a tool awaits an
AgentTaskand the task completes, the parent's next LLM turn sometimes calls the same tool again instead of using the result. A second task starts, the caller hangs up, and the tool fails withAgentTask ... is cancelled. Seen in the data-capture-sim CI job (examples/data_capture_sim) on main since at least Aug 20, in the phone and date-of-birth scenarios.Cause
The parent's
FunctionCallitem is created before the task's sub-conversation exists. When that conversation is merged into the parent'schat_ctx(sorted bycreated_at), the call sorts ahead of it, andgroup_tool_callsplaces its output beside the call. The parent model reads:and treats the capture as still in progress.
Fix
Date the call at task completion. The call then sorts after the sub-conversation it produced, next to its output:
Parallel tool calls sharing a
group_idare grouped at the first call's position, so this is a no-op for them.Measured
Real
DataCaptureAgenton gpt-4.1-mini, 5-turn phone scenario, text modality: 3/10 re-calls before, 0/20 after. Unit suite: 2133 passed.agents-js has the same
merge+insert-by-createdAtshape inagents/src/voice/agent.tsand needs the same change.