Skip to content

Commit 2017b73

Browse files
committed
Fix MultiAgent container compilation by using inline Handoff definitions
The container compiler was incorrectly inlining Handoff service references, causing empty arrays to be passed instead of proper references. Fixed by using inline Definition objects for handoffs instead of registering them as separate services. This resolves the container lint error: "argument 3 of MultiAgent::__construct() accepts AgentInterface, array passed" - Reverted to inline Handoff Definition objects - Updated tests to expect Definition objects instead of References - Fixed test assertions for exception messages with quotes
1 parent 32157c2 commit 2017b73

File tree

2 files changed

+32
-45
lines changed

2 files changed

+32
-45
lines changed

src/ai-bundle/src/AiBundle.php

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1204,16 +1204,12 @@ private function processMultiAgentConfig(string $name, array $config, ContainerB
12041204
$handoffReferences = [];
12051205

12061206
foreach ($config['handoffs'] as $agentName => $whenConditions) {
1207-
// Register each handoff as a service
1208-
$handoffId = 'ai.multi_agent.'.$name.'.handoff.'.$agentName;
1209-
$handoffDefinition = new Definition(Handoff::class, [
1207+
// Create handoff definitions directly (not as separate services)
1208+
// The container will inline simple value objects like Handoff
1209+
$handoffReferences[] = new Definition(Handoff::class, [
12101210
new Reference(self::normalizeAgentServiceId($agentName)),
12111211
$whenConditions,
12121212
]);
1213-
$container->setDefinition($handoffId, $handoffDefinition);
1214-
1215-
// Reference the handoff service
1216-
$handoffReferences[] = new Reference($handoffId);
12171213
}
12181214

12191215
$multiAgentId = 'ai.multi_agent.'.$name;

src/ai-bundle/tests/DependencyInjection/AiBundleTest.php

Lines changed: 29 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -2127,20 +2127,16 @@ public function testValidMultiAgentConfiguration()
21272127
$this->assertInstanceOf(Reference::class, $arguments[0]);
21282128
$this->assertSame('ai.agent.dispatcher', (string) $arguments[0]);
21292129

2130-
// Second argument: handoffs array (now references to handoff services)
2130+
// Second argument: handoffs array
21312131
$handoffs = $arguments[1];
21322132
$this->assertIsArray($handoffs);
21332133
$this->assertCount(1, $handoffs);
21342134

2135-
// Verify handoff reference
2136-
$handoffRef = $handoffs[0];
2137-
$this->assertInstanceOf(Reference::class, $handoffRef);
2138-
$this->assertSame('ai.multi_agent.support.handoff.technical', (string) $handoffRef);
2139-
2140-
// Check the actual handoff service definition
2141-
$handoffDef = $container->getDefinition('ai.multi_agent.support.handoff.technical');
2142-
$this->assertSame(Handoff::class, $handoffDef->getClass());
2143-
$handoffArgs = $handoffDef->getArguments();
2135+
// Verify handoff structure
2136+
$handoff = $handoffs[0];
2137+
$this->assertInstanceOf(Definition::class, $handoff);
2138+
$this->assertSame(Handoff::class, $handoff->getClass());
2139+
$handoffArgs = $handoff->getArguments();
21442140
$this->assertCount(2, $handoffArgs);
21452141
$this->assertInstanceOf(Reference::class, $handoffArgs[0]);
21462142
$this->assertSame('ai.agent.technical', (string) $handoffArgs[0]);
@@ -2201,26 +2197,25 @@ public function testMultiAgentWithMultipleHandoffs()
22012197
$this->assertIsArray($handoffs);
22022198
$this->assertCount(2, $handoffs);
22032199

2204-
// Both handoffs should be References to handoff services
2200+
// Both handoffs should be Definition objects
22052201
foreach ($handoffs as $handoff) {
2206-
$this->assertInstanceOf(Reference::class, $handoff);
2202+
$this->assertInstanceOf(Definition::class, $handoff);
2203+
$this->assertSame(Handoff::class, $handoff->getClass());
2204+
$handoffArgs = $handoff->getArguments();
2205+
$this->assertCount(2, $handoffArgs);
2206+
$this->assertInstanceOf(Reference::class, $handoffArgs[0]);
2207+
$this->assertIsArray($handoffArgs[1]);
22072208
}
22082209

2209-
// Verify first handoff service (code_expert)
2210-
$codeHandoffRef = $handoffs[0];
2211-
$this->assertSame('ai.multi_agent.customer_service.handoff.code_expert', (string) $codeHandoffRef);
2212-
$codeHandoffDef = $container->getDefinition('ai.multi_agent.customer_service.handoff.code_expert');
2213-
$this->assertSame(Handoff::class, $codeHandoffDef->getClass());
2214-
$codeHandoffArgs = $codeHandoffDef->getArguments();
2210+
// Verify first handoff (code_expert)
2211+
$codeHandoff = $handoffs[0];
2212+
$codeHandoffArgs = $codeHandoff->getArguments();
22152213
$this->assertSame('ai.agent.code_expert', (string) $codeHandoffArgs[0]);
22162214
$this->assertSame(['bug', 'code', 'programming', 'technical'], $codeHandoffArgs[1]);
22172215

2218-
// Verify second handoff service (billing_expert)
2219-
$billingHandoffRef = $handoffs[1];
2220-
$this->assertSame('ai.multi_agent.customer_service.handoff.billing_expert', (string) $billingHandoffRef);
2221-
$billingHandoffDef = $container->getDefinition('ai.multi_agent.customer_service.handoff.billing_expert');
2222-
$this->assertSame(Handoff::class, $billingHandoffDef->getClass());
2223-
$billingHandoffArgs = $billingHandoffDef->getArguments();
2216+
// Verify second handoff (billing_expert)
2217+
$billingHandoff = $handoffs[1];
2218+
$billingHandoffArgs = $billingHandoff->getArguments();
22242219
$this->assertSame('ai.agent.billing_expert', (string) $billingHandoffArgs[0]);
22252220
$this->assertSame(['payment', 'invoice', 'subscription', 'refund'], $billingHandoffArgs[1]);
22262221
}
@@ -2310,7 +2305,7 @@ public function testMultiAgentReferenceToNonExistingAgentThrowsException()
23102305
public function testAgentAndMultiAgentNameConflictThrowsException()
23112306
{
23122307
$this->expectException(InvalidConfigurationException::class);
2313-
$this->expectExceptionMessage('Agent names and multi-agent names must be unique. Duplicate name(s) found: support');
2308+
$this->expectExceptionMessage('Agent names and multi-agent names must be unique. Duplicate name(s) found: "support"');
23142309

23152310
$this->buildContainer([
23162311
'ai' => [
@@ -2335,7 +2330,7 @@ public function testAgentAndMultiAgentNameConflictThrowsException()
23352330
public function testMultipleAgentAndMultiAgentNameConflictsThrowsException()
23362331
{
23372332
$this->expectException(InvalidConfigurationException::class);
2338-
$this->expectExceptionMessage('Agent names and multi-agent names must be unique. Duplicate name(s) found: support, billing');
2333+
$this->expectExceptionMessage('Agent names and multi-agent names must be unique. Duplicate name(s) found: "support, billing"');
23392334

23402335
$this->buildContainer([
23412336
'ai' => [
@@ -2466,21 +2461,17 @@ public function testComprehensiveMultiAgentHappyPath()
24662461
$this->assertIsArray($csHandoffs);
24672462
$this->assertCount(2, $csHandoffs);
24682463

2469-
// Code expert handoff reference
2470-
$codeHandoffRef = $csHandoffs[0];
2471-
$this->assertInstanceOf(Reference::class, $codeHandoffRef);
2472-
$this->assertSame('ai.multi_agent.customer_support.handoff.code_expert', (string) $codeHandoffRef);
2473-
$codeHandoffDef = $container->getDefinition('ai.multi_agent.customer_support.handoff.code_expert');
2474-
$codeHandoffArgs = $codeHandoffDef->getArguments();
2464+
// Code expert handoff
2465+
$codeHandoff = $csHandoffs[0];
2466+
$this->assertInstanceOf(Definition::class, $codeHandoff);
2467+
$codeHandoffArgs = $codeHandoff->getArguments();
24752468
$this->assertSame('ai.agent.code_expert', (string) $codeHandoffArgs[0]);
24762469
$this->assertSame(['bug', 'error', 'code', 'debug', 'performance', 'optimization'], $codeHandoffArgs[1]);
24772470

2478-
// Docs expert handoff reference
2479-
$docsHandoffRef = $csHandoffs[1];
2480-
$this->assertInstanceOf(Reference::class, $docsHandoffRef);
2481-
$this->assertSame('ai.multi_agent.customer_support.handoff.docs_expert', (string) $docsHandoffRef);
2482-
$docsHandoffDef = $container->getDefinition('ai.multi_agent.customer_support.handoff.docs_expert');
2483-
$docsHandoffArgs = $docsHandoffDef->getArguments();
2471+
// Docs expert handoff
2472+
$docsHandoff = $csHandoffs[1];
2473+
$this->assertInstanceOf(Definition::class, $docsHandoff);
2474+
$docsHandoffArgs = $docsHandoff->getArguments();
24842475
$this->assertSame('ai.agent.docs_expert', (string) $docsHandoffArgs[0]);
24852476
$this->assertSame(['documentation', 'docs', 'readme', 'api', 'guide', 'tutorial'], $docsHandoffArgs[1]);
24862477

0 commit comments

Comments
 (0)