Skip to content

fix(voice): include conversation items added during tool execution in reply context#6084

Open
ShayneP wants to merge 1 commit into
mainfrom
ShayneP/agent-task-chat-ctx-refresh
Open

fix(voice): include conversation items added during tool execution in reply context#6084
ShayneP wants to merge 1 commit into
mainfrom
ShayneP/agent-task-chat-ctx-refresh

Conversation

@ShayneP

@ShayneP ShayneP commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

When a function tool awaits an inline AgentTask, the sub-conversation it runs is merged into the agent's chat_ctx at handoff-return. But the reply generated after tool execution uses a chat_ctx snapshot taken before the tool ran, so it's blind to everything said inside the task β€” in practice the agent re-asks for fields the task already collected.

This refreshes the snapshot with any chat items added during tool execution before generating the tool reply, mirroring the existing update_instructions() refresh just below it.

Found while benchmarking the hotel receptionist example, where the card-collection AgentTask would complete and the agent would immediately ask for the card number again.

@ShayneP ShayneP requested a review from a team as a code owner June 12, 2026 20:26
devin-ai-integration[bot]

This comment was marked as resolved.

# Conversational analog of the update_instructions() refresh below.
known_ids = {item.id for item in chat_ctx.items}
known_ids.update(item.id for item in tool_messages)
chat_ctx.items.extend(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe

merged_chat_ctx = old_agent.chat_ctx.merge(
self.chat_ctx,
exclude_function_call=not self._preserve_function_call_history,
exclude_instructions=True,
)
# set the chat_ctx directly, `session._update_activity` will sync it to the rt_session if needed
old_agent._chat_ctx.items[:] = merged_chat_ctx.items
isn't working properly?

… reply context

When a function tool awaits an inline AgentTask, the sub-conversation it
runs is merged into the agent's chat_ctx at handoff-return. The reply
generated after tool execution used a chat_ctx snapshot taken before the
tool ran, so it was blind to everything said inside the task and would
re-ask for fields the task had already collected.

Merge the agent's chat_ctx back into the snapshot (after adding the tool
messages, so merge() dedups them) before generating the tool reply,
mirroring the existing update_instructions() refresh.
@ShayneP ShayneP force-pushed the ShayneP/agent-task-chat-ctx-refresh branch from 8746591 to 04ac3be Compare June 12, 2026 20:43

@theomonnom theomonnom left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm! discussed in a meeting

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Devin Review found 1 new potential issue.

Open in Devin Review

# Conversational analog of the update_instructions() refresh below.
# tool_messages must be added first so merge() dedups them by id.
chat_ctx.items.extend(tool_messages)
chat_ctx.merge(self._agent._chat_ctx, exclude_instructions=True)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚩 exclude_instructions=True excludes all system/developer messages, not just the instruction message

The merge call at line 3056 passes exclude_instructions=True, which in chat_context.py:583-588 skips ALL items where item.type == 'message' and item.role in ['system', 'developer']. This means if the sub-conversation (run inside an inline AgentTask) produced any system or developer messages beyond instructions β€” e.g., system-level context injected by the sub-agent β€” those would be excluded from the merge into the tool-response generation context. This appears intentional since the update_instructions call at lines 3061-3065 handles instruction refresh separately, but it's worth noting that non-instruction system messages from sub-conversations will be silently dropped.

Open in Devin Review

Was this helpful? React with πŸ‘ or πŸ‘Ž to provide feedback.

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.

2 participants