Skip to content

Conversation

paulinevos
Copy link
Contributor

So that system prompts can be written in any locale

Q A
Bug fix? no
New feature? yes
Docs? no (there's no documentation for system input, so not sure where to put it. Open to ideas!
Issues Fix #370
License MIT

This adds an optional translator to the SystemInputProcessor which, if set, will translate the configured system prompt.

@carsonbot carsonbot changed the title 370: Support translations for system input processor 370: Support translations for system input processor Sep 11, 2025
@paulinevos paulinevos force-pushed the main branch 3 times, most recently from 7580100 to ecddc1f Compare September 11, 2025 14:52
@OskarStark OskarStark changed the title 370: Support translations for system input processor Support translations for system input processor Sep 11, 2025
@OskarStark OskarStark added the Agent Issues & PRs about the AI Agent component label Sep 11, 2025
@carsonbot carsonbot changed the title Support translations for system input processor [Agent] Support translations for system input processor Sep 11, 2025
@OskarStark
Copy link
Contributor

Can we please make the translator configurable in the bundle? Thanks

@paulinevos paulinevos force-pushed the main branch 2 times, most recently from e99f400 to b602f56 Compare September 11, 2025 17:14
@chr-hertel
Copy link
Member

so, what we just discussed as config structure:

system_prompt:
    prompt: '...',
    enable_translation: true|false, # default: true if translator is present
    translation_domain: '...', # default: "messages"
    include_tools: true|false # default same as now

@VincentLanglet
Copy link
Contributor

so, what we just discussed as config structure:

    enable_translation: true|false, # default: true if translator is present
    translation_domain: '...', # default: "messages"

@chr-hertel I feel like this is kinda redundant, you could have only one key by allowing string|null (default to message)|false like lot of other places where translation is used

@OskarStark
Copy link
Contributor

You are right, but it's some kind of a hidden feature. It's not clear, that string or null means, the translator is enabled. So lets go with @chr-hertel proposal

Copy link
Contributor

@VincentLanglet VincentLanglet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Speaking of symfony/translation-contracts, there is a TranslatableInterface.

Not sure if it would be better to have

public function __construct(
        private \Stringable|string|Translatable $systemPrompt,
        private ?ToolboxInterface $toolbox = null,
        private ?TranslatorInterface $translator = null,
        private LoggerInterface $logger = new NullLogger(),
    ) {	
         if ($systemPrompt instanceof Translatable && null === TranslatorInterface) {
              throw new InvalidArgumentException(...);
         }
    }
    
private function translateIfEnabled(): string
{
     if ($systemPrompt instance Translatable) {
          return $systemPrompt->trans($this->translator);
     }
     
     return (string) $systemPrompt;
}    

And the AiBundle

if ($config['prompt']['enable_translation']) {
     if (!class_exists(TranslatableMessage::class) {
          throw new InvalidArgumentException('Please install symfony/translation');
     }
     
     $prompText = new TranslatableMessage($config['prompt']['text'], domain: $config['prompt']['translation_domain']);
} else {
     $prompText = $config['prompt']['text'];
}

...
->setArguments([
                    $prompText,
                    $includeTools ? new Reference('ai.toolbox.'.$name) : null,
                    new Reference('translator', ContainerInterface::NULL_ON_INVALID_REFERENCE),
                    new Reference('logger', ContainerInterface::IGNORE_ON_INVALID_REFERENCE),
])

This can also be done in another pr

@paulinevos
Copy link
Contributor Author

Hmm, I'm not super convinced about using TranslatableMessage in this way, as it seems to add some complexity for a fairly simple use case and it puts a lot of behavior in the bundle that (in my eyes) "belongs to" SystemPromptInputProcessor


private function translateIfEnabled(): string
{
if ($this->enableTranslation && !$this->translator) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shall we do this validation in the constructor?

@VincentLanglet
Copy link
Contributor

Hmm, I'm not super convinced about using TranslatableMessage in this way, as it seems to add some complexity for a fairly simple use case and it puts a lot of behavior in the bundle that (in my eyes) "belongs to" SystemPromptInputProcessor

We could argue the opposite.

Currently we're adding complexity in SystemPromptInputProcessor which has to be aware about

  • if we want enable translation or not
  • the translation domain

Such things should be "prompt" knownledge rather than SystemPromptInputProcessor one. Quoting the original PR symfony/symfony#37670

The service shouldn't need to care how the message is going to be handled, but just needs to create it in a way that it can be translated if needed.

TranslatableMessage is a way to avoid putting this knownledge inside the SystemPromptInputProcessor

It's also a way to allow using translation parameters.

So that system prompts can be written in any locale
@OskarStark
Copy link
Contributor

It took time, but here we go, this is in now. Thank you very much @paulinevos.

@OskarStark OskarStark merged commit 9892c8f into symfony:main Sep 16, 2025
13 checks passed
OskarStark added a commit that referenced this pull request Sep 16, 2025
Documents the new system prompt translation functionality added in PR #514, including:
- Configuration options for enabling translation and setting custom domains
- Usage examples and integration patterns
- Advanced examples with service factories and testing approaches
- Performance optimization strategies with caching

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
@VincentLanglet
Copy link
Contributor

@OskarStark would you be interested with a Poc with translatableMessage ?

@OskarStark
Copy link
Contributor

Why not, shouldn't be to much code, right?

OskarStark added a commit that referenced this pull request Sep 17, 2025
…dation of bundle options (chr-hertel)

This PR was merged into the main branch.

Discussion
----------

[AI Bundle] Fix validation on system prompt translation validation of bundle options

| Q             | A
| ------------- | ---
| Bug fix?      | yes
| New feature?  | no
| Docs?         | no
| Issues        |
| License       | MIT

Follow up #514

<img width="1260" height="632" alt="image" src="https://github.com/user-attachments/assets/16ae5600-a35f-45db-a39f-39a5adc5ab64" />

Commits
-------

5be7070 Fix validation on system prompt translation validation of bundle options
OskarStark added a commit that referenced this pull request Sep 27, 2025
…Processor` (VincentLanglet)

This PR was squashed before being merged into the main branch.

Discussion
----------

[Agent] Allow translatable prompts in `SystemPromptInputProcessor`

| Q             | A
| ------------- | ---
| Bug fix?      | no
| New feature?  | yes/no
| Docs?         |  no <!-- required for new features -->
| Issues        | Fix #...
| License       | MIT

This is a follow up of #514 with a suggestion of using TranslatableMessage instance for prompts rather than the need in SystemPromptInputProcessor constructor of
- A boolean enableTranslation
- A domain

Since we're passing a TranslatableMessage this also allow to use translation parameters.

cc `@OskarStark` that was the suggestion in #514 (comment)

Commits
-------

868581f [Agent] Allow translatable prompts in `SystemPromptInputProcessor`
symfony-splitter pushed a commit to symfony/ai-bundle that referenced this pull request Sep 27, 2025
…Processor` (VincentLanglet)

This PR was squashed before being merged into the main branch.

Discussion
----------

[Agent] Allow translatable prompts in `SystemPromptInputProcessor`

| Q             | A
| ------------- | ---
| Bug fix?      | no
| New feature?  | yes/no
| Docs?         |  no <!-- required for new features -->
| Issues        | Fix #...
| License       | MIT

This is a follow up of symfony/ai#514 with a suggestion of using TranslatableMessage instance for prompts rather than the need in SystemPromptInputProcessor constructor of
- A boolean enableTranslation
- A domain

Since we're passing a TranslatableMessage this also allow to use translation parameters.

cc `@OskarStark` that was the suggestion in symfony/ai#514 (comment)

Commits
-------

868581f4 [Agent] Allow translatable prompts in `SystemPromptInputProcessor`
symfony-splitter pushed a commit to symfony/ai-agent that referenced this pull request Sep 27, 2025
…Processor` (VincentLanglet)

This PR was squashed before being merged into the main branch.

Discussion
----------

[Agent] Allow translatable prompts in `SystemPromptInputProcessor`

| Q             | A
| ------------- | ---
| Bug fix?      | no
| New feature?  | yes/no
| Docs?         |  no <!-- required for new features -->
| Issues        | Fix #...
| License       | MIT

This is a follow up of symfony/ai#514 with a suggestion of using TranslatableMessage instance for prompts rather than the need in SystemPromptInputProcessor constructor of
- A boolean enableTranslation
- A domain

Since we're passing a TranslatableMessage this also allow to use translation parameters.

cc `@OskarStark` that was the suggestion in symfony/ai#514 (comment)

Commits
-------

868581f4 [Agent] Allow translatable prompts in `SystemPromptInputProcessor`
devmatt000 added a commit to devmatt000/dev_ai that referenced this pull request Oct 2, 2025
… nest `include_tools` (OskarStark)

This PR was squashed before being merged into the main branch.

Discussion
----------

[AI Bundle] Restructure `system_prompt` configuration to nest `include_tools`

| Q | A |
|---|---|
| Bug fix? | no |
| New feature? | yes |
| Docs? | yes |
| Issues | Eases implementation of [#514](symfony/ai#514) |
| License | MIT |

## Summary

Restructures `system_prompt` configuration to nest `include_tools` for better organization and ergonomics.

## Changes

- Move `include_tools` from agent level to `system_prompt` level
- Support both string (simple) and array (advanced) formats

## Before

```yaml
system_prompt: 'You are helpful.'
include_tools: true
```

## After

### simple
```yaml
system_prompt: 'You are helpful.'
```

### advanced
```yaml
system_prompt:
    prompt: 'You are helpful.'
    include_tools: true
```

Commits
-------

5f786809 [AI Bundle] Restructure `system_prompt` configuration to nest `include_tools`
devmatt000 added a commit to devmatt000/dev_ai that referenced this pull request Oct 2, 2025
…Processor` (VincentLanglet)

This PR was squashed before being merged into the main branch.

Discussion
----------

[Agent] Allow translatable prompts in `SystemPromptInputProcessor`

| Q             | A
| ------------- | ---
| Bug fix?      | no
| New feature?  | yes/no
| Docs?         |  no <!-- required for new features -->
| Issues        | Fix #...
| License       | MIT

This is a follow up of symfony/ai#514 with a suggestion of using TranslatableMessage instance for prompts rather than the need in SystemPromptInputProcessor constructor of
- A boolean enableTranslation
- A domain

Since we're passing a TranslatableMessage this also allow to use translation parameters.

cc `@OskarStark` that was the suggestion in symfony/ai#514 (comment)

Commits
-------

868581f4 [Agent] Allow translatable prompts in `SystemPromptInputProcessor`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Agent Issues & PRs about the AI Agent component Feature New feature Hackathon 2025 This issue or pull request was part of the Symfony AI Hackathon 2025 Status: Reviewed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Agent] Support Translations with System Prompt Processor
6 participants