Skip to content

Enable asynchronous function calling for Realtime session #1942

@SalvatoreMarragony

Description

@SalvatoreMarragony

Please read this first

  • Have you read the docs?Agents SDK docs - Yes
  • Have you searched for related issues? Others may have had similar requests - Yes, no similar issues.

Describe the feature

With the current Realtime session implementation, when a function_call event is received, execution pauses until the function completes. This can cause long periods of silence if the function takes time to run. Supporting asynchronous function calls would allow the user to continue interacting with the model while the tool executes. According to the latest gpt-realtime release, the new model is well-equipped to handle such calls.

The update to the code is very straightforward.

This line:

elif event.type == "function_call":
await self._handle_tool_call(event)

should be replaced with:

elif event.type == "function_call":
    asyncio.create_task(self._handle_tool_call(event))

or, in case of a parameter to control it:

elif event.type == "function_call":
    if self.async:
        asyncio.create_task(self._handle_tool_call(event))
    else:
        await self._handle_tool_call(event) 

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions