Skip to content

Conversation

@devin-ai-integration
Copy link
Contributor

Fix: Set crew attribute on planning agent to prevent EventBus errors

Summary

Fixes issue #3782 where the planning agent created by CrewPlanner didn't have its crew attribute set, causing EventBus errors like 'NoneType' object has no attribute 'key' when telemetry tried to access task.agent.crew.key.

Root cause: In CrewPlanner._create_planning_agent(), the agent was created without setting its crew attribute, unlike regular agents which get their crew set in Crew.kickoff() (line 692). When the planning task executes, event handlers try to access agent.crew.key, which fails.

Fix:

  • Pass the crew instance to CrewPlanner constructor
  • Set the crew attribute on the planning agent if provided
  • Backward compatible (crew parameter defaults to None)

Changes:

  • CrewPlanner.__init__: Added optional crew parameter
  • CrewPlanner._create_planning_agent: Sets planning_agent.crew = self.crew if crew is provided
  • Crew._handle_crew_planning: Passes crew=self to CrewPlanner
  • Added test test_planning_agent_has_crew_attribute to verify the fix
  • Renamed test class from InternalCrewPlanner to TestCrewPlanner (pytest convention)

Review & Testing Checklist for Human

  • Reproduce the original error: Create a crew with planning=True, execute it, and verify the EventBus error mentioned in [BUG] planning_agent创建的时候为什么没有指定crew,导致了后面流程中使用crew的时候报错了 #3782 no longer occurs
  • Verify test catches the bug: Comment out the if self.crew: planning_agent.crew = self.crew lines in planning_handler.py and confirm the new test fails
  • Check for other CrewPlanner instantiations: Search codebase for other places where CrewPlanner might be created without the crew parameter (I found only one call site in Crew._handle_crew_planning)
  • Test planning functionality end-to-end: Run a real crew with planning=True and verify no regressions in planning behavior
  • Verify CI passes: Ensure all CI checks pass, especially the planning-related tests

Notes

  • One pre-existing test failure in test_create_tasks_summary_with_knowledge_and_tools (unrelated to this PR - chromadb mock issue)
  • Test class renamed from InternalCrewPlanner to TestCrewPlanner to fix pytest discovery
  • Had to regenerate uv.lock during testing (it was corrupted), but restored it from git - should be clean now

Session: https://app.devin.ai/sessions/35dc88450fa54b8d9ca784bfab6dc3b4
Requested by: João ([email protected])

- Added crew parameter to CrewPlanner.__init__() to accept crew reference
- Modified _create_planning_agent() to set crew attribute on planning agent
- Updated Crew._handle_crew_planning() to pass crew reference to CrewPlanner
- Added test to verify planning agent has crew attribute set
- Renamed test class from InternalCrewPlanner to TestCrewPlanner for pytest compatibility

Fixes #3782

Co-Authored-By: João <[email protected]>
@devin-ai-integration
Copy link
Contributor Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants