呼び出し間で会話コンテキストを保持するには、 AgentSession を使用します。
コア使用パターン
ほとんどのアプリケーションは、同じフローに従います。
- セッションの作成 (
create_session()) - そのセッションをそれぞれに渡す
run(...) - サービス会話 ID (
get_session(...)) またはシリアル化された状態からのリハイドレート
// Create and reuse a session
AgentSession session = await agent.CreateSessionAsync();
var first = await agent.RunAsync("My name is Alice.", session);
var second = await agent.RunAsync("What is my name?", session);
// Persist and restore later
var serialized = agent.SerializeSession(session);
AgentSession resumed = await agent.DeserializeSessionAsync(serialized);
# Create and reuse a session
session = agent.create_session()
first = await agent.run("My name is Alice.", session=session)
second = await agent.run("What is my name?", session=session)
# Rehydrate by service conversation ID when needed
service_session = agent.get_session(service_session_id="<service-conversation-id>")
# Persist and restore later
serialized = session.to_dict()
resumed = AgentSession.from_dict(serialized)
ガイド マップ
| ページ | フォーカス |
|---|---|
| セッション |
AgentSession 構造体 (session_id、 service_session_id、 state) とシリアル化 |
| コンテキスト プロバイダー | 組み込みおよびカスタムコンテキスト/履歴プロバイダー パターン |
| ストレージ | 組み込みのストレージ モードと外部永続化戦略 |