crewai - ✅(Solved) Fix [BUG] Flows do not work with kickoff_for_each [3 pull requests, 3 comments, 3 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
crewAIInc/crewAI#4555Fetched 2026-04-08 00:41:22
View on GitHub
Comments
3
Participants
3
Timeline
13
Reactions
0
Timeline (top)
commented ×3cross-referenced ×3referenced ×3labeled ×2

I am trying to write a flow that will do the following :

  • Research on {Chapter Name} and generate List<{topic}>
  • For Each {topic}, trigger WriterCrew that will write a section on {topic}

I am hitting the below error :

ERROR:crewai.flow.flow:Error executing listener generate_section: 1 validation error for Crew
parent_flow
  Input should be an instance of Flow.__class_getitem__.<locals>._FlowGeneric [type=is_instance_of, input_value=<authoring_flow.main.Rese...w object at 0x100e30b00>, input_type=ResearchFlow]
    For further information visit https://errors.pydantic.dev/2.11/v/is_instance_of
ERROR:crewai.flow.flow:Error executing listener research_topics: 1 validation error for Crew
parent_flow
  Input should be an instance of Flow.__class_getitem__.<locals>._FlowGeneric [type=is_instance_of, input_value=<authoring_flow.main.Rese...w object at 0x100e30b00>, input_type=ResearchFlow]
    For further information visit https://errors.pydantic.dev/2.11/v/is_instance_of
╭───────────────────────────────────────────────────────────────────────────────────────────── ❌ Flow Method Failed ─────────────────────────────────────────────────────────────────────────────────────────────╮
│                                                                                                                                                                                                                 │
│  Method: generate_section                                                                                                                                                                                       │
│  Status: Failed                                                                                                                                                                                                 │
│                                                                                                                                                                                                                 │
│                                                                                                                                                                                                                 │
╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯

Traceback (most recent call last):
  File "/Users/aswunnik/Feb 2026/Learning/Multi Agent Systems/book_author/authoring_flow/.venv/bin/kickoff", line 12, in <module>
    sys.exit(kickoff())
             ^^^^^^^^^
  File "/Users/aswunnik/Feb 2026/Learning/Multi Agent Systems/book_author/authoring_flow/src/authoring_flow/main.py", line 70, in kickoff
    poem_flow.kickoff()
  File "/Users/aswunnik/Feb 2026/Learning/Multi Agent Systems/book_author/authoring_flow/.venv/lib/python3.12/site-packages/crewai/flow/flow.py", line 1475, in kickoff
    return asyncio.run(_run_flow())
           ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/aswunnik/.local/share/uv/python/cpython-3.12.11-macos-aarch64-none/lib/python3.12/asyncio/runners.py", line 195, in run
    return runner.run(main)
           ^^^^^^^^^^^^^^^^
  File "/Users/aswunnik/.local/share/uv/python/cpython-3.12.11-macos-aarch64-none/lib/python3.12/asyncio/runners.py", line 118, in run
    return self._loop.run_until_complete(task)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/aswunnik/.local/share/uv/python/cpython-3.12.11-macos-aarch64-none/lib/python3.12/asyncio/base_events.py", line 691, in run_until_complete
    return future.result()
           ^^^^^^^^^^^^^^^
  File "/Users/aswunnik/Feb 2026/Learning/Multi Agent Systems/book_author/authoring_flow/.venv/lib/python3.12/site-packages/crewai/flow/flow.py", line 1473, in _run_flow
    return await self.kickoff_async(inputs, input_files)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/aswunnik/Feb 2026/Learning/Multi Agent Systems/book_author/authoring_flow/.venv/lib/python3.12/site-packages/crewai/flow/flow.py", line 1628, in kickoff_async
    await asyncio.gather(*tasks)
  File "/Users/aswunnik/Feb 2026/Learning/Multi Agent Systems/book_author/authoring_flow/.venv/lib/python3.12/site-packages/crewai/flow/flow.py", line 1813, in _execute_start_method
    await self._execute_listeners(start_method_name, result, finished_event_id)
  File "/Users/aswunnik/Feb 2026/Learning/Multi Agent Systems/book_author/authoring_flow/.venv/lib/python3.12/site-packages/crewai/flow/flow.py", line 2074, in _execute_listeners
    await asyncio.gather(*tasks)
  File "/Users/aswunnik/Feb 2026/Learning/Multi Agent Systems/book_author/authoring_flow/.venv/lib/python3.12/site-packages/crewai/flow/flow.py", line 2327, in _execute_single_listener
    await self._execute_listeners(
  File "/Users/aswunnik/Feb 2026/Learning/Multi Agent Systems/book_author/authoring_flow/.venv/lib/python3.12/site-packages/crewai/flow/flow.py", line 2074, in _execute_listeners
    await asyncio.gather(*tasks)
  File "/Users/aswunnik/Feb 2026/Learning/Multi Agent Systems/book_author/authoring_flow/.venv/lib/python3.12/site-packages/crewai/flow/flow.py", line 2313, in _execute_single_listener
    listener_result, finished_event_id = await self._execute_method(
                                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/aswunnik/Feb 2026/Learning/Multi Agent Systems/book_author/authoring_flow/.venv/lib/python3.12/site-packages/crewai/flow/flow.py", line 1960, in _execute_method
    raise e
  File "/Users/aswunnik/Feb 2026/Learning/Multi Agent Systems/book_author/authoring_flow/.venv/lib/python3.12/site-packages/crewai/flow/flow.py", line 1892, in _execute_method
    result = await asyncio.to_thread(ctx.run, method, *args, **kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/aswunnik/.local/share/uv/python/cpython-3.12.11-macos-aarch64-none/lib/python3.12/asyncio/threads.py", line 25, in to_thread
    return await loop.run_in_executor(None, func_call)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/aswunnik/.local/share/uv/python/cpython-3.12.11-macos-aarch64-none/lib/python3.12/concurrent/futures/thread.py", line 59, in run
    result = self.fn(*self.args, **self.kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/aswunnik/Feb 2026/Learning/Multi Agent Systems/book_author/authoring_flow/.venv/lib/python3.12/site-packages/crewai/flow/flow_wrappers.py", line 93, in __call__
    return self._meth(self._instance, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/aswunnik/Feb 2026/Learning/Multi Agent Systems/book_author/authoring_flow/src/authoring_flow/main.py", line 52, in generate_section
    .kickoff_for_each(inputs=inputs)
     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/aswunnik/Feb 2026/Learning/Multi Agent Systems/book_author/authoring_flow/.venv/lib/python3.12/site-packages/crewai/crew.py", line 789, in kickoff_for_each
    crew = self.copy()
           ^^^^^^^^^^^
  File "/Users/aswunnik/Feb 2026/Learning/Multi Agent Systems/book_author/authoring_flow/.venv/lib/python3.12/site-packages/crewai/crew.py", line 1704, in copy
    return Crew(
           ^^^^^
  File "/Users/aswunnik/Feb 2026/Learning/Multi Agent Systems/book_author/authoring_flow/.venv/lib/python3.12/site-packages/pydantic/main.py", line 253, in __init__
    validated_self = self.__pydantic_validator__.validate_python(data, self_instance=self)
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
pydantic_core._pydantic_core.ValidationError: 1 validation error for Crew
parent_flow
  Input should be an instance of Flow.__class_getitem__.<locals>._FlowGeneric [type=is_instance_of, input_value=<authoring_flow.main.Rese...w object at 0x100e30b00>, input_type=ResearchFlow]
    For further information visit https://errors.pydantic.dev/2.11/v/is_instance_of
An error occurred while running the flow: Command '['uv', 'run', 'kickoff']' returned non-zero exit status 1.

Error Message

ERROR:crewai.flow.flow:Error executing listener generate_section: 1 validation error for Crew parent_flow Input should be an instance of Flow.class_getitem.<locals>._FlowGeneric [type=is_instance_of, input_value=<authoring_flow.main.Rese...w object at 0x100e30b00>, input_type=ResearchFlow] For further information visit https://errors.pydantic.dev/2.11/v/is_instance_of ERROR:crewai.flow.flow:Error executing listener research_topics: 1 validation error for Crew parent_flow Input should be an instance of Flow.class_getitem.<locals>._FlowGeneric [type=is_instance_of, input_value=<authoring_flow.main.Rese...w object at 0x100e30b00>, input_type=ResearchFlow] For further information visit https://errors.pydantic.dev/2.11/v/is_instance_of ╭───────────────────────────────────────────────────────────────────────────────────────────── ❌ Flow Method Failed ─────────────────────────────────────────────────────────────────────────────────────────────╮ │ │ │ Method: generate_section │ │ Status: Failed │ │ │ │ │ ╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯

Traceback (most recent call last): File "/Users/aswunnik/Feb 2026/Learning/Multi Agent Systems/book_author/authoring_flow/.venv/bin/kickoff", line 12, in <module> sys.exit(kickoff()) ^^^^^^^^^ File "/Users/aswunnik/Feb 2026/Learning/Multi Agent Systems/book_author/authoring_flow/src/authoring_flow/main.py", line 70, in kickoff poem_flow.kickoff() File "/Users/aswunnik/Feb 2026/Learning/Multi Agent Systems/book_author/authoring_flow/.venv/lib/python3.12/site-packages/crewai/flow/flow.py", line 1475, in kickoff return asyncio.run(_run_flow()) ^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/aswunnik/.local/share/uv/python/cpython-3.12.11-macos-aarch64-none/lib/python3.12/asyncio/runners.py", line 195, in run return runner.run(main) ^^^^^^^^^^^^^^^^ File "/Users/aswunnik/.local/share/uv/python/cpython-3.12.11-macos-aarch64-none/lib/python3.12/asyncio/runners.py", line 118, in run return self._loop.run_until_complete(task) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/aswunnik/.local/share/uv/python/cpython-3.12.11-macos-aarch64-none/lib/python3.12/asyncio/base_events.py", line 691, in run_until_complete return future.result() ^^^^^^^^^^^^^^^ File "/Users/aswunnik/Feb 2026/Learning/Multi Agent Systems/book_author/authoring_flow/.venv/lib/python3.12/site-packages/crewai/flow/flow.py", line 1473, in _run_flow return await self.kickoff_async(inputs, input_files) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/aswunnik/Feb 2026/Learning/Multi Agent Systems/book_author/authoring_flow/.venv/lib/python3.12/site-packages/crewai/flow/flow.py", line 1628, in kickoff_async await asyncio.gather(*tasks) File "/Users/aswunnik/Feb 2026/Learning/Multi Agent Systems/book_author/authoring_flow/.venv/lib/python3.12/site-packages/crewai/flow/flow.py", line 1813, in _execute_start_method await self._execute_listeners(start_method_name, result, finished_event_id) File "/Users/aswunnik/Feb 2026/Learning/Multi Agent Systems/book_author/authoring_flow/.venv/lib/python3.12/site-packages/crewai/flow/flow.py", line 2074, in _execute_listeners await asyncio.gather(*tasks) File "/Users/aswunnik/Feb 2026/Learning/Multi Agent Systems/book_author/authoring_flow/.venv/lib/python3.12/site-packages/crewai/flow/flow.py", line 2327, in _execute_single_listener await self._execute_listeners( File "/Users/aswunnik/Feb 2026/Learning/Multi Agent Systems/book_author/authoring_flow/.venv/lib/python3.12/site-packages/crewai/flow/flow.py", line 2074, in _execute_listeners await asyncio.gather(*tasks) File "/Users/aswunnik/Feb 2026/Learning/Multi Agent Systems/book_author/authoring_flow/.venv/lib/python3.12/site-packages/crewai/flow/flow.py", line 2313, in _execute_single_listener listener_result, finished_event_id = await self._execute_method( ^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/aswunnik/Feb 2026/Learning/Multi Agent Systems/book_author/authoring_flow/.venv/lib/python3.12/site-packages/crewai/flow/flow.py", line 1960, in _execute_method raise e File "/Users/aswunnik/Feb 2026/Learning/Multi Agent Systems/book_author/authoring_flow/.venv/lib/python3.12/site-packages/crewai/flow/flow.py", line 1892, in _execute_method result = await asyncio.to_thread(ctx.run, method, *args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/aswunnik/.local/share/uv/python/cpython-3.12.11-macos-aarch64-none/lib/python3.12/asyncio/threads.py", line 25, in to_thread return await loop.run_in_executor(None, func_call) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/aswunnik/.local/share/uv/python/cpython-3.12.11-macos-aarch64-none/lib/python3.12/concurrent/futures/thread.py", line 59, in run result = self.fn(*self.args, **self.kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/aswunnik/Feb 2026/Learning/Multi Agent Systems/book_author/authoring_flow/.venv/lib/python3.12/site-packages/crewai/flow/flow_wrappers.py", line 93, in call return self._meth(self._instance, *args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/aswunnik/Feb 2026/Learning/Multi Agent Systems/book_author/authoring_flow/src/authoring_flow/main.py", line 52, in generate_section .kickoff_for_each(inputs=inputs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/aswunnik/Feb 2026/Learning/Multi Agent Systems/book_author/authoring_flow/.venv/lib/python3.12/site-packages/crewai/crew.py", line 789, in kickoff_for_each crew = self.copy() ^^^^^^^^^^^ File "/Users/aswunnik/Feb 2026/Learning/Multi Agent Systems/book_author/authoring_flow/.venv/lib/python3.12/site-packages/crewai/crew.py", line 1704, in copy return Crew( ^^^^^ File "/Users/aswunnik/Feb 2026/Learning/Multi Agent Systems/book_author/authoring_flow/.venv/lib/python3.12/site-packages/pydantic/main.py", line 253, in init validated_self = self.pydantic_validator.validate_python(data, self_instance=self) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ pydantic_core._pydantic_core.ValidationError: 1 validation error for Crew parent_flow Input should be an instance of Flow.class_getitem.<locals>._FlowGeneric [type=is_instance_of, input_value=<authoring_flow.main.Rese...w object at 0x100e30b00>, input_type=ResearchFlow] For further information visit https://errors.pydantic.dev/2.11/v/is_instance_of An error occurred while running the flow: Command '['uv', 'run', 'kickoff']' returned non-zero exit status 1.

Root Cause

I am trying to write a flow that will do the following :

  • Research on {Chapter Name} and generate List<{topic}>
  • For Each {topic}, trigger WriterCrew that will write a section on {topic}

I am hitting the below error :

ERROR:crewai.flow.flow:Error executing listener generate_section: 1 validation error for Crew
parent_flow
  Input should be an instance of Flow.__class_getitem__.<locals>._FlowGeneric [type=is_instance_of, input_value=<authoring_flow.main.Rese...w object at 0x100e30b00>, input_type=ResearchFlow]
    For further information visit https://errors.pydantic.dev/2.11/v/is_instance_of
ERROR:crewai.flow.flow:Error executing listener research_topics: 1 validation error for Crew
parent_flow
  Input should be an instance of Flow.__class_getitem__.<locals>._FlowGeneric [type=is_instance_of, input_value=<authoring_flow.main.Rese...w object at 0x100e30b00>, input_type=ResearchFlow]
    For further information visit https://errors.pydantic.dev/2.11/v/is_instance_of
╭───────────────────────────────────────────────────────────────────────────────────────────── ❌ Flow Method Failed ─────────────────────────────────────────────────────────────────────────────────────────────╮
│                                                                                                                                                                                                                 │
│  Method: generate_section                                                                                                                                                                                       │
│  Status: Failed                                                                                                                                                                                                 │
│                                                                                                                                                                                                                 │
│                                                                                                                                                                                                                 │
╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯

Traceback (most recent call last):
  File "/Users/aswunnik/Feb 2026/Learning/Multi Agent Systems/book_author/authoring_flow/.venv/bin/kickoff", line 12, in <module>
    sys.exit(kickoff())
             ^^^^^^^^^
  File "/Users/aswunnik/Feb 2026/Learning/Multi Agent Systems/book_author/authoring_flow/src/authoring_flow/main.py", line 70, in kickoff
    poem_flow.kickoff()
  File "/Users/aswunnik/Feb 2026/Learning/Multi Agent Systems/book_author/authoring_flow/.venv/lib/python3.12/site-packages/crewai/flow/flow.py", line 1475, in kickoff
    return asyncio.run(_run_flow())
           ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/aswunnik/.local/share/uv/python/cpython-3.12.11-macos-aarch64-none/lib/python3.12/asyncio/runners.py", line 195, in run
    return runner.run(main)
           ^^^^^^^^^^^^^^^^
  File "/Users/aswunnik/.local/share/uv/python/cpython-3.12.11-macos-aarch64-none/lib/python3.12/asyncio/runners.py", line 118, in run
    return self._loop.run_until_complete(task)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/aswunnik/.local/share/uv/python/cpython-3.12.11-macos-aarch64-none/lib/python3.12/asyncio/base_events.py", line 691, in run_until_complete
    return future.result()
           ^^^^^^^^^^^^^^^
  File "/Users/aswunnik/Feb 2026/Learning/Multi Agent Systems/book_author/authoring_flow/.venv/lib/python3.12/site-packages/crewai/flow/flow.py", line 1473, in _run_flow
    return await self.kickoff_async(inputs, input_files)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/aswunnik/Feb 2026/Learning/Multi Agent Systems/book_author/authoring_flow/.venv/lib/python3.12/site-packages/crewai/flow/flow.py", line 1628, in kickoff_async
    await asyncio.gather(*tasks)
  File "/Users/aswunnik/Feb 2026/Learning/Multi Agent Systems/book_author/authoring_flow/.venv/lib/python3.12/site-packages/crewai/flow/flow.py", line 1813, in _execute_start_method
    await self._execute_listeners(start_method_name, result, finished_event_id)
  File "/Users/aswunnik/Feb 2026/Learning/Multi Agent Systems/book_author/authoring_flow/.venv/lib/python3.12/site-packages/crewai/flow/flow.py", line 2074, in _execute_listeners
    await asyncio.gather(*tasks)
  File "/Users/aswunnik/Feb 2026/Learning/Multi Agent Systems/book_author/authoring_flow/.venv/lib/python3.12/site-packages/crewai/flow/flow.py", line 2327, in _execute_single_listener
    await self._execute_listeners(
  File "/Users/aswunnik/Feb 2026/Learning/Multi Agent Systems/book_author/authoring_flow/.venv/lib/python3.12/site-packages/crewai/flow/flow.py", line 2074, in _execute_listeners
    await asyncio.gather(*tasks)
  File "/Users/aswunnik/Feb 2026/Learning/Multi Agent Systems/book_author/authoring_flow/.venv/lib/python3.12/site-packages/crewai/flow/flow.py", line 2313, in _execute_single_listener
    listener_result, finished_event_id = await self._execute_method(
                                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/aswunnik/Feb 2026/Learning/Multi Agent Systems/book_author/authoring_flow/.venv/lib/python3.12/site-packages/crewai/flow/flow.py", line 1960, in _execute_method
    raise e
  File "/Users/aswunnik/Feb 2026/Learning/Multi Agent Systems/book_author/authoring_flow/.venv/lib/python3.12/site-packages/crewai/flow/flow.py", line 1892, in _execute_method
    result = await asyncio.to_thread(ctx.run, method, *args, **kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/aswunnik/.local/share/uv/python/cpython-3.12.11-macos-aarch64-none/lib/python3.12/asyncio/threads.py", line 25, in to_thread
    return await loop.run_in_executor(None, func_call)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/aswunnik/.local/share/uv/python/cpython-3.12.11-macos-aarch64-none/lib/python3.12/concurrent/futures/thread.py", line 59, in run
    result = self.fn(*self.args, **self.kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/aswunnik/Feb 2026/Learning/Multi Agent Systems/book_author/authoring_flow/.venv/lib/python3.12/site-packages/crewai/flow/flow_wrappers.py", line 93, in __call__
    return self._meth(self._instance, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/aswunnik/Feb 2026/Learning/Multi Agent Systems/book_author/authoring_flow/src/authoring_flow/main.py", line 52, in generate_section
    .kickoff_for_each(inputs=inputs)
     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/aswunnik/Feb 2026/Learning/Multi Agent Systems/book_author/authoring_flow/.venv/lib/python3.12/site-packages/crewai/crew.py", line 789, in kickoff_for_each
    crew = self.copy()
           ^^^^^^^^^^^
  File "/Users/aswunnik/Feb 2026/Learning/Multi Agent Systems/book_author/authoring_flow/.venv/lib/python3.12/site-packages/crewai/crew.py", line 1704, in copy
    return Crew(
           ^^^^^
  File "/Users/aswunnik/Feb 2026/Learning/Multi Agent Systems/book_author/authoring_flow/.venv/lib/python3.12/site-packages/pydantic/main.py", line 253, in __init__
    validated_self = self.__pydantic_validator__.validate_python(data, self_instance=self)
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
pydantic_core._pydantic_core.ValidationError: 1 validation error for Crew
parent_flow
  Input should be an instance of Flow.__class_getitem__.<locals>._FlowGeneric [type=is_instance_of, input_value=<authoring_flow.main.Rese...w object at 0x100e30b00>, input_type=ResearchFlow]
    For further information visit https://errors.pydantic.dev/2.11/v/is_instance_of
An error occurred while running the flow: Command '['uv', 'run', 'kickoff']' returned non-zero exit status 1.

Fix Action

Fixed

PR fix notes

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

Description (problem / solution / changelog)

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

Changed files

  • lib/crewai/src/crewai/crew.py (modified, +1/-0)
  • lib/crewai/tests/test_crew.py (modified, +364/-1)

PR #4668: fix(flow): allow Flow subclasses in crew.copy() for kickoff_for_each (fixes #4555)

Description (problem / solution / changelog)

Summary

Fixes #4555 — Flows do not work with kickoff_for_each.

Root Cause

FlowTrackable (prior to 1.10.0) had a parent_flow: InstanceOf[Flow[Any]] Pydantic field. Flow[Any] creates a dynamic _FlowGeneric subclass via __class_getitem__, so Pydantic's isinstance check rejected concrete Flow subclasses (e.g. ResearchFlow) during crew.copy(), breaking kickoff_for_each inside Flow methods.

Changes

  • Added "parent_flow" to the exclude set in Crew.copy() so the field is never round-tripped through model_dump()/Crew() constructor
  • Added 5 regression tests covering:
    • copy() excludes parent_flow from serialized data
    • copy() preserves agents and tasks as independent copies
    • kickoff_for_each creates independent copies per input
    • copy() works when parent_flow is set as a regular attribute
    • copy() works within a Flow execution context

Tests

All 5 new tests pass. Existing copy and kickoff_for_each tests unaffected.

Fixes #4555

<!-- CURSOR_SUMMARY -->

[!NOTE] Low Risk Low risk: change is limited to Crew.copy() serialization/exclude behavior plus regression tests; runtime impact should only be avoiding a Pydantic validation failure in flow contexts.

Overview Fixes a Flow regression where kickoff_for_each could fail because Crew.copy() inadvertently round-tripped a legacy parent_flow field through model_dump()/Crew() construction.

Crew.copy() now excludes parent_flow and also defensively pop()s it from the serialized dict before constructing the cloned crew; adds a regression test suite covering copy behavior, per-input copying in kickoff_for_each, and flow-context scenarios.

<sup>Written by Cursor Bugbot for commit 91d9b6748f567ace7544f60e1bc6fa728eb00186. This will update automatically on new commits. Configure here.</sup>

<!-- /CURSOR_SUMMARY -->

Changed files

  • lib/crewai/src/crewai/agents/crew_agent_executor.py (modified, +3/-1)
  • lib/crewai/src/crewai/crew.py (modified, +7/-3)
  • lib/crewai/tests/test_flow_kickoff_for_each.py (added, +157/-0)

PR #4716: fix(crew): exclude parent_flow from Crew.copy() to fix kickoff_for_each in Flows

Description (problem / solution / changelog)

Summary

Fixes #4555 — Flows do not work with kickoff_for_each.

When a Crew is created inside a Flow method and kickoff_for_each is called, crew.copy() could pass a parent_flow reference through model_dump() to the new Crew constructor. Pydantic's InstanceOf validator would reject the concrete Flow subclass (e.g. ResearchFlow) because it expected the dynamic _FlowGeneric type from Flow.__class_getitem__, causing a ValidationError.

Although the underlying FlowTrackable was refactored to use contextvars (removing the parent_flow field in v1.10.0), this change adds a defensive exclusion of parent_flow in Crew.copy() to:

  • Prevent regression if the field is reintroduced
  • Protect against edge cases where parent_flow could leak into model_dump() output

Changes

  • Added "parent_flow" to the exclude set in Crew.copy() so it is never included in model_dump() output
  • Added copied_data.pop("parent_flow", None) as a belt-and-suspenders safety check
  • Added 3 regression tests:
    • test_crew_copy_excludes_parent_flow — verifies copy() succeeds even when parent_flow leaks through model_dump()
    • test_crew_copy_inside_flow_context — verifies copy() works within an active flow execution context
    • test_kickoff_for_each_creates_independent_copies — verifies kickoff_for_each creates one independent copy per input

Test plan

  • All 3 new regression tests pass
  • Existing copy and kickoff_for_each tests remain unaffected
  • No changes to execution logic or external interfaces
<!-- CURSOR_SUMMARY -->

[!NOTE] Low Risk Low risk defensive change limited to Crew.copy() serialization/exclusion logic, with added regression tests to prevent flow-related copy validation failures.

Overview Fixes a Crew.copy() edge case where a parent_flow reference could leak through model_dump() and be round-tripped into the Crew constructor, causing Pydantic validation failures during kickoff_for_each inside Flows.

Crew.copy() now explicitly excludes parent_flow (and also pops it from copied_data as a backstop), and new tests cover the exclusion behavior, copying under an active flow context, and that kickoff_for_each produces independent crew copies per input.

<sup>Written by Cursor Bugbot for commit 5ec07071a749102d8b2aec9495086f4a31c45370. This will update automatically on new commits. Configure here.</sup>

<!-- /CURSOR_SUMMARY -->

Changed files

  • lib/crewai/src/crewai/crew.py (modified, +2/-0)
  • lib/crewai/tests/test_crew.py (modified, +128/-0)

Code Example

ERROR:crewai.flow.flow:Error executing listener generate_section: 1 validation error for Crew
parent_flow
  Input should be an instance of Flow.__class_getitem__.<locals>._FlowGeneric [type=is_instance_of, input_value=<authoring_flow.main.Rese...w object at 0x100e30b00>, input_type=ResearchFlow]
    For further information visit https://errors.pydantic.dev/2.11/v/is_instance_of
ERROR:crewai.flow.flow:Error executing listener research_topics: 1 validation error for Crew
parent_flow
  Input should be an instance of Flow.__class_getitem__.<locals>._FlowGeneric [type=is_instance_of, input_value=<authoring_flow.main.Rese...w object at 0x100e30b00>, input_type=ResearchFlow]
    For further information visit https://errors.pydantic.dev/2.11/v/is_instance_of
╭───────────────────────────────────────────────────────────────────────────────────────────── ❌ Flow Method Failed ─────────────────────────────────────────────────────────────────────────────────────────────╮
│                                                                                                                                                                                                                 │
Method: generate_section                                                                                                                                                                                       │
Status: Failed│                                                                                                                                                                                                                 │
│                                                                                                                                                                                                                 │
╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯

Traceback (most recent call last):
  File "/Users/aswunnik/Feb 2026/Learning/Multi Agent Systems/book_author/authoring_flow/.venv/bin/kickoff", line 12, in <module>
    sys.exit(kickoff())
             ^^^^^^^^^
  File "/Users/aswunnik/Feb 2026/Learning/Multi Agent Systems/book_author/authoring_flow/src/authoring_flow/main.py", line 70, in kickoff
    poem_flow.kickoff()
  File "/Users/aswunnik/Feb 2026/Learning/Multi Agent Systems/book_author/authoring_flow/.venv/lib/python3.12/site-packages/crewai/flow/flow.py", line 1475, in kickoff
    return asyncio.run(_run_flow())
           ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/aswunnik/.local/share/uv/python/cpython-3.12.11-macos-aarch64-none/lib/python3.12/asyncio/runners.py", line 195, in run
    return runner.run(main)
           ^^^^^^^^^^^^^^^^
  File "/Users/aswunnik/.local/share/uv/python/cpython-3.12.11-macos-aarch64-none/lib/python3.12/asyncio/runners.py", line 118, in run
    return self._loop.run_until_complete(task)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/aswunnik/.local/share/uv/python/cpython-3.12.11-macos-aarch64-none/lib/python3.12/asyncio/base_events.py", line 691, in run_until_complete
    return future.result()
           ^^^^^^^^^^^^^^^
  File "/Users/aswunnik/Feb 2026/Learning/Multi Agent Systems/book_author/authoring_flow/.venv/lib/python3.12/site-packages/crewai/flow/flow.py", line 1473, in _run_flow
    return await self.kickoff_async(inputs, input_files)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/aswunnik/Feb 2026/Learning/Multi Agent Systems/book_author/authoring_flow/.venv/lib/python3.12/site-packages/crewai/flow/flow.py", line 1628, in kickoff_async
    await asyncio.gather(*tasks)
  File "/Users/aswunnik/Feb 2026/Learning/Multi Agent Systems/book_author/authoring_flow/.venv/lib/python3.12/site-packages/crewai/flow/flow.py", line 1813, in _execute_start_method
    await self._execute_listeners(start_method_name, result, finished_event_id)
  File "/Users/aswunnik/Feb 2026/Learning/Multi Agent Systems/book_author/authoring_flow/.venv/lib/python3.12/site-packages/crewai/flow/flow.py", line 2074, in _execute_listeners
    await asyncio.gather(*tasks)
  File "/Users/aswunnik/Feb 2026/Learning/Multi Agent Systems/book_author/authoring_flow/.venv/lib/python3.12/site-packages/crewai/flow/flow.py", line 2327, in _execute_single_listener
    await self._execute_listeners(
  File "/Users/aswunnik/Feb 2026/Learning/Multi Agent Systems/book_author/authoring_flow/.venv/lib/python3.12/site-packages/crewai/flow/flow.py", line 2074, in _execute_listeners
    await asyncio.gather(*tasks)
  File "/Users/aswunnik/Feb 2026/Learning/Multi Agent Systems/book_author/authoring_flow/.venv/lib/python3.12/site-packages/crewai/flow/flow.py", line 2313, in _execute_single_listener
    listener_result, finished_event_id = await self._execute_method(
                                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/aswunnik/Feb 2026/Learning/Multi Agent Systems/book_author/authoring_flow/.venv/lib/python3.12/site-packages/crewai/flow/flow.py", line 1960, in _execute_method
    raise e
  File "/Users/aswunnik/Feb 2026/Learning/Multi Agent Systems/book_author/authoring_flow/.venv/lib/python3.12/site-packages/crewai/flow/flow.py", line 1892, in _execute_method
    result = await asyncio.to_thread(ctx.run, method, *args, **kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/aswunnik/.local/share/uv/python/cpython-3.12.11-macos-aarch64-none/lib/python3.12/asyncio/threads.py", line 25, in to_thread
    return await loop.run_in_executor(None, func_call)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/aswunnik/.local/share/uv/python/cpython-3.12.11-macos-aarch64-none/lib/python3.12/concurrent/futures/thread.py", line 59, in run
    result = self.fn(*self.args, **self.kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/aswunnik/Feb 2026/Learning/Multi Agent Systems/book_author/authoring_flow/.venv/lib/python3.12/site-packages/crewai/flow/flow_wrappers.py", line 93, in __call__
    return self._meth(self._instance, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/aswunnik/Feb 2026/Learning/Multi Agent Systems/book_author/authoring_flow/src/authoring_flow/main.py", line 52, in generate_section
    .kickoff_for_each(inputs=inputs)
     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/aswunnik/Feb 2026/Learning/Multi Agent Systems/book_author/authoring_flow/.venv/lib/python3.12/site-packages/crewai/crew.py", line 789, in kickoff_for_each
    crew = self.copy()
           ^^^^^^^^^^^
  File "/Users/aswunnik/Feb 2026/Learning/Multi Agent Systems/book_author/authoring_flow/.venv/lib/python3.12/site-packages/crewai/crew.py", line 1704, in copy
    return Crew(
           ^^^^^
  File "/Users/aswunnik/Feb 2026/Learning/Multi Agent Systems/book_author/authoring_flow/.venv/lib/python3.12/site-packages/pydantic/main.py", line 253, in __init__
    validated_self = self.__pydantic_validator__.validate_python(data, self_instance=self)
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
pydantic_core._pydantic_core.ValidationError: 1 validation error for Crew
parent_flow
  Input should be an instance of Flow.__class_getitem__.<locals>._FlowGeneric [type=is_instance_of, input_value=<authoring_flow.main.Rese...w object at 0x100e30b00>, input_type=ResearchFlow]
    For further information visit https://errors.pydantic.dev/2.11/v/is_instance_of
An error occurred while running the flow: Command '['uv', 'run', 'kickoff']' returned non-zero exit status 1.

---

#!/usr/bin/env python
from random import randint
from typing import Dict, List

from pydantic import BaseModel

from crewai.flow import Flow, listen, start

from authoring_flow.crews.research_crew.research_crew import ResearchCrew, ResearchOutput
from authoring_flow.crews.writer_crew.writer_crew import WriterCrew



class ResearchState(BaseModel):
    chapter: str = "Basics of Distributed Systems"
    topics: Dict[str, str] = {}
    sections: Dict[str, str] = {}

class ResearchFlow(Flow[ResearchState]):

    @start()
    def generate_sentence_count(self, crewai_trigger_payload: dict = None):
        print("Generating sentence count")

        # Use trigger payload if available
        if crewai_trigger_payload:
            # Example: use trigger data to influence sentence count
            print(f"Using trigger payload: {crewai_trigger_payload}")

    @listen(generate_sentence_count)
    def research_topics(self):
        print("Generating topics for chapter: ", self.state.chapter)
        result = (
            ResearchCrew()
            .crew()
            .kickoff(inputs={"chapter": self.state.chapter})
        )
        print("Pydantic: ", result.pydantic)
        self.state.topics = result.pydantic.topics

    @listen(research_topics)
    def generate_section(self):
        inputs = []
        for topic in self.state.topics : 
            inputs.append({"topic": topic, "description": self.state.topics[topic]})
            if(len(inputs) == 3):
                break
            
        result = (
            WriterCrew()
            .crew()
            .kickoff_for_each(inputs=inputs)
        )
        
        return result
    
    @listen(generate_section)
    def save_poem(self):
        result = ""
        for section in self.state.sections:
            result += "### " + section
            result += self.state.sections[section]
        with open("report.txt", "w") as f:
            
            f.write(result)


def kickoff():
    poem_flow = ResearchFlow()
    poem_flow.kickoff()


def plot():
    poem_flow = ResearchFlow()
    poem_flow.plot()


def run_with_trigger():
    """
    Run the flow with trigger payload.
    """
    import json
    import sys

    # Get trigger payload from command line argument
    if len(sys.argv) < 2:
        raise Exception("No trigger payload provided. Please provide JSON payload as argument.")

    try:
        trigger_payload = json.loads(sys.argv[1])
    except json.JSONDecodeError:
        raise Exception("Invalid JSON payload provided as argument")

    # Create flow and kickoff with trigger payload
    # The @start() methods will automatically receive crewai_trigger_payload parameter
    poem_flow = ResearchFlow()

    try:
        result = poem_flow.kickoff({"crewai_trigger_payload": trigger_payload})
        return result
    except Exception as e:
        raise Exception(f"An error occurred while running the flow with trigger: {e}")


if __name__ == "__main__":
    kickoff()

---

ERROR:crewai.flow.flow:Error executing listener generate_section: 1 validation error for Crew
parent_flow
  Input should be an instance of Flow.__class_getitem__.<locals>._FlowGeneric [type=is_instance_of, input_value=<authoring_flow.main.Rese...w object at 0x100e30b00>, input_type=ResearchFlow]
    For further information visit https://errors.pydantic.dev/2.11/v/is_instance_of
ERROR:crewai.flow.flow:Error executing listener research_topics: 1 validation error for Crew
parent_flow
  Input should be an instance of Flow.__class_getitem__.<locals>._FlowGeneric [type=is_instance_of, input_value=<authoring_flow.main.Rese...w object at 0x100e30b00>, input_type=ResearchFlow]
    For further information visit https://errors.pydantic.dev/2.11/v/is_instance_of
╭───────────────────────────────────────────────────────────────────────────────────────────── ❌ Flow Method Failed ─────────────────────────────────────────────────────────────────────────────────────────────╮
│                                                                                                                                                                                                                 │
Method: generate_section                                                                                                                                                                                       │
Status: Failed│                                                                                                                                                                                                                 │
│                                                                                                                                                                                                                 │
╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯

Traceback (most recent call last):
  File "/Users/aswunnik/Feb 2026/Learning/Multi Agent Systems/book_author/authoring_flow/.venv/bin/kickoff", line 12, in <module>
    sys.exit(kickoff())
             ^^^^^^^^^
  File "/Users/aswunnik/Feb 2026/Learning/Multi Agent Systems/book_author/authoring_flow/src/authoring_flow/main.py", line 70, in kickoff
    poem_flow.kickoff()
  File "/Users/aswunnik/Feb 2026/Learning/Multi Agent Systems/book_author/authoring_flow/.venv/lib/python3.12/site-packages/crewai/flow/flow.py", line 1475, in kickoff
    return asyncio.run(_run_flow())
           ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/aswunnik/.local/share/uv/python/cpython-3.12.11-macos-aarch64-none/lib/python3.12/asyncio/runners.py", line 195, in run
    return runner.run(main)
           ^^^^^^^^^^^^^^^^
  File "/Users/aswunnik/.local/share/uv/python/cpython-3.12.11-macos-aarch64-none/lib/python3.12/asyncio/runners.py", line 118, in run
    return self._loop.run_until_complete(task)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/aswunnik/.local/share/uv/python/cpython-3.12.11-macos-aarch64-none/lib/python3.12/asyncio/base_events.py", line 691, in run_until_complete
    return future.result()
           ^^^^^^^^^^^^^^^
  File "/Users/aswunnik/Feb 2026/Learning/Multi Agent Systems/book_author/authoring_flow/.venv/lib/python3.12/site-packages/crewai/flow/flow.py", line 1473, in _run_flow
    return await self.kickoff_async(inputs, input_files)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/aswunnik/Feb 2026/Learning/Multi Agent Systems/book_author/authoring_flow/.venv/lib/python3.12/site-packages/crewai/flow/flow.py", line 1628, in kickoff_async
    await asyncio.gather(*tasks)
  File "/Users/aswunnik/Feb 2026/Learning/Multi Agent Systems/book_author/authoring_flow/.venv/lib/python3.12/site-packages/crewai/flow/flow.py", line 1813, in _execute_start_method
    await self._execute_listeners(start_method_name, result, finished_event_id)
  File "/Users/aswunnik/Feb 2026/Learning/Multi Agent Systems/book_author/authoring_flow/.venv/lib/python3.12/site-packages/crewai/flow/flow.py", line 2074, in _execute_listeners
    await asyncio.gather(*tasks)
  File "/Users/aswunnik/Feb 2026/Learning/Multi Agent Systems/book_author/authoring_flow/.venv/lib/python3.12/site-packages/crewai/flow/flow.py", line 2327, in _execute_single_listener
    await self._execute_listeners(
  File "/Users/aswunnik/Feb 2026/Learning/Multi Agent Systems/book_author/authoring_flow/.venv/lib/python3.12/site-packages/crewai/flow/flow.py", line 2074, in _execute_listeners
    await asyncio.gather(*tasks)
  File "/Users/aswunnik/Feb 2026/Learning/Multi Agent Systems/book_author/authoring_flow/.venv/lib/python3.12/site-packages/crewai/flow/flow.py", line 2313, in _execute_single_listener
    listener_result, finished_event_id = await self._execute_method(
                                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/aswunnik/Feb 2026/Learning/Multi Agent Systems/book_author/authoring_flow/.venv/lib/python3.12/site-packages/crewai/flow/flow.py", line 1960, in _execute_method
    raise e
  File "/Users/aswunnik/Feb 2026/Learning/Multi Agent Systems/book_author/authoring_flow/.venv/lib/python3.12/site-packages/crewai/flow/flow.py", line 1892, in _execute_method
    result = await asyncio.to_thread(ctx.run, method, *args, **kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/aswunnik/.local/share/uv/python/cpython-3.12.11-macos-aarch64-none/lib/python3.12/asyncio/threads.py", line 25, in to_thread
    return await loop.run_in_executor(None, func_call)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/aswunnik/.local/share/uv/python/cpython-3.12.11-macos-aarch64-none/lib/python3.12/concurrent/futures/thread.py", line 59, in run
    result = self.fn(*self.args, **self.kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/aswunnik/Feb 2026/Learning/Multi Agent Systems/book_author/authoring_flow/.venv/lib/python3.12/site-packages/crewai/flow/flow_wrappers.py", line 93, in __call__
    return self._meth(self._instance, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/aswunnik/Feb 2026/Learning/Multi Agent Systems/book_author/authoring_flow/src/authoring_flow/main.py", line 52, in generate_section
    .kickoff_for_each(inputs=inputs)
     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/aswunnik/Feb 2026/Learning/Multi Agent Systems/book_author/authoring_flow/.venv/lib/python3.12/site-packages/crewai/crew.py", line 789, in kickoff_for_each
    crew = self.copy()
           ^^^^^^^^^^^
  File "/Users/aswunnik/Feb 2026/Learning/Multi Agent Systems/book_author/authoring_flow/.venv/lib/python3.12/site-packages/crewai/crew.py", line 1704, in copy
    return Crew(
           ^^^^^
  File "/Users/aswunnik/Feb 2026/Learning/Multi Agent Systems/book_author/authoring_flow/.venv/lib/python3.12/site-packages/pydantic/main.py", line 253, in __init__
    validated_self = self.__pydantic_validator__.validate_python(data, self_instance=self)
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
pydantic_core._pydantic_core.ValidationError: 1 validation error for Crew
parent_flow
  Input should be an instance of Flow.__class_getitem__.<locals>._FlowGeneric [type=is_instance_of, input_value=<authoring_flow.main.Rese...w object at 0x100e30b00>, input_type=ResearchFlow]
    For further information visit https://errors.pydantic.dev/2.11/v/is_instance_of
An error occurred while running the flow: Command '['uv', 'run', 'kickoff']' returned non-zero exit status 1.
RAW_BUFFERClick to expand / collapse

Description

I am trying to write a flow that will do the following :

  • Research on {Chapter Name} and generate List<{topic}>
  • For Each {topic}, trigger WriterCrew that will write a section on {topic}

I am hitting the below error :

ERROR:crewai.flow.flow:Error executing listener generate_section: 1 validation error for Crew
parent_flow
  Input should be an instance of Flow.__class_getitem__.<locals>._FlowGeneric [type=is_instance_of, input_value=<authoring_flow.main.Rese...w object at 0x100e30b00>, input_type=ResearchFlow]
    For further information visit https://errors.pydantic.dev/2.11/v/is_instance_of
ERROR:crewai.flow.flow:Error executing listener research_topics: 1 validation error for Crew
parent_flow
  Input should be an instance of Flow.__class_getitem__.<locals>._FlowGeneric [type=is_instance_of, input_value=<authoring_flow.main.Rese...w object at 0x100e30b00>, input_type=ResearchFlow]
    For further information visit https://errors.pydantic.dev/2.11/v/is_instance_of
╭───────────────────────────────────────────────────────────────────────────────────────────── ❌ Flow Method Failed ─────────────────────────────────────────────────────────────────────────────────────────────╮
│                                                                                                                                                                                                                 │
│  Method: generate_section                                                                                                                                                                                       │
│  Status: Failed                                                                                                                                                                                                 │
│                                                                                                                                                                                                                 │
│                                                                                                                                                                                                                 │
╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯

Traceback (most recent call last):
  File "/Users/aswunnik/Feb 2026/Learning/Multi Agent Systems/book_author/authoring_flow/.venv/bin/kickoff", line 12, in <module>
    sys.exit(kickoff())
             ^^^^^^^^^
  File "/Users/aswunnik/Feb 2026/Learning/Multi Agent Systems/book_author/authoring_flow/src/authoring_flow/main.py", line 70, in kickoff
    poem_flow.kickoff()
  File "/Users/aswunnik/Feb 2026/Learning/Multi Agent Systems/book_author/authoring_flow/.venv/lib/python3.12/site-packages/crewai/flow/flow.py", line 1475, in kickoff
    return asyncio.run(_run_flow())
           ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/aswunnik/.local/share/uv/python/cpython-3.12.11-macos-aarch64-none/lib/python3.12/asyncio/runners.py", line 195, in run
    return runner.run(main)
           ^^^^^^^^^^^^^^^^
  File "/Users/aswunnik/.local/share/uv/python/cpython-3.12.11-macos-aarch64-none/lib/python3.12/asyncio/runners.py", line 118, in run
    return self._loop.run_until_complete(task)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/aswunnik/.local/share/uv/python/cpython-3.12.11-macos-aarch64-none/lib/python3.12/asyncio/base_events.py", line 691, in run_until_complete
    return future.result()
           ^^^^^^^^^^^^^^^
  File "/Users/aswunnik/Feb 2026/Learning/Multi Agent Systems/book_author/authoring_flow/.venv/lib/python3.12/site-packages/crewai/flow/flow.py", line 1473, in _run_flow
    return await self.kickoff_async(inputs, input_files)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/aswunnik/Feb 2026/Learning/Multi Agent Systems/book_author/authoring_flow/.venv/lib/python3.12/site-packages/crewai/flow/flow.py", line 1628, in kickoff_async
    await asyncio.gather(*tasks)
  File "/Users/aswunnik/Feb 2026/Learning/Multi Agent Systems/book_author/authoring_flow/.venv/lib/python3.12/site-packages/crewai/flow/flow.py", line 1813, in _execute_start_method
    await self._execute_listeners(start_method_name, result, finished_event_id)
  File "/Users/aswunnik/Feb 2026/Learning/Multi Agent Systems/book_author/authoring_flow/.venv/lib/python3.12/site-packages/crewai/flow/flow.py", line 2074, in _execute_listeners
    await asyncio.gather(*tasks)
  File "/Users/aswunnik/Feb 2026/Learning/Multi Agent Systems/book_author/authoring_flow/.venv/lib/python3.12/site-packages/crewai/flow/flow.py", line 2327, in _execute_single_listener
    await self._execute_listeners(
  File "/Users/aswunnik/Feb 2026/Learning/Multi Agent Systems/book_author/authoring_flow/.venv/lib/python3.12/site-packages/crewai/flow/flow.py", line 2074, in _execute_listeners
    await asyncio.gather(*tasks)
  File "/Users/aswunnik/Feb 2026/Learning/Multi Agent Systems/book_author/authoring_flow/.venv/lib/python3.12/site-packages/crewai/flow/flow.py", line 2313, in _execute_single_listener
    listener_result, finished_event_id = await self._execute_method(
                                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/aswunnik/Feb 2026/Learning/Multi Agent Systems/book_author/authoring_flow/.venv/lib/python3.12/site-packages/crewai/flow/flow.py", line 1960, in _execute_method
    raise e
  File "/Users/aswunnik/Feb 2026/Learning/Multi Agent Systems/book_author/authoring_flow/.venv/lib/python3.12/site-packages/crewai/flow/flow.py", line 1892, in _execute_method
    result = await asyncio.to_thread(ctx.run, method, *args, **kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/aswunnik/.local/share/uv/python/cpython-3.12.11-macos-aarch64-none/lib/python3.12/asyncio/threads.py", line 25, in to_thread
    return await loop.run_in_executor(None, func_call)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/aswunnik/.local/share/uv/python/cpython-3.12.11-macos-aarch64-none/lib/python3.12/concurrent/futures/thread.py", line 59, in run
    result = self.fn(*self.args, **self.kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/aswunnik/Feb 2026/Learning/Multi Agent Systems/book_author/authoring_flow/.venv/lib/python3.12/site-packages/crewai/flow/flow_wrappers.py", line 93, in __call__
    return self._meth(self._instance, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/aswunnik/Feb 2026/Learning/Multi Agent Systems/book_author/authoring_flow/src/authoring_flow/main.py", line 52, in generate_section
    .kickoff_for_each(inputs=inputs)
     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/aswunnik/Feb 2026/Learning/Multi Agent Systems/book_author/authoring_flow/.venv/lib/python3.12/site-packages/crewai/crew.py", line 789, in kickoff_for_each
    crew = self.copy()
           ^^^^^^^^^^^
  File "/Users/aswunnik/Feb 2026/Learning/Multi Agent Systems/book_author/authoring_flow/.venv/lib/python3.12/site-packages/crewai/crew.py", line 1704, in copy
    return Crew(
           ^^^^^
  File "/Users/aswunnik/Feb 2026/Learning/Multi Agent Systems/book_author/authoring_flow/.venv/lib/python3.12/site-packages/pydantic/main.py", line 253, in __init__
    validated_self = self.__pydantic_validator__.validate_python(data, self_instance=self)
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
pydantic_core._pydantic_core.ValidationError: 1 validation error for Crew
parent_flow
  Input should be an instance of Flow.__class_getitem__.<locals>._FlowGeneric [type=is_instance_of, input_value=<authoring_flow.main.Rese...w object at 0x100e30b00>, input_type=ResearchFlow]
    For further information visit https://errors.pydantic.dev/2.11/v/is_instance_of
An error occurred while running the flow: Command '['uv', 'run', 'kickoff']' returned non-zero exit status 1.

Steps to Reproduce

Code is provided for reproducing the issue

Operating System : MacOs Tahoe

Expected behavior

kickoff_for_each triggers parallel agents in the second step.

Screenshots/Code snippets

#!/usr/bin/env python
from random import randint
from typing import Dict, List

from pydantic import BaseModel

from crewai.flow import Flow, listen, start

from authoring_flow.crews.research_crew.research_crew import ResearchCrew, ResearchOutput
from authoring_flow.crews.writer_crew.writer_crew import WriterCrew



class ResearchState(BaseModel):
    chapter: str = "Basics of Distributed Systems"
    topics: Dict[str, str] = {}
    sections: Dict[str, str] = {}

class ResearchFlow(Flow[ResearchState]):

    @start()
    def generate_sentence_count(self, crewai_trigger_payload: dict = None):
        print("Generating sentence count")

        # Use trigger payload if available
        if crewai_trigger_payload:
            # Example: use trigger data to influence sentence count
            print(f"Using trigger payload: {crewai_trigger_payload}")

    @listen(generate_sentence_count)
    def research_topics(self):
        print("Generating topics for chapter: ", self.state.chapter)
        result = (
            ResearchCrew()
            .crew()
            .kickoff(inputs={"chapter": self.state.chapter})
        )
        print("Pydantic: ", result.pydantic)
        self.state.topics = result.pydantic.topics

    @listen(research_topics)
    def generate_section(self):
        inputs = []
        for topic in self.state.topics : 
            inputs.append({"topic": topic, "description": self.state.topics[topic]})
            if(len(inputs) == 3):
                break
            
        result = (
            WriterCrew()
            .crew()
            .kickoff_for_each(inputs=inputs)
        )
        
        return result
    
    @listen(generate_section)
    def save_poem(self):
        result = ""
        for section in self.state.sections:
            result += "### " + section
            result += self.state.sections[section]
        with open("report.txt", "w") as f:
            
            f.write(result)


def kickoff():
    poem_flow = ResearchFlow()
    poem_flow.kickoff()


def plot():
    poem_flow = ResearchFlow()
    poem_flow.plot()


def run_with_trigger():
    """
    Run the flow with trigger payload.
    """
    import json
    import sys

    # Get trigger payload from command line argument
    if len(sys.argv) < 2:
        raise Exception("No trigger payload provided. Please provide JSON payload as argument.")

    try:
        trigger_payload = json.loads(sys.argv[1])
    except json.JSONDecodeError:
        raise Exception("Invalid JSON payload provided as argument")

    # Create flow and kickoff with trigger payload
    # The @start() methods will automatically receive crewai_trigger_payload parameter
    poem_flow = ResearchFlow()

    try:
        result = poem_flow.kickoff({"crewai_trigger_payload": trigger_payload})
        return result
    except Exception as e:
        raise Exception(f"An error occurred while running the flow with trigger: {e}")


if __name__ == "__main__":
    kickoff()

Operating System

Other (specify in additional context)

Python Version

3.12

crewAI Version

1.9.3

crewAI Tools Version

No tools..

Virtual Environment

Venv

Evidence

I am hitting the below error :

ERROR:crewai.flow.flow:Error executing listener generate_section: 1 validation error for Crew
parent_flow
  Input should be an instance of Flow.__class_getitem__.<locals>._FlowGeneric [type=is_instance_of, input_value=<authoring_flow.main.Rese...w object at 0x100e30b00>, input_type=ResearchFlow]
    For further information visit https://errors.pydantic.dev/2.11/v/is_instance_of
ERROR:crewai.flow.flow:Error executing listener research_topics: 1 validation error for Crew
parent_flow
  Input should be an instance of Flow.__class_getitem__.<locals>._FlowGeneric [type=is_instance_of, input_value=<authoring_flow.main.Rese...w object at 0x100e30b00>, input_type=ResearchFlow]
    For further information visit https://errors.pydantic.dev/2.11/v/is_instance_of
╭───────────────────────────────────────────────────────────────────────────────────────────── ❌ Flow Method Failed ─────────────────────────────────────────────────────────────────────────────────────────────╮
│                                                                                                                                                                                                                 │
│  Method: generate_section                                                                                                                                                                                       │
│  Status: Failed                                                                                                                                                                                                 │
│                                                                                                                                                                                                                 │
│                                                                                                                                                                                                                 │
╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯

Traceback (most recent call last):
  File "/Users/aswunnik/Feb 2026/Learning/Multi Agent Systems/book_author/authoring_flow/.venv/bin/kickoff", line 12, in <module>
    sys.exit(kickoff())
             ^^^^^^^^^
  File "/Users/aswunnik/Feb 2026/Learning/Multi Agent Systems/book_author/authoring_flow/src/authoring_flow/main.py", line 70, in kickoff
    poem_flow.kickoff()
  File "/Users/aswunnik/Feb 2026/Learning/Multi Agent Systems/book_author/authoring_flow/.venv/lib/python3.12/site-packages/crewai/flow/flow.py", line 1475, in kickoff
    return asyncio.run(_run_flow())
           ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/aswunnik/.local/share/uv/python/cpython-3.12.11-macos-aarch64-none/lib/python3.12/asyncio/runners.py", line 195, in run
    return runner.run(main)
           ^^^^^^^^^^^^^^^^
  File "/Users/aswunnik/.local/share/uv/python/cpython-3.12.11-macos-aarch64-none/lib/python3.12/asyncio/runners.py", line 118, in run
    return self._loop.run_until_complete(task)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/aswunnik/.local/share/uv/python/cpython-3.12.11-macos-aarch64-none/lib/python3.12/asyncio/base_events.py", line 691, in run_until_complete
    return future.result()
           ^^^^^^^^^^^^^^^
  File "/Users/aswunnik/Feb 2026/Learning/Multi Agent Systems/book_author/authoring_flow/.venv/lib/python3.12/site-packages/crewai/flow/flow.py", line 1473, in _run_flow
    return await self.kickoff_async(inputs, input_files)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/aswunnik/Feb 2026/Learning/Multi Agent Systems/book_author/authoring_flow/.venv/lib/python3.12/site-packages/crewai/flow/flow.py", line 1628, in kickoff_async
    await asyncio.gather(*tasks)
  File "/Users/aswunnik/Feb 2026/Learning/Multi Agent Systems/book_author/authoring_flow/.venv/lib/python3.12/site-packages/crewai/flow/flow.py", line 1813, in _execute_start_method
    await self._execute_listeners(start_method_name, result, finished_event_id)
  File "/Users/aswunnik/Feb 2026/Learning/Multi Agent Systems/book_author/authoring_flow/.venv/lib/python3.12/site-packages/crewai/flow/flow.py", line 2074, in _execute_listeners
    await asyncio.gather(*tasks)
  File "/Users/aswunnik/Feb 2026/Learning/Multi Agent Systems/book_author/authoring_flow/.venv/lib/python3.12/site-packages/crewai/flow/flow.py", line 2327, in _execute_single_listener
    await self._execute_listeners(
  File "/Users/aswunnik/Feb 2026/Learning/Multi Agent Systems/book_author/authoring_flow/.venv/lib/python3.12/site-packages/crewai/flow/flow.py", line 2074, in _execute_listeners
    await asyncio.gather(*tasks)
  File "/Users/aswunnik/Feb 2026/Learning/Multi Agent Systems/book_author/authoring_flow/.venv/lib/python3.12/site-packages/crewai/flow/flow.py", line 2313, in _execute_single_listener
    listener_result, finished_event_id = await self._execute_method(
                                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/aswunnik/Feb 2026/Learning/Multi Agent Systems/book_author/authoring_flow/.venv/lib/python3.12/site-packages/crewai/flow/flow.py", line 1960, in _execute_method
    raise e
  File "/Users/aswunnik/Feb 2026/Learning/Multi Agent Systems/book_author/authoring_flow/.venv/lib/python3.12/site-packages/crewai/flow/flow.py", line 1892, in _execute_method
    result = await asyncio.to_thread(ctx.run, method, *args, **kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/aswunnik/.local/share/uv/python/cpython-3.12.11-macos-aarch64-none/lib/python3.12/asyncio/threads.py", line 25, in to_thread
    return await loop.run_in_executor(None, func_call)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/aswunnik/.local/share/uv/python/cpython-3.12.11-macos-aarch64-none/lib/python3.12/concurrent/futures/thread.py", line 59, in run
    result = self.fn(*self.args, **self.kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/aswunnik/Feb 2026/Learning/Multi Agent Systems/book_author/authoring_flow/.venv/lib/python3.12/site-packages/crewai/flow/flow_wrappers.py", line 93, in __call__
    return self._meth(self._instance, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/aswunnik/Feb 2026/Learning/Multi Agent Systems/book_author/authoring_flow/src/authoring_flow/main.py", line 52, in generate_section
    .kickoff_for_each(inputs=inputs)
     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/aswunnik/Feb 2026/Learning/Multi Agent Systems/book_author/authoring_flow/.venv/lib/python3.12/site-packages/crewai/crew.py", line 789, in kickoff_for_each
    crew = self.copy()
           ^^^^^^^^^^^
  File "/Users/aswunnik/Feb 2026/Learning/Multi Agent Systems/book_author/authoring_flow/.venv/lib/python3.12/site-packages/crewai/crew.py", line 1704, in copy
    return Crew(
           ^^^^^
  File "/Users/aswunnik/Feb 2026/Learning/Multi Agent Systems/book_author/authoring_flow/.venv/lib/python3.12/site-packages/pydantic/main.py", line 253, in __init__
    validated_self = self.__pydantic_validator__.validate_python(data, self_instance=self)
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
pydantic_core._pydantic_core.ValidationError: 1 validation error for Crew
parent_flow
  Input should be an instance of Flow.__class_getitem__.<locals>._FlowGeneric [type=is_instance_of, input_value=<authoring_flow.main.Rese...w object at 0x100e30b00>, input_type=ResearchFlow]
    For further information visit https://errors.pydantic.dev/2.11/v/is_instance_of
An error occurred while running the flow: Command '['uv', 'run', 'kickoff']' returned non-zero exit status 1.

Possible Solution

Not sure

Additional context

None

extent analysis

Fix Plan

The error occurs because kickoff_for_each expects a flow as input, but you're passing a list of inputs. To fix this, you need to create a new flow for each input and then kickoff each flow.

Here's how you can modify your generate_section method:

@listen(research_topics)
def generate_section(self):
    inputs = []
    for topic in self.state.topics : 
        inputs.append({"topic": topic, "description": self.state.topics[topic]})
        if(len(inputs) == 3):
            break
            
    results = []
    for input in inputs:
        result = (
            WriterCrew()
            .crew()
            .kickoff(inputs=input)
        )
        results.append(result)
        
    return results

Alternatively, you can use asyncio.gather to run all the flows concurrently:

@listen(research_topics)
async def generate_section(self):
    inputs = []
    for topic in self.state.topics : 
        inputs.append({"topic": topic, "description": self.state.topics[topic]})
        if(len(inputs) == 3):
            break
            
    tasks = []
    for input in inputs:
        task = asyncio.create_task(
            WriterCrew()
            .crew()
            .kickoff(inputs=input)
        )
        tasks.append(task)
        
    results = await asyncio.gather(*tasks)
    return results

Verification

To verify that the fix worked, you can check the output of the generate_section method. It should now return a list of results, one for each input. You can also check the logs to see if the flows are running correctly.

Extra Tips

Make sure to handle any exceptions that might occur when running the flows. You can use a try-except block to catch any exceptions and handle them accordingly.

Also, be aware that running multiple flows concurrently can be resource-intensive. Make sure your system has enough resources to handle the load.

You can also use concurrent.futures to limit the number of concurrent flows:

with concurrent.futures.ThreadPoolExecutor(max_workers=5) as executor:
    tasks = []
    for input in inputs:
        task = executor.submit(
            WriterCrew()
            .crew()
            .kickoff, inputs=input
        )
        tasks.append(task)
        
    results = [task.result() for task in tasks]
    return results

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

FAQ

Expected behavior

kickoff_for_each triggers parallel agents in the second step.

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING