|
18 | 18 | use Symfony\AI\Agent\Toolbox\Toolbox;
|
19 | 19 | use Symfony\AI\Agent\Toolbox\ToolboxInterface;
|
20 | 20 | use Symfony\AI\Agent\Toolbox\ToolCallArgumentResolver;
|
| 21 | +use Symfony\AI\Agent\Toolbox\ToolFactory\AbstractToolFactory; |
21 | 22 | use Symfony\AI\Agent\Toolbox\ToolFactory\ReflectionToolFactory;
|
22 |
| -use Symfony\AI\Agent\Toolbox\ToolFactoryInterface; |
23 | 23 | use Symfony\AI\Agent\Toolbox\ToolResultConverter;
|
24 | 24 | use Symfony\AI\AIBundle\Profiler\DataCollector;
|
25 | 25 | use Symfony\AI\AIBundle\Profiler\TraceableToolbox;
|
26 | 26 | use Symfony\AI\AIBundle\Security\EventListener\IsGrantedToolAttributeListener;
|
| 27 | +use Symfony\AI\Platform\Bridge\Anthropic\Contract\AnthropicContract; |
| 28 | +use Symfony\AI\Platform\Bridge\Google\Contract\GoogleContract; |
| 29 | +use Symfony\AI\Platform\Bridge\OpenAI\Whisper\AudioNormalizer; |
| 30 | +use Symfony\AI\Platform\Contract; |
| 31 | +use Symfony\AI\Platform\Contract\JsonSchema\DescriptionParser; |
| 32 | +use Symfony\AI\Platform\Contract\JsonSchema\Factory as SchemaFactory; |
27 | 33 |
|
28 | 34 | return static function (ContainerConfigurator $container): void {
|
29 | 35 | $container->services()
|
30 |
| - ->defaults() |
31 |
| - ->autowire() |
32 |
| - |
| 36 | + ->set('ai.platform.contract.default', Contract::class) |
| 37 | + ->factory([Contract::class, 'create']) |
| 38 | + ->set('ai.platform.contract.openai') |
| 39 | + ->parent('ai.platform.contract.default') |
| 40 | + ->args([ |
| 41 | + inline_service(AudioNormalizer::class), |
| 42 | + ]) |
| 43 | + ->set('ai.platform.contract.anthropic', Contract::class) |
| 44 | + ->factory([AnthropicContract::class, 'create']) |
| 45 | + ->set('ai.platform.contract.google', Contract::class) |
| 46 | + ->factory([GoogleContract::class, 'create']) |
33 | 47 | // structured output
|
34 |
| - ->set(ResponseFormatFactory::class) |
35 |
| - ->alias(ResponseFormatFactoryInterface::class, ResponseFormatFactory::class) |
36 |
| - ->set(StructureOutputProcessor::class) |
| 48 | + ->set('ai.agent.response_format_factory', ResponseFormatFactory::class) |
| 49 | + ->args([ |
| 50 | + service('ai.platform.json_schema_factory'), |
| 51 | + ]) |
| 52 | + ->set('ai.platform.json_schema.description_parser', DescriptionParser::class) |
| 53 | + ->set('ai.platform.json_schema_factory', SchemaFactory::class) |
| 54 | + ->args([ |
| 55 | + service('ai.platform.json_schema.description_parser'), |
| 56 | + service('type_info.resolver')->nullOnInvalid(), |
| 57 | + ]) |
| 58 | + ->alias(ResponseFormatFactoryInterface::class, 'ai.agent.response_format_factory') |
| 59 | + ->set('ai.agent.structured_output_processor', StructureOutputProcessor::class) |
| 60 | + ->args([ |
| 61 | + service('ai.agent.response_format_factory'), |
| 62 | + service('serializer'), |
| 63 | + ]) |
37 | 64 | ->tag('ai.agent.input_processor')
|
38 | 65 | ->tag('ai.agent.output_processor')
|
39 | 66 |
|
40 | 67 | // tools
|
41 |
| - ->set('ai.toolbox.abstract') |
42 |
| - ->class(Toolbox::class) |
43 |
| - ->autowire() |
| 68 | + ->set('ai.toolbox.abstract', Toolbox::class) |
44 | 69 | ->abstract()
|
45 | 70 | ->args([
|
46 |
| - '$toolFactory' => service(ToolFactoryInterface::class), |
47 |
| - '$tools' => abstract_arg('Collection of tools'), |
| 71 | + service('ai.tool_factory'), |
| 72 | + abstract_arg('Collection of tools'), |
| 73 | + service('ai.tool_call_argument_resolver'), |
| 74 | + service('logger')->ignoreOnInvalid(), |
| 75 | + service('event_dispatcher')->nullOnInvalid(), |
48 | 76 | ])
|
49 |
| - ->set(Toolbox::class) |
| 77 | + ->set('ai.toolbox', Toolbox::class) |
50 | 78 | ->parent('ai.toolbox.abstract')
|
| 79 | + ->arg('index_1', tagged_iterator('ai.tool')) |
| 80 | + ->alias(ToolboxInterface::class, 'ai.toolbox') |
| 81 | + ->set('ai.tool_factory.abstract', AbstractToolFactory::class) |
| 82 | + ->abstract() |
51 | 83 | ->args([
|
52 |
| - '$tools' => tagged_iterator('ai.tool'), |
| 84 | + service('ai.platform.json_schema_factory'), |
53 | 85 | ])
|
54 |
| - ->alias(ToolboxInterface::class, Toolbox::class) |
55 |
| - ->set(ReflectionToolFactory::class) |
56 |
| - ->alias(ToolFactoryInterface::class, ReflectionToolFactory::class) |
57 |
| - ->set(ToolResultConverter::class) |
58 |
| - ->set(ToolCallArgumentResolver::class) |
59 |
| - ->set('ai.tool.agent_processor.abstract') |
60 |
| - ->class(ToolProcessor::class) |
| 86 | + ->set('ai.tool_factory', ReflectionToolFactory::class) |
| 87 | + ->parent('ai.tool_factory.abstract') |
| 88 | + ->set('ai.tool_result_converter', ToolResultConverter::class) |
| 89 | + ->args([ |
| 90 | + service('serializer'), |
| 91 | + ]) |
| 92 | + ->set('ai.tool_call_argument_resolver', ToolCallArgumentResolver::class) |
| 93 | + ->args([ |
| 94 | + service('serializer'), |
| 95 | + ]) |
| 96 | + ->set('ai.tool.agent_processor.abstract', ToolProcessor::class) |
61 | 97 | ->abstract()
|
62 | 98 | ->args([
|
63 |
| - '$toolbox' => abstract_arg('Toolbox'), |
| 99 | + abstract_arg('Toolbox'), |
| 100 | + service('ai.tool_result_converter'), |
| 101 | + service('event_dispatcher')->nullOnInvalid(), |
| 102 | + false, |
64 | 103 | ])
|
65 |
| - ->set(ToolProcessor::class) |
| 104 | + ->set('ai.tool.agent_processor', ToolProcessor::class) |
66 | 105 | ->parent('ai.tool.agent_processor.abstract')
|
67 | 106 | ->tag('ai.agent.input_processor')
|
68 | 107 | ->tag('ai.agent.output_processor')
|
| 108 | + ->arg('index_0', service('ai.toolbox')) |
| 109 | + ->set('ai.security.is_granted_attribute_listener', IsGrantedToolAttributeListener::class) |
69 | 110 | ->args([
|
70 |
| - '$toolbox' => service(ToolboxInterface::class), |
71 |
| - '$eventDispatcher' => service('event_dispatcher')->nullOnInvalid(), |
| 111 | + service('security.authorization_checker'), |
| 112 | + service('expression_language')->nullOnInvalid(), |
72 | 113 | ])
|
73 |
| - ->set('ai.security.is_granted_attribute_listener', IsGrantedToolAttributeListener::class) |
74 | 114 | ->tag('kernel.event_listener')
|
75 | 115 |
|
76 | 116 | // profiler
|
77 |
| - ->set(DataCollector::class) |
| 117 | + ->set('ai.data_collector', DataCollector::class) |
| 118 | + ->args([ |
| 119 | + tagged_iterator('ai.traceable_platform'), |
| 120 | + service('ai.toolbox'), |
| 121 | + tagged_iterator('ai.traceable_toolbox'), |
| 122 | + ]) |
78 | 123 | ->tag('data_collector')
|
79 |
| - ->set(TraceableToolbox::class) |
80 |
| - ->decorate(ToolboxInterface::class) |
| 124 | + ->set('ai.traceable_toolbox', TraceableToolbox::class) |
| 125 | + ->decorate('ai.toolbox') |
| 126 | + ->args([ |
| 127 | + service('.inner'), |
| 128 | + ]) |
81 | 129 | ->tag('ai.traceable_toolbox')
|
82 | 130 | ;
|
83 | 131 | };
|
0 commit comments