1+ #!/usr/bin/env python3
2+ """Comprehensive test script to verify self-reflection works with tools after the fix"""
3+
4+ from praisonaiagents import Agent , Task , PraisonAIAgents
5+ from praisonaiagents .tools import duckduckgo_search
6+
7+ def test_self_reflection_with_tools ():
8+ """Test self-reflection with tools - should work after the fix"""
9+ print ("=== Testing Self-Reflection WITH Tools ===" )
10+
11+ # Create an agent with self-reflection and tools
12+ agent = Agent (
13+ role = "Senior Research Analyst" ,
14+ goal = "Analyze and provide insights on given topics" ,
15+ backstory = "You are an expert analyst with strong critical thinking skills" ,
16+ self_reflect = True ,
17+ llm = "gemini/gemini-2.5-flash-lite-preview-06-17" ,
18+ verbose = True ,
19+ tools = [duckduckgo_search ]
20+ )
21+
22+ # Create a task
23+ task = Task (
24+ description = "Search for recent developments in AI and provide a brief analysis" ,
25+ expected_output = "A detailed analysis report" ,
26+ agent = agent
27+ )
28+
29+ # Create and start the agents
30+ agents = PraisonAIAgents (
31+ agents = [agent ],
32+ tasks = [task ],
33+ process = "sequential"
34+ )
35+
36+ try :
37+ # Start execution
38+ result = agents .start ()
39+ print (f"Result with tools: { result } " )
40+
41+ assert result , "Self-reflection with tools failed to produce a result."
42+ print ("\n ✅ SUCCESS: Self-reflection with tools is working!" )
43+ return result
44+
45+ except Exception as e :
46+ print (f"\n ❌ ERROR: { str (e )} " )
47+ raise AssertionError (f"Test with tools failed: { str (e )} " )
48+
49+ def test_self_reflection_without_tools ():
50+ """Test self-reflection without tools - should work (baseline)"""
51+ print ("\n === Testing Self-Reflection WITHOUT Tools ===" )
52+
53+ # Create an agent with self-reflection but no tools
54+ agent = Agent (
55+ role = "Senior Research Analyst" ,
56+ goal = "Analyze and provide insights on given topics" ,
57+ backstory = "You are an expert analyst with strong critical thinking skills" ,
58+ self_reflect = True ,
59+ llm = "gemini/gemini-2.5-flash-lite-preview-06-17" ,
60+ verbose = True
61+ )
62+
63+ # Create a task
64+ task = Task (
65+ description = "Analyze recent developments in AI" ,
66+ expected_output = "A detailed analysis report" ,
67+ agent = agent
68+ )
69+
70+ # Create and start the agents
71+ agents = PraisonAIAgents (
72+ agents = [agent ],
73+ tasks = [task ],
74+ process = "sequential"
75+ )
76+
77+ try :
78+ # Start execution
79+ result = agents .start ()
80+ print (f"Result without tools: { result } " )
81+
82+ assert result , "Self-reflection without tools failed to produce a result."
83+ print ("\n ✅ SUCCESS: Self-reflection without tools is working!" )
84+ return result
85+
86+ except Exception as e :
87+ print (f"\n ❌ ERROR: { str (e )} " )
88+ raise AssertionError (f"Test without tools failed: { str (e )} " )
89+
90+ if __name__ == "__main__" :
91+ print ("Testing self-reflection fix..." )
92+
93+ # Test without tools (should work)
94+ try :
95+ result_without_tools = test_self_reflection_without_tools ()
96+ without_tools_success = True
97+ except Exception as e :
98+ print (f"Test without tools failed: { e } " )
99+ without_tools_success = False
100+
101+ # Test with tools (should work after fix)
102+ try :
103+ result_with_tools = test_self_reflection_with_tools ()
104+ with_tools_success = True
105+ except Exception as e :
106+ print (f"Test with tools failed: { e } " )
107+ with_tools_success = False
108+
109+ print ("\n === Test Summary ===" )
110+ print (f"Without tools: { 'SUCCESS' if without_tools_success else 'FAILED' } " )
111+ print (f"With tools: { 'SUCCESS' if with_tools_success else 'FAILED' } " )
112+
113+ if with_tools_success :
114+ print ("\n ✅ Fix verified: Self-reflection now works with tools!" )
115+ else :
116+ print ("\n ❌ Fix failed: Self-reflection still not working with tools" )
117+ raise AssertionError ("Self-reflection with tools test failed" )
0 commit comments