Skip to content

Conversation

@OskarStark
Copy link
Contributor

@OskarStark OskarStark commented Sep 13, 2025

Q A
Bug fix? no
New feature? yes
Docs? yes
Issues Follows #117
License MIT

This PR introduces comprehensive memory provider configuration capabilities for AI agents, enabling both simple static memory and advanced dynamic memory scenarios.

🚀 Key Features

Smart Detection Logic

The system automatically detects the intent:

  • If the value matches an existing service/alias → uses that service directly
  • If no matching service exists → creates StaticMemoryProvider with the string as static content

Memory as System Prompt

  • When only memory is provided (no prompt), memory serves as the system prompt
  • When both memory and prompt are provided, memory is prepended to the prompt

Configuration Examples

Static Memory (Most Common):

ai:
  agent:
    my_agent:
      model:
        class: 'Symfony\AI\Platform\Bridge\OpenAi\Gpt'
        name: !php/const Symfony\AI\Platform\Bridge\OpenAi\Gpt::GPT_4O_MINI
      memory: 'You have access to user preferences and conversation history'
      prompt:
        text: 'You are a helpful assistant.'

Dynamic Memory (Advanced):

ai:
  agent:
    my_agent:
      model:
        class: 'Symfony\AI\Platform\Bridge\OpenAi\Gpt'
        name: !php/const Symfony\AI\Platform\Bridge\OpenAi\Gpt::GPT_4O_MINI
      memory: 'my_custom_memory_service'  # References existing service
      prompt:
        text: 'You are a helpful assistant.'

Memory as System Prompt:

ai:
  agent:
    my_agent:
      model:
        class: 'Symfony\AI\Platform\Bridge\OpenAi\Gpt'
        name: !php/const Symfony\AI\Platform\Bridge\OpenAi\Gpt::GPT_4O_MINI
      memory: 'You are a helpful assistant with access to user context.'
      # No prompt needed - memory serves as system prompt

This enhancement significantly improves the developer experience while maintaining full backward compatibility and adding powerful new memory capabilities for AI agents.

cc @DZunke

@OskarStark OskarStark self-assigned this Sep 13, 2025
@carsonbot carsonbot changed the title Add memory provider configuration support Add memory provider configuration support Sep 13, 2025
@OskarStark OskarStark added the AI Bundle Issues & PRs about the AI integration bundle label Sep 13, 2025
@carsonbot carsonbot changed the title Add memory provider configuration support [AI Bundle] Add memory provider configuration support Sep 13, 2025
@chr-hertel
Copy link
Member

hmm, i know that it is injected in the prompt, but still i feel it should be standalone config, not below the prompt

@OskarStark
Copy link
Contributor Author

OskarStark commented Sep 13, 2025

hmm, i know that it is injected in the prompt, but still i feel it should be standalone config, not below the prompt

I thought the same, but it can only work with the SystemInputProcessor and this is only registered, once a prompt is defined 🤷‍♂️ Imagine, you don't add a system prompt but memory, then the memory will be your system prompt, which is weird to me.

@chr-hertel
Copy link
Member

but it can only work with the SystemInputProcessor

i think it works on every MessageBag with system prompt - no matter if pushed by the user or the SystemPromptProcessor:

$systemMessage = $input->messages->getSystemMessage()->content ?? '';
$combinedMessage = self::MEMORY_PROMPT_MESSAGE.$memory;
if ('' !== $systemMessage) {
$combinedMessage .= \PHP_EOL.\PHP_EOL.'# System Prompt'.\PHP_EOL.\PHP_EOL.$systemMessage;
}
$messages = $input->messages
->withoutSystemMessage()
->prepend(Message::forSystem($combinedMessage));
$input->messages = $messages;

@OskarStark
Copy link
Contributor Author

I updated my comment, it's about the result

@DZunke
Copy link
Contributor

DZunke commented Sep 14, 2025

hmm, i know that it is injected in the prompt, but still i feel it should be standalone config, not below the prompt

Yeah, feels a bit weird but i was inspired by other libraries doing the same. The memory was always injected to the prompt message type as the memory do not have an own message type. I had shortly also seen some internal OpenAI / Antrophic internal prompt collections where there memory was also injected into the prompt.

Another approach i have seen was to have bio or memory tools to give the LLM more possibilitied to manage the memory. That approach was also combined with the "static" memory approach.

I, for example, have replaced a static configured fantasy calendar that was a "forced" tooling for each LLM call with this static memory. Also some other personal information are injected here from different sources. I understand the tooling approach more as a dynamic memory to let the LLM decide information from conversation to be stored into a memory that could then be injected again.

An interesting overview about how complex prompts can be filled, for me, was https://github.com/asgeirtj/system_prompts_leaks/tree/main - There is a lot going on in the system prompts that is going beyond just the "System Prompt".

@OskarStark
Copy link
Contributor Author

In my case I have a demo where I have a system prompt and adding all activities and apartments of the client. Roughly 15 apartments an 19 activities. I would love to be able to split the "data" front he prompt, so this feels handy.

@chr-hertel
Copy link
Member

No, don't get me wrong, i'm not questioning that this belongs in the system prompt when looking at the actual payload. I'm questioning if from the configuration point of view, it should go there.
tbh, i would hide the entire prompt thing going forward, making it more like:

my_agent:
    platform: 'service_id'
    model: 'model_name'
    instruction:
        text: '...'
        ...
    memory: '...'
    tools: [...]

I think the memory is a feature of the agent, not a feature of the prompt - even tho from an implementation point of view, it is implemented via the system prompt.

@OskarStark
Copy link
Contributor Author

Fine, but validating, that you can only use memory once a prompt is set, agree?

@chr-hertel
Copy link
Member

Fine, but validating, that you can only use memory once a prompt is set, agree?

The memory itself has a prompt - I think even if no system prompt is around, we should add this - and this is actually what the MemoryInputProcessor does, if i get it right

@OskarStark OskarStark merged commit f9c28e0 into symfony:main Sep 15, 2025
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

AI Bundle Issues & PRs about the AI integration bundle Feature New feature Status: Needs Review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants