You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/components/agent.rst
+28-27Lines changed: 28 additions & 27 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,8 +1,9 @@
1
1
Symfony AI - Agent Component
2
2
============================
3
3
4
-
The Agent component provides a framework for building AI agents that, sits on top of the Platform and Store components,
5
-
allowing you to create agents that can interact with users, perform tasks, and manage workflows.
4
+
The Agent component provides a framework for building AI agents that,
5
+
sits on top of the Platform and Store components, allowing you to create
6
+
agents that can interact with users, perform tasks, and manage workflows.
6
7
7
8
Installation
8
9
------------
@@ -14,8 +15,8 @@ Installation
14
15
Basic Usage
15
16
-----------
16
17
17
-
To instantiate an agent, you need to pass a ``Symfony\AI\Platform\PlatformInterface`` and a
18
-
``Symfony\AI\Platform\Model`` instance to the ``Symfony\AI\Agent\Agent`` class::
18
+
To instantiate an agent, you need to pass a :class:`Symfony\\AI\\Platform\\PlatformInterface` and a
19
+
:class:`Symfony\\AI\\Platform\\Model` instance to the :class:`Symfony\\AI\\Agent\\Agent` class::
19
20
20
21
use Symfony\AI\Agent\Agent;
21
22
use Symfony\AI\Platform\Bridge\OpenAi\Gpt;
@@ -26,7 +27,7 @@ To instantiate an agent, you need to pass a ``Symfony\AI\Platform\PlatformInterf
26
27
27
28
$agent = new Agent($platform, $model);
28
29
29
-
You can then run the agent with a ``Symfony\AI\Platform\Message\MessageBagInterface`` instance as input and an optional
30
+
You can then run the agent with a :class:`Symfony\\AI\\Platform\\Message\\MessageBagInterface` instance as input and an optional
30
31
array of options::
31
32
32
33
use Symfony\AI\Agent\Agent;
@@ -74,7 +75,7 @@ Tool calling can be enabled by registering the processors in the agent::
74
75
75
76
$agent = new Agent($platform, $model, inputProcessors: [$toolProcessor], outputProcessors: [$toolProcessor]);
76
77
77
-
Custom tools can basically be any class, but must configure by the ``#[AsTool]`` attribute::
78
+
Custom tools can basically be any class, but must configure by the :class:`Symfony\\AI\\Agent\\Toolbox\\Attribute\\AsTool` attribute::
78
79
79
80
use Symfony\AI\Toolbox\Attribute\AsTool;
80
81
@@ -96,7 +97,7 @@ JsonSerializable interface, to JSON strings for you. So you can return arrays or
96
97
Tool Methods
97
98
~~~~~~~~~~~~
98
99
99
-
You can configure the method to be called by the LLM with the ``#[AsTool]`` attribute and have multiple tools per class::
100
+
You can configure the method to be called by the LLM with the :class:`Symfony\\AI\\Agent\\Toolbox\\Attribute\\AsTool` attribute and have multiple tools per class::
100
101
101
102
use Symfony\AI\Toolbox\Attribute\AsTool;
102
103
@@ -126,14 +127,14 @@ You can configure the method to be called by the LLM with the ``#[AsTool]`` attr
126
127
Tool Parameters
127
128
~~~~~~~~~~~~~~~
128
129
129
-
Symfony AI generates a JSON Schema representation for all tools in the Toolbox based on the ``#[AsTool]`` attribute and
130
+
Symfony AI generates a JSON Schema representation for all tools in the :class:`Symfony\\AI\\Agent\\Toolbox\\Toolbox` based on the :class:`Symfony\\AI\\Agent\\Toolbox\\Attribute\\AsTool` attribute and
130
131
method arguments and param comments in the doc block. Additionally, JSON Schema support validation rules, which are
131
132
partially supported by LLMs like GPT.
132
133
133
134
Parameter Validation with ``#[With]`` Attribute
134
135
...............................................
135
136
136
-
To leverage JSON Schema validation rules, configure the ``#[With]`` attribute on the method arguments of your tool::
137
+
To leverage JSON Schema validation rules, configure the :class:`Symfony\\AI\\Platform\\Contract\\JsonSchema\\Attribute\\With` attribute on the method arguments of your tool::
137
138
138
139
use Symfony\AI\Agent\Toolbox\Attribute\AsTool;
139
140
use Symfony\AI\Platform\Contract\JsonSchema\Attribute\With;
@@ -158,12 +159,12 @@ To leverage JSON Schema validation rules, configure the ``#[With]`` attribute on
158
159
}
159
160
}
160
161
161
-
See attribute class ``Symfony\AI\Platform\Contract\JsonSchema\Attribute\With`` for all available options.
162
+
See attribute class :class:`Symfony\\AI\\Platform\\Contract\\JsonSchema\\Attribute\\With` for all available options.
162
163
163
164
Automatic Enum Validation
164
165
.........................
165
166
166
-
For PHP backed enums, automatic validation without requiring any ``#[With]`` attribute is supported::
167
+
For PHP backed enums, automatic validation without requiring any :class:`Symfony\\AI\\Platform\\Contract\\JsonSchema\\Attribute\\With` attribute is supported::
167
168
168
169
enum Priority: int
169
170
{
@@ -208,8 +209,8 @@ This eliminates the need for manual ``#[With(enum: [...])]`` attributes when usi
208
209
Third-Party Tools
209
210
~~~~~~~~~~~~~~~~~
210
211
211
-
In some cases you might want to use third-party tools, which are not part of your application. Adding the ``#[AsTool]``
212
-
attribute to the class is not possible in those cases, but you can explicitly register the tool in the MemoryFactory::
212
+
In some cases you might want to use third-party tools, which are not part of your application. Adding the :class:`Symfony\\AI\\Agent\\Toolbox\\Attribute\\AsTool`
213
+
attribute to the class is not possible in those cases, but you can explicitly register the tool in the :class:`Symfony\\AI\\Agent\\Toolbox\\ToolFactory\\MemoryToolFactory`::
213
214
214
215
use Symfony\AI\Agent\Toolbox\Toolbox;
215
216
use Symfony\AI\Agent\Toolbox\ToolFactory\MemoryToolFactory;
@@ -223,7 +224,7 @@ attribute to the class is not possible in those cases, but you can explicitly re
223
224
224
225
Please be aware that not all return types are supported by the toolbox, so a decorator might still be needed.
225
226
226
-
This can be combined with the ``ChainFactory`` which enables you to use explicitly registered tools and ``#[AsTool]`` tagged
227
+
This can be combined with the :class:`Symfony\\AI\\Agent\\Toolbox\\ToolFactory\\ChainFactory` which enables you to use explicitly registered tools and :class:`Symfony\\AI\\Agent\\Toolbox\\Attribute\\AsTool` tagged
227
228
tools in the same chain - which even enables you to overwrite the pre-existing configuration of a tool::
228
229
229
230
use Symfony\AI\Agent\Toolbox\Toolbox;
@@ -261,7 +262,7 @@ Fault Tolerance
261
262
~~~~~~~~~~~~~~~
262
263
263
264
To gracefully handle errors that occur during tool calling, e.g. wrong tool names or runtime errors, you can use the
264
-
``FaultTolerantToolbox`` as a decorator for the Toolbox. It will catch the exceptions and return readable error messages
265
+
:class:`Symfony\\AI\\Agent\\Toolbox\\FaultTolerantToolbox` as a decorator for the :class:`Symfony\\AI\\Agent\\Toolbox\\Toolbox`. It will catch the exceptions and return readable error messages
265
266
to the LLM::
266
267
267
268
use Symfony\AI\Agent\Agent;
@@ -275,7 +276,7 @@ to the LLM::
275
276
276
277
$agent = new Agent($platform, $model, inputProcessor: [$toolProcessor], outputProcessor: [$toolProcessor]);
277
278
278
-
If you want to expose the underlying error to the LLM, you can throw a custom exception that implements `ToolExecutionExceptionInterface`::
279
+
If you want to expose the underlying error to the LLM, you can throw a custom exception that implements :class:`Symfony\\AI\\Agent\\Toolbox\\Exception\\ToolExecutionExceptionInterface`::
279
280
280
281
use Symfony\AI\Agent\Toolbox\Exception\ToolExecutionExceptionInterface;
281
282
@@ -325,7 +326,7 @@ Tool Result Interception
325
326
~~~~~~~~~~~~~~~~~~~~~~~~
326
327
327
328
To react to the result of a tool, you can implement an EventListener, that listens to the
328
-
``ToolCallsExecuted`` event. This event is dispatched after the Toolbox executed all current
329
+
:class:`Symfony\\AI\\Agent\\Toolbox\\Event\\ToolCallsExecuted` event. This event is dispatched after the :class:`Symfony\\AI\\Agent\\Toolbox\\Toolbox` executed all current
329
330
tool calls and enables you to skip the next LLM call by setting a result yourself::
330
331
331
332
$eventDispatcher->addListener(ToolCallsExecuted::class, function (ToolCallsExecuted $event): void {
@@ -525,8 +526,8 @@ They are provided while instantiating the agent instance::
525
526
InputProcessor
526
527
~~~~~~~~~~~~~~
527
528
528
-
InputProcessor instances are called in the agent before handing over the MessageBag and the $options array to the LLM
529
-
and are able to mutate both on top of the Input instance provided::
529
+
:class:`Symfony\\AI\\Agent\\InputProcessorInterface` instances are called in the agent before handing over the :class:`Symfony\\AI\\Platform\\Message\\MessageBag` and the $options array to the LLM
530
+
and are able to mutate both on top of the :class:`Symfony\\AI\\Agent\\Input` instance provided::
530
531
531
532
use Symfony\AI\Agent\Input;
532
533
use Symfony\AI\Agent\InputProcessorInterface;
@@ -549,7 +550,7 @@ and are able to mutate both on top of the Input instance provided::
549
550
OutputProcessor
550
551
~~~~~~~~~~~~~~~
551
552
552
-
OutputProcessor instances are called after the model provided a result and can - on top of options and messages - mutate
553
+
:class:`Symfony\\AI\\Agent\\OutputProcessorInterface` instances are called after the model provided a result and can - on top of options and messages - mutate
553
554
or replace the given result::
554
555
555
556
use Symfony\AI\Agent\Output;
@@ -569,9 +570,9 @@ or replace the given result::
569
570
Agent Awareness
570
571
~~~~~~~~~~~~~~~
571
572
572
-
Both, Input and Output instances, provide access to the LLM used by the agent, but the agent itself is only provided,
573
-
in case the processor implemented the AgentAwareInterface interface, which can be combined with using the
574
-
AgentAwareTrait::
573
+
Both, :class:`Symfony\\AI\\Agent\\Input` and :class:`Symfony\\AI\\Agent\\Output` instances, provide access to the LLM used by the agent, but the agent itself is only provided,
574
+
in case the processor implemented the :class:`Symfony\\AI\\Agent\\AgentAwareInterface` interface, which can be combined with using the
575
+
:class:`Symfony\\AI\\Agent\\AgentAwareTrait`::
575
576
576
577
use Symfony\AI\Agent\AgentAwareInterface;
577
578
use Symfony\AI\Agent\AgentAwareTrait;
@@ -599,7 +600,7 @@ model with context without changing your application logic.
599
600
Using Memory
600
601
^^^^^^^^^^^^
601
602
602
-
Memory integration is handled through the ``MemoryInputProcessor`` and one or more ``MemoryProviderInterface`` implementations::
603
+
Memory integration is handled through the :class:`Symfony\\AI\\Agent\\Memory\\MemoryInputProcessor` and one or more :class:`Symfony\\AI\\Agent\\Memory\\MemoryProviderInterface` implementations::
603
604
604
605
use Symfony\AI\Agent\Agent;
605
606
use Symfony\AI\Agent\Memory\MemoryInputProcessor;
@@ -669,7 +670,7 @@ Testing
669
670
MockAgent
670
671
^^^^^^^^^
671
672
672
-
For testing purposes, the Agent component provides a ``MockAgent`` class that behaves like Symfony's ``MockHttpClient``.
673
+
For testing purposes, the Agent component provides a :class:`Symfony\\AI\\Agent\\MockAgent` class that behaves like Symfony's :class:`Symfony\\Component\\HttpClient\\MockHttpClient`.
673
674
It provides predictable responses without making external API calls and includes assertion methods for verifying interactions::
674
675
675
676
use Symfony\AI\Agent\MockAgent;
@@ -702,7 +703,7 @@ Call Tracking and Assertions::
702
703
MockResponse Objects
703
704
^^^^^^^^^^^^^^^^^^^^
704
705
705
-
Similar to ``MockHttpClient``, you can use ``MockResponse`` objects for more complex scenarios::
706
+
Similar to :class:`Symfony\\Component\\HttpClient\\MockHttpClient`, you can use :class:`Symfony\\AI\\Agent\\MockResponse` objects for more complex scenarios::
706
707
707
708
use Symfony\AI\Agent\MockResponse;
708
709
@@ -715,7 +716,7 @@ Similar to ``MockHttpClient``, you can use ``MockResponse`` objects for more com
715
716
Callable Responses
716
717
^^^^^^^^^^^^^^^^^^
717
718
718
-
Like ``MockHttpClient``, ``MockAgent`` supports callable responses for dynamic behavior::
719
+
Like :class:`Symfony\\Component\\HttpClient\\MockHttpClient`, :class:`Symfony\\AI\\Agent\\MockAgent` supports callable responses for dynamic behavior::
Copy file name to clipboardExpand all lines: docs/components/platform.rst
+9-9Lines changed: 9 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -126,8 +126,8 @@ One central feature of the Platform component is the support for language
126
126
models and easing the interaction with them. This is supported by providing
127
127
an extensive set of data classes around the concept of messages and their content.
128
128
129
-
Messages can be of different types, most importantly ``UserMessage``, ``SystemMessage``, or ``AssistantMessage``, can
130
-
have different content types, like ``Text``, ``Image`` or ``Audio``, and can be grouped into a ``MessageBag``::
129
+
Messages can be of different types, most importantly :class:`Symfony\\AI\\Platform\\Message\\UserMessage`, :class:`Symfony\\AI\\Platform\\Message\\SystemMessage`, or :class:`Symfony\\AI\\Platform\\Message\\AssistantMessage`, can
130
+
have different content types, like :class:`Symfony\\AI\\Platform\\Message\\Content\\Text`, :class:`Symfony\\AI\\Platform\\Message\\Content\\Image` or :class:`Symfony\\AI\\Platform\\Message\\Content\\Audio`, and can be grouped into a :class:`Symfony\\AI\\Platform\\Message\\MessageBag`::
131
131
132
132
use Symfony\AI\Platform\Message\Content\Image;
133
133
use Symfony\AI\Platform\Message\Message;
@@ -170,7 +170,7 @@ Result Streaming
170
170
----------------
171
171
172
172
Since LLMs usually generate a result word by word, most of them also support streaming the result using Server Side
173
-
Events. Symfony AI supports that by abstracting the conversion and returning a ``Generator`` as content of the result::
173
+
Events. Symfony AI supports that by abstracting the conversion and returning a :class:`Generator` as content of the result::
174
174
175
175
use Symfony\AI\Agent\Agent;
176
176
use Symfony\AI\Message\Message;
@@ -206,7 +206,7 @@ Code Examples
206
206
Image Processing
207
207
----------------
208
208
209
-
Some LLMs also support images as input, which Symfony AI supports as content type within the ``UserMessage``::
209
+
Some LLMs also support images as input, which Symfony AI supports as content type within the :class:`Symfony\\AI\\Platform\\Message\\UserMessage`::
210
210
211
211
use Symfony\AI\Platform\Message\Content\Image;
212
212
use Symfony\AI\Platform\Message\Message;
@@ -235,7 +235,7 @@ Audio Processing
235
235
----------------
236
236
237
237
Similar to images, some LLMs also support audio as input, which is just another content type within the
Creating embeddings of word, sentences, or paragraphs is a typical use case around the interaction with LLMs.
263
263
264
-
The standalone usage results in an ``Vector`` instance::
264
+
The standalone usage results in a :class:`Symfony\\AI\\Store\\Vector` instance::
265
265
266
266
use Symfony\AI\Platform\Bridge\OpenAi\Embeddings;
267
267
@@ -307,13 +307,13 @@ which can be useful to speed up the processing::
307
307
Testing Tools
308
308
-------------
309
309
310
-
For unit or integration testing, you can use the `InMemoryPlatform`,
311
-
which implements `PlatformInterface` without calling external APIs.
310
+
For unit or integration testing, you can use the :class:`Symfony\\AI\\Platform\\InMemoryPlatform`,
311
+
which implements :class:`Symfony\\AI\\Platform\\PlatformInterface` without calling external APIs.
312
312
313
313
It supports returning either:
314
314
315
315
- A fixed string result
316
-
- A callable that dynamically returns a simple string or any ``ResultInterface`` based on the model, input, and options::
316
+
- A callable that dynamically returns a simple string or any :class:`Symfony\\AI\\Platform\\Result\\ResultInterface` based on the model, input, and options::
0 commit comments