Fix #4555: Flows do not work with kickoff_for_each#4556
Open
devin-ai-integration[bot] wants to merge 1 commit intomainfrom
Open
Fix #4555: Flows do not work with kickoff_for_each#4556devin-ai-integration[bot] wants to merge 1 commit intomainfrom
devin-ai-integration[bot] wants to merge 1 commit intomainfrom
Conversation
- 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>
Contributor
Author
|
Prompt hidden (unlisted session) |
Contributor
Author
🤖 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:
|
| 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): |
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.
Fix #4555: Flows do not work with kickoff_for_each
Summary
Addresses #4555 —
kickoff_for_each(and async variants) fails with a Pydantic validation error when called inside a Flow method.Root cause: The old
FlowTrackablemixin had aparent_flow: InstanceOf[Flow[Any]]Pydantic field. WhenCrew.copy()calledmodel_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(replacingparent_flowwith context variables). This PR adds:"parent_flow"added to theexcludeset inCrew.copy()so that if the field ever reappears or a user is on a transitional version,copy()won't break.kickoff_for_eachinside a@listenmethod of aFlow[TypedState]kickoff_for_eachwith@CrewBasepattern inside a flow listenercrew.copy()preserving flow context (_flow_id,_request_id) in listenerskickoff_for_each_asyncin flow listenersakickoff_for_eachin flow listenerskickoff_for_eachacross chained@listenmethodsReview & Testing Checklist for Human
"parent_flow"exclusion is the right approach. Sinceparent_flowno longer exists as a field on the current model, adding it toexcludeis a no-op today. Consider whether a more generic safeguard (e.g., catching unknown fields) would be preferable.parent_flowwas already removed. If the field were re-added (e.g., by a future change), theexcludeentry would protectcopy(), but it's worth verifying this mental model.Flow[SomeState]that callscrew.kickoff_for_each()inside a@listenmethod (matching the pattern in the issue) and confirm it works end-to-end with real LLM calls.Notes
parent_flowfield removal (the real fix) was done in commit9d7f4537and is already onmainbut only in pre-release tags (1.10.0a1). Users on1.9.xwill still hit this bug.kickoff/kickoff_async/akickoffto avoid LLM dependency.Requested by: João
Link to Devin run