Skip to content

fix(artifacts): never cache save_artifact tool results - #9595

Merged
Gabe Milani (gabemilani) merged 1 commit into
crewAIInc:mainfrom
MaiAditya:fix/artifact-tool-cache
Nov 20, 2026
Merged

Gabe Milani (gabemilani) merged 1 commit into
crewAIInc:mainfrom
MaiAditya:fix/artifact-tool-cache

Conversation

@MaiAditya

Copy link
Copy Markdown
Contributor

Related issue

Fixes #9594

Summary

SaveArtifactTool kept the default cache_function, so with Crew(cache=True) a second save_artifact call with the same arguments was served from the tool cache: no new version was saved and the agent got the old URL back. For a file the agent rewrites at the same path (a redrawn chart), the revision was silently lost.

The tool now uses _never_cache_function, the same opt-out the spreadsheet tools use. Each call saves a new version, as the artifacts docs describe.

Verification

  • Tests added or updated for the changed behavior

  • Relevant tests and quality checks pass locally

  • New test_tool_saves_a_rewritten_file_again_when_tool_caching_is_on runs two identical save_artifact calls through execute_single_native_tool_call with a cache on, rewriting the file in between. It fails on main ([1, 1] != [1, 2]) and passes with the fix.

  • uv run pytest lib/crewai/tests/test_artifacts.py lib/crewai/tests/test_tool_cache_default.py lib/crewai/tests/tools/test_deserialization_guard.py lib/crewai/tests/test_checkpoint.py lib/crewai/tests/tools/test_tool_usage.py

  • uv run ruff check / ruff format --check / mypy on the changed files.

Additional context

None.

AI disclosure: this PR was prepared with help from an AI coding assistant; I reviewed and tested the change. Please apply the llm-generated label per CONTRIBUTING (I may not have permission to add it).

@strix-security

strix-security Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

Strix Security Review

Warning

This pull request has 3 commits after the last Strix review (4bf11a6). 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: Disables tool-result caching for `SaveArtifactTool` so a second `save_artifact` call with the same arguments saves a new artifact version instead of returning the previous cached URL, with a regression test covering two identical calls on a rewritten file.

Review summary

Reviewed the full change: SaveArtifactTool in lib/crewai/src/crewai/artifacts.py now pins cache_function to _never_cache_function, plus a test exercising two identical calls through execute_single_native_tool_call with a cache enabled.

The field is not new surface — BaseTool already declares cache_function with the same SerializableCallable annotation, and the spreadsheet tools already override it the same way, so nothing becomes settable that wasn't before. The value is never handed to the model (the prompt block is built from args_schema, and the init-params schema explicitly filters cache_function out), and the serialized value resolves through the existing builtin allowlist in _resolve_tool_dict rather than the env-gated dotted-path import path. Call-time semantics also move in the safe direction: the predicate is only consulted when writing a result, the read path never uses it, and _claim_usage now runs on every save instead of being skipped on a cache hit. Because a cache hit previously short-circuited the tool body, the path-containment and single-source checks in save_artifact now run more often, not less, and artifact results no longer land in the crew-shared tool cache where a different agent could be served an earlier version's URL.

No security-relevant findings in the changed code; the change is a net reduction in exposure.

Review 1 on this PR · 4bf11a6 · requested Nov 20 07:20 UTC when the PR was opened


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

@gabemilani Gabe Milani (gabemilani) left a comment

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.

Good catch, thank you!

With Crew(cache=True), a second save_artifact call with the same
arguments was served from the tool cache, so no new version was saved
and a file rewritten at the same path was silently dropped.

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.

Lgtm

@gabemilani
Gabe Milani (gabemilani) merged commit 70a31b6 into crewAIInc:main Nov 20, 2026
54 checks passed
@github-actions

Copy link
Copy Markdown
Contributor

Thanks for your first contribution to CrewAI, Aditya Gupta (@MaiAditya)!

We really appreciate the time and care you put into this PR. Your work is now part of CrewAI — welcome to the contributor community.

Want to share your contribution? Totally optional:

Share on X · Share the PR on LinkedIn

If the links don't work, feel free to copy and personalize this:

I just made my first contribution to @crewAIInc!

Excited to help build the future of AI agents with CrewAI.

https://github.com/crewAIInc/crewAI/pull/9595

#OpenSource #AI #CrewAI

If you share, we'd love to see it — tag crewAI (@crewAIInc) on X and CrewAI on LinkedIn.

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] With Crew(cache=True), save_artifact returns the old version instead of saving a rewritten file

3 participants