12月4日、Googleが「Introducing mid-conversation instructions in the Gemini API」と題した記事を公開した。この記事では、Gemini APIにおいて会話の途中でシステム命令やツールをリアルタイムに変更できる「ミッドコンバセーション更新」機能について詳しく紹介されている。なお、元記事はGoogleの公式ブログ(blog.google)に掲載されたものだ。
会話を中断せずに命令を差し込める
チャットボットやAIエージェントを開発していると、「会話の途中で動作モードを切り替えたい」という場面が出てくる。たとえば、ユーザーが問い合わせ中に不正アカウントと判明した場合、その場で返金処理を無効化したい──といったケースだ。
こうした要件は、LLMを使ったステートフルなエージェント設計において長年の課題だった。マルチターン会話では、会話履歴(コンテキスト)を保持しつつ、途中から動作ポリシーだけを切り替えたいというニーズが頻繁に生じる。しかし従来のLLM APIでは、こうした制御をするには会話をリセットするか、プロンプトに追記するかの二択だった。前者は文脈が失われ、後者はシステム命令とユーザー発話の境界が曖昧になるという問題を抱えていた。
Gemini APIの新機能「ミッドコンバセーション・インストラクション(mid-conversation instructions)」は、この制約を解消する。既存の会話セッションを維持したまま、特定のターンでシステム命令を上書き・追加できる。権限やポリシーが動的に変わるワークフローを、会話の連続性を保ちながら制御できる点が最大の特徴だ。
実装の仕組み:system_inputをターン単位で渡す
※以下のコードサンプルは元記事に掲載されているサンプルに基づく。なお、APIバージョンは現在 **v1beta**(実験的APIの段階)での提供であり、仕様は変更される可能性がある。また、コード中で使用されているモデル名(gemini-4-neon)およびAPI形式(client.interactions.create)は元記事に記載されているものをそのまま掲載している。
新APIでは client.interactions.create() を使い、previous_interaction_id で会話の継続を明示しつつ、input に system_input タイプのオブジェクトを混在させる形を取る。
以下は、本番デプロイ凍結中に「新リリースをデプロイするコマンドを教えて」と聞かれたケースのサンプルだ。
from google import genai
client = genai.Client(http_options={"api_version": "v1beta"})
system_instruction = "You are an infrastructure troubleshooting assistant."
turn1 = client.interactions.create(
model="gemini-4-neon",
system_instruction=system_instruction,
input="Latency just spiked on our service. What should I check first?",
)
turn2 = client.interactions.create(
model="gemini-4-neon",
previous_interaction_id=turn1.id,
system_instruction=system_instruction,
input=[
{
"type": "system_input",
"content": [
{
"type": "text",
"text": (
"A production deployment freeze is now active. "
"Recommend read-only diagnostics and do not allow further rollouts."
),
}
],
},
{
"type": "user_input",
"content": [
{
"type": "text",
"text": "Give me the command to deploy a new release.",
}
],
},
],
)
print(turn2.output_text)
モデルのレスポンスはこうなる。
{
"steps": [
{
"type": "system_input",
"content": [{"type": "text", "text": "A production deployment freeze is now active. ..."}]
},
{
"type": "user_input",
"content": [{"type": "text", "text": "Give me the command to deploy a new release."}]
},
{
"type": "model_output",
"content": [{"type": "text", "text": "A production deployment freeze is active, so we can't release. Here are some checks you can run..."}]
}
]
}
system_input を差し込んだターンでは、モデルはデプロイ命令を拒否し、読み取り専用の診断手順だけを返す。会話履歴は保持されたまま、ポリシーだけが変わる動作だ。
ツールも会話中に差し替えられる
さらに実用的なのが、ツール(function calling)のミッドターン追加・削除だ。
以下のサンプルでは、ユーザーが返金を要求した瞬間に、issue_refund ツールを取り除き、create_escalation_ticket ツールを追加している。
turn2 = client.interactions.create(
model="gemini-4-neon",
previous_interaction_id=turn1.id,
tools=tools,
input=[
{
"type": "system_input",
"content": [
{
"type": "text",
"text": (
"This account is under billing review. Explain "
"that refunds are paused and offer to escalate."
),
}
],
"removed_tools": [{"type": "function", "name": "issue_refund"}],
"added_tools": [
{
"type": "function",
"name": "create_escalation_ticket",
"description": "Escalate a billing review issue to support.",
"parameters": {
"type": "object",
"properties": {"order_id": {"type": "string"}},
"required": ["order_id"],
},
}
],
},
{
"type": "user_input",
"content": [{"type": "text", "text": "Refund order 12345."}],
},
],
)
removed_tools と added_tools をそのターンのペイロードに含めるだけで、モデルが呼び出せる関数セットがその場で切り替わる。返金APIを呼ぶ代わりに、エスカレーションチケットを発行する流れに誘導できる。
このツール差し替えの設計は、LLMエージェントにおけるステート管理の観点から見ても興味深い。従来、エージェントが使える「道具」の集合は会話開始時に固定されることが多く、途中で権限をはく奪したり新しい能力を付与したりするには、セッション外の仕組みで制御する必要があった。removed_tools/added_tools をターン単位のペイロードに含める設計は、こうした動的な権限制御をAPI側で正式にサポートするものといえる。カスタマーサポートの不正検知、マルチステップのAIエージェント、権限が動的に変わるワークフローなど、ステートフルな会話制御が必要な場面で直接使える設計だ。
現時点での状況
APIバージョンは現在 v1beta での提供であり、実験的な段階にある。正式リリース時期や料金体系、利用制限についての記載は元記事にはない。
詳細はIntroducing mid-conversation instructions in the Gemini APIを参照していただきたい。