Skip to content

Commit 1f3892a

Browse files
committed
[AIBundle] Simplify agent-as-tool configuration
1 parent d022fa1 commit 1f3892a

File tree

4 files changed

+13
-7
lines changed

4 files changed

+13
-7
lines changed

demo/config/packages/ai.yaml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,9 @@ ai:
4646
system_prompt: 'You are a friendly chatbot that likes to have a conversation with users and asks them some questions.'
4747
tools:
4848
# Agent in agent 🤯
49-
- service: 'ai.agent.blog'
49+
- agent: 'blog'
5050
name: 'symfony_blog'
5151
description: 'Can answer questions based on the Symfony blog.'
52-
is_agent: true
5352
store:
5453
chroma_db:
5554
symfonycon:

src/ai-bundle/config/options.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,18 +114,22 @@
114114
->arrayNode('services')
115115
->arrayPrototype()
116116
->children()
117-
->scalarNode('service')->isRequired()->end()
117+
->scalarNode('service')->cannotBeEmpty()->end()
118+
->scalarNode('agent')->cannotBeEmpty()->end()
118119
->scalarNode('name')->end()
119120
->scalarNode('description')->end()
120121
->scalarNode('method')->end()
121-
->booleanNode('is_agent')->defaultFalse()->end()
122122
->end()
123123
->beforeNormalization()
124124
->ifString()
125125
->then(function (string $v) {
126126
return ['service' => $v];
127127
})
128128
->end()
129+
->validate()
130+
->ifFalse(static fn ($v) => empty($v['agent']) xor empty($v['service']))
131+
->thenInvalid('Either "agent" or "service" must be configured, and never both.')
132+
->end()
129133
->end()
130134
->end()
131135
->end()

src/ai-bundle/doc/index.rst

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,9 @@ Configuration
7272
method: 'foo' # Optional with default value '__invoke'
7373
7474
# Referencing a agent => agent in agent 🤯
75-
- service: 'ai.agent.research'
75+
- agent: 'research'
7676
name: 'wikipedia_research'
7777
description: 'Can research on Wikipedia'
78-
is_agent: true
7978
research:
8079
platform: 'ai.platform.anthropic'
8180
model:

src/ai-bundle/src/AIBundle.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,10 +319,14 @@ private function processAgentConfig(string $name, array $config, ContainerBuilde
319319

320320
$tools = [];
321321
foreach ($config['tools']['services'] as $tool) {
322+
if (isset($tool['agent'])) {
323+
$tool['name'] ??= $tool['agent'];
324+
$tool['service'] ??= \sprintf('ai.agent.%s', $tool['agent']);
325+
}
322326
$reference = new Reference($tool['service']);
323327
// We use the memory factory in case method, description and name are set
324328
if (isset($tool['name'], $tool['description'])) {
325-
if ($tool['is_agent']) {
329+
if (isset($tool['agent'])) {
326330
$agentWrapperDefinition = new Definition(AgentTool::class, ['$agent' => $reference]);
327331
$container->setDefinition('ai.toolbox.'.$name.'.agent_wrapper.'.$tool['name'], $agentWrapperDefinition);
328332
$reference = new Reference('ai.toolbox.'.$name.'.agent_wrapper.'.$tool['name']);

0 commit comments

Comments
 (0)