Skip to content

Fix JSON crew template rendering#6359

Merged
vinibrsl merged 1 commit into
mainfrom
fix-json-crew-template-rendering
Jun 26, 2026
Merged

Fix JSON crew template rendering#6359
vinibrsl merged 1 commit into
mainfrom
fix-json-crew-template-rendering

Conversation

@vinibrsl

@vinibrsl vinibrsl commented Jun 26, 2026

Copy link
Copy Markdown
Member

JSON crews were not using existing CLI templates.


Note

Low Risk
Scaffolding and CLI template plumbing only; behavior is intended to stay the same, with added tests for templates and the JSON runner import path.

Overview
JSON crew project scaffolding no longer builds agent, task, and crew JSONC (plus pyproject.toml, README, .gitignore, and knowledge placeholders) from large inline strings in create_json_crew.py. Those outputs now come from templates/json_crew/ via a shared render_template helper in utils.py (also used by copy_template), with {{placeholder}} substitution and no recursive expansion inside replacement values.

run_crew.py defers crewai_core.project imports until read_toml, get_crewai_project_type, and configured_project_json_crew run, so the JSON crew subprocess runner can load the current CLI when the project environment ships an older crewai_core. Tests cover on-disk templates, safe template rendering, and that runner path.

Reviewed by Cursor Bugbot for commit 2dd335b. Bugbot is set up for automated code reviews on this repo. Configure here.

Summary by CodeRabbit

  • New Features

    • Added support for generating JSON-based crew projects with ready-made templates and scaffolding files.
    • Included clearer starter content for project setup, crew/task/agent definitions, and knowledge files.
  • Bug Fixes

    • Improved compatibility when running crews in older environments.
    • Preserved placeholder text more reliably during template rendering.
  • Chores

    • Updated generated project defaults and ignore rules for a cleaner starter experience.

@corridor-security corridor-security Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Summary: This PR moves JSON crew scaffolding content into static template files and adds a simple placeholder renderer for CLI-generated project files. No exploitable security vulnerabilities were identified in the added code.

Risk: Low risk. The changes affect local CLI project generation and import timing, do not add public endpoints or authentication/authorization logic, and template values used in executable JSON crew definitions are JSON-encoded before insertion.

@coderabbitai

coderabbitai Bot commented Jun 26, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The PR switches JSON crew generation to file-based templates, adds a reusable placeholder renderer, and updates the runner to lazy-load project-definition helpers. Tests now cover template discovery, placeholder substitution, and older project-environment compatibility.

Changes

JSON crew scaffolding

