Framework for orchestrating role-playing, autonomous AI agents. By fostering collaborative intelligence, CrewAI empowers agents to work together seamlessly, tackling complex tasks.
fix: store deferred tool results in tmp (#8229)
Vidit Ostwalb1c9279918dc
diff --git a/lib/crewai/src/crewai/utilities/tool_result_artifacts.py b/lib/crewai/src/crewai/utilities/tool_result_artifacts.pyindex 42bf23f43..b4f003c62 100644--- a/lib/crewai/src/crewai/utilities/tool_result_artifacts.py+++ b/lib/crewai/src/crewai/utilities/tool_result_artifacts.py@@ -11,6 +11,7 @@ from tempfile import TemporaryDirectoryTOOL_RESULT_PREVIEW_LINE_COUNT = 10TOOL_RESULT_PREVIEW_MAX_CHARS = 2_000TOOL_RESULT_READ_CONTEXT_WINDOW_RATIO = 0.05+_TOOL_RESULT_TEMP_DIR = Path("/tmp") # noqa: S108 - intentional POSIX temp dir@dataclass(frozen=True)@@ -41,10 +42,19 @@ class ToolResultArtifactStore:Args:base_dir: Parent directory for the private execution directory.- Intended for tests; production defaults to the system temp- directory.+ Intended for tests; production uses ``/tmp`` when available,+ otherwise the platform's system temp directory."""- directory = str(base_dir) if base_dir is not None else None+ # Keep potentially large tool output out of the project and user data+ # directories. ``/tmp`` is the conventional ephemeral location on+ # POSIX; retain Python's platform-specific fallback where it is absent.+ directory = (+ str(base_dir)+ if base_dir is not None+ else str(_TOOL_RESULT_TEMP_DIR)+ if _TOOL_RESULT_TEMP_DIR.is_dir()+ else None+ )self._temporary_directory = TemporaryDirectory(prefix="crewai-tool-results-", dir=directory)diff --git a/lib/crewai/tests/utilities/test_tool_result_artifacts.py b/lib/crewai/tests/utilities/test_tool_result_artifacts.pyindex 3645f4a7a..daca1da4c 100644--- a/lib/crewai/tests/utilities/test_tool_result_artifacts.py+++ b/lib/crewai/tests/utilities/test_tool_result_artifacts.py@@ -3,6 +3,16 @@ from pathlib import Pathfrom crewai.utilities.tool_result_artifacts import ToolResultArtifactStore+def test_store_defaults_to_tmp() -> None:+ store = ToolResultArtifactStore()++ try:+ if Path("/tmp").is_dir():+ assert store.directory.parent == Path("/tmp")+ finally:+ store.cleanup()++def test_store_returns_opaque_identifier_and_preserves_content(tmp_path: Path) -> None:store = ToolResultArtifactStore(base_dir=tmp_path)