重构:通讯录子图支持 async 和 API 注入工厂模式
Some checks failed
构建并部署 AI Agent 服务 / deploy (push) Has been cancelled
Some checks failed
构建并部署 AI Agent 服务 / deploy (push) Has been cancelled
This commit is contained in:
@@ -1,32 +1,55 @@
|
||||
"""
|
||||
通讯录子图构建器
|
||||
Contact Subgraph Builder
|
||||
支持 API 注入的工厂模式
|
||||
"""
|
||||
|
||||
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
|
||||
)
|
||||
from .nodes import create_contact_nodes
|
||||
|
||||
|
||||
def build_contact_subgraph() -> StateGraph:
|
||||
def build_contact_subgraph(contact_api=None):
|
||||
"""
|
||||
构建通讯录子图
|
||||
构建通讯录子图(工厂模式)
|
||||
|
||||
Args:
|
||||
contact_api: 可选的 ContactAPIClient 实例(支持真实数据库或模拟模式)
|
||||
不传入则使用默认模拟 API(向后兼容)
|
||||
|
||||
Returns:
|
||||
配置好的 StateGraph
|
||||
"""
|
||||
# 创建节点(传入 API)
|
||||
nodes = create_contact_nodes(contact_api) if contact_api else None
|
||||
|
||||
# 如果没有传入 API,使用向后兼容的导入
|
||||
if nodes is None:
|
||||
from .nodes import (
|
||||
parse_intent,
|
||||
list_contacts,
|
||||
add_contact,
|
||||
list_emails,
|
||||
generate_email_draft,
|
||||
human_review,
|
||||
send_email,
|
||||
sniff_contacts,
|
||||
format_result,
|
||||
should_continue
|
||||
)
|
||||
else:
|
||||
parse_intent = nodes["parse_intent"]
|
||||
list_contacts = nodes["list_contacts"]
|
||||
add_contact = nodes["add_contact"]
|
||||
list_emails = nodes["list_emails"]
|
||||
generate_email_draft = nodes["generate_email_draft"]
|
||||
human_review = nodes["human_review"]
|
||||
send_email = nodes["send_email"]
|
||||
sniff_contacts = nodes["sniff_contacts"]
|
||||
format_result = nodes["format_result"]
|
||||
should_continue = nodes["should_continue"]
|
||||
|
||||
# 创建图
|
||||
graph = StateGraph(ContactState)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user