Skip to content

Fix #5931: Propagate Crew.prompt_file to all components during execution#5933

Open
devin-ai-integration[bot] wants to merge 3 commits into
mainfrom
devin/1779801490-fix-prompt-file-propagation
Open

Fix #5931: Propagate Crew.prompt_file to all components during execution#5933
devin-ai-integration[bot] wants to merge 3 commits into
mainfrom
devin/1779801490-fix-prompt-file-propagation

Conversation

@devin-ai-integration
Copy link
Copy Markdown
Contributor

Summary

Fixes #5931

Setting prompt_file on a Crew previously 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 hardcoded I18N_DEFAULT module-level singleton.

Root cause: Every file that needed prompt text imported and used I18N_DEFAULT directly — a module-level constant that always points to the built-in en.json prompts. The Crew.prompt_file parameter 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:

  1. Added get_crew_i18n() / set_crew_i18n() / reset_crew_i18n() to i18n.py — when no override is set, get_crew_i18n() falls back to I18N_DEFAULT, so default behavior is unchanged.
  2. prepare_kickoff() sets the context var when prompt_file is provided on the crew.
  3. Crew.kickoff() resets the context var in its finally block (even on exceptions).
  4. Replaced all I18N_DEFAULT references across 29 source files with get_crew_i18n() calls, so every component (Prompts, Task, agent tools, tool usage, memory, reasoning, planners, etc.) now respects the crew's prompt_file.

This approach is:

  • Thread-safe: each crew execution has its own context via contextvars
  • Backward-compatible: get_crew_i18n() returns I18N_DEFAULT when no crew override is active
  • Minimal surface area: no new fields on Agent/Task, no signature changes

Review & Testing Checklist for Human

  • Verify that a custom prompt_file on a Crew actually changes the system/task prompts during execution (create a crew with prompt_file pointing to a custom JSON file, run kickoff, and check that prompts contain the custom text)
  • Verify that crews without prompt_file still use default prompts (regression check)
  • Verify hierarchical process still works correctly with prompt_file (manager agent + delegation tools should use custom prompts)
  • Check that concurrent/nested crews with different prompt_file values don't leak I18N state between each other
  • Inspect the get_crew_i18n() replacements in a few key files (prompts.py, task.py, tool_usage.py) to confirm the mechanical replacement is correct

Notes

  • telemetry.py was intentionally left using I18N_DEFAULT since it only reports the prompt_file metadata value, not actual prompt content.
  • Class-level field defaults using I18N_DEFAULT in default_factory lambdas (e.g., AddImageTool.name) were also updated to use get_crew_i18n() — since these lambdas execute at instantiation time (during crew execution), they correctly pick up the context var.
  • The lru_cache on get_i18n() means each unique prompt_file path only triggers one file read/JSON parse across the entire process lifetime.
  • 12 new tests were added covering the context variable mechanism, Prompts class, Task.prompt(), AgentTools, and full Crew.kickoff() integration.

Link to Devin session: https://app.devin.ai/sessions/67e13fa57a594ef0ab900d1d73643ba3

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]>
@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.

Impossible to set specific prompts for Crew with prompt_file

0 participants