-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_agentic.py
More file actions
41 lines (34 loc) · 1.28 KB
/
test_agentic.py
File metadata and controls
41 lines (34 loc) · 1.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
"""测试 Agentic RAG —— LangGraph 多智能体"""
import sys
sys.path.insert(0, '/home/zshyc/cer')
from dotenv import load_dotenv; load_dotenv('/home/zshyc/cer/.env')
from rag.graph.build_graph import build_tutor_graph, classify_query
print("Compiling graph...")
graph = build_tutor_graph()
print(f"Nodes: {list(graph.nodes.keys())}")
queries = [
"What is Rational Ship Structural Design?",
"计算正方形截面的形状系数",
]
for q in queries:
qtype = classify_query(q)
print(f"\n{'='*60}")
print(f"Q [{qtype}]: {q}")
print("="*60)
state = {
"query": q, "chat_history": [], "query_type": qtype,
"retrieval_attempts": 0, "retrieval_results": [],
"retrieval_sufficient": False,
"plan": [], "current_step": 0, "next_agent": "",
}
for step in graph.stream(state, {"recursion_limit": 20}):
node = list(step.keys())[0]
data = step[node]
plan = data.get("plan", [])
attempts = data.get("retrieval_attempts", 0)
ndocs = len(data.get("retrieval_results", []))
print(f" [{node}] plan={plan[:2]} docs={ndocs} retries={attempts}")
if node in ("concept", "calc"):
answer = data.get("final_answer", "")[:300]
print(f" Answer preview: {answer}...")
print()