crewAI icon indicating copy to clipboard operation
crewAI copied to clipboard

[BUG] Crew.copy() fails with ValidationError when a task has input_files

Open TehilaTheStudent opened this issue 1 week ago • 1 comments

Description

Crew.copy() raises a pydantic ValidationError when any task has input_files. Task.copy() rebuilds the task from self.model_dump(), which turns each file's source (FileBytes, a path, FileUrl) into a plain dict, and the file types' source validator rejects a dict: Cannot convert dict to file source.

Anything that copies a crew therefore cannot be used with file inputs, e.g. code that copies a crew per request so concurrent runs don't share state.

Steps to Reproduce

  1. pip install "crewai[file-processing]==1.15.45" (also reproduced on 1.15.45.dev20261126)
  2. Run the snippet below.

Expected behavior

crew.copy() returns a copy whose task keeps its input_files, as it does for a task without them.

Screenshots/Code snippets

from crewai import Agent, Crew, Task
from crewai_files import FileBytes, ImageFile

agent = Agent(role="Analyst", goal="Describe images", backstory="You describe images.", llm="gpt-4o")
task = Task(
    description="Describe the attached image.",
    expected_output="One sentence.",
    agent=agent,
    input_files={"chart": ImageFile(source=FileBytes(data=b"\x89PNG\r\n\x1a\n", filename="chart.png"))},
)
crew = Crew(agents=[agent], tasks=[task])
crew.copy()  # raises pydantic ValidationError

The same happens with a path source (ImageFile(source=Path("chart.png"))) and with FileUrl(url=...).

Operating System

macOS (also expected on Linux; the failure is in pydantic validation, not platform-specific)

Python Version

3.12

crewAI Version

1.15.45 (and 1.15.45.dev20261126); crewai-files same version

crewAI Tools Version

not installed

Virtual Environment

Venv

Evidence

pydantic_core._pydantic_core.ValidationError: 6 validation errors for Task
input_files.chart.AudioFile.source
  Value error, Cannot convert dict to file source [type=value_error, input_value={'data': b'\x89PNG\r\n\x1...'filename': 'chart.png'}, input_type=dict]
input_files.chart.File.source
  Value error, Cannot convert dict to file source [...]
input_files.chart.ImageFile.source
  Value error, Cannot convert dict to file source [...]
input_files.chart.PDFFile.source
  Value error, Cannot convert dict to file source [...]
input_files.chart.TextFile.source
  Value error, Cannot convert dict to file source [...]
input_files.chart.VideoFile.source
  Value error, Cannot convert dict to file source [...]

With a path source the input value is {'path': PosixPath('.../chart.png')}, same error.

Possible Solution

In Task.copy() (crewai/task.py), exclude input_files from the model_dump and pass the original file objects (or a shallow copy of the dict) to the new task, as is already done for context, agent and tools. Alternatively, let the file source validator accept the dict form it dumps to.

Additional context

Related: #8952 (copying a crew loses task/agent input templates).

TehilaTheStudent avatar Nov 26 '26 11:11 TehilaTheStudent

Thanks for the reproducer, @TehilaTheStudent. I reproduced this on Python 3.12.13 with both crewai and crewai-files at 1.15.45. An ImageFile backed by bytes, a local path, or a URL fails at the same point, before kickoff.

Your diagnosis matches the traceback. For the path case, Task.copy() dumps the source as {"path": Path("chart.png")} and passes it into the new task constructor. All six file types in the union try to validate that same dictionary, which explains the six errors for one attachment. I’d fix this in Task.copy() by excluding input_files from the dump and passing a fresh mapping of the typed file objects to the constructor. Task.copy() · File source validator

For your per-request setup, I also verified this workaround with a byte-backed image. Leave input_files empty on the template task and attach the image to the copy:

request_crew = template_crew.copy()
request_crew.tasks[0].input_files["chart"] = ImageFile(source=image_bytes)

The copied task registered the attachment under its own ID, and the template task’s file mapping stayed empty.

juemimgcd avatar Nov 26 '26 11:11 juemimgcd