Skip to content

Fix #5534: propagate Task.input_files when Crew.agents is not set explicitly#5535

Open
devin-ai-integration[bot] wants to merge 1 commit intomainfrom
devin/1776615925-fix-issue-5534-task-input-files-without-agents
Open

Fix #5534: propagate Task.input_files when Crew.agents is not set explicitly#5535
devin-ai-integration[bot] wants to merge 1 commit intomainfrom
devin/1776615925-fix-issue-5534-task-input-files-without-agents

Conversation

@devin-ai-integration
Copy link
Copy Markdown
Contributor

@devin-ai-integration devin-ai-integration bot commented Apr 19, 2026

Summary

Fixes #5534.

When a Task had an agent assigned but the Crew was constructed without an explicit agents=[...] list (e.g. Crew(tasks=[task])), setup_agents iterated an empty list and never set agent.crew = crew. Downstream paths that rely on the crew reference — task.prompt() file injection, CrewAgentExecutor file lookups via get_all_files(crew.id, task.id), delegation tools — then silently no-op'd, so input_files attached at the Task level were ignored by the model (no error raised).

The fix adds a model_validator(mode="after") on Crew that auto-populates self.agents with any agent referenced by a task so the crew behaves identically whether agents=[...] is passed explicitly or inferred from tasks. The manager agent is explicitly excluded to preserve the existing manager_agent_in_agents validation.

Changes:

  • <ref_snippet file="/home/ubuntu/repos/crewAI/lib/crewai/src/crewai/crew.py" lines="627-661" /> — new sync_agents_with_tasks validator.
  • <ref_snippet file="/home/ubuntu/repos/crewAI/lib/crewai/tests/test_crew_multimodal.py" lines="463-568" /> — regression tests covering the auto-population, no duplication when explicit, agent.crew wiring through prepare_kickoff, and task.prompt() including the input files when only task.agent is set.

Review & Testing Checklist for Human

  • Confirm the auto-populated ordering of Crew.agents is acceptable — agents inferred from tasks are appended in task order after any explicitly provided agents.
  • Verify the fix with the exact reproduction from the issue: a real multimodal call (Crew(tasks=[task]) + input_files at kickoff time) — the model should now receive the image.
  • Confirm there is no downstream consumer that relied on Crew.agents being empty when only task.agent was used (e.g. UI, serialization, or external schemas).

Notes

  • No behavior change when agents=[...] is already passed (validator is a no-op: the list length doesn't change).
  • The new validator runs before check_manager_llm and check_config, so cache/rpm handlers are wired onto every task agent too.
  • Ran ruff check and mypy on the changed files — both clean. 4 new unit tests pass; lib/crewai/tests/test_crew.py (121 tests) and related agent/task suites remain green.

Link to Devin session: https://app.devin.ai/sessions/2258f5fb63894d9db54bbcad01c76281


Note

Medium Risk
Changes Crew model validation to mutate agents based on tasks, which can affect agent ordering/identity and any logic that assumed Crew.agents stayed user-provided only. Coverage is added, but this touches core kickoff/agent setup behavior used broadly.

Overview
Fixes a regression where constructing a Crew with only tasks=[...] (and each Task having task.agent) left crew.agents empty, so setup_agents never set agent.crew and task-level input_files/delegation/memory features could silently no-op.

Adds an after model_validator (sync_agents_with_tasks) that auto-populates Crew.agents with any agents referenced by tasks (excluding manager_agent) and adds regression tests ensuring agents are inferred, not duplicated when explicitly provided, and that prepare_kickoff + task.prompt() correctly see stored input_files.

Reviewed by Cursor Bugbot for commit 518c9af. Bugbot is set up for automated code reviews on this repo. Configure here.

When a Task has an agent assigned but the Crew is built without an
explicit agents=[...] list, setup_agents iterates an empty list and
never wires agent.crew = crew. Downstream paths that rely on the crew
reference (task.prompt() file injection, crew_agent_executor file
lookups, delegation tools) then silently no-op, so input_files attached
at the Task level are ignored.

Add a model_validator that auto-populates Crew.agents with any agent
referenced by a task so the crew behaves the same whether agents=[...]
is passed explicitly or inferred from tasks, and cover the regression
with unit tests.

Co-Authored-By: João <joao@crewai.com>
@devin-ai-integration
Copy link
Copy Markdown
Contributor Author

Prompt hidden (unlisted session)

@devin-ai-integration
Copy link
Copy Markdown
Contributor Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] CrewAI: Task.input_files + missing Crew.agents causes multimodal files to be ignored

0 participants