question for devs working with openai realtime api...
# agents
a
question for devs working with openai realtime api: • when using async function calls (particularly for long tool calls >10s), how do you manage the flow of running the tool call in bg, keep the conversation and when result is ready have the AI notify the user? we have delays particulary with tools that require on device starting some services that are slow due to discovery with external api's and can't be speed up
e
Well you can use asyncio fire and forget method. In the function tool call you can create a task, the task will execute in the background and you can return the response right away, something like "I have initiated X, do something else meanwhile". And in the task itself you can update the chat context with the response returned by the slow external api for the llm to take actions. Assuming you are using python.
a
okay thx, have you tried that? thinking if it could interfere with the possibly continued conversation? also, the tool output will not correspond to the tool call unless i manually link them right?
e
No it won't interfere with the ongoing convo, you can try that with a simple function tool, put asyncio sleep to simulate that long api call and you will see. TBH i haven't used realtime coz its crazy expensive, i use asyncio task orchestration for my own product, so i know.
Copy code
the tool output will not correspond to the tool call unless i manually link them right?
Yeah, coz in the function tool itself, you are returning early so you wont know the output for the slow api yet, but later when you do, you have to update the chat with the output for the llm to know.
a
ahah okey cool thanks ser
šŸ™Œ 1