Skip to content

Commit 4231c60

Browse files
committed
Add config options for keeping tool call messages and sources + expose metadata in profiler
1 parent 0eeb101 commit 4231c60

File tree

6 files changed

+33
-5
lines changed

6 files changed

+33
-5
lines changed

demo/config/packages/ai.yaml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,11 @@ ai:
2525
options:
2626
temperature: 0.5
2727
prompt:
28-
text: 'Please answer the users question based on Wikipedia and provide a link to the article.'
28+
text: 'Please answer the users question based on Wikipedia, only use information provided in the messages.'
2929
include_tools: true
3030
tools:
3131
- 'Symfony\AI\Agent\Toolbox\Tool\Wikipedia'
32+
keep_tool_sources: true
3233
audio:
3334
model: 'gpt-4o-mini?temperature=1.0'
3435
prompt: 'You are a friendly chatbot that likes to have a conversation with users and asks them some questions.'
@@ -89,7 +90,7 @@ services:
8990

9091
Symfony\AI\Store\Document\Loader\RssFeedLoader: ~
9192
Symfony\AI\Store\Document\Transformer\TextTrimTransformer: ~
92-
93+
9394
app.filter.week_of_symfony:
9495
class: 'Symfony\AI\Store\Document\Filter\TextContainsFilter'
9596
arguments:

src/ai-bundle/config/options.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,18 @@
409409
->end()
410410
->end()
411411
->end()
412-
->booleanNode('fault_tolerant_toolbox')->defaultTrue()->end()
412+
->booleanNode('keep_tool_messages')
413+
->info('Keep tool messages in the conversation history')
414+
->defaultFalse()
415+
->end()
416+
->booleanNode('keep_tool_sources')
417+
->info('Keep tool sources as part of the tool result metadata')
418+
->defaultFalse()
419+
->end()
420+
->booleanNode('fault_tolerant_toolbox')
421+
->info('Continue the agent run even if a tool call fails')
422+
->defaultTrue()
423+
->end()
413424
->end()
414425
->end()
415426
->end()

src/ai-bundle/config/services.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@
157157
service('ai.tool_result_converter'),
158158
service('event_dispatcher')->nullOnInvalid(),
159159
false,
160+
false,
160161
])
161162
->set('ai.security.is_granted_attribute_listener', IsGrantedToolAttributeListener::class)
162163
->args([

src/ai-bundle/src/AiBundle.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -613,7 +613,9 @@ private function processAgentConfig(string $name, array $config, ContainerBuilde
613613
}
614614

615615
$toolProcessorDefinition = (new ChildDefinition('ai.tool.agent_processor.abstract'))
616-
->replaceArgument(0, new Reference('ai.toolbox.'.$name));
616+
->replaceArgument(0, new Reference('ai.toolbox.'.$name))
617+
->replaceArgument(3, $config['keep_tool_messages'])
618+
->replaceArgument(4, $config['keep_tool_sources']);
617619

618620
$container->setDefinition('ai.tool.agent_processor.'.$name, $toolProcessorDefinition)
619621
->addTag('ai.agent.input_processor', ['agent' => $agentId, 'priority' => -10])

src/ai-bundle/src/Profiler/DataCollector.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\AI\AiBundle\Profiler;
1313

1414
use Symfony\AI\Agent\Toolbox\ToolResult;
15+
use Symfony\AI\Platform\Metadata\Metadata;
1516
use Symfony\AI\Platform\Tool\Tool;
1617
use Symfony\Bundle\FrameworkBundle\DataCollector\AbstractDataCollector;
1718
use Symfony\Component\HttpFoundation\Request;
@@ -103,7 +104,8 @@ private function getAllTools(): array
103104
* model: string,
104105
* input: array<mixed>|string|object,
105106
* options: array<string, mixed>,
106-
* result: string|iterable<mixed>|object|null
107+
* result: string|iterable<mixed>|object|null,
108+
* metadata: Metadata,
107109
* }[]
108110
*/
109111
private function awaitCallResults(TraceablePlatform $platform): array
@@ -118,6 +120,8 @@ private function awaitCallResults(TraceablePlatform $platform): array
118120
$call['result'] = $result->getContent();
119121
}
120122

123+
$call['metadata'] = $result->getMetadata();
124+
121125
$calls[$key] = $call;
122126
}
123127

src/ai-bundle/templates/data_collector.html.twig

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,15 @@
164164
{% else %}
165165
{{ call.result }}
166166
{% endif %}
167+
{% if call.metadata|length > 0 %}
168+
<br />
169+
<strong>Metadata</strong>
170+
<ul>
171+
{% for key, value in call.metadata.all %}
172+
<li>{{ key }}:<br />{{ dump(value) }}</li>
173+
{% endfor %}
174+
</ul>
175+
{% endif %}
167176
</td>
168177
</tr>
169178
</tbody>

0 commit comments

Comments
 (0)