gemini-robotics-er-2-streaming-preview モデル エンドポイントは、
Live API と統合された専用の
ストリーミング エンドポイントを公開し、アプリケーションとロボット間のリアルタイムの
双方向通信を可能にします。これにより、迅速なフィードバック ループと環境への反応型レスポンスを必要とするエージェントに適しています。
ユースケース
- マルチロボット連携: 共有セッションを通じてタスクの状態を通信し、 サブタスクを委任する複数のロボット。
- 継続的なモニタリング: シーンを観察し、コンテナが満杯になったときなど、特定のイベントが発生したときにアクションをトリガーするロボット。
- 倉庫と物流: 品物を 目視で確認し、梱包の進捗状況を追跡し、エラーから復旧するピッキングと梱包のエージェント。
技術仕様
次の表に、Live API の技術仕様の概要を示します。
| カテゴリ | 詳細 |
|---|---|
| 入力モダリティ | 音声(RAW 16 ビット PCM 音声、16kHz、リトル エンディアン)、画像(JPEG <= 1FPS)、テキスト |
| 出力モダリティ | テキスト |
| プロトコル | ステートフル WebSocket 接続(WSS) |
エージェントの設定を作成する
Live API で構築されたロボット工学エージェントは、次の 3 つのステップに従います。
- ロボットの機能をツールとして宣言する。ロボットが実行できる各アクション(移動、把握、発話)は、名前、説明、パラメータ スキーマを持つ関数宣言になります。物理アクションでは、
"behavior": "BLOCKING"を使用する必要があります。これにより、モデルはロボットが完了するまで待ってから 次のステップを選択します。 - マルチモーダル入力を永続的なセッションにストリーミングする。
live.connectセッションを開き、タスクの実行中は開いたままにします。ロボットのセンサーから到着した動画フレーム、音声、テキストを送信します。 - 受信ループでツール呼び出しを処理する。モデルがアクションを選択するたびに、
tool_callメッセージが送信されます。受信ループは、ロボット SDK に対して関数を実行し、tool_responseを返します。セッションは開いたままになり、モデルは結果に基づいて次のアクションを選択します。
以降のセクションでは、これらのステップを 3 つの一般的なパターン(ベースライン エージェント ループ、ハートビートを使用したプロアクティブなシーン モニタリング、ツールとしての TTS を介した音声のルーティング)に適用する方法について説明します。
関数呼び出しでロボットをオーケストレートする
次の例は、3 つのステップすべてを 1 つの Python スクリプトにまとめたものです。
ステップ 1(ツールの定義)では、ロボットの機能を関数宣言として宣言します。navigate 関数は "behavior": "BLOCKING" を使用するため、
モデルはロボットがウェイポイントに到達するまで待ってから別のツールを呼び出します。
同じリストに関数宣言を追加すると、ロボットの機能を追加できます。
ステップ 2(入力ヘルパー)では、さまざまなモダリティ入力をセッションにストリーミングする 3 つの関数を示します。send_text はコマンド用、send_image はカメラフレーム用(テキスト プロンプトは省略可)、send_audio はマイクからの RAW PCM 音声用です。
ステップ 3(受信ループ)は同時に実行され、server_content メッセージ(モデルのテキスト出力)と tool_call メッセージ(ロボット アクションをリクエストするモデル)の 2 種類のメッセージを処理します。ツール呼び出しが到着すると、ループは execute_tool(実際のロボット SDK に置き換えるスタブ)を呼び出し、tool_response を返して、モデルが次のアクションを選択できるようにします。
import asyncio
from google import genai
from google.genai import types
MODEL = "gemini-robotics-er-2-streaming-preview"
# ── Tool definitions ─────────────────────────────────────────────────────────
tools = [
{
"function_declarations": [
{
"name": "navigate",
"description": "Navigate the robot to a named waypoint.",
"behavior": "BLOCKING",
"parameters": {
"type": "OBJECT",
"properties": {"name": {"type": "STRING"}},
"required": ["name"],
},
},
# Add more function definitions here
]
}
]
# ── Stub tool executor (replace with real robot SDK calls) ───────────────────
def execute_tool(name: str, args: dict) -> dict:
print(f" [Tool] {name}({args})")
return {"status": "success"}
# ── Input helpers ────────────────────────────────────────────────────────────
def send_text(session, text: str):
"""Send a text turn."""
return session.send_client_content(
turns=types.Content(role="user", parts=[types.Part(text=text)]),
turn_complete=True,
)
def send_image(session, image_bytes: bytes, prompt: str = ""):
"""Send a JPEG image with an optional text prompt."""
parts = [
types.Part(
inline_data=types.Blob(data=image_bytes, mime_type="image/jpeg")
)
]
if prompt:
parts.append(types.Part(text=prompt))
return session.send_client_content(
turns=types.Content(role="user", parts=parts),
turn_complete=True,
)
def send_audio(session, audio_chunk: bytes):
"""Stream a chunk of raw PCM audio (16-bit, 16 kHz, mono)."""
return session.send_realtime_input(
media=types.Blob(data=audio_chunk, mime_type="audio/pcm;rate=16000")
)
# ── Receive loop ─────────────────────────────────────────────────────────────
async def receive_loop(session):
"""Print model text and handle tool calls until the session ends."""
async for message in session.receive():
if message.server_content:
sc = message.server_content
if sc.model_turn and sc.model_turn.parts:
for part in sc.model_turn.parts:
if part.text:
print(f"Model: {part.text}", end="", flush=True)
if sc.turn_complete:
print("\n[Turn Complete]")
elif message.tool_call:
responses = []
for call in message.tool_call.function_calls:
print(f"\n[Tool Call] {call.name}({call.args})")
result = execute_tool(call.name, call.args)
responses.append(
types.FunctionResponse(
name=call.name,
response=result,
id=call.id,
)
)
await session.send_tool_response(function_responses=responses)
# ── Main ─────────────────────────────────────────────────────────────────────
async def main():
client = genai.Client(api_key=os.environ["GEMINI_API_KEY"])
config = types.LiveConnectConfig(
response_modalities=["TEXT"],
tools=tools,
system_instruction=types.Content(
parts=[types.Part(text="You are a robot controller. Use tools to execute commands.")]
),
)
async with client.aio.live.connect(model=MODEL, config=config) as session:
recv_task = asyncio.create_task(receive_loop(session))
# Connect robot perception callbacks and user inputs to the helpers above.
recv_task.cancel()
asyncio.run(main())
受信ループは、各ツール レスポンスの後もアクティブなままです。モデルは、アクション シーケンス全体を事前にエンコードすることなく、長期的な計画を構築して修正します。
プロアクティブな空間時間推論
Live API は動画をストリーミングしますが、動画フレームだけでは新しい推論ターンはトリガーされません。モデル レスポンスをトリガーするには、動画フレームにテキストまたは音声プロンプトを添える必要があります。背景については、 Live API の機能をご覧ください。
プロアクティブな推論を有効にするには、ハートビート を実装します。 最新のカメラフレームを定期的に送信し、モデルが シーンを検査して明示的な決定を下すようにする短いテキスト プロンプトを送信します。動画入力は 1 秒あたり 1 フレームにレート制限されます。
前のセクションの受信ループとともに、このコルーチンを追加します。同じセッションで別の asyncio タスクとして実行されます。
async def heartbeat(session, camera): # camera is your robot camera API
while True:
frame = await camera.latest_jpeg()
await session.send_realtime_input(
video=types.Blob(data=frame, mime_type="image/jpeg")
)
await session.send_realtime_input(
text=(
"[HEARTBEAT] If no task is active, call 'ack' and wait for user"
" input. If a task is active: observe the scene. If the current"
" step is progressing correctly, call 'ack'. If the current step"
" is complete, call 'run_instruction' with the next step. If the"
" overall goal is achieved, call 'reset' and inform the user."
)
)
await asyncio.sleep(1)
ロボット アクション中にハートビートを一時停止する必要はありません。暗黙的な成功検出機能として使用すると、実行中のアクションをモデルが継続的に観察できます。つまり、把握が安全かどうか、注ぎ込みがターゲット上にあるかどうか、オブジェクトが正しく配置されているかどうかを追跡し、結果が明確になった瞬間に反応します。
外部 TTS によるオーディオ出力
Gemini Robotics ER 2 はテキストを返します。アプリケーションは、挿入されたコールバックを介して、完了したレスポンス を別の TTS プロバイダ( Gemini TTSなど)にルーティングします。 これにより、音声のレイテンシ、音声の選択、中断動作を制御し、エージェント ロジックを変更せずに TTS バックエンドを切り替えることができます。
TTS をツールとして宣言して、モデルが「何か言う」を「アームを動かす」と同じように扱うこともできます。 最初のセクションの tools リストに次の関数宣言を追加します。
TOOLS = [
{
"name": "send_message",
"description": (
"Speak a message aloud via TTS, then deliver it to the"
" specified target. Use target='user' to speak directly"
" to the user, or a peer agent name (e.g., 'duo') to"
" communicate with another robot."
),
"parameters": {
"type": "object",
"properties": {
"target": {
"type": "string",
"description": "Recipient: 'user' or a peer agent name.",
},
"message": {
"type": "string",
"description": "The message to speak and deliver.",
},
},
"required": ["target", "message"],
},
},
]
TTS を関数宣言でラップすることで、モデルは他のロボット アクションと同じツール呼び出しパスで音声を処理します。アプリケーションは、挿入されたコールバックで呼び出しを完了します。
GitHub の例
Spot ロボットのおやつ取得デモや Tinybot パンチルト Hello World など、実際の動作例については、 Robotics Live API の例をご覧ください。
次のステップ
- 動画理解 - 瞬間検出と進捗状況の分類。
- タスク オーケストレーション - ストリーミングなしの長期的なタスク。
- Live API の概要 - Live API の完全なドキュメント。