AS AgentScopeAPI 手册 / API Reference
类class agentscope.realtime

GeminiRealtimeModel

class GeminiRealtimeModel(RealtimeModelBase)
源码Source agentscope/realtime/_gemini/_model.py:27–480

Gemini 实时模型,处理低延迟的实时语音与多模态交互。位于 agentscope.realtime 包,继承自 RealtimeModelBase。核心成员包括 connect、close、events、push_audio、push_text、push_tool_result。

Three protocol traits shape this adapter:

  • Nothing on the wire is addressable. An item id is minted here for each model turn and each user turn so every event carries one.
  • Generation is implicit: a finished user turn or a tool response starts the reply, so :meth:request_response sends nothing.
  • Interruption is the server's job — it reports serverContent.interrupted and drops the rest of the reply itself — so :meth:cancel_response is a no-op. With caller-owned turns the caller silences the reply locally instead, and the server is told not to interrupt on its own.

嵌套类摘要Nested Class Summary

类Class类型Kind说明Description
Parameters类class
参数,处理低延迟的实时语音与多模态交互。
Tuneables surfaced to the UI.

构造器摘要Constructor Summary

构造器Constructor说明Description
def __init__(model: str, credential: GeminiCredential, parameters: 'GeminiRealtimeModel.Parameters | None' = None, mode…
初始化 `GeminiRealtimeModel` 实例。
Initialize the Gemini realtime model.

属性摘要Property Summary

属性Property说明Description
input_transcription_enabled
读取 `input_transcription_enabled` 属性。
Whether Gemini input transcription is enabled.

属性摘要Attribute Summary

属性Attribute类型Type说明Description值Value
type—
类型字段。
'gemini_realtime'
supports_text_input—
支持文本输入字段。
True

方法摘要Method Summary

方法Method说明Description
async def connect(instructions: str, tools: list[dict] | None = None, **kwargs: Any) -> Noneasync
建立连接并完成初始化。
Open the WebSocket and send the setup message.
async def close() -> Noneasync
关闭连接并释放相关资源。
Close the WebSocket and stop reading.
async def events() -> AsyncIterator[me.ModelEvent]async
返回事件。
Yield events until the session ends.
async def push_audio(pcm: bytes) -> Noneasync
设置推送音频。
Send PCM16 mono audio at :attr:`input_sample_rate`. With caller-owned turns, the first chunk opens the activity window that :meth:`commit_turn` closes.
async def push_text(text: str) -> Noneasync
设置推送文本。
Send a complete text turn, which the model answers at once.
async def push_tool_result(block: ToolResultBlock) -> Noneasync
设置推送工具结果。
Send one ``functionResponse``; the model resumes on its own.
async def commit_turn() -> Noneasync
返回提交轮次。
Close the activity window, which asks for the reply.
async def request_response() -> Noneasync
返回请求响应。
No-op: a finished turn or a tool response is the request.
async def cancel_response() -> Noneasync
返回取消响应。
No-op: the protocol has no cancel frame.

构造器详情Constructor Detail

GeminiRealtimeModel

def __init__(model: str, credential: GeminiCredential, parameters: 'GeminiRealtimeModel.Parameters | None' = None, model_card: RealtimeModelCard | None = None) -> None

初始化 GeminiRealtimeModel 实例。

Initialize the Gemini realtime model.

参数Parameters
名称Name类型Type说明Description
modelstr模型实例(类型 `str`)。The model name, e.g. `"gemini-3.1-flash-live-preview"`.
credentialGeminiCredential凭证对象(类型 `GeminiCredential`)。The Gemini credential.
parameters默认default None'GeminiRealtimeModel.Parameters | None'参数(类型 `'GeminiRealtimeModel.Parameters | None'`)。Provider parameters; defaults are used if omitted.
model_card默认default NoneRealtimeModelCard | None模型卡片(类型 `RealtimeModelCard | None`)。The model card, looked up by name if omitted.
源码Source agentscope/realtime/_gemini/_model.py:76–108

属性详情Attribute Detail

type

 = 'gemini_realtime'

类型字段。

The type field.

源码Source agentscope/realtime/_gemini/_model.py:68

supports_text_input

 = True

支持文本输入字段。

The supports text input field.

源码Source agentscope/realtime/_gemini/_model.py:69

属性详情Property Detail

input_transcription_enabled

def input_transcription_enabled() -> bool

读取 input_transcription_enabled 属性。

Whether Gemini input transcription is enabled.

返回Returns bool
返回布尔值,表示判断结果。Returns a boolean result.
源码Source agentscope/realtime/_gemini/_model.py:72–74

方法详情Method Detail

connect

async def connect(instructions: str, tools: list[dict] | None = None, **kwargs: Any) -> None
async

建立连接并完成初始化。

Open the WebSocket and send the setup message.

参数Parameters
名称Name类型Type说明Description
instructionsstr指令(类型 `str`)。The instructions.
tools默认default Nonelist[dict] | None工具列表(类型 `list[dict] | None`)。The tools.
kwargsAny关键字参数(类型 `Any`)。The kwargs.
返回Returns None
无返回值。No value is returned.
源码Source agentscope/realtime/_gemini/_model.py:114–151

close

async def close() -> None
async

关闭连接并释放相关资源。

Close the WebSocket and stop reading.

返回Returns None
无返回值。No value is returned.
源码Source agentscope/realtime/_gemini/_model.py:153–162

events

async def events() -> AsyncIterator[me.ModelEvent]
async

返回事件。

Yield events until the session ends.

返回Returns AsyncIterator[me.ModelEvent]
以异步流的形式返回me.ModelEvent。Returns a stream of me model event.
源码Source agentscope/realtime/_gemini/_model.py:164–170

push_audio

async def push_audio(pcm: bytes) -> None
async

设置推送音频。

Send PCM16 mono audio at :attr:input_sample_rate.

参数Parameters
名称Name类型Type说明Description
pcmbytespcm(类型 `bytes`)。The pcm.
返回Returns None
无返回值。No value is returned.
源码Source agentscope/realtime/_gemini/_model.py:176–192

push_text

async def push_text(text: str) -> None
async

设置推送文本。

Send a complete text turn, which the model answers at once.

参数Parameters
名称Name类型Type说明Description
textstr文本(类型 `str`)。The text.
返回Returns None
无返回值。No value is returned.
源码Source agentscope/realtime/_gemini/_model.py:194–203

push_tool_result

async def push_tool_result(block: ToolResultBlock) -> None
async

设置推送工具结果。

Send one functionResponse; the model resumes on its own.

参数Parameters
名称Name类型Type说明Description
blockToolResultBlock内容块(类型 `ToolResultBlock`)。The block.
返回Returns None
无返回值。No value is returned.
源码Source agentscope/realtime/_gemini/_model.py:205–226

commit_turn

async def commit_turn() -> None
async

返回提交轮次。

Close the activity window, which asks for the reply.

返回Returns None
无返回值。No value is returned.
源码Source agentscope/realtime/_gemini/_model.py:228–232

request_response

async def request_response() -> None
async

返回请求响应。

No-op: a finished turn or a tool response is the request.

返回Returns None
无返回值。No value is returned.
源码Source agentscope/realtime/_gemini/_model.py:238–239

cancel_response

async def cancel_response() -> None
async

返回取消响应。

No-op: the protocol has no cancel frame.

返回Returns None
无返回值。No value is returned.
源码Source agentscope/realtime/_gemini/_model.py:241–242

嵌套类详情Nested Class Detail

Parameters

class Parameters

参数,处理低延迟的实时语音与多模态交互。位于 agentscope.realtime 包,继承自 RealtimeModelBase.Parameters。

Tuneables surfaced to the UI. Declared in agentscope.realtime. Extends RealtimeModelBase.Parameters.

继承成员Inherited Members

基于官方固定版本源码静态生成Generated from pinned official sources · Python 2.0.11 · Java 2.0.4
签名与文档为静态抽取;如有疑问请以源码为准。Signatures and docs are extracted statically; verify against the source when in doubt.