diff --git a/.changeset/brave-plums-help.md b/.changeset/brave-plums-help.md new file mode 100644 index 000000000..c2364ad6b --- /dev/null +++ b/.changeset/brave-plums-help.md @@ -0,0 +1,5 @@ +--- +"livekit-agents": patch +--- + +fix: empty agent transcript diff --git a/livekit-agents/livekit/agents/pipeline/pipeline_agent.py b/livekit-agents/livekit/agents/pipeline/pipeline_agent.py index ccd394652..5772a14bb 100644 --- a/livekit-agents/livekit/agents/pipeline/pipeline_agent.py +++ b/livekit-agents/livekit/agents/pipeline/pipeline_agent.py @@ -883,24 +883,25 @@ async def _execute_function_calls() -> None: if interrupted: collected_text += "..." - msg = ChatMessage.create(text=collected_text, role="assistant") - self._chat_ctx.messages.append(msg) + if collected_text: + msg = ChatMessage.create(text=collected_text, role="assistant") + self._chat_ctx.messages.append(msg) - speech_handle.mark_speech_committed() + speech_handle.mark_speech_committed() - if interrupted: - self.emit("agent_speech_interrupted", msg) - else: - self.emit("agent_speech_committed", msg) + if interrupted: + self.emit("agent_speech_interrupted", msg) + else: + self.emit("agent_speech_committed", msg) - logger.debug( - "committed agent speech", - extra={ - "agent_transcript": collected_text, - "interrupted": interrupted, - "speech_id": speech_handle.id, - }, - ) + logger.debug( + "committed agent speech", + extra={ + "agent_transcript": collected_text, + "interrupted": interrupted, + "speech_id": speech_handle.id, + }, + ) # mark the speech as done speech_handle._set_done()