This commit is contained in:
@@ -172,5 +172,59 @@ def format_result(state: ContactState) -> ContactState:
|
||||
state.final_result = "\n".join(output_lines)
|
||||
state.success = True
|
||||
state.current_phase = "completed"
|
||||
|
||||
|
||||
return state
|
||||
|
||||
|
||||
def human_review(state: ContactState) -> ContactState:
|
||||
"""
|
||||
人工审核节点(用于邮件草稿)
|
||||
"""
|
||||
state.current_phase = "reviewing"
|
||||
# 标记需要审核,等待用户决定
|
||||
state.needs_approval = True
|
||||
return state
|
||||
|
||||
|
||||
def send_email(state: ContactState) -> ContactState:
|
||||
"""
|
||||
发送邮件节点
|
||||
"""
|
||||
state.current_phase = "executing"
|
||||
# 使用 API 客户端发送邮件
|
||||
success = contact_api.send_email(
|
||||
state.user_id,
|
||||
state.draft_recipient,
|
||||
state.draft_subject,
|
||||
state.draft_body
|
||||
)
|
||||
state.success = success
|
||||
return state
|
||||
|
||||
|
||||
def should_continue(state: ContactState) -> str:
|
||||
"""
|
||||
条件路由函数:根据 action 和状态决定下一个节点
|
||||
"""
|
||||
# 如果是从 human_review 来的,根据审核状态决定
|
||||
if state.current_phase == "reviewing":
|
||||
if state.needs_approval:
|
||||
# 这里会等待用户操作,实际运行时通过 checkpointer 或后端 API 处理
|
||||
return "format_result"
|
||||
else:
|
||||
return "send_email"
|
||||
|
||||
# 普通路由
|
||||
action = state.action
|
||||
if action == ContactAction.CONTACT_LIST:
|
||||
return "list_contacts"
|
||||
elif action == ContactAction.CONTACT_ADD:
|
||||
return "add_contact"
|
||||
elif action == ContactAction.EMAIL_LIST:
|
||||
return "list_emails"
|
||||
elif action == ContactAction.EMAIL_SEND:
|
||||
return "generate_email_draft"
|
||||
elif action == ContactAction.SNIFF_CONTACTS:
|
||||
return "sniff_contacts"
|
||||
else:
|
||||
return "format_result"
|
||||
|
||||
Reference in New Issue
Block a user