Add declarative Flow CLI support

Currently, declarative flows can be loaded by the runtime, but the CLI
still treats them as an experimental definition file instead of a
first-class Flow project shape.

With this PR, `crewai create flow --declarative` scaffolds a YAML-backed
Flow project, and `crewai run`, `crewai flow kickoff`, and `crewai flow
plot` can run against the configured definition.

This also lets crew actions reference reusable crew definition files or
folders and override their inputs from the Flow definition, so
declarative flows can compose existing declarative crews without
inlining everything.
This commit is contained in:
Vinicius Brasil
2026-06-22 16:13:12 -07:00
parent 0391febc6c
commit 9e220b1617
20 changed files with 1226 additions and 348 deletions

View File

@@ -130,31 +130,49 @@ def test_run_uses_project_runner_by_default(run_crew, runner):
assert "experimental" not in result.output.lower()
@mock.patch("crewai_cli.cli.run_flow_definition")
def test_run_with_definition_uses_definition_runner(run_flow_definition, runner):
@mock.patch("crewai_cli.cli.run_declarative_flow_in_project_env")
def test_run_with_definition_uses_project_env_declarative_runner(
run_declarative_flow_in_project_env, runner, monkeypatch
):
monkeypatch.delenv("UV_RUN_RECURSION_DEPTH", raising=False)
result = runner.invoke(
run,
["--definition", "flow.yaml", "--inputs", '{"topic":"AI"}'],
)
assert result.exit_code == 0
assert (
"Warning: `crewai run --definition` is experimental and may change without notice."
in result.output
assert "experimental" not in result.output.lower()
run_declarative_flow_in_project_env.assert_called_once_with(
definition="flow.yaml", inputs='{"topic":"AI"}'
)
run_flow_definition.assert_called_once_with(
@mock.patch("crewai_cli.cli.run_declarative_flow_in_project_env")
def test_run_with_definition_delegates_project_env_detection_to_runner(
run_declarative_flow_in_project_env, runner
):
result = runner.invoke(
run,
["--definition", "flow.yaml", "--inputs", '{"topic":"AI"}'],
env={"UV_RUN_RECURSION_DEPTH": "1"},
)
assert result.exit_code == 0
run_declarative_flow_in_project_env.assert_called_once_with(
definition="flow.yaml", inputs='{"topic":"AI"}'
)
@mock.patch("crewai_cli.cli.run_crew")
@mock.patch("crewai_cli.cli.run_flow_definition")
def test_run_rejects_inputs_without_definition(run_flow_definition, run_crew, runner):
@mock.patch("crewai_cli.cli.run_declarative_flow_in_project_env")
def test_run_rejects_inputs_without_definition(
run_declarative_flow_in_project_env, run_crew, runner
):
result = runner.invoke(run, ["--inputs", '{"topic":"AI"}'])
assert result.exit_code == 2
assert "Error: --inputs requires --definition" in result.output
run_flow_definition.assert_not_called()
run_declarative_flow_in_project_env.assert_not_called()
run_crew.assert_not_called()
@@ -166,6 +184,23 @@ def test_create_crew_in_dmn_mode_skips_provider_prompts(create_json_crew, runner
create_json_crew.assert_called_once_with("DMN Crew", None, True)
@mock.patch("crewai_cli.create_flow.create_flow")
def test_create_flow_declarative_uses_declarative_scaffold(create_flow, runner):
result = runner.invoke(create, ["flow", "My Flow", "--declarative"])
assert result.exit_code == 0
create_flow.assert_called_once_with("My Flow", declarative=True)
@mock.patch("crewai_cli.create_json_crew.create_json_crew")
def test_create_crew_rejects_declarative_flag(create_json_crew, runner):
result = runner.invoke(create, ["crew", "My Crew", "--declarative"])
assert result.exit_code == 2
assert "--declarative can only be used with flow projects" in result.output
create_json_crew.assert_not_called()
def test_create_requires_type_in_dmn_mode(runner):
result = runner.invoke(create, env={"CREWAI_DMN": "True"})