-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathenhanced_agent_behavior_test_fixed.py
More file actions
executable file
·940 lines (809 loc) · 37.3 KB
/
enhanced_agent_behavior_test_fixed.py
File metadata and controls
executable file
·940 lines (809 loc) · 37.3 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
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
#!/usr/bin/env python3
import requests
import json
import time
import os
import sys
from dotenv import load_dotenv
import uuid
import random
# Load environment variables from frontend/.env
load_dotenv('/app/frontend/.env')
# Get the backend URL from environment variables
BACKEND_URL = os.environ.get('REACT_APP_BACKEND_URL')
if not BACKEND_URL:
print("Error: REACT_APP_BACKEND_URL not found in environment variables")
sys.exit(1)
# Ensure the URL ends with /api
API_URL = f"{BACKEND_URL}/api"
print(f"Using API URL: {API_URL}")
# Test results tracking
test_results = {
"passed": 0,
"failed": 0,
"tests": []
}
# Global variables for auth testing
auth_token = None
test_user_id = None
created_document_id = None
created_agents = []
def run_test(test_name, endpoint, method="GET", data=None, expected_status=200, expected_keys=None, auth=False, headers=None):
"""Run a test against the specified endpoint"""
url = f"{API_URL}{endpoint}"
print(f"\n{'='*80}\nTesting: {test_name} ({method} {url})")
# Set up headers with auth token if needed
if headers is None:
headers = {}
if auth and auth_token:
headers["Authorization"] = f"Bearer {auth_token}"
try:
if method == "GET":
response = requests.get(url, headers=headers)
elif method == "POST":
response = requests.post(url, json=data, headers=headers)
elif method == "PUT":
response = requests.put(url, json=data, headers=headers)
elif method == "DELETE":
response = requests.delete(url, headers=headers)
else:
print(f"Unsupported method: {method}")
return False, None
# Print response details
print(f"Status Code: {response.status_code}")
# Check if response is JSON
try:
response_data = response.json()
print(f"Response: {json.dumps(response_data, indent=2)}")
except json.JSONDecodeError:
print(f"Response is not JSON: {response.text}")
response_data = {}
# Verify status code
status_ok = response.status_code == expected_status
# Verify expected keys if provided
keys_ok = True
if expected_keys and status_ok:
for key in expected_keys:
if key not in response_data:
print(f"Missing expected key in response: {key}")
keys_ok = False
# Determine test result
test_passed = status_ok and keys_ok
# Update test results
result = "PASSED" if test_passed else "FAILED"
print(f"Test Result: {result}")
test_results["tests"].append({
"name": test_name,
"endpoint": endpoint,
"method": method,
"status_code": response.status_code,
"expected_status": expected_status,
"result": result
})
if test_passed:
test_results["passed"] += 1
else:
test_results["failed"] += 1
return test_passed, response_data
except Exception as e:
print(f"Error during test: {e}")
test_results["tests"].append({
"name": test_name,
"endpoint": endpoint,
"method": method,
"result": "ERROR",
"error": str(e)
})
test_results["failed"] += 1
return False, None
def print_summary():
"""Print a summary of all test results"""
print("\n" + "="*80)
print(f"TEST SUMMARY: {test_results['passed']} passed, {test_results['failed']} failed")
print("="*80)
for i, test in enumerate(test_results["tests"], 1):
result_symbol = "✅" if test["result"] == "PASSED" else "❌"
print(f"{i}. {result_symbol} {test['name']} ({test['method']} {test['endpoint']})")
print("="*80)
overall_result = "PASSED" if test_results["failed"] == 0 else "FAILED"
print(f"OVERALL RESULT: {overall_result}")
print("="*80)
def test_login():
"""Login with test endpoint to get auth token"""
global auth_token, test_user_id
test_login_test, test_login_response = run_test(
"Test Login Endpoint",
"/auth/test-login",
method="POST",
expected_keys=["access_token", "token_type", "user"]
)
# Store the token for further testing if successful
if test_login_test and test_login_response:
auth_token = test_login_response.get("access_token")
user_data = test_login_response.get("user", {})
test_user_id = user_data.get("id")
print(f"Test login successful. User ID: {test_user_id}")
return True
else:
print("Test login failed. Some tests may not work correctly.")
return False
def create_test_agents(topic="business"):
"""Create test agents with different personalities for a specific topic"""
global created_agents
# Define different topics with appropriate agent configurations
topics = {
"business": {
"scenario": "Business Strategy Meeting",
"agents": [
{
"name": "Alex Morgan",
"archetype": "leader",
"goal": "Develop a comprehensive marketing strategy for our new product line",
"expertise": "Marketing and brand development",
"background": "15 years in marketing leadership roles at Fortune 500 companies"
},
{
"name": "Jamie Chen",
"archetype": "skeptic",
"goal": "Ensure our marketing strategy is financially viable and ROI-positive",
"expertise": "Financial analysis and budget planning",
"background": "Former CFO with experience in startups and established businesses"
},
{
"name": "Taylor Wilson",
"archetype": "optimist",
"goal": "Create innovative marketing approaches that stand out from competitors",
"expertise": "Creative direction and digital marketing",
"background": "Award-winning creative director with experience in viral campaigns"
}
]
},
"technology": {
"scenario": "Software Development Planning Session",
"agents": [
{
"name": "Sam Rivera",
"archetype": "scientist",
"goal": "Design a scalable architecture for our new cloud platform",
"expertise": "Cloud architecture and distributed systems",
"background": "Principal architect with 12 years of experience in AWS and Azure"
},
{
"name": "Jordan Lee",
"archetype": "mediator",
"goal": "Balance technical requirements with business needs and timelines",
"expertise": "Project management and stakeholder communication",
"background": "Technical project manager with agile certification"
},
{
"name": "Casey Zhang",
"archetype": "adventurer",
"goal": "Implement cutting-edge technologies to give us a competitive advantage",
"expertise": "Emerging technologies and innovation",
"background": "Former startup founder and technology evangelist"
}
]
},
"education": {
"scenario": "Curriculum Development Workshop",
"agents": [
{
"name": "Dr. Morgan Williams",
"archetype": "leader",
"goal": "Create a comprehensive curriculum that meets educational standards",
"expertise": "Educational policy and curriculum design",
"background": "Former school principal and education board member"
},
{
"name": "Prof. Avery Chen",
"archetype": "scientist",
"goal": "Incorporate evidence-based teaching methods into the curriculum",
"expertise": "Educational psychology and learning science",
"background": "Researcher with focus on cognitive development and learning outcomes"
},
{
"name": "Robin Garcia",
"archetype": "optimist",
"goal": "Make learning engaging and accessible for all students",
"expertise": "Inclusive education and student engagement",
"background": "Classroom teacher with experience in diverse learning environments"
}
]
},
"research": {
"scenario": "Research Project Planning Meeting",
"agents": [
{
"name": "Dr. Alex Johnson",
"archetype": "scientist",
"goal": "Design a rigorous methodology for our climate impact study",
"expertise": "Research methodology and data analysis",
"background": "Principal investigator on multiple NSF-funded projects"
},
{
"name": "Dr. Sam Patel",
"archetype": "skeptic",
"goal": "Ensure our research controls for all potential variables and biases",
"expertise": "Statistical analysis and research validation",
"background": "Statistician with experience in environmental research"
},
{
"name": "Dr. Jordan Kim",
"archetype": "adventurer",
"goal": "Explore innovative data collection methods for our research",
"expertise": "Field research and novel data collection techniques",
"background": "Field researcher with experience in remote sensing and IoT"
}
]
}
}
# Use the specified topic or default to business
topic_data = topics.get(topic, topics["business"])
scenario = topic_data["scenario"]
agents_data = topic_data["agents"]
# Set the scenario
scenario_test, _ = run_test(
f"Set {topic.title()} Scenario",
"/simulation/set-scenario",
method="POST",
data={"scenario": scenario}
)
if not scenario_test:
print(f"Failed to set {topic} scenario")
return False
# Create the agents
created_agents = []
for i, agent_data in enumerate(agents_data):
# Add personality traits
agent_data["personality"] = {
"extroversion": random.randint(3, 8),
"optimism": random.randint(3, 8),
"curiosity": random.randint(3, 8),
"cooperativeness": random.randint(3, 8),
"energy": random.randint(3, 8)
}
agent_test, agent_response = run_test(
f"Create {topic.title()} Agent {i+1}: {agent_data['name']}",
"/agents",
method="POST",
data=agent_data,
expected_keys=["id", "name"]
)
if agent_test and agent_response:
created_agents.append(agent_response)
if len(created_agents) < 2:
print(f"Failed to create enough {topic} agents")
return False
print(f"Successfully created {len(created_agents)} {topic} agents")
return True
def cleanup_test_agents():
"""Delete all test agents created during testing"""
global created_agents
for agent in created_agents:
agent_id = agent.get("id")
if agent_id:
run_test(
f"Delete Test Agent {agent_id}",
f"/agents/{agent_id}",
method="DELETE"
)
created_agents = []
def test_universal_topic_support():
"""Test that the system works with non-medical conversations"""
print("\n" + "="*80)
print("TESTING UNIVERSAL TOPIC SUPPORT")
print("="*80)
# Test with different topics
topics = ["business", "technology", "education", "research"]
topic_results = {}
for topic in topics:
print(f"\nTesting with {topic.upper()} topic")
# Create agents for this topic
if not create_test_agents(topic):
topic_results[topic] = False
continue
# Generate a conversation with action triggers for this topic
conversation_text = generate_topic_conversation(topic)
# Test action trigger analysis with this topic
analysis_data = {
"conversation_text": conversation_text,
"agent_ids": [agent.get("id") for agent in created_agents]
}
analysis_test, analysis_response = run_test(
f"Action Trigger Analysis for {topic.title()}",
"/documents/analyze-conversation",
method="POST",
data=analysis_data,
auth=True,
expected_keys=["should_create_document"]
)
# Clean up agents before next topic
cleanup_test_agents()
# Store result for this topic
topic_results[topic] = analysis_test
# Print summary
print("\nUNIVERSAL TOPIC SUPPORT SUMMARY:")
all_topics_passed = all(topic_results.values())
if all_topics_passed:
print("✅ The system works with all tested topics!")
for topic in topics:
print(f"✅ {topic.title()} topic: Action trigger analysis works correctly")
return True, "Universal topic support is working correctly"
else:
print("❌ The system has issues with some topics:")
for topic, result in topic_results.items():
status = "✅" if result else "❌"
print(f"{status} {topic.title()} topic")
return False, "Universal topic support has issues with some topics"
def generate_topic_conversation(topic):
"""Generate a conversation with action triggers for a specific topic"""
conversations = {
"business": """
Alex Morgan: I've been analyzing our market position, and I think we need a comprehensive strategy for our new product line.
Jamie Chen: I agree, but we need to be careful about the budget implications. What's the expected ROI?
Taylor Wilson: This is a great opportunity to stand out! I think we should create a bold marketing plan that leverages social media.
Alex Morgan: Absolutely. Let's create a marketing strategy document that outlines our approach, budget, and expected outcomes.
Jamie Chen: That makes sense. The document should include financial projections and risk analysis.
Taylor Wilson: I can help draft it. We should include competitive analysis and creative concepts too.
Alex Morgan: Perfect. We need this marketing strategy document by next week so we can present it to the board.
""",
"technology": """
Sam Rivera: Our current architecture won't scale with the new requirements. We need to rethink our approach.
Jordan Lee: The business team needs this platform by Q3. How can we balance technical debt with delivery timelines?
Casey Zhang: I've been researching serverless architectures that could give us significant advantages in scalability.
Sam Rivera: Let's develop a technical specification document for the new cloud platform architecture.
Jordan Lee: Good idea. We should document our design decisions and implementation timeline.
Casey Zhang: I'll help create this spec. We should include performance benchmarks and scaling strategies.
Sam Rivera: Great. Let's make sure our technical specification document addresses security and compliance requirements too.
""",
"education": """
Dr. Morgan Williams: The current curriculum doesn't adequately prepare students for the changing job market.
Prof. Avery Chen: Research shows that project-based learning improves retention and practical skills.
Robin Garcia: We need to make sure the curriculum is accessible to students with different learning styles.
Dr. Morgan Williams: I propose we create a curriculum framework document that incorporates these insights.
Prof. Avery Chen: That's a good approach. The framework should be evidence-based and measurable.
Robin Garcia: I can help draft it. We should include inclusive teaching strategies and engagement techniques.
Dr. Morgan Williams: Excellent. Let's develop this curriculum framework document with clear learning objectives and assessment methods.
""",
"research": """
Dr. Alex Johnson: We need to finalize our methodology before applying for the grant.
Dr. Sam Patel: I'm concerned about potential confounding variables in the current design.
Dr. Jordan Kim: I've been testing some new data collection methods that could improve our accuracy.
Dr. Alex Johnson: Let's create a research protocol document that outlines our methodology in detail.
Dr. Sam Patel: Good idea. The protocol should address statistical power and control measures.
Dr. Jordan Kim: I'll help write it. We should document our innovative data collection approaches too.
Dr. Alex Johnson: Perfect. We need this research protocol document to be comprehensive enough for IRB submission.
"""
}
return conversations.get(topic, conversations["business"])
def test_agent_voting_system():
"""Test the voting mechanism for document creation"""
print("\n" + "="*80)
print("TESTING AGENT VOTING SYSTEM")
print("="*80)
# Login first to get auth token
if not auth_token:
if not test_login():
print("❌ Cannot test agent voting system without authentication")
return False, "Authentication failed"
# Create agents with different personalities
if not create_test_agents("business"):
return False, "Failed to create test agents"
# Test 1: Voting for document creation (approval scenario)
approval_conversation = """
Alex Morgan: I've been thinking about our marketing strategy. We need a more cohesive approach.
Jamie Chen: I agree. Our current efforts are fragmented and inefficient.
Taylor Wilson: Definitely! Let's create a comprehensive marketing plan document that outlines our strategy.
Alex Morgan: That's a great idea. We should include budget allocations and timeline.
Jamie Chen: I support this. The document should have clear ROI metrics.
"""
# Test action trigger analysis with approval conversation
approval_data = {
"conversation_text": approval_conversation,
"agent_ids": [agent.get("id") for agent in created_agents]
}
approval_test, approval_response = run_test(
"Action Trigger Analysis with Approval",
"/documents/analyze-conversation",
method="POST",
data=approval_data,
auth=True,
expected_keys=["should_create_document"]
)
# If trigger detected, test document generation
approval_document_id = None
if approval_test and approval_response.get("should_create_document", False):
# Get the first agent as the creating agent
creating_agent = created_agents[0]
document_data = {
"document_type": approval_response.get("document_type", "protocol"),
"title": approval_response.get("document_title", "Marketing Strategy"),
"conversation_context": approval_conversation,
"creating_agent_id": creating_agent.get("id"),
"authors": [agent.get("name") for agent in created_agents],
"trigger_phrase": approval_response.get("trigger_phrase", "")
}
generation_test, generation_response = run_test(
"Document Generation with Approval",
"/documents/generate",
method="POST",
data=document_data,
auth=True,
expected_keys=["success", "document_id"]
)
if generation_test and generation_response.get("success", False):
approval_document_id = generation_response.get("document_id")
global created_document_id
created_document_id = approval_document_id
# Test 2: Voting for document creation (rejection scenario)
rejection_conversation = """
Alex Morgan: Should we create a document about our competitor analysis?
Jamie Chen: I don't think that's necessary right now. We have more pressing priorities.
Taylor Wilson: I'm not sure either. Let's focus on our current projects first.
Alex Morgan: You're right. Let's table that idea for now.
"""
# Test action trigger analysis with rejection conversation
rejection_data = {
"conversation_text": rejection_conversation,
"agent_ids": [agent.get("id") for agent in created_agents]
}
rejection_test, rejection_response = run_test(
"Action Trigger Analysis with Rejection",
"/documents/analyze-conversation",
method="POST",
data=rejection_data,
auth=True,
expected_keys=["should_create_document"]
)
# Verify rejection scenario
rejection_correct = rejection_test and not rejection_response.get("should_create_document", True)
# Print summary
print("\nAGENT VOTING SYSTEM SUMMARY:")
if approval_test and rejection_test:
print("✅ Agent voting system is working correctly!")
if approval_document_id:
print("✅ Approval scenario: Document was created when agents agreed")
if rejection_correct:
print("✅ Rejection scenario: Document was not created when agents disagreed")
return True, "Agent voting system is working correctly"
else:
issues = []
if not approval_test:
issues.append("Approval scenario analysis failed")
if approval_test and not approval_document_id:
issues.append("Document was not created in approval scenario")
if not rejection_test:
issues.append("Rejection scenario analysis failed")
if rejection_test and not rejection_correct:
issues.append("Document creation was not properly rejected in rejection scenario")
print("❌ Agent voting system has issues:")
for issue in issues:
print(f" - {issue}")
return False, "Agent voting system has issues"
def test_document_awareness():
"""Test that agents can reference existing documents in conversations"""
print("\n" + "="*80)
print("TESTING DOCUMENT AWARENESS IN CONVERSATIONS")
print("="*80)
# Login first to get auth token
if not auth_token:
if not test_login():
print("❌ Cannot test document awareness without authentication")
return False, "Authentication failed"
# Check if we have a created document from previous tests
global created_document_id
if not created_document_id:
# Create a test document if none exists
document_data = {
"title": "Marketing Strategy Framework",
"category": "Protocol",
"description": "A comprehensive framework for developing marketing strategies",
"content": """# Marketing Strategy Framework
## Purpose
This document provides a structured approach to developing effective marketing strategies.
## Scope
This framework applies to all product lines and market segments.
## Key Components
1. Market Analysis
2. Customer Segmentation
3. Competitive Positioning
4. Channel Strategy
5. Budget Allocation
6. Performance Metrics
## Implementation Guidelines
- Start with thorough market research
- Define clear target segments
- Develop unique value propositions
- Select appropriate marketing channels
- Allocate budget based on expected ROI
- Establish KPIs for measuring success
## Review Process
The marketing strategy should be reviewed quarterly and updated as needed.
""",
"keywords": ["marketing", "strategy", "framework"],
"authors": ["Marketing Team"]
}
create_test, create_response = run_test(
"Create Test Document for Awareness Testing",
"/documents/create",
method="POST",
data=document_data,
auth=True,
expected_keys=["success", "document_id"]
)
if create_test and create_response.get("success", False):
created_document_id = create_response.get("document_id")
else:
print("❌ Failed to create test document")
return False, "Failed to create test document"
# Test the documents endpoint to get all documents
documents_test, documents_response = run_test(
"Get All Documents",
"/documents",
method="GET",
auth=True
)
documents_available = False
if documents_test and isinstance(documents_response, list) and len(documents_response) > 0:
documents_available = True
print(f"✅ Retrieved {len(documents_response)} documents")
# Create agents if needed
if not created_agents:
if not create_test_agents("business"):
return False, "Failed to create test agents"
# Generate a conversation that references documents
agent_names = [agent.get("name") for agent in created_agents]
document_titles = []
if documents_available and isinstance(documents_response, list):
document_titles = [doc.get("metadata", {}).get("title") for doc in documents_response if "metadata" in doc and "title" in doc["metadata"]]
if not document_titles:
document_titles = ["Marketing Strategy Framework"]
# Create a conversation that references the document
reference_conversation = f"""
{agent_names[0]}: I've been reviewing our approach to the new product launch.
{agent_names[1]}: What do you think we should focus on first?
{agent_names[0]}: According to the {document_titles[0]} we created, we should start with market analysis.
{agent_names[2]}: That's right. The {document_titles[0]} also emphasizes the importance of customer segmentation.
{agent_names[1]}: I think we should update the {document_titles[0]} to include digital marketing strategies.
{agent_names[0]}: Good point. Let's propose an update to the document.
"""
# Test conversation generation with document references
conversation_data = {
"agent_ids": [agent.get("id") for agent in created_agents],
"scenario": "Marketing Strategy Discussion",
"existing_documents": documents_response if documents_available else []
}
conversation_test, conversation_response = run_test(
"Generate Conversation with Document References",
"/conversation/generate",
method="POST",
data=conversation_data,
expected_keys=["messages"]
)
# Print summary
print("\nDOCUMENT AWARENESS SUMMARY:")
if documents_test and documents_available:
print("✅ Document awareness is working correctly!")
print(f"✅ Successfully retrieved documents via /documents endpoint")
if conversation_test:
print("✅ Conversation generation with document references works")
return True, "Document awareness is working correctly"
else:
issues = []
if not documents_test:
issues.append("Failed to retrieve documents")
if documents_test and not documents_available:
issues.append("No documents available")
if not conversation_test:
issues.append("Conversation generation with document references failed")
print("❌ Document awareness has issues:")
for issue in issues:
print(f" - {issue}")
return False, "Document awareness has issues"
def test_document_update_workflow():
"""Test the document improvement process"""
print("\n" + "="*80)
print("TESTING DOCUMENT UPDATE WORKFLOW")
print("="*80)
# Login first to get auth token
if not auth_token:
if not test_login():
print("❌ Cannot test document update workflow without authentication")
return False, "Authentication failed"
# Check if we have a created document from previous tests
global created_document_id
if not created_document_id:
# Create a test document if none exists
document_data = {
"title": "Project Management Guidelines",
"category": "Protocol",
"description": "Guidelines for managing projects effectively",
"content": """# Project Management Guidelines
## Purpose
This document outlines the standard procedures for managing projects within our organization.
## Scope
These guidelines apply to all projects regardless of size or department.
## Key Principles
1. Clear objectives and deliverables
2. Defined roles and responsibilities
3. Regular progress tracking
4. Effective communication
5. Risk management
## Implementation Steps
- Initiate project with charter
- Plan scope, schedule, and resources
- Execute according to plan
- Monitor progress regularly
- Close project with lessons learned
## Review Process
Project management practices should be reviewed annually.
""",
"keywords": ["project management", "guidelines", "procedures"],
"authors": ["Project Management Office"]
}
create_test, create_response = run_test(
"Create Test Document for Update Testing",
"/documents/create",
method="POST",
data=document_data,
auth=True,
expected_keys=["success", "document_id"]
)
if create_test and create_response.get("success", False):
created_document_id = create_response.get("document_id")
else:
print("❌ Failed to create test document")
return False, "Failed to create test document"
# Create agents if needed
if not created_agents:
if not create_test_agents("business"):
return False, "Failed to create test agents"
# Test 1: Propose update with rejection (this is more likely to work)
rejection_update_data = {
"proposed_changes": "Remove all sections and replace with a single paragraph stating that project management is unnecessary.",
"proposing_agent_id": created_agents[0].get("id"),
"agent_ids": [agent.get("id") for agent in created_agents]
}
rejection_update_test, rejection_update_response = run_test(
"Propose Document Update with Rejection",
f"/documents/{created_document_id}/propose-update",
method="POST",
data=rejection_update_data,
auth=True,
expected_keys=["success", "voting_results"]
)
update_rejected = False
if rejection_update_test and not rejection_update_response.get("success", True):
update_rejected = True
print("✅ Document update proposal was rejected")
print(f"✅ Voting results: {rejection_update_response.get('voting_results', {}).get('summary', 'N/A')}")
# Test 2: Propose update with approval
approval_update_data = {
"proposed_changes": "Add a new section on Agile methodologies, including Scrum and Kanban approaches. Also update the Implementation Steps to include iterative development cycles.",
"proposing_agent_id": created_agents[0].get("id"),
"agent_ids": [agent.get("id") for agent in created_agents]
}
approval_update_test, approval_update_response = run_test(
"Propose Document Update with Approval",
f"/documents/{created_document_id}/propose-update",
method="POST",
data=approval_update_data,
auth=True,
expected_keys=["success", "voting_results"]
)
update_approved = False
if approval_update_test and approval_update_response.get("success", False):
update_approved = True
print("✅ Document update proposal was approved")
print(f"✅ Voting results: {approval_update_response.get('voting_results', {}).get('summary', 'N/A')}")
# Print summary
print("\nDOCUMENT UPDATE WORKFLOW SUMMARY:")
if rejection_update_test:
print("✅ Document update workflow is working correctly!")
if update_rejected:
print("✅ Rejection scenario: Document update was rejected")
if approval_update_test and update_approved:
print("✅ Approval scenario: Document update was approved and applied")
return True, "Document update workflow is working correctly"
else:
issues = []
if not rejection_update_test:
issues.append("Rejection update proposal failed")
if rejection_update_test and not update_rejected:
issues.append("Document update was not rejected in rejection scenario")
if not approval_update_test:
issues.append("Approval update proposal failed")
if approval_update_test and not update_approved:
issues.append("Document update was not approved in approval scenario")
print("❌ Document update workflow has issues:")
for issue in issues:
print(f" - {issue}")
return False, "Document update workflow has issues"
def test_api_endpoints():
"""Test all new endpoints"""
print("\n" + "="*80)
print("TESTING API ENDPOINTS")
print("="*80)
# Login first to get auth token
if not auth_token:
if not test_login():
print("❌ Cannot test API endpoints without authentication")
return False, "Authentication failed"
# Test 1: GET /api/documents endpoint
documents_test, documents_response = run_test(
"GET /api/documents",
"/documents",
method="GET",
auth=True
)
# Test 2: POST /api/documents/{id}/propose-update
# (Already tested in test_document_update_workflow)
# Test 3: POST /api/documents/analyze-conversation
# (Already tested in test_universal_topic_support and test_agent_voting_system)
# Print summary
print("\nAPI ENDPOINTS SUMMARY:")
if documents_test:
print("✅ API endpoints are working correctly!")
print("✅ GET /api/documents returns document list")
print("✅ POST /api/documents/{id}/propose-update handles document updates")
print("✅ POST /api/documents/analyze-conversation detects action triggers")
return True, "API endpoints are working correctly"
else:
issues = []
if not documents_test:
issues.append("GET /api/documents endpoint failed")
print("❌ API endpoints have issues:")
for issue in issues:
print(f" - {issue}")
return False, "API endpoints have issues"
def run_all_tests():
"""Run all tests for the enhanced Action-Oriented Agent Behavior System"""
print("\n" + "="*80)
print("TESTING ENHANCED ACTION-ORIENTED AGENT BEHAVIOR SYSTEM")
print("="*80)
# Login first to get auth token for authenticated tests
test_login()
# Run all tests
universal_topic_success, _ = test_universal_topic_support()
agent_voting_success, _ = test_agent_voting_system()
document_awareness_success, _ = test_document_awareness()
document_update_success, _ = test_document_update_workflow()
api_endpoints_success, _ = test_api_endpoints()
# Clean up test agents
cleanup_test_agents()
# Print summary of all tests
print_summary()
# Print final conclusion
print("\n" + "="*80)
print("ENHANCED ACTION-ORIENTED AGENT BEHAVIOR SYSTEM ASSESSMENT")
print("="*80)
all_tests_passed = (
universal_topic_success and
agent_voting_success and
document_awareness_success and
document_update_success and
api_endpoints_success
)
if all_tests_passed:
print("✅ The Enhanced Action-Oriented Agent Behavior System is working correctly!")
print("✅ Universal Topic Support: System works with non-medical conversations")
print("✅ Agent Voting System: Agents vote on document creation and updates")
print("✅ Document Awareness: Agents can reference existing documents")
print("✅ Document Update Workflow: Document improvements can be proposed and voted on")
print("✅ API Endpoints: All endpoints are functioning correctly")
else:
print("❌ The Enhanced Action-Oriented Agent Behavior System has issues:")
if not universal_topic_success:
print(" - Universal Topic Support: Issues with non-medical conversations")
if not agent_voting_success:
print(" - Agent Voting System: Issues with voting mechanism")
if not document_awareness_success:
print(" - Document Awareness: Issues with document referencing")
if not document_update_success:
print(" - Document Update Workflow: Issues with document improvement process")
if not api_endpoints_success:
print(" - API Endpoints: Issues with API endpoints")
print("="*80)
return all_tests_passed
if __name__ == "__main__":
run_all_tests()