[AAASM-1183] ✨ (crewai): Add team_id, delegation_reason, and hierarchical Crew.kickoff patch#40
Merged
Chisanan232 merged 4 commits intoMay 9, 2026
Conversation
Adds team_id: str | None = None to carry the crew/team identifier through the spawn lineage chain. Required by AAASM-1183 for CrewAI. Closes AAASM-1183
…ical patch - team_id: str(crew.id) extracted via task.agent.crew path in patched_execute_sync - delegation_reason: task.description[:256] (None when empty) on every delegated task - _apply_crew_kickoff_patch / _revert_crew_kickoff_patch: wraps Crew.kickoff with spawn_context_scope when Process.hierarchical detected; sets team_id and spawned_by_tool="crewai_kickoff_hierarchical" - CrewAIPatch.apply/revert wired to include crew kickoff lifecycle - Fix pre-existing UP035, B010 violations in crewai/patch.py
- TestTaskExecuteSyncSpawnContext: +5 cases for team_id from agent.crew, team_id=None when no crew, delegation_reason propagation, 256-char truncation, None when description empty - TestExtractCrewTeamId: 4 cases (str conversion, None crew, no id attr, non-str id) - TestExtractManagerAgentId: 3 cases - TestIsHierarchicalProcess: 2 cases (sequential bypass, ImportError guard) - TestApplyCrewKickoffPatch: 5 cases (non-hierarchical bypass, hierarchical sets ctx, ctx reset after kickoff, idempotent apply, revert restores original)
Test 8: Crew.kickoff (hierarchical) sets _SPAWN_CTX with team_id="crew-team-42", parent_agent_id from manager_agent, spawned_by_tool="crewai_kickoff_hierarchical" at depth=1. Delegated tasks within the kickoff see depth=2, team_id propagated, delegation_reason from task.description. _SPAWN_CTX reset to None on exit.
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



What changed
Extends the CrewAI adapter with three spawn lineage enrichments:
team_id— added toSpawnContext; set tostr(crew.id)when a task is delegated within a Crew (resolved viatask.agent.crew.id).delegation_reason— set totask.description[:256](None when empty) on every delegated task execution.Crew.kickoffhierarchical hook — patchesCrew.kickoffto wrap the entire hierarchical execution in aspawn_context_scopecarrying the manager agent's ID,spawned_by_tool="crewai_kickoff_hierarchical", andteam_id. Tasks executed within the kickoff inherit the outer context and increment depth correctly.Also fixes pre-existing UP035, B010 violations in
crewai/patch.py.Why it changed
AAASM-1183: the flat-process
task.execute_syncpath was already intercepted (AAASM-1181), butteam_id,delegation_reason, and the hierarchical manager delegation loop were missing.Changes
agent_assembly/core/spawn.py—team_id: str | None = Nonefield onSpawnContextagent_assembly/adapters/crewai/patch.py_load_crewai_crew_class,_extract_crew_team_id,_extract_manager_agent_id,_is_hierarchical_processhelperspatched_execute_syncenriched withteam_idanddelegation_reason_apply_crew_kickoff_patch/_revert_crew_kickoff_patchfor hierarchical processCrewAIPatch.apply/revertwired to include crew kickoff lifecycletest/unit/adapters/crewai/test_crewai_spawn_context.py— 23 new cases across 5 new test classestest/integration/test_spawn_lineage_integration.py— Test 8: hierarchical kickoff end-to-endHow to verify
uv sync .venv/bin/python -m pytest test/unit/adapters/crewai/test_crewai_spawn_context.py -v .venv/bin/python -m pytest test/integration/test_spawn_lineage_integration.py::test_crewai_hierarchical_kickoff_sets_team_id_and_spawn_ctx -v .venv/bin/python -m pytest test/ -q # 302 passed, 9 skipped .venv/bin/ruff check agent_assembly/adapters/crewai/patch.py .venv/bin/mypy agent_assembly/adapters/crewai/patch.pyRelated
Closes AAASM-1183
Refs AAASM-212 (parent story)