Hi guys, I’m trying to find the best way to handle the case when we are adding a new message to a thread with an active run, and the payload I get is the following:
{
“status”: 400,
“error”: {
“message”: “Can’t add messages to thread_4SDeWVBwqyVnfxcBXFfja74P while a run run_ggjNMB3WBFeL5aLquaxOM1iC is active.”,
“type”: “invalid_request_error”,
“param”: null,
“code”: null
},
“code”: null,
“param”: null,
“type”: “invalid_request_error”
}
There isn’t any specific code that lets me know this error is related to this problem, just the message. However, the error message changes and can’t be used as a realiable pattern to handle this case. Since status 400 is generic and also can be triggered by another factors it’s not also reliable to identify and treat this case. I’d like to know how you’ve been dealing with this problem to identify whether the error is actually related to adding a message to a thread with an active run, in order to take actions like adding the messages to a queue to handle them later.
I’m encountering the same issue when calling two functions in GPT simultaneously. For example:
‘Get Bob’s location and then provide the current weather there.’
I created a search_db function to find a user’s location and a search_weather function to retrieve the weather for a specific location.
When I call each function individually, everything works fine. However, when I try to call both at the same time, the process gets stuck in the thread.run.requires_action state.
You mean “when the API attempts to call both at the same time”? That’s the only way that parallel tool calls can work.
Parallel calls are not ordered or dependent.
An AI that would ask for your location by tool should know that there is no way to also send a weather request at the same time that requires that location as a field.
Unfortunately, AI is dumb. It doesn’t often understand “then” means call a tool again after getting a first return.
Turn off parallel tool calls with run parameter "parallel_tool_calls": "false". The AI can’t jank things up then. You also save tokens of additional tool instructions every run.
To return a parallel tool call, you will need to return both tool responses in a list, with their respective matching IDs.
Check this API Reference link, and expand tool_outputs:
You would see that the AI sending both of the tool calls at the same time where you could return this is not really possible, unless you have some advanced understanding in your code of receiving both at the same time and connecting them sequentially:
from openai import OpenAI
client = OpenAI()
run = client.beta.threads.runs.submit_tool_outputs(
thread_id="thread_123",
run_id="run_123",
tool_outputs=[
{
"tool_call_id": "call_001",
"output": "Bob is in Miami, FL"
},
{
"tool_call_id": "call_002",
"output": "70 degrees and sunny in Miami"
}
]
)
print(run)
Or just a function “get weather at user’s location” that does it all…
So you do two operations in parallel where one tasks needs the output of the other?
Does it implement some sort of timetravel?
I think that might work. I read about photons having a superposition in multiple timezones… maybe it is possible to give them a signature and store bobs location in it and then let the one service find bob and store it in that superpositioned photon to send the information back in time to the event that triggered both parallel calls so the second one can take the information from the future, decode it and run in parallel… If you need any help in the implementation of that service just message me. I’d be happy to assist (won’t be cheap though - i think it might require to buy the university of vienna)…
ah and speaking of timetravel… the weather forecast would be a lot better too
or just get the weather in every location and combine bobs location with one of the results (might be a lot data)