-
Notifications
You must be signed in to change notification settings - Fork 614
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
"Conversation already has an active response" error with MultimodalAgent #1056
Comments
I've been getting this error quite a bit recently. I feel like it happens more when I give a pretty long-winded response to the LLM. |
Hey Guys! just got the same error I have implemented a function to switch the prompt. In my use case the prompt is so long that I'm trying to split it into several files. So at some point of the first prompt I call the action to switch to the following one, and then I do the same thing in the second prompt. Here's the snippet:
when I asked chatgpt it says: "The main issue seems to be that an attempt was made to switch prompts/agents while there was an active response in progress. OpenAI does not allow starting a new response while a conversation is still ongoing." |
I'm getting this error, too. It seems to be happening right after a functional call tells the agent what to do next. Here is the function I have:
In the meantime, how would I recover from this error? The agent just stops talking. How do I detect the issue and get the agent going again? |
Hi Nate, same thing here. Once the error happens, if you speak again, does the LLM start talking again? |
Related thread on OpenAI forum: |
yes. If I speak again then the agent will respond. |
@nbrustein Can you share me a simple example to reproduce this error, maybe an agent with some mock function calls? I think can track if there is an in-progress response then either wait for or cancel it (with https://platform.openai.com/docs/api-reference/realtime-client-events/response/cancel). cc @davidzhao |
This does it pretty reliably for me. Probably about 50% of the function calls result in the error.
|
Thanks @nbrustein! I was able to reproduce it and I think the root cause is that when there are more than one function calls, each of them will trigger a |
Great. Thanks for looking into it. Can you post the fix here whenever there is one? I'm curious to see where this gets implemented. |
I tried to track the activate response and provide the options to wait for cancel the in-progress response. However, I found that this error cannot be completely avoided in I suggest we cancel the "known" existing response before |
@nbrustein In your example, the issue happened most likely because the |
I understand how my Am I right in believing |
Yes, Tracking and canceling (or waiting for) the active response before sending the |
I'm still getting this error after tool calls on
|
I'm also still seeing this issue, using pretty much the same code that I pasted previously. My logs are slightly different from @simplegr33n I don't see anything in those logs that would suggest what the in progress response is. I don't see another response being created before or during the function call.
|
I looked into this more deeply, but I didn't find an explanation. I don't see any issues with the way the code currently checks for an active response, but even when there is no active response in the RealtimeModel, a message created after a function call regularly triggers the "Conversation already has an active response" error. I had some success by listening for that error and then just sending a new assistant message followed by a new I only saw one instance where this created a loop of "Conversation already has an active response" errors triggering a new response.create, but even in that case it resolved itself after 7 quick iterations and the conversation continued. |
I've also dug into this a bit further to try to debug but can't really figure out the core issue. If I return Attempting to set the on_duplicate parameter to "cancel_existing" instead of "keep_both" behaves well for me for a few turns, but eventually the conversation will hit a
error:
|
@simplegr33n @nbrustein Do you have an example to reproduce this issue so I can help to debug? There is a gap between the response created and we received the "event of response created". Perhaps the error was caused bc creating response between this gap. What will happen when this happened, the agent stuck or continue speaking? |
Do you have a theory about what the open response is when we hit this error? It seems like it can't be the previous response that triggered the function call, because we're received a Could this be a bug inside OpenAI, rather than in the livekit-agents code? |
I have tested with the example on the main branch, I can see some warnings # user speech end and ask for a next question
2025-01-08 17:42:07,942 - DEBUG livekit.plugins.openai.realtime - conversation item created {"type": "conversation.item.created", "event_id": "event_AnMq5SdC66vO7lYSNtYW2", "previous_item_id": "item_AnMpnAIIAHimrJiSx22sj", "item": {"id": "item_AnMq08uV3KmJ0CLEZvsco", "object": "realtime.item", "type": "message", "status": "completed", "role": "user", "content": [{"type": "input_audio", "transcript": null}]}, "pid": 2900269, "job_id": "AJ_vB4igeLXEbjJ"}
# response to trigger get_topic function (id: resp_AnMq5L3sM00rdh65xBgPP)
2025-01-08 17:42:07,950 - INFO livekit.plugins.openai.realtime - response created resp_AnMq5L3sM00rdh65xBgPP {"pid": 2900269, "job_id": "AJ_vB4igeLXEbjJ"}
2025-01-08 17:42:08,397 - DEBUG livekit.plugins.openai.realtime - conversation item created {"type": "conversation.item.created", "event_id": "event_AnMq6psGpXNkc4l72K5YV", "previous_item_id": "item_AnMq08uV3KmJ0CLEZvsco", "item": {"id": "item_AnMq5XhewslsZJqxyohfA", "object": "realtime.item", "type": "function_call", "status": "in_progress", "name": "get_topic", "call_id": "call_Sj950dBv4zdE0xoN", "arguments": ""}, "pid": 2900269, "job_id": "AJ_vB4igeLXEbjJ"}
2025-01-08 17:42:08,412 - DEBUG livekit.plugins.openai.realtime - executing ai function {"function": "get_topic", "pid": 2900269, "job_id": "AJ_vB4igeLXEbjJ"}
2025-01-08 17:42:08,412 - INFO my-worker - New topic: Topic starting question: "How can outliers affect the calculation and interpretation of the mean in a dataset?". Topic summary: The mean is calculated by summing all data values and dividing by their count. While it is a valuable measure of central tendency, it is sensitive to outliers, which can skew results. For instance, adding a single high value to a dataset can disproportionately increase the mean, making it less representative of the majority. {"pid": 2900269, "job_id": "AJ_vB4igeLXEbjJ"}
# function call finished
2025-01-08 17:42:08,412 - INFO livekit.plugins.openai.realtime - creating response for tool call {"function": "get_topic", "pid": 2900269, "job_id": "AJ_vB4igeLXEbjJ"}
# waiting for resp_AnMq5L3sM00rdh65xBgPP done
2025-01-08 17:42:08,412 - WARNING livekit.plugins.openai.realtime - waiting for in-progress response to be done before creating a new one {"existing_response_id": "resp_AnMq5L3sM00rdh65xBgPP", "session_id": "sess_AnMp6blwzmz7AweddYcHI", "pid": 2900269, "job_id": "AJ_vB4igeLXEbjJ"}
# creating a new response for next topic
2025-01-08 17:42:08,416 - INFO livekit.plugins.openai.realtime - in-progress response is done, creating a new one {"existing_response_id": "resp_AnMq5L3sM00rdh65xBgPP", "session_id": "sess_AnMp6blwzmz7AweddYcHI", "pid": 2900269, "job_id": "AJ_vB4igeLXEbjJ"}
# function call output was synced to the API
2025-01-08 17:42:08,673 - DEBUG livekit.plugins.openai.realtime - conversation item created {"type": "conversation.item.created", "event_id": "event_AnMq6bGHdH8YCuup9umyH", "previous_item_id": "item_AnMq5XhewslsZJqxyohfA", "item": {"id": "item_c4b13263ae86", "object": "realtime.item", "type": "function_call_output", "call_id": "call_Sj950dBv4zdE0xoN", "output": "Topic starting question: \"How can outliers affect the calculation and interpretation of the mean in a dataset?\". Topic summary: The mean is calculated by summing all data values and dividing by their count. While it is a valuable measure of central tendency, it is sensitive to outliers, which can skew results. For instance, adding a single high value to a dataset can disproportionately increase the mean, making it less representative of the majority."}, "pid": 2900269, "job_id": "AJ_vB4igeLXEbjJ"}
# new response created
2025-01-08 17:42:08,674 - INFO livekit.plugins.openai.realtime - response created resp_AnMq62GEBtOUx50nMJybS {"pid": 2900269, "job_id": "AJ_vB4igeLXEbjJ"} I added a log to the
It should be helpful to log the response id of both If this is the case, the frequency with which the error occurs may be related to network latency (the speed at which the response_created event is received) or background noise (the response may be created from background noise). But there is no way to avoid this completely if so, and one solution is for the agent to handle it internally: listen for the error and try to resend @nbrustein @simplegr33n it would be great if you could help to print the logs of |
I'm using the code that I pasted previously and can reproduce the error reliably every 2 or 3 function calls. Here is an example, showing the In this case there were 3 function calls, with an error coming on the third one. I don't see why the 3rd function call would have triggered an error when the first one didn't. From the events, it seems like the exact same order of events. At
At
At
|
Hey @nbrustein I was having the same error when executing the tool/function and found a way to solve it. Could you please try it and let me know if it worked for you? Instead for making the changes inside the function I added an event listener. Now, the function returns a void, and when the event listener detects the function executed it makes the changes. So basically it's about moving the logic from inside the tool to the listener. Here's how:
|
@nbrustein Thanks for your testing! Can you share some more logs after the error occurs. I would like to see if there is a "response.created" message after the error "Conversation already has an active response" (if you didn't perform any action after the error) and what conversation items it has. My assumption is that there is an response created by the realtime API right before we send the |
Btw, I created a pr to support local VAD #1347 that can disable the auto response creation on the server side. |
No, after that nothing else will happen unless I start talking again to get it going. I have no idea which response it is that it's complaining about. It seems like maybe it sends the |
@rpiacquadioryz can you try to fix up the formatting in your comment? I'm having trouble figuring out what's supposed to indented. |
fixed it! @nbrustein |
Ok, then I have no idea why the error happens. And it's weird that I cannot reproduce it on my end. I do see a lot of warnings like this I am wondering if we cannot find a root cause, is that make sense internally we check this specific error type and try to re-send the |
I'm unable to reproduce either with the example above |
I feel like it would be helpful if there was more information in the error. We need to know what response it is that is in-progress when the error is triggered. Is there an OpenAI project where you could make a request for that? |
We've gotten reports in Slack that when certain function calls are used with MultimodalAgent, it would sometimes error out with:
It'd be great if anyone could produce a path to reproducing the error.
The text was updated successfully, but these errors were encountered: