跳过内容

实时事件

会话事件

由实时会话发出的事件。

事件类型

Agent 事件

一个新的 Agent 已经启动。

源代码位于 src/agents/realtime/events.py
@dataclass
class RealtimeAgentStartEvent:
    """A new agent has started."""

    agent: RealtimeAgent
    """The new agent."""

    info: RealtimeEventInfo
    """Common info for all events, such as the context."""

    type: Literal["agent_start"] = "agent_start"

agent 实例属性

新的 Agent。

信息 实例属性

info: RealtimeEventInfo

所有事件的通用信息,例如上下文。

一个 Agent 已经结束。

源代码位于 src/agents/realtime/events.py
@dataclass
class RealtimeAgentEndEvent:
    """An agent has ended."""

    agent: RealtimeAgent
    """The agent that ended."""

    info: RealtimeEventInfo
    """Common info for all events, such as the context."""

    type: Literal["agent_end"] = "agent_end"

agent 实例属性

结束的 Agent。

信息 实例属性

info: RealtimeEventInfo

所有事件的通用信息,例如上下文。

音频事件

当 Agent 生成新的音频以供播放时触发。

源代码位于 src/agents/realtime/events.py
@dataclass
class RealtimeAudio:
    """Triggered when the agent generates new audio to be played."""

    audio: RealtimeModelAudioEvent
    """The audio event from the model layer."""

    item_id: str
    """The ID of the item containing audio."""

    content_index: int
    """The index of the audio content in `item.content`"""

    info: RealtimeEventInfo
    """Common info for all events, such as the context."""

    type: Literal["audio"] = "audio"

音频 实例属性

来自模型层的音频事件。

item_id 实例属性

item_id: str

包含音频的项目的 ID。

内容索引 实例属性

content_index: int

item.content 中的音频内容的索引

信息 实例属性

info: RealtimeEventInfo

所有事件的通用信息,例如上下文。

当 Agent 停止生成音频时触发。

源代码位于 src/agents/realtime/events.py
@dataclass
class RealtimeAudioEnd:
    """Triggered when the agent stops generating audio."""

    info: RealtimeEventInfo
    """Common info for all events, such as the context."""

    item_id: str
    """The ID of the item containing audio."""

    content_index: int
    """The index of the audio content in `item.content`"""

    type: Literal["audio_end"] = "audio_end"

信息 实例属性

info: RealtimeEventInfo

所有事件的通用信息,例如上下文。

item_id 实例属性

item_id: str

包含音频的项目的 ID。

内容索引 实例属性

content_index: int

item.content 中的音频内容的索引

当 Agent 被中断时触发。用户可以监听此事件以停止音频播放或向用户提供视觉指示。

源代码位于 src/agents/realtime/events.py
@dataclass
class RealtimeAudioInterrupted:
    """Triggered when the agent is interrupted. Can be listened to by the user to stop audio
    playback or give visual indicators to the user.
    """

    info: RealtimeEventInfo
    """Common info for all events, such as the context."""

    item_id: str
    """The ID of the item containing audio."""

    content_index: int
    """The index of the audio content in `item.content`"""

    type: Literal["audio_interrupted"] = "audio_interrupted"

信息 实例属性

info: RealtimeEventInfo

所有事件的通用信息,例如上下文。

item_id 实例属性

item_id: str

包含音频的项目的 ID。

内容索引 实例属性

content_index: int

item.content 中的音频内容的索引

工具事件

一个 Agent 正在启动工具调用。

源代码位于 src/agents/realtime/events.py
@dataclass
class RealtimeToolStart:
    """An agent is starting a tool call."""

    agent: RealtimeAgent
    """The agent that updated."""

    tool: Tool
    """The tool being called."""

    arguments: str
    """The arguments passed to the tool as a JSON string."""

    info: RealtimeEventInfo
    """Common info for all events, such as the context."""

    type: Literal["tool_start"] = "tool_start"

agent 实例属性

更新的 Agent。

工具 实例属性

tool: Tool

正在调用的工具。

参数 实例属性

arguments: str

作为 JSON 字符串传递给工具的参数。

信息 实例属性

info: RealtimeEventInfo

所有事件的通用信息,例如上下文。

一个 Agent 已经结束工具调用。

源代码位于 src/agents/realtime/events.py
@dataclass
class RealtimeToolEnd:
    """An agent has ended a tool call."""

    agent: RealtimeAgent
    """The agent that ended the tool call."""

    tool: Tool
    """The tool that was called."""

    arguments: str
    """The arguments passed to the tool as a JSON string."""

    output: Any
    """The output of the tool call."""

    info: RealtimeEventInfo
    """Common info for all events, such as the context."""

    type: Literal["tool_end"] = "tool_end"

agent 实例属性

结束工具调用的 Agent。

工具 实例属性

tool: Tool

被调用的工具。

参数 实例属性

arguments: str

作为 JSON 字符串传递给工具的参数。

输出 实例属性

output: Any

工具调用的输出。

信息 实例属性

info: RealtimeEventInfo

所有事件的通用信息,例如上下文。

交接事件

一个 Agent 已将任务交接给另一个 Agent。

源代码位于 src/agents/realtime/events.py
@dataclass
class RealtimeHandoffEvent:
    """An agent has handed off to another agent."""

    from_agent: RealtimeAgent
    """The agent that handed off."""

    to_agent: RealtimeAgent
    """The agent that was handed off to."""

    info: RealtimeEventInfo
    """Common info for all events, such as the context."""

    type: Literal["handoff"] = "handoff"

来自 Agent 实例属性

from_agent: RealtimeAgent

发起交接的 Agent。

前往 Agent 实例属性

to_agent: RealtimeAgent

被交接到的 Agent。

信息 实例属性

info: RealtimeEventInfo

所有事件的通用信息,例如上下文。

护栏事件

一个护栏被触发,并且 Agent 已被中断。

源代码位于 src/agents/realtime/events.py
@dataclass
class RealtimeGuardrailTripped:
    """A guardrail has been tripped and the agent has been interrupted."""

    guardrail_results: list[OutputGuardrailResult]
    """The results from all triggered guardrails."""

    message: str
    """The message that was being generated when the guardrail was triggered."""

    info: RealtimeEventInfo
    """Common info for all events, such as the context."""

    type: Literal["guardrail_tripped"] = "guardrail_tripped"

护栏结果 实例属性

guardrail_results: list[OutputGuardrailResult]

所有触发的护栏的结果。

message 实例属性

message: str

触发护栏时正在生成的消息。

信息 实例属性

info: RealtimeEventInfo

所有事件的通用信息,例如上下文。

历史事件

已向历史记录添加一个新项目。

源代码位于 src/agents/realtime/events.py
@dataclass
class RealtimeHistoryAdded:
    """A new item has been added to the history."""

    item: RealtimeItem
    """The new item that was added to the history."""

    info: RealtimeEventInfo
    """Common info for all events, such as the context."""

    type: Literal["history_added"] = "history_added"

项目 实例属性

添加到历史记录中的新项目。

信息 实例属性

info: RealtimeEventInfo

所有事件的通用信息,例如上下文。

历史记录已更新。包含会话的完整历史记录。

源代码位于 src/agents/realtime/events.py
@dataclass
class RealtimeHistoryUpdated:
    """The history has been updated. Contains the full history of the session."""

    history: list[RealtimeItem]
    """The full history of the session."""

    info: RealtimeEventInfo
    """Common info for all events, such as the context."""

    type: Literal["history_updated"] = "history_updated"

历史记录 实例属性

history: list[RealtimeItem]

会话的完整历史记录。

信息 实例属性

info: RealtimeEventInfo

所有事件的通用信息,例如上下文。

错误事件

发生了一个错误。

源代码位于 src/agents/realtime/events.py
@dataclass
class RealtimeError:
    """An error has occurred."""

    error: Any
    """The error that occurred."""

    info: RealtimeEventInfo
    """Common info for all events, such as the context."""

    type: Literal["error"] = "error"

错误 实例属性

error: Any

发生的错误。

信息 实例属性

info: RealtimeEventInfo

所有事件的通用信息,例如上下文。

原始模型事件

转发来自模型层的原始事件。

源代码位于 src/agents/realtime/events.py
@dataclass
class RealtimeRawModelEvent:
    """Forwards raw events from the model layer."""

    data: RealtimeModelEvent
    """The raw data from the model layer."""

    info: RealtimeEventInfo
    """Common info for all events, such as the context."""

    type: Literal["raw_model_event"] = "raw_model_event"

data instance-attribute

data: RealtimeModelEvent

来自模型层的原始数据。

信息 实例属性

info: RealtimeEventInfo

所有事件的通用信息,例如上下文。