Layer / File(s) Summary
Template renderer
lib/cli/src/crewai_cli/utils.py
Adds regex token substitution and changes template copying to render through the new helper.
Template files
lib/cli/src/crewai_cli/templates/json_crew/*
Adds the crew, agent, task, metadata, and README/ignore/knowledge templates used by JSON crew scaffolding.
Generator wiring
lib/cli/src/crewai_cli/create_json_crew.py
create_json_crew() now renders the new templates for agents, tasks, crew output, and generated project files.
Validation
lib/cli/tests/test_create_crew.py
Adds template-discovery and placeholder-substitution coverage and updates the tools dependency assertion.

Runner imports

Layer / File(s) Summary
Lazy project imports
lib/cli/src/crewai_cli/run_crew.py, lib/cli/tests/test_run_crew.py
Replaces module-level crewai_core.project imports with local wrappers and adds a subprocess test for the older project environment path.

Suggested reviewers

  • akaKuruma
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 47.06% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: fixing JSON crew template rendering.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix-json-crew-template-rendering

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 Biome (2.5.0)
lib/cli/src/crewai_cli/templates/json_crew/agent_settings.jsonc

File contains syntax errors that prevent linting: Line 2: End of file expected; Line 2: End of file expected; Line 2: End of file expected; Line 5: End of file expected; Line 5: End of file expected; Line 5: Expected a property but instead found '{'.; Line 5: Property key must be double quoted; Line 5: expected : but instead found }; Line 5: End of file expected; Line 5: Expected a property but instead found '{'.; Line 5: Property key must be double quoted; Line 5: expected : but instead found }; Line 5: End of file expected; Line 32: Expected a property but instead found '{'.; Line 32: Property key must be double quoted; Line 32: expected : but instead found }; Line 32: End of file expected

lib/cli/src/crewai_cli/templates/json_crew/agent.jsonc

File contains syntax errors that prevent linting: Line 5: Expected a property but instead found '{'.; Line 5: Property key must be double quoted; Line 5: expected : but instead found }; Line 11: Expected a property but instead found '{'.; Line 11: Property key must be double quoted; Line 11: expected : but instead found }; Line 14: Expected a property but instead found '{'.; Line 14: Property key must be double quoted; Line 14: expected : but instead found }; Line 21: Expected a property but instead found '{'.; Line 21: Property key must be double quoted; Line 21: expected : but instead found }; Line 29: Expected a property but instead found '{'.; Line 29: Property key must be double quoted; Line 29: expected : but instead found }; Line 57: Expected a property but instead found '{'.; Line 57: Expected a property but instead found '{'.; Line 57: Property key must be double quoted; Line 57: expected : but instead found }

lib/cli/src/crewai_cli/templates/json_crew/crew.jsonc

File contains syntax errors that prevent linting: Line 3: Expected a property but instead found '{'.; Line 3: Property key must be double quoted; Line 3: expected : but instead found }; Line 6: Expected a property but instead found '{'.; Line 6: Property key must be double quoted; Line 6: expected : but instead found }; Line 10: Expected a property but instead found '{'.; Line 10: Property key must be double quoted; Line 10: expected : but instead found }; Line 16: Expected a property but instead found '{'.; Line 16: Property key must be double quoted; Line 16: expected : but instead found }; Line 22: Expected a property but instead found '{'.; Line 22: Property key must be double quoted; Line 22: expected : but instead found }; Line 57: Expected a property but instead found '{'.; Line 57: Property key must be double quoted; Line 57: expected : but instead found }

  • 1 others

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

JSON crews were not using existing CLI templates.
@vinibrsl vinibrsl force-pushed the fix-json-crew-template-rendering branch from fd23dbb to 2dd335b Compare June 26, 2026 19:31

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
lib/cli/src/crewai_cli/run_crew.py (1)

111-132: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Older crewai_core still breaks the normal run_crew() path.

The older crewai_core.project stub introduced in lib/cli/tests/test_run_crew.py Lines 238-249 does not define ProjectDefinitionError or configured_project_definition. Importing them here means run_crew() will still raise ImportError before it can fall back to the classic crew path, so the compatibility fix only covers the direct JSON runner subprocess path.

Suggested guard
 def configured_project_json_crew(
     pyproject_data: dict[str, Any] | None = None,
     project_root: Path | None = None,
 ) -> Path | None:
     """Return the configured JSON crew definition for crew projects."""
-    from crewai_core.project import (
-        ProjectDefinitionError,
-        configured_project_definition,
-    )
+    from crewai_core import project as project_helpers
+
+    configured_project_definition = getattr(
+        project_helpers, "configured_project_definition", None
+    )
+    ProjectDefinitionError = getattr(
+        project_helpers, "ProjectDefinitionError", None
+    )
+    if configured_project_definition is None or ProjectDefinitionError is None:
+        return None
🤖 Prompt for 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.

In `@lib/cli/src/crewai_cli/run_crew.py` around lines 111 - 132, The import in
configured_project_json_crew still makes run_crew() fail with older crewai_core
stubs because ProjectDefinitionError and configured_project_definition are
imported unconditionally. Move the crewai_core.project import logic inside the
function with a compatibility guard so missing symbols fall back cleanly to the
classic crew path, and keep the existing click.UsageError conversion only when
configured_project_definition is actually available.
🧹 Nitpick comments (1)
lib/cli/tests/test_run_crew.py (1)

230-301: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Add coverage for the actual run_crew() entrypoint.

This subprocess only executes _JSON_CREW_RUNNER_CODE, so it will not catch the remaining failure mode where run_crew() calls configured_project_json_crew() under the same older crewai_core stub. A second subprocess that imports crewai_cli.run_crew and invokes run_crew() would lock in the compatibility behavior this change is aiming for.

🤖 Prompt for 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.

In `@lib/cli/tests/test_run_crew.py` around lines 230 - 301, Add a subprocess test
that exercises the actual run_crew() entrypoint, not just
_JSON_CREW_RUNNER_CODE. Reuse the older crewai_core stub setup, then import
crewai_cli.run_crew and call run_crew() so the test covers the
configured_project_json_crew() path under legacy environments. Keep the existing
marker-based assertion to verify the crew still kicks off successfully.
🤖 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.

Outside diff comments:
In `@lib/cli/src/crewai_cli/run_crew.py`:
- Around line 111-132: The import in configured_project_json_crew still makes
run_crew() fail with older crewai_core stubs because ProjectDefinitionError and
configured_project_definition are imported unconditionally. Move the
crewai_core.project import logic inside the function with a compatibility guard
so missing symbols fall back cleanly to the classic crew path, and keep the
existing click.UsageError conversion only when configured_project_definition is
actually available.

---

Nitpick comments:
In `@lib/cli/tests/test_run_crew.py`:
- Around line 230-301: Add a subprocess test that exercises the actual
run_crew() entrypoint, not just _JSON_CREW_RUNNER_CODE. Reuse the older
crewai_core stub setup, then import crewai_cli.run_crew and call run_crew() so
the test covers the configured_project_json_crew() path under legacy
environments. Keep the existing marker-based assertion to verify the crew still
kicks off successfully.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 6b780523-9909-4afa-9c58-c933cc70c03e

📥 Commits

Reviewing files that changed from the base of the PR and between 8eaae40 and fd23dbb.

📒 Files selected for processing (13)
  • lib/cli/src/crewai_cli/create_json_crew.py
  • lib/cli/src/crewai_cli/run_crew.py
  • lib/cli/src/crewai_cli/templates/json_crew/.gitignore
  • lib/cli/src/crewai_cli/templates/json_crew/README.md
  • lib/cli/src/crewai_cli/templates/json_crew/agent.jsonc
  • lib/cli/src/crewai_cli/templates/json_crew/agent_settings.jsonc
  • lib/cli/src/crewai_cli/templates/json_crew/crew.jsonc
  • lib/cli/src/crewai_cli/templates/json_crew/knowledge/user_preference.txt
  • lib/cli/src/crewai_cli/templates/json_crew/pyproject.toml
  • lib/cli/src/crewai_cli/templates/json_crew/task.jsonc
  • lib/cli/src/crewai_cli/utils.py
  • lib/cli/tests/test_create_crew.py
  • lib/cli/tests/test_run_crew.py

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 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/cli/src/crewai_cli/create_json_crew.py`:
- Line 83: The JSON crew template directory referenced by create_json_crew.py
via _TEMPLATES_DIR is not guaranteed to be packaged, so installed CLI builds can
miss these files and raise FileNotFoundError. Update lib/cli/pyproject.toml to
explicitly include or force-include src/crewai_cli/templates/json_crew/** in the
package data so the templates are bundled with the CLI artifact.

In `@lib/cli/src/crewai_cli/templates/json_crew/agent.jsonc`:
- Around line 1-59: The template files under the json_crew generator are being
parsed as JSONC even though they still contain unrendered {{...}} placeholders,
so Biome fails on them. Update the template handling by either renaming these
sources to a non-JSONC template extension such as .jsonc.tmpl or excluding the
entire lib/cli/src/crewai_cli/templates/json_crew/** set from JSONC linting.
Apply the same fix consistently to agent.jsonc and the other template JSONC
files in that directory.
🪄 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: 9f985614-827e-4356-9681-2bcf68e9579b

📥 Commits

Reviewing files that changed from the base of the PR and between fd23dbb and 2dd335b.

📒 Files selected for processing (13)
  • lib/cli/src/crewai_cli/create_json_crew.py
  • lib/cli/src/crewai_cli/run_crew.py
  • lib/cli/src/crewai_cli/templates/json_crew/.gitignore
  • lib/cli/src/crewai_cli/templates/json_crew/README.md
  • lib/cli/src/crewai_cli/templates/json_crew/agent.jsonc
  • lib/cli/src/crewai_cli/templates/json_crew/agent_settings.jsonc
  • lib/cli/src/crewai_cli/templates/json_crew/crew.jsonc
  • lib/cli/src/crewai_cli/templates/json_crew/knowledge/user_preference.txt
  • lib/cli/src/crewai_cli/templates/json_crew/pyproject.toml
  • lib/cli/src/crewai_cli/templates/json_crew/task.jsonc
  • lib/cli/src/crewai_cli/utils.py
  • lib/cli/tests/test_create_crew.py
  • lib/cli/tests/test_run_crew.py
✅ Files skipped from review due to trivial changes (3)
  • lib/cli/src/crewai_cli/templates/json_crew/knowledge/user_preference.txt
  • lib/cli/src/crewai_cli/templates/json_crew/README.md
  • lib/cli/src/crewai_cli/templates/json_crew/.gitignore
🚧 Files skipped from review as they are similar to previous changes (4)
  • lib/cli/src/crewai_cli/templates/json_crew/pyproject.toml
  • lib/cli/tests/test_create_crew.py
  • lib/cli/src/crewai_cli/utils.py
  • lib/cli/src/crewai_cli/run_crew.py

Comment thread lib/cli/src/crewai_cli/create_json_crew.py
Comment thread lib/cli/src/crewai_cli/templates/json_crew/agent.jsonc
@vinibrsl vinibrsl merged commit a149a30 into main Jun 26, 2026
57 checks passed
@vinibrsl vinibrsl deleted the fix-json-crew-template-rendering branch June 26, 2026 20:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants