Skip to content

Commit 21ce467

Browse files
committed
feat(session_store): add asynchronous and synchronous methods for initializing ADK tables
- Introduced `init_adk_tables_async` and `init_adk_tables` methods to create necessary tables and indexes for Google ADK. - Updated example server initialization to reflect new ADK table setup. - Cleaned up comments and improved code formatting for better readability. This enhancement supports the integration of Google ADK within the conversation service.
1 parent a91c494 commit 21ce467

File tree

4 files changed

+44
-17
lines changed

4 files changed

+44
-17
lines changed

agentrun/conversation_service/__session_store_async_template.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,17 @@ async def init_langgraph_tables_async(self) -> None:
8484
await self._backend.init_search_index_async()
8585
await self._backend.init_checkpoint_tables_async()
8686

87+
async def init_adk_tables_async(self) -> None:
88+
"""创建 Google ADK 所需的全部表和索引(异步)。
89+
90+
包含核心表(Conversation + Event + 二级索引)、三级 State 表
91+
(state / app_state / user_state)以及多元索引。
92+
表或索引已存在时跳过,可重复调用。
93+
"""
94+
await self._backend.init_core_tables_async()
95+
await self._backend.init_state_tables_async()
96+
await self._backend.init_search_index_async()
97+
8798
# -------------------------------------------------------------------
8899
# Checkpoint 管理(LangGraph)(异步)
89100
# -------------------------------------------------------------------

agentrun/conversation_service/session_store.py

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -133,10 +133,6 @@ async def init_langgraph_tables_async(self) -> None:
133133
await self._backend.init_search_index_async()
134134
await self._backend.init_checkpoint_tables_async()
135135

136-
# -------------------------------------------------------------------
137-
# Checkpoint 管理(LangGraph)(同步)
138-
# -------------------------------------------------------------------
139-
140136
def init_langgraph_tables(self) -> None:
141137
"""创建 LangGraph 所需的全部表和索引(同步)。
142138
@@ -148,10 +144,36 @@ def init_langgraph_tables(self) -> None:
148144
self._backend.init_search_index()
149145
self._backend.init_checkpoint_tables()
150146

147+
async def init_adk_tables_async(self) -> None:
148+
"""创建 Google ADK 所需的全部表和索引(异步)。
149+
150+
包含核心表(Conversation + Event + 二级索引)、三级 State 表
151+
(state / app_state / user_state)以及多元索引。
152+
表或索引已存在时跳过,可重复调用。
153+
"""
154+
await self._backend.init_core_tables_async()
155+
await self._backend.init_state_tables_async()
156+
await self._backend.init_search_index_async()
157+
151158
# -------------------------------------------------------------------
152159
# Checkpoint 管理(LangGraph)(异步)
153160
# -------------------------------------------------------------------
154161

162+
def init_adk_tables(self) -> None:
163+
"""创建 Google ADK 所需的全部表和索引(同步)。
164+
165+
包含核心表(Conversation + Event + 二级索引)、三级 State 表
166+
(state / app_state / user_state)以及多元索引。
167+
表或索引已存在时跳过,可重复调用。
168+
"""
169+
self._backend.init_core_tables()
170+
self._backend.init_state_tables()
171+
self._backend.init_search_index()
172+
173+
# -------------------------------------------------------------------
174+
# Checkpoint 管理(LangGraph)(同步)
175+
# -------------------------------------------------------------------
176+
155177
async def put_checkpoint_async(
156178
self,
157179
thread_id: str,
@@ -366,7 +388,7 @@ async def delete_thread_checkpoints_async(
366388
await self._backend.delete_thread_checkpoints_async(thread_id)
367389

368390
# -------------------------------------------------------------------
369-
# Checkpoint 清理(同步)
391+
# Session 管理(异步)/ Session management (async)
370392
# -------------------------------------------------------------------
371393

372394
def delete_thread_checkpoints(
@@ -377,7 +399,7 @@ def delete_thread_checkpoints(
377399
self._backend.delete_thread_checkpoints(thread_id)
378400

379401
# -------------------------------------------------------------------
380-
# Session 管理(异步)/ Session management (async)
402+
# Session 管理(同步)/ Session management (async)
381403
# -------------------------------------------------------------------
382404

383405
async def create_session_async(
@@ -426,10 +448,6 @@ async def create_session_async(
426448
await self._backend.put_session_async(session)
427449
return session
428450

429-
# -------------------------------------------------------------------
430-
# Session 管理(同步)/ Session management (sync)
431-
# -------------------------------------------------------------------
432-
433451
def create_session(
434452
self,
435453
agent_id: str,

agentrun/conversation_service/utils.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,8 @@
1010
from typing import Any, TYPE_CHECKING
1111

1212
if TYPE_CHECKING:
13-
from tablestore import (
14-
AsyncOTSClient, # type: ignore[import-untyped]
15-
OTSClient,
16-
)
13+
from tablestore import AsyncOTSClient # type: ignore[import-untyped]
14+
from tablestore import OTSClient
1715

1816
# OTS 单个属性列值上限为 2MB,留 0.5MB 余量(按字符数计)
1917
MAX_COLUMN_SIZE: int = 1_500_000 # 1.5M 字符

examples/conversation_service_adk_server.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""Google ADK Agent Server —— 使用 OTSSessionService 持久化会话。
22
33
集成步骤:
4-
Step 1: 初始化 SessionStore(OTS 后端)
4+
Step 1: 初始化 SessionStore + 创建 ADK 所需表和索引
55
Step 2: 创建 OTSSessionService
66
Step 3: 创建 ADK Agent + Runner,传入 session_service
77
Step 4: 实现 invoke_agent,将 AgentRequest 转为 ADK 调用并流式输出
@@ -71,10 +71,10 @@ def get_session_state(tool_context: ToolContext) -> dict[str, Any]:
7171
return tool_context.state.to_dict()
7272

7373

74-
# ── Step 1: 初始化 SessionStore ──────────────────────────────
74+
# ── Step 1: 初始化 SessionStore + 创建 ADK 所需表和索引 ────
7575

7676
store = SessionStore.from_memory_collection(MEMORY_COLLECTION_NAME)
77-
store.init_tables()
77+
store.init_adk_tables()
7878

7979
# ── Step 2: 创建 OTSSessionService ──────────────────────────
8080

0 commit comments

Comments
 (0)