Skip to content

Commit 38d3049

Browse files
committed
fix(voice): keep session tool results in the next agent's context
During a handoff, a session-scoped async tool inserts its result into the next agent before that agent starts. Agent.update_chat_ctx then filters by the agent's own tools, which drops the session tool's call and output, and the reply is generated without them. Skip that filter for session-scoped executors, whose tools are valid for every agent in the session.
1 parent 7064666 commit 38d3049

2 files changed

Lines changed: 5 additions & 1 deletion

File tree

‎livekit-agents/livekit/agents/voice/tool_executor.py‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -529,7 +529,10 @@ async def _enqueue_reply(self, ctx: RunContext, items: list[ChatItem]) -> None:
529529
)
530530
chat_ctx = target.chat_ctx.copy()
531531
chat_ctx.insert(items)
532-
await target.update_chat_ctx(chat_ctx)
532+
# session tools are valid for any agent, but one not yet started filters by its own tools
533+
await target.update_chat_ctx(
534+
chat_ctx, exclude_invalid_function_calls=self._owning_activity is not None
535+
)
533536
ctx.session.history.insert(items)
534537

535538
if not any(item.type == "function_call_output" and item.reply_required for item in items):

‎tests/test_deferred_tool_reply.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,7 @@ async def test_session_scoped_reply_follows_handoff(caplog: pytest.LogCaptureFix
203203
speakers, current = await _run(first, "handoff", caplog, session_tools=[toolset])
204204
assert isinstance(current, _Second)
205205
assert speakers == ["_First", "_Second"]
206+
assert "link sent" in _outputs(current)
206207

207208

208209
async def test_session_scoped_reply_is_dropped_on_close() -> None:

0 commit comments

Comments
 (0)