Skip to content

Commit 49615ae

Browse files
committed
fix: address code review feedback on LangGraph checkpoint PR
- Fix sync/async section comment headers in ots_backend.py and session_store.py - Add langgraph optional dependency in pyproject.toml - Improve build_ots_clients return type annotation with TYPE_CHECKING import - Handle missing state table gracefully in init_search_index Made-with: Cursor
1 parent b4eaa7a commit 49615ae

File tree

4 files changed

+27
-8
lines changed

4 files changed

+27
-8
lines changed

agentrun/conversation_service/ots_backend.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2542,7 +2542,7 @@ async def delete_state_row_async(
25422542
await self._async_client.delete_row(table_name, row, condition)
25432543

25442544
# -----------------------------------------------------------------------
2545-
# Checkpoint CRUD(LangGraph)(异步
2545+
# State CRUD(同步
25462546
# -----------------------------------------------------------------------
25472547

25482548
def delete_state_row(
@@ -2561,7 +2561,7 @@ def delete_state_row(
25612561
self._client.delete_row(table_name, row, condition)
25622562

25632563
# -----------------------------------------------------------------------
2564-
# Checkpoint CRUD(LangGraph)(同步
2564+
# Checkpoint CRUD(LangGraph)(异步
25652565
# -----------------------------------------------------------------------
25662566

25672567
async def put_checkpoint_async(
@@ -2591,6 +2591,10 @@ async def put_checkpoint_async(
25912591
condition = Condition(RowExistenceExpectation.IGNORE)
25922592
await self._async_client.put_row(self._checkpoint_table, row, condition)
25932593

2594+
# -----------------------------------------------------------------------
2595+
# Checkpoint CRUD(LangGraph)(同步)
2596+
# -----------------------------------------------------------------------
2597+
25942598
def put_checkpoint(
25952599
self,
25962600
thread_id: str,

agentrun/conversation_service/session_store.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ async def init_langgraph_tables_async(self) -> None:
134134
await self._backend.init_checkpoint_tables_async()
135135

136136
# -------------------------------------------------------------------
137-
# Checkpoint 管理(LangGraph)(异步
137+
# Checkpoint 管理(LangGraph)(同步
138138
# -------------------------------------------------------------------
139139

140140
def init_langgraph_tables(self) -> None:
@@ -149,7 +149,7 @@ def init_langgraph_tables(self) -> None:
149149
self._backend.init_checkpoint_tables()
150150

151151
# -------------------------------------------------------------------
152-
# Checkpoint 管理(LangGraph)(同步
152+
# Checkpoint 管理(LangGraph)(异步
153153
# -------------------------------------------------------------------
154154

155155
async def put_checkpoint_async(
@@ -366,7 +366,7 @@ async def delete_thread_checkpoints_async(
366366
await self._backend.delete_thread_checkpoints_async(thread_id)
367367

368368
# -------------------------------------------------------------------
369-
# Session 管理(异步)/ Session management (async)
369+
# Checkpoint 清理(同步)
370370
# -------------------------------------------------------------------
371371

372372
def delete_thread_checkpoints(
@@ -377,7 +377,7 @@ def delete_thread_checkpoints(
377377
self._backend.delete_thread_checkpoints(thread_id)
378378

379379
# -------------------------------------------------------------------
380-
# Session 管理(同步)/ Session management (async)
380+
# Session 管理(异步)/ Session management (async)
381381
# -------------------------------------------------------------------
382382

383383
async def create_session_async(
@@ -426,6 +426,10 @@ async def create_session_async(
426426
await self._backend.put_session_async(session)
427427
return session
428428

429+
# -------------------------------------------------------------------
430+
# Session 管理(同步)/ Session management (sync)
431+
# -------------------------------------------------------------------
432+
429433
def create_session(
430434
self,
431435
agent_id: str,

agentrun/conversation_service/utils.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,13 @@
77

88
import json
99
import time
10-
from typing import Any
10+
from typing import Any, TYPE_CHECKING
11+
12+
if TYPE_CHECKING:
13+
from tablestore import (
14+
AsyncOTSClient, # type: ignore[import-untyped]
15+
OTSClient,
16+
)
1117

1218
# OTS 单个属性列值上限为 2MB,留 0.5MB 余量(按字符数计)
1319
MAX_COLUMN_SIZE: int = 1_500_000 # 1.5M 字符
@@ -106,7 +112,7 @@ def build_ots_clients(
106112
instance_name: str,
107113
*,
108114
sts_token: str | None = None,
109-
) -> tuple[Any, Any]:
115+
) -> tuple[OTSClient, AsyncOTSClient]:
110116
"""构建 OTSClient 和 AsyncOTSClient 实例。
111117
112118
独立于 codegen 模板,避免 AsyncOTSClient 被替换为 OTSClient。

pyproject.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,11 @@ tablestore = [
6363
"tablestore>=6.1.0",
6464
]
6565

66+
langgraph = [
67+
"langgraph>=0.2.0; python_version >= '3.10'",
68+
"langchain-core>=0.3.0; python_version >= '3.10'",
69+
]
70+
6671
[dependency-groups]
6772
dev = [
6873
"coverage>=7.10.7",

0 commit comments

Comments
 (0)