-
Notifications
You must be signed in to change notification settings - Fork 5.6k
fix: use endpoint-scoped task IDs for A2A delegations (fixes #4166) #4167
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
base: main
Are you sure you want to change the base?
Conversation
This fixes issue #4166 where delegating to a second A2A agent fails because the task_id from the first agent is in 'completed' state. The fix introduces endpoint-scoped task ID storage in task.config using a2a_task_ids_by_endpoint dictionary. This ensures that: - Each A2A endpoint gets its own task_id - Multi-turn conversations with the same endpoint reuse the task_id - Sequential delegations to different endpoints use separate task_ids Added tests to verify: - Sequential delegation to multiple endpoints uses separate task IDs - Multi-turn conversations with same endpoint reuse task IDs - Endpoint-scoped task IDs are properly persisted to task.config Co-Authored-By: João <joao@crewai.com>
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
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.
This is the final PR Bugbot will review for you during this billing cycle
Your free Bugbot reviews will reset on January 28
Details
Your team is on the Bugbot Free tier. On this plan, Bugbot will review limited PRs each billing cycle for each member of your team.
To receive Bugbot reviews on all of your PRs, visit the Cursor dashboard to activate Pro and start your 14-day free trial.
…rsist completed task IDs - Make defensive copy of a2a_task_ids_by_endpoint dict to avoid in-place mutation - Don't persist completed task IDs since A2A protocol rejects terminal state task IDs - Update task_id_config locally for current loop only, not in shared dict - Update tests to verify correct behavior: - Completed task IDs are NOT persisted for reuse - Each new delegation gets a fresh task_id (None) - Completed task IDs are still tracked in reference_task_ids Co-Authored-By: João <joao@crewai.com>
Address Bugbot feedback - handle case where a2a_task_ids_by_endpoint is explicitly set to None (e.g., from JSON/YAML config) to avoid TypeError when calling dict() on None. Co-Authored-By: João <joao@crewai.com>
| class MockResponseA: | ||
| is_a2a = True | ||
| message = "Please help with task A" | ||
| a2a_ids = ["http://endpoint-a.com/"] |
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.
URL trailing slash mismatch causes tests to fail
All three tests have a URL mismatch that would cause them to fail with ValueError before testing the intended behavior. The mock responses use a2a_ids with trailing slashes (e.g., "http://endpoint-a.com/") while the A2AConfig endpoints are configured without trailing slashes (e.g., "http://endpoint-a.com"). The validation at wrapper.py lines 526-529 checks if agent_id is in the configured agent_ids, and these mismatched URLs would fail the check, raising a ValueError immediately. The tests would never reach the code they're designed to verify.
Additional Locations (2)
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.
This is a false positive. The tests pass because they mock _fetch_agent_cards_concurrently and pass agent_cards directly to _delegate_to_a2a. The validation at lines 526-529 checks if agent_id is in the agent_cards dictionary keys, not in the A2AConfig endpoints. Since the tests provide agent_cards with trailing slashes that match the a2a_ids, the validation passes correctly.
The tests are passing in CI (all 3 tests pass across Python 3.10, 3.11, 3.12, and 3.13), confirming this is not an issue.
fix: use endpoint-scoped task IDs for A2A delegations (fixes #4166)
Summary
Fixes issue #4166 where delegating to a second A2A agent fails with
Task <UUID> is in terminal state: completedbecause the task_id from the first agent was being reused.The fix introduces endpoint-scoped task ID handling in
_delegate_to_a2a:reference_task_idsfor history/context purposesNone(e.g., from JSON/YAML)Key changes:
wrapper.py: Changed from globaltask.config["task_id"]to endpoint-scoped lookup; removed persistence of completed task IDsReview & Testing Checklist for Human
task_idby endpoint. Review ifcontext_id(line 589-590) also needs endpoint-scoping to prevent similar issuesRecommended test plan:
Notes