feat: 完善词典子图,添加API调用和前端格式化工具
Some checks failed
构建并部署 AI Agent 服务 / deploy (push) Failing after 6m5s
Some checks failed
构建并部署 AI Agent 服务 / deploy (push) Failing after 6m5s
- 完善词典子图:添加生词本功能 - 创建API调用工具:dictionary_api - 添加前端格式化展示工具:result_formatter.py - 创建通讯录和资讯子图的基本结构 - 更新主图状态结构,添加MainGraphState - 添加subgraph_builder.py用于子图集成
This commit is contained in:
71
backend/app/agent_subgraphs/dictionary/graph.py
Normal file
71
backend/app/agent_subgraphs/dictionary/graph.py
Normal file
@@ -0,0 +1,71 @@
|
||||
"""
|
||||
词典子图构建器 - 完善版
|
||||
Dictionary Subgraph Builder - Complete
|
||||
"""
|
||||
|
||||
from langgraph.graph import StateGraph, START, END
|
||||
|
||||
from .state import DictionaryState
|
||||
from .nodes import (
|
||||
parse_intent,
|
||||
query_word,
|
||||
translate_text,
|
||||
extract_terms,
|
||||
get_daily_word,
|
||||
lookup_word_book,
|
||||
add_to_word_book,
|
||||
format_result,
|
||||
should_continue
|
||||
)
|
||||
|
||||
|
||||
def build_dictionary_subgraph() -> StateGraph:
|
||||
"""
|
||||
构建词典子图
|
||||
|
||||
Returns:
|
||||
配置好的 StateGraph
|
||||
"""
|
||||
# 创建图
|
||||
graph = StateGraph(DictionaryState)
|
||||
|
||||
# 添加节点
|
||||
graph.add_node("parse_intent", parse_intent)
|
||||
graph.add_node("query_word", query_word)
|
||||
graph.add_node("translate_text", translate_text)
|
||||
graph.add_node("extract_terms", extract_terms)
|
||||
graph.add_node("get_daily_word", get_daily_word)
|
||||
graph.add_node("lookup_word_book", lookup_word_book)
|
||||
graph.add_node("add_to_word_book", add_to_word_book)
|
||||
graph.add_node("format_result", format_result)
|
||||
|
||||
# 添加边
|
||||
# 从START开始
|
||||
graph.add_edge(START, "parse_intent")
|
||||
|
||||
# 从parse_intent根据条件路由
|
||||
graph.add_conditional_edges(
|
||||
"parse_intent",
|
||||
should_continue,
|
||||
{
|
||||
"query_word": "query_word",
|
||||
"translate_text": "translate_text",
|
||||
"extract_terms": "extract_terms",
|
||||
"get_daily_word": "get_daily_word",
|
||||
"lookup_word_book": "lookup_word_book",
|
||||
"add_to_word_book": "add_to_word_book",
|
||||
}
|
||||
)
|
||||
|
||||
# 从各个操作节点到format_result
|
||||
graph.add_edge("query_word", "format_result")
|
||||
graph.add_edge("translate_text", "format_result")
|
||||
graph.add_edge("extract_terms", "format_result")
|
||||
graph.add_edge("get_daily_word", "format_result")
|
||||
graph.add_edge("lookup_word_book", "format_result")
|
||||
graph.add_edge("add_to_word_book", "format_result")
|
||||
|
||||
# 最终到END
|
||||
graph.add_edge("format_result", END)
|
||||
|
||||
return graph
|
||||
Reference in New Issue
Block a user