Skip to content

Commit a23b6aa

Browse files
committed
minor #756 Improve documentation structure and content (OskarStark)
This PR was squashed before being merged into the main branch. Discussion ---------- Improve documentation structure and content | Q | A | ------------- | --- | Bug fix? | no | New feature? | no | Docs? | yes | Issues | -- | License | MIT Commits ------- 63cb1f7 Improve documentation structure and content
2 parents 2c4d20d + 63cb1f7 commit a23b6aa

File tree

8 files changed

+690
-5
lines changed

8 files changed

+690
-5
lines changed

docs/bundles/profiler.png

168 KB
Loading

docs/components/chat.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ with a ``Symfony\AI\Agent\AgentInterface`` and a ``Symfony\AI\Chat\MessageStoreI
2626

2727
$platform = PlatformFactory::create($apiKey);
2828

29-
$agent = new Agent($platform, 'gpt-40-mini');
29+
$agent = new Agent($platform, 'gpt-4o-mini');
3030
$chat = new Chat($agent, new InMemoryStore());
3131

3232
$chat->submit(Message::ofUser('Hello'));

docs/components/platform.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -283,10 +283,10 @@ Server Tools
283283

284284
Some platforms provide built-in server-side tools for enhanced capabilities without custom implementations:
285285

286-
1. **[Gemini](platform/gemini-server-tools.rst)** - URL Context, Google Search, Code Execution
287-
1. **[VertexAI](platform/vertexai-server-tools.rst)** - URL Context, Google Search, Code Execution
286+
* :doc:`platform/gemini-server-tools` - URL Context, Google Search, Code Execution
287+
* :doc:`platform/vertexai-server-tools` - URL Context, Google Search, Code Execution
288288

289-
For complete Vertex AI setup and usage guide, see :doc:`vertexai`.
289+
For complete Vertex AI setup and usage guide, see :doc:`platform/vertexai`.
290290

291291
Parallel Platform Calls
292292
-----------------------

docs/components/store.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ This leads to a store implementing two methods::
124124
}
125125
}
126126

