Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions livekit-agents/livekit/agents/voice/agent_activity.py
Original file line number Diff line number Diff line change
Expand Up @@ -3045,7 +3045,15 @@ async def _next_segment() -> _SpeechSegment | None:

tool_messages = new_calls + new_fnc_outputs
if fnc_executed_ev._reply_required:
# refresh conversation items added during tool execution: a tool that
# awaits an inline AgentTask runs a whole sub-conversation, merged into
# the agent's chat_ctx at handoff-return - this turn's snapshot predates
# it. Without the refresh, the tool response is generated blind to what
# was actually said inside the tool call (and re-asks captured fields).
# 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.


# refresh instructions in chat_ctx so that any update_instructions()
# calls made inside tool functions are reflected in the tool response
Expand Down
Loading