-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest_intelligent_enhancement.py
More file actions
194 lines (159 loc) · 6.32 KB
/
Copy pathtest_intelligent_enhancement.py
File metadata and controls
194 lines (159 loc) · 6.32 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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
#!/usr/bin/env python3
"""
Test script to demonstrate intelligent enhancement decision making
by the Supervisor Agent.
"""
import os
import sys
from dotenv import load_dotenv
# Load environment variables
load_dotenv()
# Add the app directory to the Python path
sys.path.append(os.path.join(os.path.dirname(__file__), 'app'))
from app.agents.supervisor_agent import SupervisorAgent
def test_enhancement_decisions():
"""Test various inputs to see if enhancement is needed"""
print("🧪 Testing Intelligent Enhancement Decision Making")
print("=" * 60)
# Initialize supervisor agent
supervisor = SupervisorAgent()
# Test cases with different levels of clarity
test_cases = [
# Clear inputs (should NOT need enhancement)
{
"input": "Send email to john@example.com about project update",
"expected": False,
"description": "Clear and specific email request"
},
{
"input": "Check my calendar for tomorrow",
"expected": False,
"description": "Clear calendar check request"
},
{
"input": "Schedule meeting with team on Friday at 2pm",
"expected": False,
"description": "Specific meeting request with time"
},
# Vague inputs (should need enhancement)
{
"input": "Schedule meeting",
"expected": True,
"description": "Vague meeting request"
},
{
"input": "Send email",
"expected": True,
"description": "Vague email request"
},
{
"input": "Meeting tomorrow",
"expected": True,
"description": "Incomplete meeting details"
},
{
"input": "Check calendar",
"expected": True,
"description": "Vague calendar request"
},
{
"input": "Send to john",
"expected": True,
"description": "Incomplete email request"
}
]
print("\n📋 Testing Enhancement Decision Logic:")
print("-" * 60)
for i, test_case in enumerate(test_cases, 1):
print(f"\n{i}. {test_case['description']}")
print(f" Input: '{test_case['input']}'")
# Test enhancement decision
decision = supervisor.should_enhance_input(test_case['input'])
print(f" Decision: {decision['needs_enhancement']}")
print(f" Reasoning: {decision['reasoning']}")
print(f" Confidence: {decision['confidence']}")
# Check if decision matches expectation
if decision['needs_enhancement'] == test_case['expected']:
print(f" ✅ PASS - Decision matches expectation")
else:
print(f" ❌ FAIL - Expected {test_case['expected']}, got {decision['needs_enhancement']}")
def test_complete_flow():
"""Test the complete flow with enhancement decision"""
print("\n\n🔄 Testing Complete Flow with Enhancement Decision")
print("=" * 60)
# Initialize supervisor agent
supervisor = SupervisorAgent()
# Test cases for complete flow
flow_test_cases = [
{
"input": "Schedule meeting",
"description": "Vague request that should be enhanced"
},
{
"input": "Send email to john@example.com about project update",
"description": "Clear request that should NOT be enhanced"
},
{
"input": "Meeting tomorrow",
"description": "Incomplete request that should be enhanced"
}
]
for i, test_case in enumerate(flow_test_cases, 1):
print(f"\n{i}. {test_case['description']}")
print(f" Input: '{test_case['input']}'")
print("-" * 40)
# Run complete flow
result = supervisor.route_to_agent(test_case['input'])
print(f" Success: {result['success']}")
print(f" Selected Agent: {result['selected_agent']}")
print(f" Enhancement Decision: {result['enhancement_decision']['needs_enhancement']}")
print(f" Enhancement Applied: {len(result['enhancement']['enhancements_made'])} enhancements")
print(f" Response: {result['response'][:100]}...")
def test_api_endpoint():
"""Test the API endpoint with enhancement decision"""
print("\n\n🌐 Testing API Endpoint with Enhancement Decision")
print("=" * 60)
import requests
import json
# Test the API endpoint
test_inputs = [
"Schedule meeting",
"Send email to john@example.com about project update",
"Meeting tomorrow"
]
for i, user_input in enumerate(test_inputs, 1):
print(f"\n{i}. Testing: '{user_input}'")
try:
response = requests.post(
"http://localhost:8000/api/supervisor/chat",
json={"prompt": user_input},
headers={"Content-Type": "application/json"}
)
if response.status_code == 200:
result = response.json()
print(f" ✅ Success")
print(f" Selected Agent: {result['selected_agent']}")
print(f" Enhancement Decision: {result.get('enhancement_decision', {}).get('needs_enhancement', 'N/A')}")
print(f" Response: {result['response'][:100]}...")
else:
print(f" ❌ Error: {response.status_code}")
print(f" Response: {response.text}")
except requests.exceptions.ConnectionError:
print(" ❌ Connection Error: Make sure the server is running")
except Exception as e:
print(f" ❌ Error: {str(e)}")
if __name__ == "__main__":
print("🚀 Starting Intelligent Enhancement Decision Tests")
print("=" * 60)
# Test 1: Enhancement decision logic
test_enhancement_decisions()
# Test 2: Complete flow
test_complete_flow()
# Test 3: API endpoint (if server is running)
print("\n" + "=" * 60)
print("💡 To test the API endpoint, make sure the server is running:")
print(" python3 -m uvicorn app.main:app --reload")
print("=" * 60)
# Uncomment to test API endpoint
# test_api_endpoint()
print("\n✅ All tests completed!")