1212namespace Symfony \AI \AiBundle \Profiler ;
1313
1414use Symfony \AI \Agent \Toolbox \ToolboxInterface ;
15- use Symfony \AI \Platform \Model ;
1615use Symfony \AI \Platform \Tool \Tool ;
1716use Symfony \Bundle \FrameworkBundle \DataCollector \AbstractDataCollector ;
1817use Symfony \Component \HttpFoundation \Request ;
2423 *
2524 * @phpstan-import-type PlatformCallData from TraceablePlatform
2625 * @phpstan-import-type ToolCallData from TraceableToolbox
26+ * @phpstan-import-type MessageStoreData from TraceableMessageStore
2727 */
2828final class DataCollector extends AbstractDataCollector implements LateDataCollectorInterface
2929{
@@ -37,17 +37,33 @@ final class DataCollector extends AbstractDataCollector implements LateDataColle
3737 */
3838 private readonly array $ toolboxes ;
3939
40+ /**
41+ * @var TraceableMessageStore[]
42+ */
43+ private readonly array $ messageStores ;
44+
45+ /**
46+ * @var TraceableChat[]
47+ */
48+ private readonly array $ chats ;
49+
4050 /**
4151 * @param TraceablePlatform[] $platforms
4252 * @param TraceableToolbox[] $toolboxes
53+ * @param TraceableMessageStore[] $messageStores
54+ * @param TraceableChat[] $chats
4355 */
4456 public function __construct (
4557 iterable $ platforms ,
4658 private readonly ToolboxInterface $ defaultToolBox ,
4759 iterable $ toolboxes ,
60+ iterable $ messageStores ,
61+ iterable $ chats ,
4862 ) {
4963 $ this ->platforms = $ platforms instanceof \Traversable ? iterator_to_array ($ platforms ) : $ platforms ;
5064 $ this ->toolboxes = $ toolboxes instanceof \Traversable ? iterator_to_array ($ toolboxes ) : $ toolboxes ;
65+ $ this ->messageStores = $ messageStores instanceof \Traversable ? iterator_to_array ($ messageStores ) : $ messageStores ;
66+ $ this ->chats = $ chats instanceof \Traversable ? iterator_to_array ($ chats ) : $ chats ;
5167 }
5268
5369 public function collect (Request $ request , Response $ response , ?\Throwable $ exception = null ): void
@@ -61,6 +77,7 @@ public function lateCollect(): void
6177 'tools ' => $ this ->defaultToolBox ->getTools (),
6278 'platform_calls ' => array_merge (...array_map ($ this ->awaitCallResults (...), $ this ->platforms )),
6379 'tool_calls ' => array_merge (...array_map (fn (TraceableToolbox $ toolbox ) => $ toolbox ->calls , $ this ->toolboxes )),
80+ 'messages ' => array_merge (...array_map (static fn (TraceableMessageStore $ messageStore ): array => $ messageStore ->calls , $ this ->messageStores )),
6481 ];
6582 }
6683
@@ -93,6 +110,14 @@ public function getToolCalls(): array
93110 return $ this ->data ['tool_calls ' ] ?? [];
94111 }
95112
113+ /**
114+ * @return MessageStoreData[]
115+ */
116+ public function getMessages (): array
117+ {
118+ return $ this ->data ['messages ' ] ?? [];
119+ }
120+
96121 /**
97122 * @return array{
98123 * model: string,
0 commit comments