-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathstart_agents.py
More file actions
60 lines (50 loc) · 1.72 KB
/
start_agents.py
File metadata and controls
60 lines (50 loc) · 1.72 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
"""
Start all agent message queue listeners
Each agent runs in its own task and processes messages from their inbox
"""
import asyncio
import logging
from agent_messaging import AgentMessageQueue, AGENT_PERSONAS
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
async def main():
"""Start all agent listeners"""
print("\n" + "="*60)
print("🤖 STARTING AGENT MESSAGE LISTENERS")
print("="*60)
print()
# Create agent queues
agents = {}
for agent_id in AGENT_PERSONAS.keys():
agent = AgentMessageQueue(agent_id)
agents[agent_id] = agent
print(f"✓ Created queue for {AGENT_PERSONAS[agent_id]['name']} ({agent_id})")
# Connect all agents
print("\n📡 Connecting agents to NATS...")
for agent_id, agent in agents.items():
success = await agent.connect()
if success:
print(f" ✓ {agent_id} connected")
else:
print(f" ✗ {agent_id} failed to connect")
# Start listening
print("\n👂 Starting message listeners...")
for agent_id, agent in agents.items():
await agent.start_listening()
print(f" ✓ {agent_id} listening on agents.{agent_id}.inbox")
print("\n" + "="*60)
print("✅ ALL AGENTS ONLINE AND LISTENING")
print("="*60)
print("\nAgents will now respond to messages automatically.")
print("Press Ctrl+C to stop all agents\n")
# Keep running
try:
while True:
await asyncio.sleep(1)
except KeyboardInterrupt:
print("\n\n🛑 Shutting down agents...")
for agent in agents.values():
await agent.close()
print("✓ All agents stopped\n")
if __name__ == '__main__':
asyncio.run(main())