-
-
Notifications
You must be signed in to change notification settings - Fork 753
fix: comprehensive task_name undefined error resolution #957
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
fix: comprehensive task_name undefined error resolution #957
Conversation
- Add task_name, task_description, task_id parameters to achat method signature - Update all achat call sites in agents.py to pass task parameters where available - Provide fallback None values for API handler contexts without task context - Fix Agent.aexecute to extract task info when available - Resolves NameError: name ''task_name'' is not defined in parallel agent execution Fixes persistent errors in agentic parallelization workflows where callbacks expect task context parameters but they were not being passed correctly through the async execution chain. Co-authored-by: Mervin Praison <MervinPraison@users.noreply.github.com>
WalkthroughThe changes extend the asynchronous agent chat method ( Changes
Sequence Diagram(s)sequenceDiagram
participant Caller
participant Agent
participant LLM
Caller->>Agent: aexecute(task)
Agent->>Agent: Extract task_name, task_description, task_id
Agent->>Agent: achat(prompt, ..., task_name, task_description, task_id)
Agent->>LLM: async_response(prompt, ..., task_name, task_description, task_id)
LLM-->>Agent: Response
Agent-->>Caller: Result
Possibly related PRs
Suggested labels
Poem
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (2)
✨ Finishing Touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
|
@claude review this pull request and do a detailed analysis and fix this if the existing code doesn't have the solution implemented. Making sure it has backward compatibility, no existing features removed. After making those changes, again review the applied changes. Use @web to search if you dont know any information or to find the latest documentation or to find the latest version. Run the code if you think you need to run it to test it. Minimal code change to start with if required any changes. |
|
Claude finished @MervinPraison's task —— View job PR Review & Analysis ✅Conducted detailed analysis of the Todo List:
✅ Review SummaryThis PR successfully addresses the persistent 🔍 Problem AnalysisThe issue occurred because:
✅ Solution Review1. Method Signature Updates -
|
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.
Summary of Changes
Hello @MervinPraison, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!
This pull request provides a comprehensive fix for NameError: name 'task_name' is not defined errors encountered in agentic parallelization workflows. The core issue, where Agent.achat expected task-related parameters not present in its signature, is addressed by updating the method signature, ensuring task context is correctly extracted and passed at all relevant call sites, and providing explicit None fallbacks where task context is not applicable. A new test suite has been added to validate the integrity of these changes.
Highlights
- Method Signature Update: The
Agent.achatmethod signature insrc/praisonai-agents/praisonaiagents/agent/agent.pyhas been updated to explicitly includetask_name,task_description, andtask_idparameters, resolvingNameErrorissues when these were implicitly expected. - Task Context Propagation: The
Agent.aexecutemethod now intelligently extractsname,description, andidfrom a giventaskobject and passes these details to theachatmethod, ensuring task context is maintained through the execution chain. - Consistent API Handler Calls: Multiple
achatcall sites within API handler contexts (e.g.,handle_agent_query,execute_agent_taskinagent.py, andhandle_query,execute_workflow_toolinagents.py) have been updated to explicitly passNonefortask_name,task_description, andtask_idwhen no specific task context is available, preventing undefined variable errors. - Agentic Parallelization Integration: Within
src/praisonai-agents/praisonaiagents/agents/agents.py, theachatcalls made during agentic parallelization workflows now correctly pass thetask.name,task.description, andtask.idattributes, ensuring comprehensive task information is available. - New Test Coverage: A new test script,
test_task_name_fix.py, has been added to validate the fix. It includes tests for theachatmethod's signature, the presence of required attributes onTaskobjects, and successful calls toachatwith task parameters, ensuring the resolution is robust.
Using Gemini Code Assist
The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.
Invoking Gemini
You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.
| Feature | Command | Description |
|---|---|---|
| Code Review | /gemini review |
Performs a code review for the current pull request in its current state. |
| Pull Request Summary | /gemini summary |
Provides a summary of the current pull request in its current state. |
| Comment | @gemini-code-assist | Responds in comments when explicitly tagged, both in issue comments and review comments. |
| Help | /gemini help |
Displays a list of available commands. |
Customization
To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.
Limitations & Feedback
Gemini Code Assist is currently in preview and may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments to provide feedback.
You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.
Footnotes
-
Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩
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.
Code Review
This pull request provides a comprehensive fix for a NameError in the Agent.achat method by adding the missing task_name, task_description, and task_id parameters. The changes correctly update the method signature and all relevant call sites to pass this information, with appropriate fallbacks where task context is unavailable. A new test script has also been added to validate the fix.
The changes are logical and directly address the issue. I've added a couple of suggestions to improve code simplicity and testing practices for better long-term maintainability.
| task_name = getattr(task, 'name', None) if hasattr(task, 'name') else None | ||
| task_description = getattr(task, 'description', None) if hasattr(task, 'description') else None | ||
| task_id = getattr(task, 'id', None) if hasattr(task, 'id') else None |
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 conditional checks with hasattr are redundant here. The getattr(object, attribute, default) function is designed to handle cases where an attribute might not exist by returning the provided default value. You can simplify this code by removing the if hasattr(...) else None part.
| task_name = getattr(task, 'name', None) if hasattr(task, 'name') else None | |
| task_description = getattr(task, 'description', None) if hasattr(task, 'description') else None | |
| task_id = getattr(task, 'id', None) if hasattr(task, 'id') else None | |
| task_name = getattr(task, 'name', None) | |
| task_description = getattr(task, 'description', None) | |
| task_id = getattr(task, 'id', None) |
| @@ -0,0 +1,168 @@ | |||
| #!/usr/bin/env python3 | |||
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.
It's great that you've added a test to validate the fix! To improve the project's test suite and long-term maintainability, I have a couple of suggestions:
-
Test Framework: Consider using a standard testing framework like
pytest. It simplifies test discovery, provides richer assertions, and would allow you to remove the manualmainfunction andprintstatements. Your test functions are already named in apytest-compatible way (test_*), so the transition would be smooth. -
Project Structure: Test files are conventionally placed in a
tests/directory at the root of the project. This helps separate test code from application code and is a standard practice that many tools recognize. -
Path Manipulation: Using
sys.path.insert()can be brittle. Adopting a standard project structure with apyproject.tomland installing the package in editable mode (pip install -e .) for development would make imports cleaner and more robust.
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.
Actionable comments posted: 0
🧹 Nitpick comments (3)
test_task_name_fix.py (3)
14-47: Good test coverage for method signature validation.The test effectively verifies that the
achatmethod includes all required parameters. However, there's a minor formatting issue to fix.Fix the unnecessary f-string prefix:
- print(f" ✅ All required parameters present") + print(" ✅ All required parameters present")
49-87: Good validation of Task class attributes.The test effectively ensures that Task objects have the required attributes that correspond to the new achat parameters.
Fix the unnecessary f-string prefix:
- print(f" ✅ Task has all required attributes") + print(" ✅ Task has all required attributes")
89-132: Excellent test for the core issue being fixed.This test directly validates that the
task_nameundefined error has been resolved, which is the main objective of this PR.Address the static analysis issues:
- response = await agent.achat( + await agent.achat( "Test prompt", task_name="test_task", task_description="Test description", task_id="test_id" ) - print(f" ✅ achat call succeeded (unexpected but good!)") + print(" ✅ achat call succeeded (unexpected but good!)")
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
src/praisonai-agents/praisonaiagents/agent/agent.py(4 hunks)src/praisonai-agents/praisonaiagents/agents/agents.py(3 hunks)test_task_name_fix.py(1 hunks)
🧰 Additional context used
🧠 Learnings (4)
📓 Common learnings
Learnt from: CR
PR: MervinPraison/PraisonAI#0
File: src/praisonai-agents/CLAUDE.md:0-0
Timestamp: 2025-06-30T10:06:17.673Z
Learning: Use the `Task` class from `praisonaiagents/task/` for defining tasks, supporting context, callbacks, output specifications, and guardrails.
Learnt from: CR
PR: MervinPraison/PraisonAI#0
File: src/praisonai-ts/.cursorrules:0-0
Timestamp: 2025-06-30T10:05:51.843Z
Learning: Applies to src/praisonai-ts/src/agents/agents.ts : The 'PraisonAIAgents' class in 'src/agents/agents.ts' should manage multiple agents, tasks, memory, and process type, mirroring the Python 'agents.py'.
Learnt from: CR
PR: MervinPraison/PraisonAI#0
File: src/praisonai-ts/.cursorrules:0-0
Timestamp: 2025-06-30T10:05:51.843Z
Learning: Applies to src/praisonai-ts/src/task/task.ts : The 'Task' class in 'src/task/task.ts' should encapsulate a single unit of work, referencing an agent, with optional callback, memory usage, and task type.
Learnt from: CR
PR: MervinPraison/PraisonAI#0
File: src/praisonai-ts/.windsurfrules:0-0
Timestamp: 2025-06-30T10:06:44.129Z
Learning: Applies to src/praisonai-ts/src/{llm,agent,agents,task}/**/*.ts : Replace all references to 'LLM' or 'litellm' with 'aisdk' usage in TypeScript code.
Learnt from: CR
PR: MervinPraison/PraisonAI#0
File: src/praisonai-ts/.cursorrules:0-0
Timestamp: 2025-06-30T10:05:51.843Z
Learning: Applies to src/praisonai-ts/src/agent/agent.ts : The 'Agent' class in 'src/agent/agent.ts' should encapsulate a single agent's role, name, and methods for calling the LLM using 'aisdk'.
Learnt from: CR
PR: MervinPraison/PraisonAI#0
File: src/praisonai-ts/.windsurfrules:0-0
Timestamp: 2025-06-30T10:06:44.129Z
Learning: Applies to src/praisonai-ts/src/**/*.ts : Implement error handling with error logging, retry mechanisms, fallback strategies, and error display functions as described in the Python library.
Learnt from: CR
PR: MervinPraison/PraisonAI#0
File: src/praisonai-agents/CLAUDE.md:0-0
Timestamp: 2025-06-30T10:06:17.673Z
Learning: Applies to src/praisonai-agents/praisonaiagents/mcp/**/*.py : Implement MCP server and SSE support for distributed execution and real-time communication in `praisonaiagents/mcp/`.
Learnt from: CR
PR: MervinPraison/PraisonAI#0
File: src/praisonai-agents/CLAUDE.md:0-0
Timestamp: 2025-06-30T10:06:17.673Z
Learning: Applies to src/praisonai-agents/praisonaiagents/{memory,knowledge}/**/*.py : Place memory-related implementations in `praisonaiagents/memory/` and knowledge/document processing in `praisonaiagents/knowledge/`.
Learnt from: CR
PR: MervinPraison/PraisonAI#0
File: src/praisonai-agents/CLAUDE.md:0-0
Timestamp: 2025-06-30T10:06:17.673Z
Learning: Support async execution in all major components by implementing async methods (e.g., `astart`, `aexecute`).
src/praisonai-agents/praisonaiagents/agents/agents.py (4)
Learnt from: CR
PR: MervinPraison/PraisonAI#0
File: src/praisonai-agents/CLAUDE.md:0-0
Timestamp: 2025-06-30T10:06:17.673Z
Learning: Applies to src/praisonai-agents/praisonaiagents/mcp/**/*.py : Implement MCP server and SSE support for distributed execution and real-time communication in `praisonaiagents/mcp/`.
Learnt from: CR
PR: MervinPraison/PraisonAI#0
File: src/praisonai-ts/.cursorrules:0-0
Timestamp: 2025-06-30T10:05:51.843Z
Learning: Applies to src/praisonai-ts/src/agents/agents.ts : The 'PraisonAIAgents' class in 'src/agents/agents.ts' should manage multiple agents, tasks, memory, and process type, mirroring the Python 'agents.py'.
Learnt from: CR
PR: MervinPraison/PraisonAI#0
File: src/praisonai-agents/CLAUDE.md:0-0
Timestamp: 2025-06-30T10:06:17.673Z
Learning: Use the `Task` class from `praisonaiagents/task/` for defining tasks, supporting context, callbacks, output specifications, and guardrails.
Learnt from: CR
PR: MervinPraison/PraisonAI#0
File: src/praisonai-ts/.cursorrules:0-0
Timestamp: 2025-06-30T10:05:51.843Z
Learning: Applies to src/praisonai-ts/src/task/task.ts : The 'Task' class in 'src/task/task.ts' should encapsulate a single unit of work, referencing an agent, with optional callback, memory usage, and task type.
test_task_name_fix.py (7)
Learnt from: CR
PR: MervinPraison/PraisonAI#0
File: src/praisonai-agents/CLAUDE.md:0-0
Timestamp: 2025-06-30T10:06:17.673Z
Learning: Applies to src/praisonai-agents/tests/**/*.py : Test files should be placed in the `tests/` directory and demonstrate specific usage patterns, serving as both test and documentation.
Learnt from: CR
PR: MervinPraison/PraisonAI#0
File: src/praisonai-agents/CLAUDE.md:0-0
Timestamp: 2025-06-30T10:06:17.673Z
Learning: Use the `Task` class from `praisonaiagents/task/` for defining tasks, supporting context, callbacks, output specifications, and guardrails.
Learnt from: CR
PR: MervinPraison/PraisonAI#0
File: src/praisonai-ts/.cursorrules:0-0
Timestamp: 2025-06-30T10:05:51.843Z
Learning: Applies to src/praisonai-ts/src/task/task.ts : The 'Task' class in 'src/task/task.ts' should encapsulate a single unit of work, referencing an agent, with optional callback, memory usage, and task type.
Learnt from: CR
PR: MervinPraison/PraisonAI#0
File: src/praisonai-ts/.cursorrules:0-0
Timestamp: 2025-06-30T10:05:51.843Z
Learning: Applies to src/praisonai-ts/src/agents/agents.ts : The 'PraisonAIAgents' class in 'src/agents/agents.ts' should manage multiple agents, tasks, memory, and process type, mirroring the Python 'agents.py'.
Learnt from: CR
PR: MervinPraison/PraisonAI#0
File: src/praisonai-agents/CLAUDE.md:0-0
Timestamp: 2025-06-30T10:06:17.673Z
Learning: Run individual test files as scripts (e.g., `python tests/basic-agents.py`) rather than using a formal test runner.
Learnt from: CR
PR: MervinPraison/PraisonAI#0
File: src/praisonai-agents/CLAUDE.md:0-0
Timestamp: 2025-06-30T10:06:17.673Z
Learning: Use conda environment activation (`conda activate praisonai-agents`) before running development or tests.
Learnt from: CR
PR: MervinPraison/PraisonAI#0
File: src/praisonai-ts/.cursorrules:0-0
Timestamp: 2025-06-30T10:05:51.843Z
Learning: Applies to src/praisonai-ts/src/tools/test.ts : The 'src/tools/test.ts' file should provide a script for running each tool's internal test or example.
src/praisonai-agents/praisonaiagents/agent/agent.py (5)
undefined
<retrieved_learning>
Learnt from: CR
PR: MervinPraison/PraisonAI#0
File: src/praisonai-agents/CLAUDE.md:0-0
Timestamp: 2025-06-30T10:06:17.673Z
Learning: Applies to src/praisonai-agents/praisonaiagents/mcp/**/*.py : Implement MCP server and SSE support for distributed execution and real-time communication in praisonaiagents/mcp/.
</retrieved_learning>
<retrieved_learning>
Learnt from: CR
PR: MervinPraison/PraisonAI#0
File: src/praisonai-agents/CLAUDE.md:0-0
Timestamp: 2025-06-30T10:06:17.673Z
Learning: Use the Task class from praisonaiagents/task/ for defining tasks, supporting context, callbacks, output specifications, and guardrails.
</retrieved_learning>
<retrieved_learning>
Learnt from: CR
PR: MervinPraison/PraisonAI#0
File: src/praisonai-ts/.cursorrules:0-0
Timestamp: 2025-06-30T10:05:51.843Z
Learning: Applies to src/praisonai-ts/src/task/task.ts : The 'Task' class in 'src/task/task.ts' should encapsulate a single unit of work, referencing an agent, with optional callback, memory usage, and task type.
</retrieved_learning>
<retrieved_learning>
Learnt from: CR
PR: MervinPraison/PraisonAI#0
File: src/praisonai-ts/.cursorrules:0-0
Timestamp: 2025-06-30T10:05:51.843Z
Learning: Applies to src/praisonai-ts/src/agents/agents.ts : The 'PraisonAIAgents' class in 'src/agents/agents.ts' should manage multiple agents, tasks, memory, and process type, mirroring the Python 'agents.py'.
</retrieved_learning>
<retrieved_learning>
Learnt from: CR
PR: MervinPraison/PraisonAI#0
File: src/praisonai-agents/CLAUDE.md:0-0
Timestamp: 2025-06-30T10:06:17.673Z
Learning: Support async execution in all major components by implementing async methods (e.g., astart, aexecute).
</retrieved_learning>
🪛 Ruff (0.12.2)
test_task_name_fix.py
42-42: f-string without any placeholders
Remove extraneous f prefix
(F541)
79-79: f-string without any placeholders
Remove extraneous f prefix
(F541)
107-107: Local variable response is assigned to but never used
Remove assignment to unused variable response
(F841)
113-113: f-string without any placeholders
Remove extraneous f prefix
(F541)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (4)
- GitHub Check: Cursor BugBot
- GitHub Check: quick-test
- GitHub Check: test-core (3.11)
- GitHub Check: Run tests and collect coverage
🔇 Additional comments (9)
src/praisonai-agents/praisonaiagents/agents/agents.py (4)
365-368: LGTM! Task metadata correctly propagated to achat.The task attributes are properly passed to the achat method, which should resolve the undefined task_name errors in agentic parallelization workflows.
375-378: LGTM! Consistent task metadata propagation.The task parameters are passed consistently in both the multimodal and non-multimodal execution paths.
1147-1147: LGTM! Appropriate fallback values for HTTP API context.Setting task parameters to
Noneis correct for the HTTP API handler where no specific task context is available.
1303-1303: LGTM! Appropriate fallback values for MCP context.Setting task parameters to
Noneis correct for the MCP workflow tool where no specific task context is available.test_task_name_fix.py (1)
134-168: Well-structured test script with clear output and proper coordination.The test script effectively validates all aspects of the task_name fix with good error handling and informative output.
src/praisonai-agents/praisonaiagents/agent/agent.py (4)
1539-1539: LGTM: Method signature correctly extended with task parameters.The
achatmethod signature has been properly updated to include the three task-related parameters with appropriate defaults, maintaining backward compatibility.
1947-1951: LGTM: Task context extraction and propagation correctly implemented.The implementation safely extracts task attributes using defensive programming patterns and properly passes them to the
achatmethod. The use ofhasattrandgetattrwith fallbacks ensures robust handling of different task object types.
2120-2120: LGTM: API handler correctly updated with task parameters.The HTTP API handler appropriately passes None values for task parameters since API requests typically don't carry task context. This maintains existing functionality while ensuring compatibility with the updated method signature.
2241-2241: LGTM: MCP server tool correctly updated with task parameters.The MCP tool execution correctly passes None values for task parameters, which is appropriate since MCP tool calls may not have specific task context. This ensures compatibility while maintaining existing functionality.
|
@claude review if the changes made in the above branch are as per the requirements and make changes to the above branch if issues still exist. |
|
Claude finished @MervinPraison's task —— View job PR Review & Analysis ✅Conducted detailed analysis of the Todo List:
✅ Review SummaryThis PR successfully addresses the persistent 🔍 Problem AnalysisThe issue occurred because:
✅ Solution Review1. Method Signature Updates -
|
- Remove redundant hasattr checks in agent.py as getattr handles missing attributes - Fix unnecessary f-string prefixes in test file - Remove unused variable assignment in test Co-authored-by: Mervin Praison <MervinPraison@users.noreply.github.com>
Comprehensive fix for persistent task_name undefined errors in agentic parallelization workflows.
Problem
The
Agent.achatmethod was trying to passtask_name,task_description, andtask_idparameters to the LLM'sget_response_asyncmethod, but these parameters were not included in theachatmethod signature, causingNameError: name 'task_name' is not defined.Solution
achatmethod signature to include task parametersFiles Changed
src/praisonai-agents/praisonaiagents/agent/agent.pysrc/praisonai-agents/praisonaiagents/agents/agents.pyTesting
Generated with Claude Code
Summary by CodeRabbit
New Features
Bug Fixes
Tests