Movatterモバイル変換


[0]ホーム

URL:


Skip to content

RealtimeRunner

ARealtimeRunner is the equivalent ofRunner for realtime agents. It automaticallyhandles multiple turns by maintaining a persistent connection with the underlying modellayer.

The session manages the local history copy, executes tools, runs guardrails and facilitateshandoffs between agents.

Since this code runs on your server, it uses WebSockets by default. You can optionally createyour own custom model layer by implementing theRealtimeModel interface.

Source code insrc/agents/realtime/runner.py
classRealtimeRunner:"""A `RealtimeRunner` is the equivalent of `Runner` for realtime agents. It automatically    handles multiple turns by maintaining a persistent connection with the underlying model    layer.    The session manages the local history copy, executes tools, runs guardrails and facilitates    handoffs between agents.    Since this code runs on your server, it uses WebSockets by default. You can optionally create    your own custom model layer by implementing the `RealtimeModel` interface.    """def__init__(self,starting_agent:RealtimeAgent,*,model:RealtimeModel|None=None,config:RealtimeRunConfig|None=None,)->None:"""Initialize the realtime runner.        Args:            starting_agent: The agent to start the session with.            context: The context to use for the session.            model: The model to use. If not provided, will use a default OpenAI realtime model.            config: Override parameters to use for the entire run.        """self._starting_agent=starting_agentself._config=configself._model=modelorOpenAIRealtimeWebSocketModel()asyncdefrun(self,*,context:TContext|None=None,model_config:RealtimeModelConfig|None=None)->RealtimeSession:"""Start and returns a realtime session.        Returns:            RealtimeSession: A session object that allows bidirectional communication with the            realtime model.        Example:            ```python            runner = RealtimeRunner(agent)            async with await runner.run() as session:                await session.send_message("Hello")                async for event in session:                    print(event)            ```        """# Create and return the connectionsession=RealtimeSession(model=self._model,agent=self._starting_agent,context=context,model_config=model_config,run_config=self._config,)returnsession

__init__

__init__(starting_agent:RealtimeAgent,*,model:RealtimeModel|None=None,config:RealtimeRunConfig|None=None,)->None

Initialize the realtime runner.

Parameters:

NameTypeDescriptionDefault
starting_agentRealtimeAgent

The agent to start the session with.

required
context

The context to use for the session.

required
modelRealtimeModel | None

The model to use. If not provided, will use a default OpenAI realtime model.

None
configRealtimeRunConfig | None

Override parameters to use for the entire run.

None
Source code insrc/agents/realtime/runner.py
def__init__(self,starting_agent:RealtimeAgent,*,model:RealtimeModel|None=None,config:RealtimeRunConfig|None=None,)->None:"""Initialize the realtime runner.    Args:        starting_agent: The agent to start the session with.        context: The context to use for the session.        model: The model to use. If not provided, will use a default OpenAI realtime model.        config: Override parameters to use for the entire run.    """self._starting_agent=starting_agentself._config=configself._model=modelorOpenAIRealtimeWebSocketModel()

runasync

run(*,context:TContext|None=None,model_config:RealtimeModelConfig|None=None,)->RealtimeSession

Start and returns a realtime session.

Returns:

NameTypeDescription
RealtimeSessionRealtimeSession

A session object that allows bidirectional communication with the

RealtimeSession

realtime model.

Example
runner=RealtimeRunner(agent)asyncwithawaitrunner.run()assession:awaitsession.send_message("Hello")asyncforeventinsession:print(event)
Source code insrc/agents/realtime/runner.py
asyncdefrun(self,*,context:TContext|None=None,model_config:RealtimeModelConfig|None=None)->RealtimeSession:"""Start and returns a realtime session.    Returns:        RealtimeSession: A session object that allows bidirectional communication with the        realtime model.    Example:        ```python        runner = RealtimeRunner(agent)        async with await runner.run() as session:            await session.send_message("Hello")            async for event in session:                print(event)        ```    """# Create and return the connectionsession=RealtimeSession(model=self._model,agent=self._starting_agent,context=context,model_config=model_config,run_config=self._config,)returnsession

[8]ページ先頭

©2009-2025 Movatter.jp