Skip to content

Conversation

@devin-ai-integration
Copy link
Contributor

feat: Add multi-language support for CrewAI prompts (Fixes #3780)

Summary

This PR adds multi-language support to CrewAI, allowing users to specify a language for agent and crew prompts. Previously, all prompts were hardcoded in English. Now users can:

  1. Set a language parameter on Agent or Crew to use translations in their preferred language
  2. CrewAI falls back to English if a requested language translation is not available
  3. A complete Spanish translation (es.json) is included as an example

Key Changes:

  • Extended I18N class with language parameter and fallback logic
  • Added language field to BaseAgent and Crew classes
  • Created Spanish translation file with all prompts, errors, tools, and reasoning messages
  • Added comprehensive test coverage for multi-language functionality

Review & Testing Checklist for Human

⚠️ IMPORTANT: The automated tests could not be run due to environment setup issues during development. Manual validation was performed but pytest execution needs verification.

  • Spanish Translation Accuracy (HIGH PRIORITY): Review es.json for translation quality. The translations were AI-generated and should be validated by a native Spanish speaker for accuracy, natural phrasing, and appropriate technical terminology
  • Test Execution: Run uv run pytest lib/crewai/tests/utilities/test_i18n_multilanguage.py lib/crewai/tests/test_agent_language.py -vv to verify all tests pass in a clean environment
  • Language Priority Logic: Test behavior when both crew and agent language parameters are set - verify the crew language properly propagates to agents during kickoff()
  • Fallback Behavior: Test with an unsupported language code (e.g., language="fr") to confirm it falls back to English gracefully
  • End-to-End Integration: Run a simple crew with language="es" and verify that:
    • Agent prompts are in Spanish
    • Error messages are in Spanish
    • Tool descriptions are in Spanish
    • The crew executes successfully

Test Plan

# Quick smoke test
from crewai import Agent, Crew, Task

agent = Agent(
    role="Investigador",
    goal="Investigar temas",
    backstory="Eres un investigador experto",
    language="es"
)

task = Task(
    description="Investigar Python",
    expected_output="Un informe sobre Python",
    agent=agent
)

crew = Crew(agents=[agent], tasks=[task], language="es")
result = crew.kickoff()

Notes

  • The implementation follows the existing pattern where prompt_file can override language-based translations
  • Fallback to English is automatic if a translation file doesn't exist
  • The Spanish translation file is comprehensive (~310 lines) and includes all prompt categories: slices, errors, tools, reasoning, and hierarchical_manager_agent
  • This is a backward-compatible change - all existing code continues to work with English as the default

Session Info:

- Add language parameter to I18N class to support multiple languages
- Implement fallback to English for unsupported languages
- Add Spanish (es.json) translation file as example
- Update Agent and Crew classes to accept language parameter
- Add comprehensive tests for multi-language support

Fixes #3780

Co-Authored-By: João <joao@crewai.com>
@devin-ai-integration
Copy link
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

None yet

1 participant