@@ -49,7 +49,8 @@ array of options::
4949
5050The structure of the input message bag is flexible, see `Platform Component `_ for more details on how to use it.
5151
52- **Options **
52+ Options
53+ ~~~~~~~
5354
5455As with the Platform component, you can pass options to the agent when running it. These options configure the agent's
5556behavior, for example available tools to execute, or are forwarded to the underlying platform and model.
@@ -88,12 +89,14 @@ Custom tools can basically be any class, but must configure by the ``#[AsTool]``
8889 }
8990 }
9091
91- **Tool Return Value **
92+ Tool Return Value
93+ ~~~~~~~~~~~~~~~~~
9294
9395In the end, the tool's result needs to be a string, but Symfony AI converts arrays and objects, that implement the
9496JsonSerializable interface, to JSON strings for you. So you can return arrays or objects directly from your tool.
9597
96- **Tool Methods **
98+ Tool Methods
99+ ~~~~~~~~~~~~
97100
98101You can configure the method to be called by the LLM with the #[AsTool] attribute and have multiple tools per class::
99102
@@ -122,13 +125,15 @@ You can configure the method to be called by the LLM with the #[AsTool] attribut
122125 }
123126 }
124127
125- **Tool Parameters **
128+ Tool Parameters
129+ ~~~~~~~~~~~~~~~
126130
127131Symfony AI generates a JSON Schema representation for all tools in the Toolbox based on the #[AsTool] attribute and
128132method arguments and param comments in the doc block. Additionally, JSON Schema support validation rules, which are
129133partially support by LLMs like GPT.
130134
131- **Parameter Validation with #[With] Attribute **
135+ Parameter Validation with #[With] Attribute
136+ ...........................................
132137
133138To leverage JSON Schema validation rules, configure the ``#[With] `` attribute on the method arguments of your tool::
134139
@@ -157,7 +162,8 @@ To leverage JSON Schema validation rules, configure the ``#[With]`` attribute on
157162
158163See attribute class ``Symfony\AI\Platform\Contract\JsonSchema\Attribute\With `` for all available options.
159164
160- **Automatic Enum Validation **
165+ Automatic Enum Validation
166+ .........................
161167
162168For PHP backed enums, Symfony AI provides automatic validation without requiring any ``#[With] `` attributes::
163169
@@ -201,7 +207,8 @@ This eliminates the need for manual ``#[With(enum: [...])]`` attributes when usi
201207
202208 Please be aware, that this is only converted in a JSON Schema for the LLM to respect, but not validated by Symfony AI.
203209
204- **Third-Party Tools **
210+ Third-Party Tools
211+ ~~~~~~~~~~~~~~~~~
205212
206213In some cases you might want to use third-party tools, which are not part of your application. Adding the ``#[AsTool] ``
207214attribute to the class is not possible in those cases, but you can explicitly register the tool in the MemoryFactory::
@@ -235,7 +242,8 @@ tools in the same chain - which even enables you to overwrite the pre-existing c
235242
236243 The order of the factories in the ChainFactory matters, as the first factory has the highest priority.
237244
238- **Agent uses Agent 🤯 **
245+ Agent uses Agent 🤯
246+ ~~~~~~~~~~~~~~~~~~
239247
240248Similar to third-party tools, an agent can also use an different agent as a tool. This can be useful to encapsulate
241249complex logic or to reuse an agent in multiple places or hide sub-agents from the LLM::
@@ -251,7 +259,8 @@ complex logic or to reuse an agent in multiple places or hide sub-agents from th
251259 ->addTool($agentTool, 'research_agent', 'Meaningful description for sub-agent');
252260 $toolbox = new Toolbox($metadataFactory, [$agentTool]);
253261
254- **Fault Tolerance **
262+ Fault Tolerance
263+ ~~~~~~~~~~~~~~~
255264
256265To gracefully handle errors that occur during tool calling, e.g. wrong tool names or runtime errors, you can use the
257266``FaultTolerantToolbox `` as a decorator for the Toolbox. It will catch the exceptions and return readable error messages
@@ -299,14 +308,16 @@ If you want to expose the underlying error to the LLM, you can throw a custom ex
299308 }
300309 }
301310
302- **Tool Filtering **
311+ Tool Filtering
312+ ~~~~~~~~~~~~~~
303313
304314To limit the tools provided to the LLM in a specific agent call to a subset of the configured tools, you can use the
305315tools option with a list of tool names::
306316
307317 $this->agent->call($messages, ['tools' => ['tavily_search']]);
308318
309- **Tool Result Interception **
319+ Tool Result Interception
320+ ~~~~~~~~~~~~~~~~~~~~~~~~
310321
311322To react to the result of a tool, you can implement an EventListener or EventSubscriber, that listens to the
312323``ToolCallsExecuted `` event. This event is dispatched after the Toolbox executed all current tool calls and enables you
@@ -320,7 +331,8 @@ to skip the next LLM call by setting a result yourself::
320331 }
321332 });
322333
323- **Keeping Tool Messages **
334+ Keeping Tool Messages
335+ ~~~~~~~~~~~~~~~~~~~~~
324336
325337Sometimes you might wish to keep the tool messages (AssistantMessage containing the toolCalls and ToolCallMessage
326338containing the result) in the context. Enable the keepToolMessages flag of the toolbox' AgentProcessor to ensure those
@@ -347,7 +359,8 @@ messages will be added to your MessageBag::
347359 $result = $agent->call($messages);
348360 // $messages will now include the tool messages
349361
350- **Code Examples (with built-in tools) **
362+ Code Examples (with built-in tools)
363+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
351364
352365* `Brave Tool `_
353366* `Clock Tool `_
@@ -391,7 +404,8 @@ more accurate and context-aware results. Therefore, the component provides a bui
391404 );
392405 $result = $agent->call($messages);
393406
394- **Code Examples **
407+ Code Examples
408+ ~~~~~~~~~~~~~
395409
396410* `RAG with MongoDB `_
397411* `RAG with Pinecone `_
@@ -400,9 +414,10 @@ Structured Output
400414-----------------
401415
402416A typical use-case of LLMs is to classify and extract data from unstructured sources, which is supported by some models
403- by features like ** Structured Output ** or providing a ** Response Format ** .
417+ by features like Structured Output or providing a Response Format.
404418
405- **PHP Classes as Output **
419+ PHP Classes as Output
420+ ~~~~~~~~~~~~~~~~~~~~~
406421
407422Symfony AI supports that use-case by abstracting the hustle of defining and providing schemas to the LLM and converting
408423the result back to PHP objects.
@@ -433,7 +448,8 @@ To achieve this, a specific agent processor needs to be registered::
433448
434449 dump($result->getContent()); // returns an instance of `MathReasoning` class
435450
436- **Array Structures as Output **
451+ Array Structures as Output
452+ ~~~~~~~~~~~~~~~~~~~~~~~~~~
437453
438454Also PHP array structures as response_format are supported, which also requires the agent processor mentioned above::
439455
@@ -462,7 +478,8 @@ Also PHP array structures as response_format are supported, which also requires
462478
463479 dump($result->getContent()); // returns an array
464480
465- **Code Examples **
481+ Code Examples
482+ ~~~~~~~~~~~~~
466483
467484* `Structured Output with PHP class `_
468485* `Structured Output with array `_
@@ -479,7 +496,8 @@ They are provided while instantiating the agent instance::
479496
480497 $agent = new Agent($platform, $model, $inputProcessors, $outputProcessors);
481498
482- **InputProcessor **
499+ InputProcessor
500+ ~~~~~~~~~~~~~~
483501
484502InputProcessor instances are called in the agent before handing over the MessageBag and the $options array to the LLM
485503and are able to mutate both on top of the Input instance provided::
@@ -502,7 +520,8 @@ and are able to mutate both on top of the Input instance provided::
502520 }
503521 }
504522
505- **OutputProcessor **
523+ OutputProcessor
524+ ~~~~~~~~~~~~~~~
506525
507526OutputProcessor instances are called after the model provided a result and can - on top of options and messages - mutate
508527or replace the given result::
@@ -521,7 +540,8 @@ or replace the given result::
521540 }
522541 }
523542
524- **Agent Awareness **
543+ Agent Awareness
544+ ~~~~~~~~~~~~~~~
525545
526546Both, Input and Output instances, provide access to the LLM used by the agent, but the agent itself is only provided,
527547in case the processor implemented the AgentAwareInterface interface, which can be combined with using the
@@ -551,7 +571,7 @@ relevant information from different sources. Memory providers inject information
551571model with context without changing your application logic.
552572
553573Using Memory
554- ~~~~~~~~~~~~
574+ ^^^^^^^^^^^^
555575
556576Memory integration is handled through the ``MemoryInputProcessor `` and one or more ``MemoryProviderInterface `` implementations::
557577
@@ -575,11 +595,12 @@ Memory integration is handled through the ``MemoryInputProcessor`` and one or mo
575595 $result = $agent->call($messages);
576596
577597Memory Providers
578- ~~~~~~~~~~~~~~~~
598+ ^^^^^^^^^^^^^^^^
579599
580600The library includes several memory provider implementations that are ready to use out of the box.
581601
582- **Static Memory **
602+ Static Memory
603+ .............
583604
584605Static memory provides fixed information to the agent, such as user preferences, application context, or any other
585606information that should be consistently available without being directly added to the system prompt::
@@ -591,7 +612,8 @@ information that should be consistently available without being directly added t
591612 'The user prefers brief explanations',
592613 );
593614
594- **Embedding Provider **
615+ Embedding Provider
616+ ..................
595617
596618This provider leverages vector storage to inject relevant knowledge based on the user's current message. It can be used
597619for retrieving general knowledge from a store or recalling past conversation pieces that might be relevant::
@@ -605,7 +627,7 @@ for retrieving general knowledge from a store or recalling past conversation pie
605627 );
606628
607629Dynamic Memory Control
608- ~~~~~~~~~~~~~~~~~~~~~~
630+ ^^^^^^^^^^^^^^^^^^^^^^
609631
610632Memory is globally configured for the agent, but you can selectively disable it for specific calls when needed. This is
611633useful when certain interactions shouldn't be influenced by the memory context::
@@ -619,7 +641,7 @@ Testing
619641-------
620642
621643MockAgent
622- ~~~~~~~~~
644+ ^^^^^^^^^
623645
624646For testing purposes, the Agent component provides a ``MockAgent `` class that behaves like Symfony's ``MockHttpClient ``.
625647It provides predictable responses without making external API calls and includes assertion methods for verifying interactions::
@@ -652,7 +674,7 @@ Call Tracking and Assertions::
652674 $agent->reset();
653675
654676MockResponse Objects
655- ~~~~~~~~~~~~~~~~~~~~
677+ ^^^^^^^^^^^^^^^^^^^^
656678
657679Similar to ``MockHttpClient ``, you can use ``MockResponse `` objects for more complex scenarios::
658680
@@ -665,7 +687,7 @@ Similar to ``MockHttpClient``, you can use ``MockResponse`` objects for more com
665687 ]);
666688
667689Callable Responses
668- ~~~~~~~~~~~~~~~~~~
690+ ^^^^^^^^^^^^^^^^^^
669691
670692Like ``MockHttpClient ``, ``MockAgent `` supports callable responses for dynamic behavior::
671693
@@ -684,7 +706,7 @@ Like ``MockHttpClient``, ``MockAgent`` supports callable responses for dynamic b
684706
685707
686708Service Testing Example
687- ~~~~~~~~~~~~~~~~~~~~~~~
709+ ^^^^^^^^^^^^^^^^^^^^^^^
688710
689711Testing a service that uses an agent::
690712
@@ -708,7 +730,8 @@ Testing a service that uses an agent::
708730The ``MockAgent `` provides all the benefits of traditional mocks while offering a more intuitive API for AI agent testing,
709731making your tests more reliable and easier to maintain.
710732
711- **Code Examples **
733+ Code Examples
734+ ~~~~~~~~~~~~~
712735
713736* `Chat with static memory `_
714737* `Chat with embedding search memory `_
0 commit comments