127-
.. _`Retrieval Augmented Generation`: https://de.wikipedia.org/wiki/Retrieval-Augmented_Generation
127+
.. _`Retrieval Augmented Generation`: https://en.wikipedia.org/wiki/Retrieval-augmented_generation
128128
.. _`Similarity Search with Cloudflare (RAG)`: https://github.com/symfony/ai/blob/main/examples/rag/cloudflare.php
129129
.. _`Similarity Search with MariaDB (RAG)`: https://github.com/symfony/ai/blob/main/examples/rag/mariadb-gemini.php
130130
.. _`Similarity Search with Meilisearch (RAG)`: https://github.com/symfony/ai/blob/main/examples/rag/meilisearch.php
Lines changed: 167 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
1+
Building a Chatbot with Memory
2+
==============================
3+
4+
This guide demonstrates how to build a chatbot that remembers context across conversations
5+
using Symfony AI's memory management features.
6+
7+
Overview
8+
--------
9+
10+
Memory providers allow your agents to access conversation history and user-specific information,
11+
enabling more personalized and context-aware responses. In this example, we'll build a personal
12+
trainer chatbot that remembers facts about the user.
13+
14+
Prerequisites
15+
-------------
16+
17+
* Symfony AI Agent component installed
18+
* OpenAI API key (or any other supported platform)
19+
* Basic understanding of Symfony AI concepts
20+
21+
Implementation
22+
--------------
23+
24+
The complete implementation consists of three main parts:
25+
26+
1. Creating a memory provider with user facts
27+
2. Configuring the agent with memory support
28+
3. Processing user messages with context awareness
29+
30+
Complete Example
31+
~~~~~~~~~~~~~~~~
32+
33+
.. literalinclude:: ../../examples/memory/static.php
34+
:language: php
35+
:linenos:
36+
37+
Key Components
38+
--------------
39+
40+
Memory Provider
41+
~~~~~~~~~~~~~~~
42+
43+
The :class:`Symfony\\AI\\Agent\\Memory\\StaticMemoryProvider` stores fixed information that should be consistently available
44+
to the agent::
45+
46+
use Symfony\AI\Agent\Memory\StaticMemoryProvider;
47+
48+
$personalFacts = new StaticMemoryProvider(
49+
'My name is Wilhelm Tell',
50+
'I wish to be a swiss national hero',
51+
'I am struggling with hitting apples but want to be professional with the bow and arrow',
52+
);
53+
54+
This information is automatically injected into the system prompt, providing the agent with
55+
context about the user without cluttering the conversation messages.
56+
57+
Memory Input Processor
58+
~~~~~~~~~~~~~~~~~~~~~~
59+
60+
The :class:`Symfony\\AI\\Agent\\Memory\\MemoryInputProcessor` handles the injection of memory content into the agent's context::
61+
62+
use Symfony\AI\Agent\Memory\MemoryInputProcessor;
63+
64+
$memoryProcessor = new MemoryInputProcessor($personalFacts);
65+
66+
This processor works alongside other input processors like :class:`Symfony\\AI\\Agent\\InputProcessor\\SystemPromptInputProcessor`
67+
to build a complete context for the agent.
68+
69+
Agent Configuration
70+
~~~~~~~~~~~~~~~~~~~
71+
72+
The agent is configured with both system prompt and memory processors::
73+
74+
use Symfony\AI\Agent\Agent;
75+
76+
$agent = new Agent(
77+
$platform,
78+
'gpt-4o-mini',
79+
[$systemPromptProcessor, $memoryProcessor]
80+
);
81+
82+
Processors are applied in order, allowing you to build up the context progressively.
83+
84+
How It Works
85+
------------
86+
87+
1. **Memory Loading**: When a user message is submitted, the ``MemoryInputProcessor`` loads
88+
relevant facts from the memory provider.
89+
90+
2. **Context Injection**: The memory content is prepended to the system prompt, giving the
91+
agent access to user-specific information.
92+
93+
3. **Response Generation**: The agent generates a personalized response based on both the
94+
current message and the remembered context.
95+
96+
4. **Conversation Flow**: The memory persists across multiple calls, enabling continuous
97+
personalized interactions.
98+
99+
Use Dynamic Memory with Embeddings
100+
----------------------------------
101+
102+
For more sophisticated scenarios, use :class:`Symfony\\AI\\Agent\\Memory\\EmbeddingProvider` to retrieve relevant context
103+
based on semantic similarity::
104+
105+
use Symfony\AI\Agent\Memory\EmbeddingProvider;
106+
107+
$embeddingsMemory = new EmbeddingProvider(
108+
$platform,
109+
$embeddings, // Your embeddings model
110+
$store // Your vector store
111+
);
112+
113+
This approach allows the agent to recall specific pieces of information from a large
114+
knowledge base based on the current conversation context.
115+
116+
Bundle Configuration
117+
--------------------
118+
119+
When using the AI Bundle, you can configure memory directly in your configuration:
120+
121+
.. code-block:: yaml
122+
123+
# config/packages/ai.yaml
124+
ai:
125+
agent:
126+
trainer:
127+
model: 'gpt-4o-mini'
128+
prompt:
129+
text: 'Provide short, motivating claims'
130+
memory: 'You are a professional trainer with personalized advice'
131+
132+
For dynamic memory using a custom service:
133+
134+
.. code-block:: yaml
135+
136+
ai:
137+
agent:
138+
trainer:
139+
model: 'gpt-4o-mini'
140+
prompt:
141+
text: 'Provide short, motivating claims'
142+
memory:
143+
service: 'app.user_memory_provider'
144+
145+
Best Practices
146+
--------------
147+
148+
* **Keep Static Memory Concise**: Only include essential facts to avoid overwhelming the agent
149+
* **Separate Concerns**: Use system prompt for behavior, memory for context
150+
* **Update Dynamically**: For user-specific applications, update memory as you learn more about the user
151+
* **Test Without Memory**: Verify your agent works correctly both with and without memory enabled
152+
* **Monitor Token Usage**: Memory content consumes input tokens, so balance comprehensiveness with cost
153+
154+
Use Cases
155+
---------
156+
157+
* **Personal Assistants**: Remember user preferences, habits, and history
158+
* **Customer Support**: Recall previous interactions and customer details
159+
* **Educational Tools**: Track student progress and learning style
160+
* **Healthcare Applications**: Maintain patient history and treatment context
161+
162+
Related Documentation
163+
---------------------
164+
165+
* :doc:`../components/agent` - Agent component documentation
166+
* :doc:`../bundles/ai-bundle` - AI Bundle configuration reference
167+
* :doc:`rag-implementation` - Retrieval Augmented Generation guide

docs/cookbook/index.rst

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
Cookbook
2+
========
3+
4+
The cookbook contains practical guides and complete examples for common use cases
5+
with Symfony AI. Each guide includes working code, explanations, and best practices.
6+
7+
Getting Started Guides
8+
----------------------
9+
10+
.. toctree::
11+
:maxdepth: 1
12+
13+
chatbot-with-memory
14+
rag-implementation
15+
16+
Memory & Context Management
17+
---------------------------
18+
19+
* :doc:`chatbot-with-memory` - Build chatbots that remember user preferences and conversation history
20+
21+
Retrieval Augmented Generation
22+
------------------------------
23+
24+
* :doc:`rag-implementation` - Implement complete RAG systems with vector stores and semantic search

0 commit comments

Comments
 (0)