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,