|
| 1 | +# Multi-Agent Configuration |
| 2 | + |
| 3 | +The AI Bundle provides a configuration system for creating multi-agent orchestrators that route requests to specialized agents based on defined handoff rules. |
| 4 | + |
| 5 | +## Configuration |
| 6 | + |
| 7 | +Configure multi-agent systems in your `config/packages/ai.yaml` file: |
| 8 | + |
| 9 | +```yaml |
| 10 | +ai: |
| 11 | + multi_agent: |
| 12 | + # Define named multi-agent systems |
| 13 | + support: |
| 14 | + # The main orchestrator agent that analyzes requests |
| 15 | + orchestrator: 'ai.agent.orchestrator' |
| 16 | + |
| 17 | + # Handoff rules defining when to route to specific agents |
| 18 | + # Minimum 2 handoffs required (otherwise use the agent directly) |
| 19 | + handoffs: |
| 20 | + # Route to technical agent for specific keywords |
| 21 | + - to: 'ai.agent.technical' |
| 22 | + when: ['bug', 'problem', 'technical', 'error', 'code', 'debug'] |
| 23 | + |
| 24 | + # Fallback to general agent when no specific conditions match |
| 25 | + - to: 'ai.agent.general' |
| 26 | + when: [] |
| 27 | + |
| 28 | + # Optional: Custom logger service |
| 29 | + logger: 'monolog.logger.ai' |
| 30 | +``` |
| 31 | +
|
| 32 | +## Service Registration |
| 33 | +
|
| 34 | +Each multi-agent configuration automatically registers a service with the ID pattern `ai.multi_agent.{name}`. |
| 35 | + |
| 36 | +For the example above, the service `ai.multi_agent.support` is registered and can be injected: |
| 37 | + |
| 38 | +```php |
| 39 | +use Symfony\AI\Agent\AgentInterface; |
| 40 | +use Symfony\Component\Routing\Attribute\Route; |
| 41 | +use Symfony\Contracts\Service\Attribute\Target; |
| 42 | +
|
| 43 | +class SupportController |
| 44 | +{ |
| 45 | + public function __construct( |
| 46 | + #[Target('supportMultiAgent')] |
| 47 | + private AgentInterface $supportAgent, |
| 48 | + ) { |
| 49 | + } |
| 50 | + |
| 51 | + #[Route('/ask-support')] |
| 52 | + public function askSupport(string $question): Response |
| 53 | + { |
| 54 | + $messages = new MessageBag(Message::ofUser($question)); |
| 55 | + $response = $this->supportAgent->call($messages); |
| 56 | + |
| 57 | + return new Response($response->getContent()); |
| 58 | + } |
| 59 | +} |
| 60 | +``` |
| 61 | + |
| 62 | +## Handoff Rules |
| 63 | + |
| 64 | +Handoff rules determine when to delegate to specific agents: |
| 65 | + |
| 66 | +### `to` (required) |
| 67 | +The service ID of the target agent to delegate to. |
| 68 | + |
| 69 | +### `when` (optional) |
| 70 | +An array of keywords or phrases that trigger this handoff. When the orchestrator identifies these keywords in the user's request, it delegates to the specified agent. |
| 71 | + |
| 72 | +If `when` is empty or not specified, the handoff acts as a fallback for requests that don't match other rules. |
| 73 | + |
| 74 | +## How It Works |
| 75 | + |
| 76 | +1. The orchestrator agent receives the initial request |
| 77 | +2. It analyzes the request content and matches it against handoff rules |
| 78 | +3. If keywords match a handoff's `when` conditions, the request is delegated to that agent |
| 79 | +4. If no specific conditions match, a fallback handoff (with empty `when`) is used |
| 80 | +5. The delegated agent processes the request and returns the response |
| 81 | + |
| 82 | +## Requirements |
| 83 | + |
| 84 | +- At least 2 handoff rules must be defined (for a single handoff, use the agent directly) |
| 85 | +- The orchestrator and all referenced agents must be registered as services |
| 86 | +- All agent services must implement `Symfony\AI\Agent\AgentInterface` |
| 87 | + |
| 88 | +## Example: Customer Service Bot |
| 89 | + |
| 90 | +```yaml |
| 91 | +ai: |
| 92 | + multi_agent: |
| 93 | + customer_service: |
| 94 | + orchestrator: 'ai.agent.analyzer' |
| 95 | + handoffs: |
| 96 | + # Technical support |
| 97 | + - to: 'ai.agent.tech_support' |
| 98 | + when: ['error', 'bug', 'crash', 'not working', 'broken'] |
| 99 | + |
| 100 | + # Billing inquiries |
| 101 | + - to: 'ai.agent.billing' |
| 102 | + when: ['payment', 'invoice', 'billing', 'subscription', 'price'] |
| 103 | + |
| 104 | + # Product information |
| 105 | + - to: 'ai.agent.product_info' |
| 106 | + when: ['features', 'how to', 'tutorial', 'guide', 'documentation'] |
| 107 | + |
| 108 | + # General inquiries (fallback) |
| 109 | + - to: 'ai.agent.general_support' |
| 110 | + when: [] |
| 111 | +``` |
0 commit comments