-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathtest_symphony.py
More file actions
177 lines (142 loc) · 5.59 KB
/
test_symphony.py
File metadata and controls
177 lines (142 loc) · 5.59 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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
#!/usr/bin/env python3
"""Test script for Symphony multi-agent task execution.
This script tests the high-level API shown in the README.
"""
import sys
import os
sys.path.insert(0, '/workspace/code')
def test_basic_import():
"""Test basic imports work correctly."""
print("[TEST] Testing basic imports...")
try:
# Test core imports
from agents.agent import Agent
from protocol.task_contract import Task
from core.capability import CapabilityManager
print("✅ Core module imports successful")
# Test Task class new API
task = Task(
description="Test task",
requirements=["testing", "validation"],
context={"domain": "test", "complexity": "low"}
)
print(f"✅ Task creation successful: {task}")
# Test Agent class new API
agent = Agent(
node_id="test_agent",
capabilities=["testing", "debugging", "validation"]
)
print(f"✅ Agent creation successful: {agent.agent_id}")
return True
except Exception as e:
print(f"❌ Basic import test failed: {e}")
import traceback
traceback.print_exc()
return False
def test_symphony_integration():
"""Test Symphony orchestrator integration."""
print("\n[TEST] Testing Symphony integration...")
try:
from symphony import execute_task, register_agent, get_registered_agents
from agents.agent import Agent
from protocol.task_contract import Task
# Create agents
math_agent = Agent(
node_id="math_specialist",
capabilities=["mathematical-reasoning", "calculus", "statistics"]
)
code_agent = Agent(
node_id="code_specialist",
capabilities=["code-generation", "debugging", "optimization"]
)
research_agent = Agent(
node_id="research_specialist",
capabilities=["web-search", "data-analysis", "summarization"]
)
print(f"✅ Created {len(get_registered_agents())} agents")
# Create complex task
complex_task = Task(
description="Build a machine learning model to predict stock prices using financial data",
requirements=["data-collection", "mathematical-modeling", "code-implementation"],
context={"domain": "finance", "complexity": "high"}
)
print(f"✅ Task created: {complex_task}")
# Execute task
print("\n[EXECUTION] Starting multi-agent task execution...")
result = execute_task(complex_task)
print("\n[RESULT] Task execution completed!")
print("=" * 60)
print(result)
print("=" * 60)
return True
except Exception as e:
print(f"❌ Symphony integration test failed: {e}")
import traceback
traceback.print_exc()
return False
def test_readme_example():
"""Test the exact example from README."""
print("\n[TEST] Testing README example...")
try:
# This is the exact code from README
from agents.agent import Agent
from protocol.task_contract import Task
from core.capability import CapabilityManager
from symphony import execute_task
# Initialize multiple specialized agents
math_agent = Agent(
node_id="math_specialist",
capabilities=["mathematical-reasoning", "calculus", "statistics"]
)
code_agent = Agent(
node_id="code_specialist",
capabilities=["code-generation", "debugging", "optimization"]
)
research_agent = Agent(
node_id="research_specialist",
capabilities=["web-search", "data-analysis", "summarization"]
)
# Create a complex task requiring multiple specialties
complex_task = Task(
description="Build a machine learning model to predict stock prices using financial data",
requirements=["data-collection", "mathematical-modeling", "code-implementation"],
context={"domain": "finance", "complexity": "high"}
)
# The framework automatically:
# 1. Decomposes the task into specialized sub-tasks
# 2. Broadcasts beacons to find suitable agents
# 3. Routes sub-tasks to best-matching specialists
# 4. Aggregates results through CoT voting
result = execute_task(complex_task)
print("\n✅ README example executed successfully!")
print(f"Result length: {len(result)} characters")
return True
except Exception as e:
print(f"❌ README example test failed: {e}")
import traceback
traceback.print_exc()
return False
def run_all_tests():
"""Run all tests."""
print("🎼 Symphony Multi-Agent Task Execution Test Suite")
print("=" * 60)
tests = [
test_basic_import,
test_symphony_integration,
test_readme_example
]
passed = 0
total = len(tests)
for test in tests:
if test():
passed += 1
print(f"\n📊 Test Results: {passed}/{total} tests passed")
if passed == total:
print("🎉 All tests passed! Symphony multi-agent task execution is working!")
return True
else:
print("❌ Some tests failed. Please check the implementation.")
return False
if __name__ == "__main__":
success = run_all_tests()
sys.exit(0 if success else 1)