From c7881f3776faa2dc4cea0bda4fd832173c00ac17 Mon Sep 17 00:00:00 2001 From: Juan Mugica Gonzalez <47819159+jmugicagonz@users.noreply.github.com> Date: Mon, 23 Dec 2024 09:21:17 +0100 Subject: [PATCH] fix context when functions have been called (#1279) Co-authored-by: David Zhao --- .changeset/witty-fishes-stare.md | 5 +++++ livekit-agents/livekit/agents/pipeline/pipeline_agent.py | 5 +++++ 2 files changed, 10 insertions(+) create mode 100644 .changeset/witty-fishes-stare.md diff --git a/.changeset/witty-fishes-stare.md b/.changeset/witty-fishes-stare.md new file mode 100644 index 000000000..4f82113d7 --- /dev/null +++ b/.changeset/witty-fishes-stare.md @@ -0,0 +1,5 @@ +--- +"livekit-agents": patch +--- + +fix context when functions have been called diff --git a/livekit-agents/livekit/agents/pipeline/pipeline_agent.py b/livekit-agents/livekit/agents/pipeline/pipeline_agent.py index 3b9f8e83b..7b5c28e79 100644 --- a/livekit-agents/livekit/agents/pipeline/pipeline_agent.py +++ b/livekit-agents/livekit/agents/pipeline/pipeline_agent.py @@ -702,6 +702,11 @@ async def _synthesize_answer_task( not playing_speech.user_question or playing_speech.user_committed ) and not playing_speech.speech_committed: # the speech is playing but not committed yet, add it to the chat context for this new reply synthesis + # First add the previous function call message if any + if playing_speech.extra_tools_messages: + copied_ctx.messages.extend(playing_speech.extra_tools_messages) + + # Then add the previous assistant message copied_ctx.messages.append( ChatMessage.create( text=playing_speech.synthesis_handle.tts_forwarder.played_text,