Skip to content

Commit 14340d1

Browse files
committed
fix(conversation_service): 按 PR review 修复 init 链、注释与测试
- LangChain 异步 init 仅创建 Conversation 多元索引(与同步一致) - model.py:澄清写入 API(PutRow/UpdateRow/BatchWriteRow)与 state 三表共享版本号 - 模板分段注释去掉「异步」后缀,避免 codegen 后标题与代码错位;已 make codegen - 新增 TestSchemaVersionSync 覆盖同步 put_* 的 _schema_version 断言 类型检查:uv run mypy --config-file mypy.ini agentrun tests — 通过,310 个源文件 Made-with: Cursor
1 parent b5e5d76 commit 14340d1

6 files changed

Lines changed: 128 additions & 38 deletions

File tree

agentrun/conversation_service/__ots_backend_async_template.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ def __init__(
120120
)
121121

122122
# -----------------------------------------------------------------------
123-
# 建表(异步)/ Table creation (async)
123+
# 建表 / Table creation
124124
# -----------------------------------------------------------------------
125125

126126
async def init_tables_async(self) -> None:
@@ -609,7 +609,7 @@ async def _create_state_search_index_async(self) -> None:
609609
raise
610610

611611
# -----------------------------------------------------------------------
612-
# Session CRUD(异步)/ Session CRUD (async)
612+
# Session CRUD
613613
# -----------------------------------------------------------------------
614614

615615
async def put_session_async(self, session: ConversationSession) -> None:
@@ -961,7 +961,7 @@ async def search_sessions_async(
961961
return sessions, search_response.total_count or 0
962962

963963
# -----------------------------------------------------------------------
964-
# Event CRUD(异步)/ Event CRUD (async)
964+
# Event CRUD
965965
# -----------------------------------------------------------------------
966966

967967
async def put_event_async(
@@ -1187,7 +1187,7 @@ async def delete_events_by_session_async(
11871187
return deleted
11881188

11891189
# -----------------------------------------------------------------------
1190-
# State CRUD(JSON 字符串存储 + 列分片)(异步)
1190+
# State CRUD(JSON 字符串存储 + 列分片)
11911191
# -----------------------------------------------------------------------
11921192

11931193
async def put_state_async(
@@ -1345,7 +1345,7 @@ async def delete_state_row_async(
13451345
await self._async_client.delete_row(table_name, row, condition)
13461346

13471347
# -----------------------------------------------------------------------
1348-
# Checkpoint CRUD(LangGraph)(异步)
1348+
# Checkpoint CRUD(LangGraph)
13491349
# -----------------------------------------------------------------------
13501350

13511351
async def put_checkpoint_async(
@@ -1767,7 +1767,7 @@ async def _scan_and_delete_async(
17671767
await self._async_client.batch_write_row(request)
17681768

17691769
# -----------------------------------------------------------------------
1770-
# 内部辅助方法(I/O 相关,异步
1770+
# 内部辅助方法(I/O 相关)
17711771
# -----------------------------------------------------------------------
17721772

17731773
async def _get_chunk_count_async(

agentrun/conversation_service/__session_store_async_template.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ async def init_adk_tables_async(self) -> None:
9696
await self._backend.init_search_index_async()
9797

9898
# -------------------------------------------------------------------
99-
# Checkpoint 管理(LangGraph)(异步)
99+
# Checkpoint 管理(LangGraph)
100100
# -------------------------------------------------------------------
101101

102102
async def put_checkpoint_async(
@@ -210,7 +210,7 @@ async def delete_thread_checkpoints_async(
210210
await self._backend.delete_thread_checkpoints_async(thread_id)
211211

212212
# -------------------------------------------------------------------
213-
# Session 管理(异步)/ Session management (async)
213+
# Session 管理 / Session management
214214
# -------------------------------------------------------------------
215215

216216
async def create_session_async(
@@ -496,7 +496,7 @@ async def update_session_async(
496496
)
497497

498498
# -------------------------------------------------------------------
499-
# Event 管理(异步)/ Event management (async)
499+
# Event 管理 / Event management
500500
# -------------------------------------------------------------------
501501

502502
async def append_event_async(
@@ -631,7 +631,7 @@ async def get_recent_events_async(
631631
return events
632632

633633
# -------------------------------------------------------------------
634-
# State 管理(异步)/ State management (async)
634+
# State 管理 / State management
635635
# -------------------------------------------------------------------
636636

637637
async def get_session_state_async(
@@ -746,7 +746,7 @@ async def get_merged_state_async(
746746
return merged
747747

748748
# -------------------------------------------------------------------
749-
# 内部辅助方法(异步)
749+
# 内部辅助方法
750750
# -------------------------------------------------------------------
751751

752752
async def _apply_delta_async(
@@ -802,7 +802,7 @@ async def _apply_delta_async(
802802
)
803803

804804
# -------------------------------------------------------------------
805-
# 工厂方法(异步)/ Factory methods (async)
805+
# 工厂方法 / Factory methods
806806
# -------------------------------------------------------------------
807807

808808
@classmethod

agentrun/conversation_service/model.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,16 @@
3131
# ---------------------------------------------------------------------------
3232
# OTS Schema 版本管理
3333
#
34-
# 每张表独立计数,用于 SDK 写入端与 Core 读取端(funagent-core)的兼容性协调。
35-
# 每次 PutRow 时在 attribute_columns 中写入 _schema_version 字段。
34+
# 用于 SDK 写入端与 Core 读取端(funagent-core)的兼容性协调。
35+
# 每次写入行(PutRow / UpdateRow / BatchWriteRow)时在
36+
# attribute_columns 中携带 _schema_version 字段。
3637
# Core 端读取时检查该字段,版本不匹配时打 WARN 日志并尽力解析。
3738
# 历史数据(无此字段)视为 v0。
3839
#
40+
# 版本计数规则:
41+
# - 大部分表独立计数
42+
# - state / app_state / user_state 三张表共享 STATE_SCHEMA_VERSION
43+
#
3944
# 升级流程:
4045
# 1. 递增对应表的 *_SCHEMA_VERSION 常量
4146
# 2. 在 PR 描述中记录变更的列名/类型/语义

agentrun/conversation_service/ots_backend.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ def __init__(
130130
)
131131

132132
# -----------------------------------------------------------------------
133-
# 建表(异步)/ Table creation (async)
133+
# 建表 / Table creation
134134
# -----------------------------------------------------------------------
135135

136136
async def init_tables_async(self) -> None:
@@ -1023,7 +1023,7 @@ async def _create_state_search_index_async(self) -> None:
10231023
raise
10241024

10251025
# -----------------------------------------------------------------------
1026-
# Session CRUD(异步)/ Session CRUD (async)
1026+
# Session CRUD
10271027
# -----------------------------------------------------------------------
10281028

10291029
def _create_state_search_index(self) -> None:
@@ -1108,7 +1108,7 @@ def _create_state_search_index(self) -> None:
11081108
raise
11091109

11101110
# -----------------------------------------------------------------------
1111-
# Session CRUD(同步)/ Session CRUD (async)
1111+
# Session CRUD
11121112
# -----------------------------------------------------------------------
11131113

11141114
async def put_session_async(self, session: ConversationSession) -> None:
@@ -1697,7 +1697,7 @@ async def search_sessions_async(
16971697
return sessions, search_response.total_count or 0
16981698

16991699
# -----------------------------------------------------------------------
1700-
# Event CRUD(异步)/ Event CRUD (async)
1700+
# Event CRUD
17011701
# -----------------------------------------------------------------------
17021702

17031703
def search_sessions(
@@ -1806,7 +1806,7 @@ def search_sessions(
18061806
return sessions, search_response.total_count or 0
18071807

18081808
# -----------------------------------------------------------------------
1809-
# Event CRUD(同步)/ Event CRUD (async)
1809+
# Event CRUD
18101810
# -----------------------------------------------------------------------
18111811

18121812
async def put_event_async(
@@ -2183,7 +2183,7 @@ async def delete_events_by_session_async(
21832183
return deleted
21842184

21852185
# -----------------------------------------------------------------------
2186-
# State CRUD(JSON 字符串存储 + 列分片)(异步)
2186+
# State CRUD(JSON 字符串存储 + 列分片)
21872187
# -----------------------------------------------------------------------
21882188

21892189
def delete_events_by_session(
@@ -2258,7 +2258,7 @@ def delete_events_by_session(
22582258
return deleted
22592259

22602260
# -----------------------------------------------------------------------
2261-
# State CRUD(JSON 字符串存储 + 列分片)(同步)
2261+
# State CRUD(JSON 字符串存储 + 列分片)
22622262
# -----------------------------------------------------------------------
22632263

22642264
async def put_state_async(
@@ -2553,7 +2553,7 @@ async def delete_state_row_async(
25532553
await self._async_client.delete_row(table_name, row, condition)
25542554

25552555
# -----------------------------------------------------------------------
2556-
# Checkpoint CRUD(LangGraph)(异步)
2556+
# Checkpoint CRUD(LangGraph)
25572557
# -----------------------------------------------------------------------
25582558

25592559
def delete_state_row(
@@ -2572,7 +2572,7 @@ def delete_state_row(
25722572
self._client.delete_row(table_name, row, condition)
25732573

25742574
# -----------------------------------------------------------------------
2575-
# Checkpoint CRUD(LangGraph)(同步)
2575+
# Checkpoint CRUD(LangGraph)
25762576
# -----------------------------------------------------------------------
25772577

25782578
async def put_checkpoint_async(
@@ -3370,7 +3370,7 @@ async def _scan_and_delete_async(
33703370
await self._async_client.batch_write_row(request)
33713371

33723372
# -----------------------------------------------------------------------
3373-
# 内部辅助方法(I/O 相关,异步
3373+
# 内部辅助方法(I/O 相关)
33743374
# -----------------------------------------------------------------------
33753375

33763376
def _scan_and_delete(
@@ -3414,7 +3414,7 @@ def _scan_and_delete(
34143414
self._client.batch_write_row(request)
34153415

34163416
# -----------------------------------------------------------------------
3417-
# 内部辅助方法(I/O 相关,同步
3417+
# 内部辅助方法(I/O 相关)
34183418
# -----------------------------------------------------------------------
34193419

34203420
async def _get_chunk_count_async(

agentrun/conversation_service/session_store.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ async def init_adk_tables_async(self) -> None:
156156
await self._backend.init_search_index_async()
157157

158158
# -------------------------------------------------------------------
159-
# Checkpoint 管理(LangGraph)(异步)
159+
# Checkpoint 管理(LangGraph)
160160
# -------------------------------------------------------------------
161161

162162
def init_adk_tables(self) -> None:
@@ -171,7 +171,7 @@ def init_adk_tables(self) -> None:
171171
self._backend.init_search_index()
172172

173173
# -------------------------------------------------------------------
174-
# Checkpoint 管理(LangGraph)(同步)
174+
# Checkpoint 管理(LangGraph)
175175
# -------------------------------------------------------------------
176176

177177
async def put_checkpoint_async(
@@ -388,7 +388,7 @@ async def delete_thread_checkpoints_async(
388388
await self._backend.delete_thread_checkpoints_async(thread_id)
389389

390390
# -------------------------------------------------------------------
391-
# Session 管理(异步)/ Session management (async)
391+
# Session 管理 / Session management
392392
# -------------------------------------------------------------------
393393

394394
def delete_thread_checkpoints(
@@ -399,7 +399,7 @@ def delete_thread_checkpoints(
399399
self._backend.delete_thread_checkpoints(thread_id)
400400

401401
# -------------------------------------------------------------------
402-
# Session 管理(同步)/ Session management (async)
402+
# Session 管理 / Session management
403403
# -------------------------------------------------------------------
404404

405405
async def create_session_async(
@@ -909,7 +909,7 @@ async def update_session_async(
909909
)
910910

911911
# -------------------------------------------------------------------
912-
# Event 管理(异步)/ Event management (async)
912+
# Event 管理 / Event management
913913
# -------------------------------------------------------------------
914914

915915
def update_session(
@@ -965,7 +965,7 @@ def update_session(
965965
)
966966

967967
# -------------------------------------------------------------------
968-
# Event 管理(同步)/ Event management (async)
968+
# Event 管理 / Event management
969969
# -------------------------------------------------------------------
970970

971971
async def append_event_async(
@@ -1199,7 +1199,7 @@ async def get_recent_events_async(
11991199
return events
12001200

12011201
# -------------------------------------------------------------------
1202-
# State 管理(异步)/ State management (async)
1202+
# State 管理 / State management
12031203
# -------------------------------------------------------------------
12041204

12051205
def get_recent_events(
@@ -1233,7 +1233,7 @@ def get_recent_events(
12331233
return events
12341234

12351235
# -------------------------------------------------------------------
1236-
# State 管理(同步)/ State management (async)
1236+
# State 管理 / State management
12371237
# -------------------------------------------------------------------
12381238

12391239
async def get_session_state_async(
@@ -1429,7 +1429,7 @@ async def get_merged_state_async(
14291429
return merged
14301430

14311431
# -------------------------------------------------------------------
1432-
# 内部辅助方法(异步)
1432+
# 内部辅助方法
14331433
# -------------------------------------------------------------------
14341434

14351435
def get_merged_state(
@@ -1457,7 +1457,7 @@ def get_merged_state(
14571457
return merged
14581458

14591459
# -------------------------------------------------------------------
1460-
# 内部辅助方法(同步)
1460+
# 内部辅助方法
14611461
# -------------------------------------------------------------------
14621462

14631463
async def _apply_delta_async(
@@ -1513,7 +1513,7 @@ async def _apply_delta_async(
15131513
)
15141514

15151515
# -------------------------------------------------------------------
1516-
# 工厂方法(异步)/ Factory methods (async)
1516+
# 工厂方法 / Factory methods
15171517
# -------------------------------------------------------------------
15181518

15191519
def _apply_delta(
@@ -1567,7 +1567,7 @@ def _apply_delta(
15671567
)
15681568

15691569
# -------------------------------------------------------------------
1570-
# 工厂方法(同步)/ Factory methods (async)
1570+
# 工厂方法 / Factory methods
15711571
# -------------------------------------------------------------------
15721572

15731573
@classmethod

0 commit comments

Comments
 (0)