1818use Symfony \Component \HttpFoundation \Request ;
1919use Symfony \Component \HttpFoundation \Response ;
2020use Symfony \Component \HttpKernel \DataCollector \LateDataCollectorInterface ;
21+ use Symfony \Component \VarDumper \Cloner \Data ;
2122
2223/**
2324 * @author Christopher Hertel <mail@christopher-hertel.de>
@@ -37,6 +38,11 @@ final class DataCollector extends AbstractDataCollector implements LateDataColle
3738 */
3839 private readonly array $ toolboxes ;
3940
41+ /**
42+ * @var list<array{method: string, duration: float, input: mixed, result: mixed, error: ?\Throwable}>
43+ */
44+ private array $ collectedChatCalls = [];
45+
4046 /**
4147 * @param TraceablePlatform[] $platforms
4248 * @param TraceableToolbox[] $toolboxes
@@ -52,7 +58,6 @@ public function __construct(
5258
5359 public function collect (Request $ request , Response $ response , ?\Throwable $ exception = null ): void
5460 {
55- $ this ->lateCollect ();
5661 }
5762
5863 public function lateCollect (): void
@@ -61,6 +66,18 @@ public function lateCollect(): void
6166 'tools ' => $ this ->defaultToolBox ->getTools (),
6267 'platform_calls ' => array_merge (...array_map ($ this ->awaitCallResults (...), $ this ->platforms )),
6368 'tool_calls ' => array_merge (...array_map (fn (TraceableToolbox $ toolbox ) => $ toolbox ->calls , $ this ->toolboxes )),
69+ 'chat_calls ' => $ this ->cloneVar ($ this ->collectedChatCalls ),
70+ ];
71+ }
72+
73+ public function collectChatCall (string $ method , float $ duration , mixed $ input , mixed $ result , ?\Throwable $ error ): void
74+ {
75+ $ this ->collectedChatCalls [] = [
76+ 'method ' => $ method ,
77+ 'duration ' => $ duration ,
78+ 'input ' => $ input ,
79+ 'result ' => $ result ,
80+ 'error ' => $ error ,
6481 ];
6582 }
6683
@@ -93,6 +110,27 @@ public function getToolCalls(): array
93110 return $ this ->data ['tool_calls ' ] ?? [];
94111 }
95112
113+ /**
114+ * @return list<array{method: string, duration: float, input: mixed, result: mixed, error: ?\Throwable}>
115+ */
116+ public function getChatCalls (): array
117+ {
118+ if (!isset ($ this ->data ['chat_calls ' ])) {
119+ return [];
120+ }
121+
122+ /** @var list<array{method: string, duration: float, input: mixed, result: mixed, error: ?\Throwable}> $chatCalls */
123+ $ chatCalls = $ this ->data ['chat_calls ' ]->getValue (true );
124+
125+ return $ chatCalls ;
126+ }
127+
128+ public function reset (): void
129+ {
130+ $ this ->data = [];
131+ $ this ->collectedChatCalls = [];
132+ }
133+
96134 /**
97135 * @return array{
98136 * model: Model,
0 commit comments