-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
121 lines (95 loc) · 3.84 KB
/
main.py
File metadata and controls
121 lines (95 loc) · 3.84 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
"""FootballGPT — AI Football Analysis Platform with Multi-Agent Collaboration."""
import time
import uuid
from rich.console import Console
from rich.markdown import Markdown
from rich.panel import Panel
from graph.workflow import build_workflow
console = Console()
def display_banner():
banner = """
⚽ **FootballGPT** — AI Football Intelligence Platform
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Multi-Agent System: Router → Scout → Analyst → Tactics → Reporter
Example queries:
• Find a right winger for Liverpool, under 25, fast
• Compare Salah and Mbappe this season
• Analyze Barcelona's tactical system and weaknesses
• Recommend a striker for Arsenal, budget under 100M
Multi-turn supported — follow up with "compare him with..." or "what about his stats?"
Type quit to exit
"""
console.print(Panel(banner, border_style="green"))
INTENT_LABELS = {
"scout": "🔍 Player Scouting",
"compare": "📊 Player Comparison",
"tactics": "📋 Tactical Analysis",
"recommend": "🎯 Player Recommendation",
}
NODE_LABELS = {
"router": "🧭 Router — Classifying intent...",
"shared_retrieval": "📚 Retrieval — Gathering shared context...",
"scout": "🔍 Scout — Searching players...",
"analyst": "📊 Analyst — Analyzing data...",
"tactics": "📋 Tactics — Evaluating fit...",
"reporter": "📝 Reporter — Generating report...",
"join_recommend": "⏳ Merging parallel results...",
}
def run():
display_banner()
app = build_workflow()
# Each session gets a unique thread_id for conversation memory
thread_id = str(uuid.uuid4())
config = {
"configurable": {"thread_id": thread_id},
"run_name": "FootballGPT-CLI", # LangSmith trace name
"metadata": {"interface": "cli", "session_id": thread_id},
}
turn_count = 0
while True:
console.print()
query = console.input("[bold green]Query > [/]").strip()
if not query or query.lower() in ("quit", "exit", "q"):
console.print("[dim]Goodbye! ⚽[/]")
break
turn_count += 1
# LangGraph 所用,每个agent工作完都只是填充这个state
# Only set query — other fields reset per turn, chat_history accumulates via MemorySaver
initial_state = {
"query": query,
"intent": "",
"parameters": {},
"scout_data": "",
"analysis": "",
"tactical_context": "",
"report": "",
"shared_knowledge": "",
"analyst_knowledge": "",
"tactics_knowledge": "",
"reporter_knowledge": "",
}
try:
start = time.time()
result = None
console.print(f" [dim]Turn {turn_count}[/]")
for event in app.stream(initial_state, config=config):
for node_name, node_output in event.items():
label = NODE_LABELS.get(node_name, node_name)
elapsed = time.time() - start
console.print(f" [dim]{elapsed:.1f}s[/] [bold cyan]{label}[/] [green]✓[/]")
if node_name == "reporter":
result = node_output
total = time.time() - start
console.print(f" [dim]Total: {total:.1f}s[/]")
console.print()
if result and result.get("report"):
console.print()
console.print(Markdown(result["report"]))
else:
console.print("[yellow]No report generated.[/]")
except Exception as e:
console.print(f"[bold red]Error:[/] {e}")
import traceback
traceback.print_exc()
if __name__ == "__main__":
run()