Skip to content

feat: update conversation when agent finishes speaking or is interrupted #34

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

RPate97
Copy link
Contributor

@RPate97 RPate97 commented Nov 28, 2024

Purpose

Resolves an issue where we record multiple instances of the user speaking and the agent responding. This would happen because we would always update the db whenever calling the function to generate a response even if the user immediately cuts of the agent such that they never actually hear any part of the agents response.

I resolved this by removing the call to the final processing function from the stream and update chat function (if the function is called in a voice call). Instead the function is called from two event hooks triggered by livekit. I added hooks for two different events: when the agent finishes speaking (agent_speech_committed) and when the agent is interrupted (agent_speech_interrupted).

I found that using these two events together worked reliably to record all messages that make sense to record because the interruption event only fires when the agent is cut off while it is actually speaking. The event also includes a message object with text that only includes what the agent actually said rather than the full message. This event never fires when you pause for a moment (and a response begins to be generated by the backend), but you do not pause long enough for the agent to actually start talking.

Known Issues

There is a known issue where the first message the agent says (Hey, great to meet you, ! How's it going?) is recorded twice for an unknown reason. Possibly both events are triggered from this even if you don't actually interrupt the agent.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant