feat:接入mongodb

This commit is contained in:
2026-09-30 04:27:35 -07:00
parent f92909ccda
commit 16212d7138
11 changed files with 663 additions and 43 deletions
+28 -26
View File
@@ -23,6 +23,32 @@ from app.processor.nodes.wait_for_user_node import WaitForUserNode
from app.processor.state import QueryState
def build_checkpoint_serde() -> JsonPlusSerializer:
# 允许恢复状态中使用的业务模型类型,使检查点读取后仍可按模型对象访问字段
# 内存与持久化检查点共用,否则持久化读回的状态无法还原为模型对象
return JsonPlusSerializer(
allowed_msgpack_modules=[
("app.schemas.input_context", "InputContext"),
("app.schemas.decision", "DecisionResponse"),
("app.schemas.requirement", "Requirement"),
("app.schemas.change_scope", "ChangeScope"),
("app.schemas.screen_plan", "ScreenPlan"),
("app.schemas.component_resource", "ComponentResult"),
("app.schemas.actions.add", "AddAction"),
("app.schemas.actions.delete", "DeleteAction"),
("app.schemas.actions.move", "MoveAction"),
("app.schemas.actions.resize", "ResizeAction"),
("app.schemas.actions.update", "UpdateAction"),
("app.schemas.actions.update_canvas", "UpdateCanvasAction"),
("app.schemas.action_validation", "ActionValidationError"),
("app.schemas.action_repair", "ActionRepairPlan"),
("app.schemas.screen", "Screen"),
("app.schemas.clarification", "Clarification"),
("app.schemas.clarification_reply", "ClarificationReply"),
]
)
def route_after_intent(state: QueryState) -> str:
# 按最终意图分流:问答进入 QA,意图不明进入澄清,新建或修改进入需求理解
return state["intent"]
@@ -222,34 +248,10 @@ def build_graph(checkpointer=None):
{"input_node": "input_node", END: END},
)
# TODO 本地默认保存在内存,可传入持久化 checkpointer
# 仅在调用方未提供检查点存储时创建默认实现,外部传入的存储直接复用
# 仅在调用方未提供检查点存储时创建默认实现,外部传入的持久化存储(如 MongoDB)直接复用
if checkpointer is None:
# 允许恢复状态中使用的业务模型类型,使检查点读取后仍可按模型对象访问字段
serde = JsonPlusSerializer(
allowed_msgpack_modules=[
("app.schemas.input_context", "InputContext"),
("app.schemas.decision", "DecisionResponse"),
("app.schemas.requirement", "Requirement"),
("app.schemas.change_scope", "ChangeScope"),
("app.schemas.screen_plan", "ScreenPlan"),
("app.schemas.component_resource", "ComponentResult"),
("app.schemas.actions.add", "AddAction"),
("app.schemas.actions.delete", "DeleteAction"),
("app.schemas.actions.move", "MoveAction"),
("app.schemas.actions.resize", "ResizeAction"),
("app.schemas.actions.update", "UpdateAction"),
("app.schemas.actions.update_canvas", "UpdateCanvasAction"),
("app.schemas.action_validation", "ActionValidationError"),
("app.schemas.action_repair", "ActionRepairPlan"),
("app.schemas.screen", "Screen"),
("app.schemas.clarification", "Clarification"),
("app.schemas.clarification_reply", "ClarificationReply"),
]
)
# 将检查点保存在当前进程内存中,支持暂停恢复,但进程退出后不会保留
checkpointer = InMemorySaver(serde=serde)
checkpointer = InMemorySaver(serde=build_checkpoint_serde())
# 编译节点和边,并绑定检查点存储,供执行时按 thread_id 保存和恢复状态
return workflow.compile(checkpointer=checkpointer).with_config(