Files
inquiry_robot/inquiry-agent/agent/graph/builder.py
T

77 lines
2.5 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""
装配询价 StateGraph(骨架线性流水线)。
本文件职责:把分文件节点串成一张图并 compile;不写业务分支。
停点:interrupt_before=INTERRUPT_BEFORE(见 pauses.py)。
禁止:单文件堆全部节点实现;禁止在本文件调企微 / soffice。
"""
from __future__ import annotations
import logging
from typing import Any
from langgraph.graph import END, START, StateGraph
from agent.graph import nodes as graph_nodes
from agent.graph.pauses import (
INTERRUPT_BEFORE,
PAUSE_ADOPT_ADJUST,
PAUSE_CLOSE_DEAL,
PAUSE_COLLABORATE,
PAUSE_CREATE_ORDER,
PAUSE_GENERATE_QUOTE,
PAUSE_PARSE_CLARIFY,
PAUSE_QUERY_QUOTE,
)
from agent.graph.state import InquiryGraphState
logger = logging.getLogger(__name__)
def build_state_graph() -> StateGraph:
"""
构建未编译的状态图。
节点顺序对齐 prompt/14:解析/补问 → 建单 → 查价 → 协同 → 报价 → 采用/调价 → 成交。
骨架为直线边;后续可加条件边,勿在此塞主账逻辑。
"""
g: StateGraph = StateGraph(InquiryGraphState)
g.add_node(PAUSE_PARSE_CLARIFY, graph_nodes.node_parse_clarify)
g.add_node(PAUSE_CREATE_ORDER, graph_nodes.node_create_order)
g.add_node(PAUSE_QUERY_QUOTE, graph_nodes.node_query_quote)
g.add_node(PAUSE_COLLABORATE, graph_nodes.node_collaborate)
g.add_node(PAUSE_GENERATE_QUOTE, graph_nodes.node_generate_quote)
g.add_node(PAUSE_ADOPT_ADJUST, graph_nodes.node_adopt_adjust)
g.add_node(PAUSE_CLOSE_DEAL, graph_nodes.node_close_deal)
g.add_edge(START, PAUSE_PARSE_CLARIFY)
g.add_edge(PAUSE_PARSE_CLARIFY, PAUSE_CREATE_ORDER)
g.add_edge(PAUSE_CREATE_ORDER, PAUSE_QUERY_QUOTE)
g.add_edge(PAUSE_QUERY_QUOTE, PAUSE_COLLABORATE)
g.add_edge(PAUSE_COLLABORATE, PAUSE_GENERATE_QUOTE)
g.add_edge(PAUSE_GENERATE_QUOTE, PAUSE_ADOPT_ADJUST)
g.add_edge(PAUSE_ADOPT_ADJUST, PAUSE_CLOSE_DEAL)
g.add_edge(PAUSE_CLOSE_DEAL, END)
return g
def compile_inquiry_graph(*, checkpointer: Any) -> Any:
"""
编译可执行图。
参数:LangGraph checkpointer(Postgres 或 Memory)。
返回:CompiledGraph;带 interrupt_before。
线程:应在 Worker 启动线程调用一次,缓存复用。
"""
graph = build_state_graph()
compiled = graph.compile(
checkpointer=checkpointer,
interrupt_before=list(INTERRUPT_BEFORE),
)
logger.info(
"询价 Graph 已编译 interrupt_before=%s",
list(INTERRUPT_BEFORE),
)
return compiled