-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
60 lines (49 loc) · 1.98 KB
/
main.py
File metadata and controls
60 lines (49 loc) · 1.98 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
"""Main application entry point."""
from langchain_core.messages import HumanMessage
from config import setup_api_keys
from graph import create_research_graph
from state import AgentState
def main():
"""Main application function."""
print("🔧 Setting up API keys...")
setup_api_keys()
print("🏗️ Building multi-agent research graph...")
research_graph = create_research_graph()
print("✅ Ready! Multi-agent weather and news research system.")
print("-" * 50)
while True:
try:
# Get user input
location = input("\nEnter your location (or 'quit' to exit): ").strip()
if location.lower() in ['quit', 'exit', 'q']:
print("Goodbye! 👋")
break
query = input("Enter your query (e.g., 'weather', 'news', or 'weather and news'): ").strip()
if not query:
print("Please enter a valid query.")
continue
# Create initial state
initial_state: AgentState = {
"messages": [HumanMessage(content=query)],
"location": location,
"intent": "unknown",
"weather_data": "",
"news_data": ""
}
print(f"\n🔍 Processing your request for {location}...")
# Execute the graph
result = research_graph.invoke(initial_state)
# Display the final response
if result["messages"]:
final_message = result["messages"][-1].content
print(f"\n📋 Results:\n{final_message}")
else:
print("\n❌ No results found.")
except KeyboardInterrupt:
print("\n\nGoodbye! 👋")
break
except Exception as e:
print(f"\n❌ Error: {str(e)}")
print("Please try again.")
if __name__ == "__main__":
main()