Skip to content
Merged
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
9 changes: 9 additions & 0 deletions livekit-agents/livekit/agents/voice/agent_activity.py
Original file line number Diff line number Diff line change
Expand Up @@ -2272,6 +2272,15 @@ def _tool_execution_completed_cb(out: ToolExecutionOutput) -> None:
if fnc_executed_ev._reply_required:
chat_ctx.items.extend(tool_messages)

# refresh instructions in chat_ctx so that any update_instructions()
# calls made inside tool functions are reflected in the tool response
# generation (fixes #4242)
update_instructions(
chat_ctx,
instructions=self._agent._instructions,
add_if_missing=False,
)
Comment on lines +2278 to +2282
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.

🟡 Missing try/except ValueError around update_instructions unlike all other call sites

The new update_instructions() call is not wrapped in a try/except ValueError, unlike every other call site in the same file (agent_activity.py:600-606 and agent_activity.py:1960-1964). The update_instructions function in generation.py:820-823 explicitly raises ValueError if the existing instructions item is not of type "message". If this exception fires, it will propagate uncaught and crash the _pipeline_reply_task_impl coroutine, potentially leaving the agent in a broken state (e.g., stuck in "thinking" without transitioning back to "listening").

Suggested change
update_instructions(
chat_ctx,
instructions=self._agent._instructions,
add_if_missing=False,
)
try:
update_instructions(
chat_ctx,
instructions=self._agent._instructions,
add_if_missing=False,
)
except ValueError:
logger.exception("failed to update the instructions")
Open in Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.


tool_response_task = self._create_speech_task(
self._pipeline_reply_task(
speech_handle=speech_handle,
Expand Down
Loading