feat:接入mongodb
This commit is contained in:
+28
-26
@@ -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(
|
||||
|
||||
@@ -69,6 +69,13 @@ class PlannerNode(BaseNode):
|
||||
feedback = f"上一次输出:\n{plan.model_dump_json()}\n\n{feedback}"
|
||||
messages = [*messages, HumanMessage(content=feedback)]
|
||||
|
||||
# 组件目录已在进入规划前完整获取,component 类资源需求不可能再有补充来源
|
||||
# 保留会让动作阶段误判为“待获取资源”而失败,能力缺口应由 assumptions 表达
|
||||
# TODO 接入数据源和 RAG 后,仅保留目录之外的资源需求
|
||||
plan.resource_needs = [
|
||||
need for need in plan.resource_needs if need.kind != "component"
|
||||
]
|
||||
|
||||
# 合并需求约束和规划约束,按首次出现顺序去重,保留需求约束在前
|
||||
plan.constraints = list(
|
||||
dict.fromkeys([*requirement.constraints, *plan.constraints])
|
||||
|
||||
Reference in New Issue
Block a user