Fix #5931: Propagate Crew.prompt_file to all components during execution#5933
Open
devin-ai-integration[bot] wants to merge 3 commits into
Open
Fix #5931: Propagate Crew.prompt_file to all components during execution#5933devin-ai-integration[bot] wants to merge 3 commits into
devin-ai-integration[bot] wants to merge 3 commits into
Conversation
Previously, setting prompt_file on a Crew had no effect on agents, tasks, tools, or any other components. The custom I18N instance was only used for the manager agent's role/goal/backstory in hierarchical mode, while all other code used the hardcoded I18N_DEFAULT singleton. This fix introduces a contextvars-based mechanism that scopes a custom I18N instance to the crew's execution: - Added get_crew_i18n() / set_crew_i18n() / reset_crew_i18n() to i18n.py using a ContextVar for thread-safe crew-scoped I18N overrides - prepare_kickoff() now sets the crew's I18N when prompt_file is provided - Crew.kickoff() resets the I18N context in its finally block (even on errors) - Replaced all I18N_DEFAULT references with get_crew_i18n() calls across 29 source files so every component (Prompts, Task, agent tools, tool usage, memory, reasoning, etc.) respects the crew's prompt_file Added 12 new tests covering: - Context variable set/get/reset/nesting behavior - Prompts class using custom I18N - Task.prompt() using custom I18N - AgentTools delegation tools using custom I18N - Full Crew.kickoff() integration (sets context, resets on success/exception) Co-Authored-By: João <[email protected]>
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:
|
Co-Authored-By: João <[email protected]>
Co-Authored-By: João <[email protected]>
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 #5931
Setting
prompt_fileon aCrewpreviously had no effect on agents, tasks, tools, or any other components during execution. The custom I18N instance was only used for the manager agent's role/goal/backstory in hierarchical mode, while all other code paths used the hardcodedI18N_DEFAULTmodule-level singleton.Root cause: Every file that needed prompt text imported and used
I18N_DEFAULTdirectly — a module-level constant that always points to the built-inen.jsonprompts. TheCrew.prompt_fileparameter was never propagated to the components that generate system prompts, task prompts, tool descriptions, error messages, memory formatting, etc.Fix: Introduced a
contextvars.ContextVar-based mechanism that scopes a custom I18N instance to the crew's execution lifetime:get_crew_i18n()/set_crew_i18n()/reset_crew_i18n()toi18n.py— when no override is set,get_crew_i18n()falls back toI18N_DEFAULT, so default behavior is unchanged.prepare_kickoff()sets the context var whenprompt_fileis provided on the crew.Crew.kickoff()resets the context var in itsfinallyblock (even on exceptions).I18N_DEFAULTreferences across 29 source files withget_crew_i18n()calls, so every component (Prompts, Task, agent tools, tool usage, memory, reasoning, planners, etc.) now respects the crew'sprompt_file.This approach is:
contextvarsget_crew_i18n()returnsI18N_DEFAULTwhen no crew override is activeReview & Testing Checklist for Human
prompt_fileon a Crew actually changes the system/task prompts during execution (create a crew withprompt_filepointing to a custom JSON file, run kickoff, and check that prompts contain the custom text)prompt_filestill use default prompts (regression check)prompt_file(manager agent + delegation tools should use custom prompts)prompt_filevalues don't leak I18N state between each otherget_crew_i18n()replacements in a few key files (prompts.py,task.py,tool_usage.py) to confirm the mechanical replacement is correctNotes
telemetry.pywas intentionally left usingI18N_DEFAULTsince it only reports the prompt_file metadata value, not actual prompt content.I18N_DEFAULTindefault_factorylambdas (e.g.,AddImageTool.name) were also updated to useget_crew_i18n()— since these lambdas execute at instantiation time (during crew execution), they correctly pick up the context var.lru_cacheonget_i18n()means each uniqueprompt_filepath only triggers one file read/JSON parse across the entire process lifetime.Link to Devin session: https://app.devin.ai/sessions/67e13fa57a594ef0ab900d1d73643ba3