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
6 changes: 5 additions & 1 deletion livekit-agents/livekit/agents/voice/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -700,6 +700,7 @@ def __init__(
llm: NotGivenOr[llm.LLM | llm.RealtimeModel | None] = NOT_GIVEN,
tts: NotGivenOr[tts.TTS | None] = NOT_GIVEN,
mcp_servers: NotGivenOr[list[mcp.MCPServer] | None] = NOT_GIVEN,
preserve_function_call_history: bool = False,
# deprecated
turn_detection: NotGivenOr[TurnDetectionMode | None] = NOT_GIVEN,
allow_interruptions: NotGivenOr[bool] = NOT_GIVEN,
Expand Down Expand Up @@ -733,6 +734,7 @@ def __init__(
self.__fut = asyncio.Future[TaskResult_T]()
self.__inactive_ev = asyncio.Event()
self.__inactive_ev.set() # set when the agent is not awaited or activity is closed
self._preserve_function_call_history = preserve_function_call_history

self._old_agent: Agent | None = None

Expand Down Expand Up @@ -892,7 +894,9 @@ def _handle_task_done(_: asyncio.Task[Any]) -> None:
run_state._watch_handle(speech_handle)

merged_chat_ctx = old_agent.chat_ctx.merge(
self.chat_ctx, exclude_function_call=True, exclude_instructions=True
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
Expand Down
Loading