-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
96 lines (76 loc) · 2.74 KB
/
Copy pathmain.py
File metadata and controls
96 lines (76 loc) · 2.74 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
"""
Mood Orchestrator Agent - Main Application
"""
import asyncio
from google.adk import Runner
from google.adk.sessions import InMemorySessionService
from google.genai import types
from agent import root_agent
def print_banner():
"""Print welcome banner."""
print("\n" + "="*60)
print("🎵 MOOD ORCHESTRATOR AGENT 🎵")
print("="*60)
print("Welcome! I'll capture your voice, detect your mood,")
print("generate personalized music, and sync your smart lights!")
print("="*60 + "\n")
async def run_agent():
"""Run the mood orchestrator agent."""
print_banner()
# Create runner with in-memory session service
runner = Runner(
app_name="mood_orchestrator",
agent=root_agent,
session_service=InMemorySessionService()
)
# User and session IDs
user_id = "user_001"
session_id = "session_001"
print("🎤 Ready to start! The agent will guide you through the process.\n")
print("Type 'start' to begin, or 'quit' to exit.\n")
while True:
user_input = input("You: ").strip()
if user_input.lower() in ['quit', 'exit', 'q']:
print("\n👋 Goodbye! Thanks for using Mood Orchestrator!\n")
break
if not user_input:
continue
# Create message content
content = types.Content(
role='user',
parts=[types.Part(text=user_input)]
)
print("\n🤖 Agent:")
print("-" * 60)
# Run agent and stream events
try:
async for event in runner.run_async(
user_id=user_id,
session_id=session_id,
new_message=content
):
# Handle different event types
if event.content and event.content.parts:
for part in event.content.parts:
if part.text:
# Print agent responses
if event.author == root_agent.name:
print(f"{part.text}")
# Show tool execution
if hasattr(event, 'tool_name') and event.tool_name:
print(f"\n🔧 Executing tool: {event.tool_name}")
except Exception as e:
print(f"\n❌ Error: {str(e)}")
print("Please try again or type 'quit' to exit.")
print("-" * 60)
print()
def main():
"""Main entry point."""
try:
asyncio.run(run_agent())
except KeyboardInterrupt:
print("\n\n👋 Interrupted. Goodbye!\n")
except Exception as e:
print(f"\n❌ Fatal error: {str(e)}\n")
if __name__ == "__main__":
main()