Skip to content

fix(flow): resolve inline agent and crew action refs relative to the flow file - #9490

Merged
Vidit Ostwal (Vidit-Ostwal) merged 1 commit into
crewAIInc:mainfrom
adityajai119:fix/flow-inline-actions-source-dir
Nov 19, 2026
Merged

Vidit Ostwal (Vidit-Ostwal) merged 1 commit into
crewAIInc:mainfrom
adityajai119:fix/flow-inline-actions-source-dir

Conversation

@adityajai119

Copy link
Copy Markdown
Contributor

Related issue

Fixes #9489

Summary

When a declarative flow is loaded from a file (Flow.from_declaration(path=...)) and kicked off from another working directory, CrewAction.run on its from_declaration branch and conversational.router.response_format (#7063) resolve relative to self.flow._definition.source_dir, whereas inline CrewAction.run (with:) and AgentAction.run left project_root unset on load_crew_from_definition and load_agent_from_definition. Both fell back to Path.cwd(), so custom:<name> tools and project-local {"python": "..."} references (response_format, output_pydantic, output_json, etc.) sitting beside flow.yaml failed to load with JSONProjectError.

Both calls now pass project_root=self.flow._definition.source_dir. When a declaration is loaded in memory (Flow.from_declaration(contents=...)), source_dir is None and both loaders still fall back to Path.cwd().

Verification

  • Tests added or updated for the changed behavior

  • Relevant tests and quality checks pass locally

  • New test_inline_flow_actions_resolve_project_refs_relative_to_flow_file[agent|crew] in lib/crewai/tests/test_flow_from_definition.py, loading flow.yaml by path after monkeypatch.chdir to another directory with Agent.kickoff_async / Crew.kickoff_async patched so no LLM is called, verifying both custom:lookup and {"python": "flow_reply_models.SupportReply"} resolve next to flow.yaml. Both cases fail on main (JSONProjectError) and pass with this change.

  • pytest lib/crewai/tests/test_flow_from_definition.py -o addopts="" (Windows 11, Python 3.13): 176 passed, 1 failed (test_a_platform_ref_amp_cannot_resolve_names_the_app, missing optional crewai_tools in this venv; fails the same way on main).

  • pytest lib/crewai/tests/test_flow_definition.py lib/crewai/tests/project/test_crew_loader.py lib/crewai/tests/project/test_json_loader.py -o addopts="": 161 passed, 2 failed (the two crewai_tools.CrewaiPlatformTools monkeypatch tests in test_json_loader.py; same on main).

  • These runs override addopts: on Windows --block-network also blocks asyncio's self-pipe socketpair().

  • ruff check on both changed files, ruff format --check on lib/crewai/src/crewai/flow/runtime/_actions.py, and mypy lib/crewai/src/crewai/flow/runtime/_actions.py: clean (0 issues).

Additional context

Written with an AI coding agent (Gemini 4 Carbon in OpenCode). CONTRIBUTING asks for the llm-generated label on AI-assisted PRs; I can't add labels, so could a maintainer add it?

@strix-security

strix-security Bot commented Nov 16, 2026 •

Copy link
Copy Markdown

Strix Security Review

Warning

This pull request has 28 commits after the last Strix review (3b56899). Strix has not reviewed these changes.
Automatic review on push is off for this repository. To review the latest changes, tag @strix-security in a comment, or turn on re-review on push.

✅ No open security findings.

PR summary: Declarative flows loaded by path now resolve inline agent and crew actions' `custom:` tools and `{"python": ...}` references relative to the flow file's own directory instead of the process working directory, with a new test covering both action kinds.

Review summary

The PR adds project_root=self.flow._definition.source_dir to the two loader calls used by inline call: crew (with:) and call: agent actions, so custom: tools and {"python": ...} references resolve beside the flow file instead of the process working directory, plus a parameterized test covering both. I traced both call sites through load_crew_from_definition / load_agent_from_definition into the project receiving code, the CLI entry point that supplies the declaration path, and the pre-existing from_declaration and conversational response_format paths. No security issues were found: the change moves the resolution anchor to a directory the declaration already owns, every project-relative lookup remains fenced by the loader's containment helpers, and no check was removed. The remaining behaviours noticed while tracing — skill path handling, role carrying messages, loader import ordering and process-global module state, and definition-supplied log/agent file paths — are pre-existing, in code this PR neither edits nor reroutes, and are driven by configuration authored by the same operator who runs the flow.

Ruled out (6)
  • Does the new flow-file anchor let an inline action import or execute Python from outside the flow directory?
    The project loader still requires the referenced module file or `tools/<name>.py` to exist under the anchor and rejects anything that resolves outside it, so the change tightens rather than loosens containment.
  • Does anchoring to the flow file widen what a declaration can import compared with the old working-directory fallback?
    The same capability already existed through the `from_declaration` crew branch and the conversational `response_format` path, and the flow's own directory is equal to or narrower than the process cwd.
  • Can an inline agent action's `skills` entries read arbitrary local directories and inject their contents into the prompt?
    The new project root never reaches skills handling, which is unchanged and only settable by whoever authors the declaration.
  • Can flow state plant system- or tool-role messages into an agent action's conversation?
    That message path is untouched by the diff and the only party able to populate it is the caller who already controls what the agent receives.
  • Is project-root containment enforced only after the module import, and can cached modules leak between projects?
    Containment is re-checked before any resolved object is returned and cached external modules are evicted first, so no foreign module is ever bound for use.
  • Can definition-supplied crew file paths such as `output_log_file` or `agents` entries write or read outside the flow directory?
    `output_log_file` never goes through the project root, `agents` names are in-memory dictionary keys on this path rather than file lookups, and the declaration author already holds code execution through project-local Python references.

Review 1 on this PR · 3b56899 · requested Nov 16 17:15 UTC when the PR was opened


Reviewed by Strix
Re-run review · Configure security review settings · Try a deeper review with @strix-security /deep

@adityajai119
T Mohan Aditya (adityajai119) force-pushed the fix/flow-inline-actions-source-dir branch from 3b56899 to f0e4317 Compare November 16, 2026 17:27
…flow file

Inline AgentAction and CrewAction (with:) definitions left project_root
unset when calling load_agent_from_definition and load_crew_from_definition,
so Flow.from_declaration(path=...) fell back to Path.cwd() for custom tools
and local Python references instead of FlowDefinition.source_dir.
@Vidit-Ostwal
Vidit Ostwal (Vidit-Ostwal) force-pushed the fix/flow-inline-actions-source-dir branch from f0e4317 to 2d99f89 Compare November 19, 2026 15:00

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks, this is a clean, minimal fix: passing project_root=self.flow._definition.source_dir in AgentAction.run and the inline CrewAction.run branch (_actions.py) matches how the from_declaration crew and the router already resolve paths.
I verified earlier that your parametrized test fails on main with JSONProjectError (custom:lookup looked up under the other cwd) and passes with your change; an independent agent-action repro behaved the same.
Optional follow-up: a small test that an in-memory declaration (source_dir None) still falls back to cwd would pin the backward-compat path.

@Vidit-Ostwal
Vidit Ostwal (Vidit-Ostwal) merged commit fe019e1 into crewAIInc:main Nov 19, 2026
54 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Flow.from_declaration(path=...) resolves inline agent and crew action refs against cwd instead of the flow file

2 participants