-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
fix: handle string tasks in AutoAgents configuration #802
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,81 @@ | ||||||||||
| #!/usr/bin/env python3 | ||||||||||
| """Test script to verify the AutoAgents fix for string tasks""" | ||||||||||
|
|
||||||||||
| import json | ||||||||||
| from praisonaiagents.agents.autoagents import AutoAgents | ||||||||||
|
|
||||||||||
| # Test the _normalize_config method directly | ||||||||||
| def test_normalize_config(): | ||||||||||
| # Create a minimal AutoAgents instance just to test the method | ||||||||||
| agents = AutoAgents( | ||||||||||
| instructions="Test", | ||||||||||
| max_agents=1 | ||||||||||
| ) | ||||||||||
|
|
||||||||||
| # Test case 1: Tasks as strings (the problematic case) | ||||||||||
| config_dict = { | ||||||||||
| "main_instruction": "Test instruction", | ||||||||||
| "process_type": "sequential", | ||||||||||
| "agents": [ | ||||||||||
| { | ||||||||||
| "name": "Agent 1", | ||||||||||
| "role": "Test role", | ||||||||||
| "goal": "Test goal", | ||||||||||
| "backstory": "Test backstory", | ||||||||||
| "tools": [], | ||||||||||
| "tasks": [ | ||||||||||
| "Get the current stock price for Google (GOOG).", | ||||||||||
| "Get the current stock price for Apple (AAPL)." | ||||||||||
| ] | ||||||||||
| } | ||||||||||
| ] | ||||||||||
| } | ||||||||||
|
|
||||||||||
| print("Original config with string tasks:") | ||||||||||
| print(json.dumps(config_dict, indent=2)) | ||||||||||
|
|
||||||||||
| # Normalize the config | ||||||||||
| normalized = agents._normalize_config(config_dict.copy()) | ||||||||||
|
|
||||||||||
| print("\nNormalized config:") | ||||||||||
| print(json.dumps(normalized, indent=2)) | ||||||||||
|
|
||||||||||
| # Verify tasks are now dictionaries | ||||||||||
| for agent in normalized['agents']: | ||||||||||
| for task in agent['tasks']: | ||||||||||
| assert isinstance(task, dict), f"Task should be dict, got {type(task)}" | ||||||||||
| assert 'name' in task, "Task missing 'name' field" | ||||||||||
| assert 'description' in task, "Task missing 'description' field" | ||||||||||
| assert 'expected_output' in task, "Task missing 'expected_output' field" | ||||||||||
| assert 'tools' in task, "Task missing 'tools' field" | ||||||||||
|
|
||||||||||
| print("\n✅ Test passed: String tasks are properly normalized to TaskConfig format") | ||||||||||
|
|
||||||||||
| # Test case 2: Tasks already as dictionaries (should work as before) | ||||||||||
| config_dict2 = { | ||||||||||
| "main_instruction": "Test instruction", | ||||||||||
| "process_type": "sequential", | ||||||||||
| "agents": [ | ||||||||||
| { | ||||||||||
| "name": "Agent 1", | ||||||||||
| "role": "Test role", | ||||||||||
| "goal": "Test goal", | ||||||||||
| "backstory": "Test backstory", | ||||||||||
| "tools": [], | ||||||||||
| "tasks": [ | ||||||||||
| { | ||||||||||
| "name": "Get Google stock", | ||||||||||
| "description": "Get the current stock price for Google (GOOG).", | ||||||||||
| "expected_output": "Stock price of Google", | ||||||||||
| "tools": ["get_stock_price"] | ||||||||||
| } | ||||||||||
| ] | ||||||||||
| } | ||||||||||
| ] | ||||||||||
| } | ||||||||||
|
|
||||||||||
| normalized2 = agents._normalize_config(config_dict2.copy()) | ||||||||||
| print("\n✅ Test passed: Dict tasks remain properly formatted") | ||||||||||
|
Comment on lines
+77
to
+79
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This test case for dictionary-based tasks is missing assertions, which means it doesn't actually verify that the Add an assertion to ensure that a valid configuration is not modified by the normalization process. Additionally, this test file appears to be a standalone script. For better maintainability and integration with CI/CD pipelines, structure it as a proper test using a framework like
Suggested change
|
||||||||||
|
|
||||||||||
| if __name__ == "__main__": | ||||||||||
| test_normalize_config() | ||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The current logic for setting a default
descriptionwhen it's missing results in it being a copy of thename. This can lead to redundant information and less descriptive task configurations, as thenameis often a summary. Consider using a more informative default for the description to improve clarity.