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
Open
Conversation
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>
Contributor
Author
|
Prompt hidden (unlisted session) |
Contributor
Author
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #5534.
When a
Taskhad anagentassigned but theCrewwas constructed without an explicitagents=[...]list (e.g.Crew(tasks=[task])),setup_agentsiterated an empty list and never setagent.crew = crew. Downstream paths that rely on the crew reference —task.prompt()file injection,CrewAgentExecutorfile lookups viaget_all_files(crew.id, task.id), delegation tools — then silently no-op'd, soinput_filesattached at the Task level were ignored by the model (no error raised).The fix adds a
model_validator(mode="after")onCrewthat auto-populatesself.agentswith any agent referenced by a task so the crew behaves identically whetheragents=[...]is passed explicitly or inferred from tasks. The manager agent is explicitly excluded to preserve the existingmanager_agent_in_agentsvalidation.Changes:
sync_agents_with_tasksvalidator.agent.crewwiring throughprepare_kickoff, andtask.prompt()including the input files when onlytask.agentis set.Review & Testing Checklist for Human
Crew.agentsis acceptable — agents inferred from tasks are appended in task order after any explicitly provided agents.Crew(tasks=[task])+input_filesat kickoff time) — the model should now receive the image.Crew.agentsbeing empty when onlytask.agentwas used (e.g. UI, serialization, or external schemas).Notes
agents=[...]is already passed (validator is a no-op: the list length doesn't change).check_manager_llmandcheck_config, so cache/rpm handlers are wired onto every task agent too.ruff checkandmypyon 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
Crewmodel validation to mutateagentsbased ontasks, which can affect agent ordering/identity and any logic that assumedCrew.agentsstayed user-provided only. Coverage is added, but this touches core kickoff/agent setup behavior used broadly.Overview
Fixes a regression where constructing a
Crewwith onlytasks=[...](and eachTaskhavingtask.agent) leftcrew.agentsempty, sosetup_agentsnever setagent.crewand task-levelinput_files/delegation/memory features could silently no-op.Adds an
aftermodel_validator(sync_agents_with_tasks) that auto-populatesCrew.agentswith any agents referenced by tasks (excludingmanager_agent) and adds regression tests ensuring agents are inferred, not duplicated when explicitly provided, and thatprepare_kickoff+task.prompt()correctly see storedinput_files.Reviewed by Cursor Bugbot for commit 518c9af. Bugbot is set up for automated code reviews on this repo. Configure here.