Split flow.py into DSL, definition, and runtime#5997
Conversation
📝 WalkthroughWalkthroughThis PR introduces a complete flow authoring DSL and analysis infrastructure. The changes add public decorators for defining flow methods ( ChangesFlow DSL and Analysis Infrastructure
🎯 3 (Moderate) | ⏱️ ~25 minutes
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
This commit separates the monolithic `flow.py` into three modules, each with one job: - `dsl.py` - the Python DSL for flows (@start/@listen/@router, or_/and_) - `flow_definition.py` - the structural model extracted from the DSL - `runtime.py` - the execution engine and state for flows This phase moves code only and should not have any breaking changes.
cee9f7b to
1c7b61a
Compare
There was a problem hiding this comment.
Actionable comments posted: 4
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@lib/crewai/src/crewai/flow/dsl.py`:
- Around line 1-320: This file fails Ruff formatting; run the formatter and
commit the changes so CI passes—invoke the ruff formatter (e.g., `ruff format
lib/crewai/src/crewai/flow/dsl.py` or `uv run ruff format --package lib`) and
stage the modified file; ensure formatting changes cover the decorator functions
and combinators (start, listen, router, or_, and and_) and their
docstrings/signatures, then re-run `uv run ruff format --check lib/` to confirm
CI will succeed.
In `@lib/crewai/src/crewai/flow/flow_definition.py`:
- Around line 587-603: The router-path branch (checking node in flow._routers
and iterating flow._router_paths) propagates ancestors[node] to listeners but
fails to include the router node itself; modify the dfs_ancestors logic so that
before merging ancestors[node] into ancestors[listener_name] you also add the
router node (node) as a direct ancestor (e.g., ensure ancestors[listener_name]
includes node along with ancestors[node]); update the block that handles
flow._router_paths within dfs_ancestors (references: flow._routers,
flow._router_paths, ancestors, dfs_ancestors, listener_name, node) and handle
the case where ancestors[node] may not yet exist.
- Around line 858-894: The helper _extract_all_methods_recursive currently
filters out any string not present in flow._methods when a flow is provided,
which strips router output labels needed by callers like process_router_paths,
build_parent_children_dict, and dfs_ancestors; change
_extract_all_methods_recursive to accept an optional flag (e.g.,
include_non_method_labels: bool = False) that, when true, returns string labels
even if they are not in flow._methods, and update the router-aware callers
(process_router_paths, build_parent_children_dict, dfs_ancestors) to call
_extract_all_methods_recursive(..., include_non_method_labels=True) so router
branches are preserved while keeping the default behavior unchanged for callers
that only want method names.
- Around line 178-181: get_possible_return_constants() currently calls
inspect.getsource(function) and uses function.__self__/__qualname__/__globals__
for class-context lookup which inspects the wrapper instead of the original
callable; update all introspection to use the already-computed unwrapped
variable: replace inspect.getsource(function) with inspect.getsource(unwrapped)
and change uses of function.__self__, function.__qualname__, and
function.__globals__ in the class-context lookup to unwrapped.__self__,
unwrapped.__qualname__, and unwrapped.__globals__ so AST/class resolution
operates on the real underlying function (note: leave any globals already taken
from unwrapped unchanged).
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 50e554b4-1a29-4f90-906b-4a11415fea91
📒 Files selected for processing (6)
lib/crewai/src/crewai/flow/dsl.pylib/crewai/src/crewai/flow/flow.pylib/crewai/src/crewai/flow/flow_definition.pylib/crewai/src/crewai/flow/runtime.pylib/crewai/src/crewai/flow/utils.pylib/crewai/tests/test_async_human_feedback.py
This commit separates the monolithic
flow.pyinto three modules, each with one job:dsl.py- the Python DSL for flows (@start/@listen/@router, or_/and_)flow_definition.py- the structural model extracted from the DSLruntime.py- the execution engine and state for flowsThis phase moves code only and should not have any breaking changes.