Skip to content

Comments

Fix #4555: Flows do not work with kickoff_for_each#4556

Open
devin-ai-integration[bot] wants to merge 1 commit intomainfrom
devin/1771676690-fix-kickoff-for-each-in-flows
Open

Fix #4555: Flows do not work with kickoff_for_each#4556
devin-ai-integration[bot] wants to merge 1 commit intomainfrom
devin/1771676690-fix-kickoff-for-each-in-flows

Conversation

@devin-ai-integration
Copy link
Contributor

Fix #4555: Flows do not work with kickoff_for_each

Summary

Addresses #4555kickoff_for_each (and async variants) fails with a Pydantic validation error when called inside a Flow method.

Root cause: The old FlowTrackable mixin had a parent_flow: InstanceOf[Flow[Any]] Pydantic field. When Crew.copy() called model_dump()Crew(**copied_data), the Flow instance couldn't survive Pydantic re-validation due to __class_getitem__ type mismatch.

The primary fix was already landed in 9d7f4537 (replacing parent_flow with context variables). This PR adds:

  1. Defensive exclusion: "parent_flow" added to the exclude set in Crew.copy() so that if the field ever reappears or a user is on a transitional version, copy() won't break.
  2. 6 regression tests covering the exact scenarios from the issue:
    • kickoff_for_each inside a @listen method of a Flow[TypedState]
    • kickoff_for_each with @CrewBase pattern inside a flow listener
    • crew.copy() preserving flow context (_flow_id, _request_id) in listeners
    • kickoff_for_each_async in flow listeners
    • akickoff_for_each in flow listeners
    • Multiple kickoff_for_each across chained @listen methods

Review & Testing Checklist for Human

  • Verify the defensive "parent_flow" exclusion is the right approach. Since parent_flow no longer exists as a field on the current model, adding it to exclude is a no-op today. Consider whether a more generic safeguard (e.g., catching unknown fields) would be preferable.
  • Confirm tests would actually catch a regression. These tests pass because parent_flow was already removed. If the field were re-added (e.g., by a future change), the exclude entry would protect copy(), but it's worth verifying this mental model.
  • Manual test: Create a simple flow with Flow[SomeState] that calls crew.kickoff_for_each() inside a @listen method (matching the pattern in the issue) and confirm it works end-to-end with real LLM calls.

Notes

  • The parent_flow field removal (the real fix) was done in commit 9d7f4537 and is already on main but only in pre-release tags (1.10.0a1). Users on 1.9.x will still hit this bug.
  • All 6 new tests pass locally. Tests mock kickoff/kickoff_async/akickoff to avoid LLM dependency.

Requested by: João
Link to Devin run

- Add 'parent_flow' to the exclude set in Crew.copy() for forward
  compatibility with older versions that had parent_flow as a Pydantic
  field on FlowTrackable
- Add comprehensive regression tests covering:
  - kickoff_for_each inside a @listen method of a Flow[TypedState]
  - kickoff_for_each with @crewbase pattern inside flow listeners
  - crew.copy() preserving flow context in listeners
  - kickoff_for_each_async in flow listeners
  - akickoff_for_each in flow listeners
  - Multiple kickoff_for_each across chained @listen methods

Co-Authored-By: João <joao@crewai.com>
@devin-ai-integration
Copy link
Contributor Author

Prompt hidden (unlisted session)

@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

Regression test for https://github.com/crewAIInc/crewAI/issues/4555
"""

class ResearchState(BaseModel):
process=Process.sequential,
)

class MyState(BaseModel):
Regression test for https://github.com/crewAIInc/crewAI/issues/4555
"""

class MyState(BaseModel):
Regression test for https://github.com/crewAIInc/crewAI/issues/4555
"""

class MyState(BaseModel):
Regression test for https://github.com/crewAIInc/crewAI/issues/4555
"""

class MyState(BaseModel):
Regression test for https://github.com/crewAIInc/crewAI/issues/4555
"""

class ChainState(BaseModel):
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.

[BUG] Flows do not work with kickoff_for_each

0 participants