1+ #!/usr/bin/env python3
2+ """
3+ Test script to validate the task_name fix for agentic parallelization.
4+ This script tests the structure without requiring API keys.
5+ """
6+
7+ import asyncio
8+ import sys
9+ import os
10+
11+ # Add the source path to sys.path
12+ sys .path .insert (0 , os .path .join (os .path .dirname (__file__ ), 'src' , 'praisonai-agents' ))
13+
14+ def test_achat_signature ():
15+ """Test that achat method has the correct signature"""
16+ try :
17+ from praisonaiagents import Agent
18+
19+ # Create a basic agent
20+ agent = Agent (
21+ name = "TestAgent" ,
22+ role = "Test Role" ,
23+ goal = "Test Goal" ,
24+ llm = "mock-llm" # Using a mock LLM
25+ )
26+
27+ # Check if achat method exists and has the correct signature
28+ import inspect
29+ achat_sig = inspect .signature (agent .achat )
30+ params = list (achat_sig .parameters .keys ())
31+
32+ required_params = ['prompt' , 'temperature' , 'tools' , 'output_json' , 'output_pydantic' , 'reasoning_steps' , 'task_name' , 'task_description' , 'task_id' ]
33+
34+ print ("✅ Agent.achat signature test:" )
35+ print (f" Method parameters: { params } " )
36+
37+ missing_params = [p for p in required_params if p not in params ]
38+ if missing_params :
39+ print (f" ❌ Missing parameters: { missing_params } " )
40+ return False
41+ else :
42+ print (" ✅ All required parameters present" )
43+ return True
44+
45+ except Exception as e :
46+ print (f"❌ Error testing achat signature: { e } " )
47+ return False
48+
49+ def test_task_structure ():
50+ """Test that Task objects have the required attributes"""
51+ try :
52+ from praisonaiagents import Agent , Task
53+
54+ # Create a basic task
55+ agent = Agent (
56+ name = "TestAgent" ,
57+ role = "Test Role" ,
58+ goal = "Test Goal" ,
59+ llm = "mock-llm"
60+ )
61+
62+ task = Task (
63+ name = "test_task" ,
64+ description = "Test task description" ,
65+ expected_output = "Test output" ,
66+ agent = agent
67+ )
68+
69+ print ("✅ Task structure test:" )
70+ print (f" Task name: { getattr (task , 'name' , 'MISSING' )} " )
71+ print (f" Task description: { getattr (task , 'description' , 'MISSING' )} " )
72+ print (f" Task id: { getattr (task , 'id' , 'MISSING' )} " )
73+
74+ has_name = hasattr (task , 'name' )
75+ has_description = hasattr (task , 'description' )
76+ has_id = hasattr (task , 'id' )
77+
78+ if has_name and has_description and has_id :
79+ print (" ✅ Task has all required attributes" )
80+ return True
81+ else :
82+ print (f" ❌ Task missing attributes - name: { has_name } , description: { has_description } , id: { has_id } " )
83+ return False
84+
85+ except Exception as e :
86+ print (f"❌ Error testing task structure: { e } " )
87+ return False
88+
89+ async def test_achat_call ():
90+ """Test that achat can be called with task parameters"""
91+ try :
92+ from praisonaiagents import Agent
93+
94+ # Create a basic agent
95+ agent = Agent (
96+ name = "TestAgent" ,
97+ role = "Test Role" ,
98+ goal = "Test Goal" ,
99+ llm = "mock-llm" # This should gracefully handle mock LLM
100+ )
101+
102+ print ("✅ Testing achat call with task parameters:" )
103+
104+ # This should not raise a NameError for task_name anymore
105+ try :
106+ # We expect this to fail due to mock LLM, but NOT due to NameError: task_name not defined
107+ await agent .achat (
108+ "Test prompt" ,
109+ task_name = "test_task" ,
110+ task_description = "Test description" ,
111+ task_id = "test_id"
112+ )
113+ print (" ✅ achat call succeeded (unexpected but good!)" )
114+ return True
115+ except NameError as e :
116+ if "task_name" in str (e ):
117+ print (f" ❌ Still getting task_name NameError: { e } " )
118+ return False
119+ else :
120+ print (f" ⚠️ Different NameError (acceptable): { e } " )
121+ return True
122+ except Exception as e :
123+ if "task_name" in str (e ) and "not defined" in str (e ):
124+ print (f" ❌ Still getting task_name error: { e } " )
125+ return False
126+ else :
127+ print (f" ✅ Different error (expected with mock LLM): { type (e ).__name__ } : { e } " )
128+ return True
129+
130+ except Exception as e :
131+ print (f"❌ Error testing achat call: { e } " )
132+ return False
133+
134+ async def main ():
135+ """Run all tests"""
136+ print ("🧪 Testing task_name fix for agentic parallelization..." )
137+ print ()
138+
139+ results = []
140+
141+ # Test 1: Check achat signature
142+ results .append (test_achat_signature ())
143+ print ()
144+
145+ # Test 2: Check task structure
146+ results .append (test_task_structure ())
147+ print ()
148+
149+ # Test 3: Test achat call
150+ results .append (await test_achat_call ())
151+ print ()
152+
153+ # Summary
154+ passed = sum (results )
155+ total = len (results )
156+
157+ print (f"📊 Test Results: { passed } /{ total } tests passed" )
158+
159+ if passed == total :
160+ print ("🎉 All tests passed! The task_name fix appears to be working." )
161+ return 0
162+ else :
163+ print ("❌ Some tests failed. The fix may need more work." )
164+ return 1
165+
166+ if __name__ == "__main__" :
167+ exit_code = asyncio .run (main ())
168+ sys .exit (exit_code )
0 commit comments