fix: resolve agent/crew skills paths against project_root, not cwd#6596
Open
MedviJenka wants to merge 1 commit into
Open
fix: resolve agent/crew skills paths against project_root, not cwd#6596MedviJenka wants to merge 1 commit into
MedviJenka wants to merge 1 commit into
Conversation
Agent and crew `skills` filesystem path strings loaded from JSON/JSONC definitions were passed through unresolved, so `discover_skills()` resolved them against the process cwd at call time instead of `project_root` like `tools` and `output_pydantic` already do. The same crew definition would succeed or fail depending on the cwd the process happened to start from (e.g. uvicorn/docker vs. running the script directly). Adds `_resolve_skill_path_strings()`, called for the `skills` field in both `_resolve_agent_python_refs` and `_resolve_crew_python_refs`, which rewrites plain filesystem path strings to absolute paths resolved against `project_root`. Registry references (`@org/name`), inline SKILL.md content, and already-resolved objects (e.g. from a Python reference) are left untouched. Fixes crewAIInc#6585.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughThe JSON loader now resolves ordinary agent and crew ChangesSkill Path Resolution
Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 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 file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #6585.
When loading a crew from JSONC (
load_crew,load_crew_from_definition,load_agent_from_definition), every relative path field (toolswith thecustom:prefix,output_pydantic/response_formatPython refs, etc.) isresolved against
project_root. The agent/crewskillsfield was the oneexception: it was passed through unresolved in
crewai/project/json_loader.py, and ultimately reachedcrewai/skills/loader.py::discover_skills(Path(skill)), which resolves thepath against
Path.cwd()at call time instead ofproject_root.This meant the same crew definition would succeed or fail purely based on
the process's current working directory at import/call time — e.g. it
works when running a script directly from its own directory, but fails
with
FileNotFoundError: Skill search path does not exist or is not a directory: skillswhen the same code runs as part of a server processlaunched from a different cwd (uvicorn, docker, IDE run configs, etc.).
_resolve_skill_path_strings()increwai/project/json_loader.py,called for the
skillsfield in both_resolve_agent_python_refs(agentdefinitions) and
_resolve_crew_python_refs(crew-levelskills)."./skills") are rewritten to absolutepaths resolved against
project_root, reusing the existing_resolve_project_pathhelper (same containment rules already applied toinput_files).@org/name), inlineSKILL.mdstring content, andvalues already resolved to non-string objects (e.g. via a
{"python": ...}reference, or a pre-loadedSkillinstance) are left unchanged.Agent(skills=...)/Crew(skills=...)usage is unaffected.Test plan
TestResolveSkillPathStringsunit tests covering: relativepath resolution against
project_root(not cwd), registry refspassed through, inline SKILL.md content passed through, pre-loaded
Skillobjects passed through, and non-list values passed through.test_skills_resolve_relative_to_project_root_not_cwdtoTestLoadAgentFromDefinition, reproducing the issue's repro caseend-to-end: agent loaded via
load_agent_from_definitionwithskills: ["./skills"]from a cwd other thanproject_rootcorrectlydiscovers the skill.
uv run pytest lib/crewai/tests/project/test_json_loader.py— 61passed.
uv run ruff checkon changed files — clean.🤖 Generated with Claude Code