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:
63
backend/app/agent_subgraphs/news_analysis/graph.py
Normal file
63
backend/app/agent_subgraphs/news_analysis/graph.py
Normal file
@@ -0,0 +1,63 @@
|
||||
"""
|
||||
资讯子图构建器
|
||||
News Analysis Subgraph Builder
|
||||
"""
|
||||
|
||||
from langgraph.graph import StateGraph, START, END
|
||||
|
||||
from .state import NewsAnalysisState
|
||||
from .nodes import (
|
||||
parse_intent,
|
||||
query_news,
|
||||
analyze_url,
|
||||
extract_keywords,
|
||||
generate_report,
|
||||
format_result,
|
||||
should_continue
|
||||
)
|
||||
|
||||
|
||||
def build_news_analysis_subgraph() -> StateGraph:
|
||||
"""
|
||||
构建资讯子图
|
||||
|
||||
Returns:
|
||||
配置好的 StateGraph
|
||||
"""
|
||||
# 创建图
|
||||
graph = StateGraph(NewsAnalysisState)
|
||||
|
||||
# 添加节点
|
||||
graph.add_node("parse_intent", parse_intent)
|
||||
graph.add_node("query_news", query_news)
|
||||
graph.add_node("analyze_url", analyze_url)
|
||||
graph.add_node("extract_keywords", extract_keywords)
|
||||
graph.add_node("generate_report", generate_report)
|
||||
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_news": "query_news",
|
||||
"analyze_url": "analyze_url",
|
||||
"extract_keywords": "extract_keywords",
|
||||
"generate_report": "generate_report",
|
||||
}
|
||||
)
|
||||
|
||||
# 从各个操作节点到format_result
|
||||
graph.add_edge("query_news", "format_result")
|
||||
graph.add_edge("analyze_url", "format_result")
|
||||
graph.add_edge("extract_keywords", "format_result")
|
||||
graph.add_edge("generate_report", "format_result")
|
||||
|
||||
# 最终到END
|
||||
graph.add_edge("format_result", END)
|
||||
|
||||
return graph
|
||||
Reference in New Issue
Block a user