Some checks failed
构建并部署 AI Agent 服务 / deploy (push) Failing after 6m5s
- 完善词典子图:添加生词本功能 - 创建API调用工具:dictionary_api - 添加前端格式化展示工具:result_formatter.py - 创建通讯录和资讯子图的基本结构 - 更新主图状态结构,添加MainGraphState - 添加subgraph_builder.py用于子图集成
87 lines
2.2 KiB
Python
87 lines
2.2 KiB
Python
"""
|
|
通讯录子图构建器
|
|
Contact Subgraph Builder
|
|
"""
|
|
|
|
from langgraph.graph import StateGraph, START, END
|
|
|
|
from .state import ContactState
|
|
from .nodes import (
|
|
parse_intent,
|
|
list_contacts,
|
|
add_contact,
|
|
list_emails,
|
|
generate_email_draft,
|
|
human_review,
|
|
send_email,
|
|
sniff_contacts,
|
|
format_result,
|
|
should_continue
|
|
)
|
|
|
|
|
|
def build_contact_subgraph() -> StateGraph:
|
|
"""
|
|
构建通讯录子图
|
|
|
|
Returns:
|
|
配置好的 StateGraph
|
|
"""
|
|
# 创建图
|
|
graph = StateGraph(ContactState)
|
|
|
|
# 添加节点
|
|
graph.add_node("parse_intent", parse_intent)
|
|
graph.add_node("list_contacts", list_contacts)
|
|
graph.add_node("add_contact", add_contact)
|
|
graph.add_node("list_emails", list_emails)
|
|
graph.add_node("generate_email_draft", generate_email_draft)
|
|
graph.add_node("human_review", human_review)
|
|
graph.add_node("send_email", send_email)
|
|
graph.add_node("sniff_contacts", sniff_contacts)
|
|
graph.add_node("format_result", format_result)
|
|
|
|
# 添加边
|
|
# 从START开始
|
|
graph.add_edge(START, "parse_intent")
|
|
|
|
# 从parse_intent根据条件路由
|
|
graph.add_conditional_edges(
|
|
"parse_intent",
|
|
should_continue,
|
|
{
|
|
"list_contacts": "list_contacts",
|
|
"add_contact": "add_contact",
|
|
"list_emails": "list_emails",
|
|
"generate_email_draft": "generate_email_draft",
|
|
"sniff_contacts": "sniff_contacts",
|
|
}
|
|
)
|
|
|
|
# 从各个操作节点到format_result
|
|
graph.add_edge("list_contacts", "format_result")
|
|
graph.add_edge("add_contact", "format_result")
|
|
graph.add_edge("list_emails", "format_result")
|
|
graph.add_edge("sniff_contacts", "format_result")
|
|
|
|
# 邮件发送的特殊流程
|
|
graph.add_edge("generate_email_draft", "human_review")
|
|
|
|
# 从human_review根据条件路由
|
|
graph.add_conditional_edges(
|
|
"human_review",
|
|
should_continue,
|
|
{
|
|
"send_email": "send_email",
|
|
"format_result": "format_result",
|
|
}
|
|
)
|
|
|
|
# 发送邮件后到格式化
|
|
graph.add_edge("send_email", "format_result")
|
|
|
|
# 最终到END
|
|
graph.add_edge("format_result", END)
|
|
|
|
return graph
|