-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest_project.py
More file actions
122 lines (100 loc) · 4.43 KB
/
test_project.py
File metadata and controls
122 lines (100 loc) · 4.43 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
122
#!/usr/bin/env python3
"""Test script to verify coordinator agents can receive project notifications."""
import asyncio
import sys
sys.path.insert(0, '/home/ubuntu/works/openagents/src')
from openagents.core.client import AgentClient
from openagents.models.event import Event
async def test_project_creation():
"""Test creating a project and verify agents respond."""
print("=" * 60)
print("Testing Project Creation with Coordinator Agents")
print("=" * 60)
# Create a test client
client = AgentClient(agent_id="test-client")
try:
# Connect to network
print("\n[1] Connecting to network...")
await client.connect(network_host="localhost", network_port=8700)
print(" ✓ Connected!")
# List available templates
print("\n[2] Listing project templates...")
list_templates_event = Event(
event_name="project.template.list",
source_id="test-client",
payload={}
)
response = await client.send_event(list_templates_event)
templates = response.data.get("templates", [])
print(f" ✓ Found {len(templates)} templates:")
for t in templates:
print(f" - {t.get('template_id')}: {t.get('name')}")
# Create a project using simple_english_practice template
print("\n[3] Creating project with 'simple_english_practice' template...")
start_event = Event(
event_name="project.start",
source_id="test-client",
payload={
"template_id": "simple_english_practice",
"name": "Test English Practice Session",
"goal": "Test that coordinator agents receive project notifications"
}
)
response = await client.send_event(start_event)
if not response.success:
print(f" ✗ Failed to create project: {response.message}")
return False
project_id = response.data.get("project_id")
print(f" ✓ Project created! ID: {project_id}")
# Wait for agents to respond (LLM calls take 10-20 seconds each)
print("\n[4] Waiting for agents to send welcome messages (45 seconds)...")
await asyncio.sleep(45)
# Get project details to see messages
print("\n[5] Checking project messages...")
get_event = Event(
event_name="project.get",
source_id="test-client",
payload={"project_id": project_id}
)
response = await client.send_event(get_event)
if response.success:
project = response.data.get("project", {})
messages = project.get("messages", [])
print(f" ✓ Found {len(messages)} messages in project:")
for msg in messages:
sender = msg.get("sender_id", "unknown")
content = msg.get("content", {})
text = content.get("text", "")[:100]
print(f"\n [{sender}]:")
print(f" {text}...")
# Check if we got messages from our coordinator agents
expected_agents = ["router_simple", "language_assistant", "learning_assistant"]
responded_agents = set(msg.get("sender_id") for msg in messages)
print("\n" + "=" * 60)
print("RESULTS:")
print("=" * 60)
for agent in expected_agents:
status = "✓" if agent in responded_agents else "✗"
print(f" {status} {agent}")
success = all(agent in responded_agents for agent in expected_agents)
if success:
print("\n🎉 SUCCESS! All coordinator agents responded to project.notification.started")
else:
missing = [a for a in expected_agents if a not in responded_agents]
print(f"\n⚠️ Some agents did not respond: {missing}")
print(" This may be due to timing - agents might still be processing.")
return success
else:
print(f" ✗ Failed to get project: {response.message}")
return False
except Exception as e:
print(f"\n✗ Error: {e}")
import traceback
traceback.print_exc()
return False
finally:
await client.disconnect()
print("\n[Done] Disconnected from network.")
if __name__ == "__main__":
result = asyncio.run(test_project_creation())
sys.exit(0 if result else 1)