@@ -1098,6 +1098,75 @@ public function testEmptyStringMemoryConfigurationThrowsException()
10981098 ]);
10991099 }
11001100
1101+ #[TestDox('Memory array configuration without service key throws validation exception ' )]
1102+ public function testMemoryArrayConfigurationWithoutServiceKeyThrowsException ()
1103+ {
1104+ $ this ->expectException (InvalidConfigurationException::class);
1105+ $ this ->expectExceptionMessage ('Memory array configuration must contain a "service" key. ' );
1106+
1107+ $ this ->buildContainer ([
1108+ 'ai ' => [
1109+ 'agent ' => [
1110+ 'test_agent ' => [
1111+ 'model ' => ['class ' => Gpt::class],
1112+ 'memory ' => ['invalid ' => 'value ' ],
1113+ 'prompt ' => [
1114+ 'text ' => 'Test prompt ' ,
1115+ ],
1116+ ],
1117+ ],
1118+ ],
1119+ ]);
1120+ }
1121+
1122+ #[TestDox('Memory array configuration with empty service throws validation exception ' )]
1123+ public function testMemoryArrayConfigurationWithEmptyServiceThrowsException ()
1124+ {
1125+ $ this ->expectException (InvalidConfigurationException::class);
1126+ $ this ->expectExceptionMessage ('Memory service cannot be empty. ' );
1127+
1128+ $ this ->buildContainer ([
1129+ 'ai ' => [
1130+ 'agent ' => [
1131+ 'test_agent ' => [
1132+ 'model ' => ['class ' => Gpt::class],
1133+ 'memory ' => ['service ' => '' ],
1134+ 'prompt ' => [
1135+ 'text ' => 'Test prompt ' ,
1136+ ],
1137+ ],
1138+ ],
1139+ ],
1140+ ]);
1141+ }
1142+
1143+ #[TestDox('Memory service configuration works correctly ' )]
1144+ public function testMemoryServiceConfigurationWorksCorrectly ()
1145+ {
1146+ $ container = $ this ->buildContainer ([
1147+ 'ai ' => [
1148+ 'agent ' => [
1149+ 'test_agent ' => [
1150+ 'model ' => ['class ' => Gpt::class],
1151+ 'memory ' => ['service ' => 'my_custom_memory_service ' ],
1152+ 'prompt ' => [
1153+ 'text ' => 'Test prompt ' ,
1154+ ],
1155+ ],
1156+ ],
1157+ ],
1158+ ]);
1159+
1160+ // Should use the service directly, not create a StaticMemoryProvider
1161+ $ this ->assertTrue ($ container ->hasDefinition ('ai.agent.test_agent.memory_input_processor ' ));
1162+ $ this ->assertFalse ($ container ->hasDefinition ('ai.agent.test_agent.static_memory_provider ' ));
1163+
1164+ $ memoryProcessor = $ container ->getDefinition ('ai.agent.test_agent.memory_input_processor ' );
1165+ $ arguments = $ memoryProcessor ->getArguments ();
1166+ $ this ->assertInstanceOf (Reference::class, $ arguments [0 ]);
1167+ $ this ->assertSame ('my_custom_memory_service ' , (string ) $ arguments [0 ]);
1168+ }
1169+
11011170 #[TestDox('Memory configuration preserves correct processor priority ordering ' )]
11021171 public function testMemoryProcessorPriorityOrdering ()
11031172 {
@@ -1182,7 +1251,7 @@ public function testMemoryWithExistingServiceUsesServiceReference()
11821251 'agent ' => [
11831252 'test_agent ' => [
11841253 'model ' => ['class ' => Gpt::class],
1185- 'memory ' => ' existing_memory_service ' , // This service exists
1254+ 'memory ' => [ ' service ' => ' existing_memory_service '] , // New array syntax for service
11861255 'prompt ' => [
11871256 'text ' => 'You are a helpful assistant. ' ,
11881257 ],
@@ -1254,7 +1323,7 @@ public function testMemoryWithServiceAliasUsesAlias()
12541323 'agent ' => [
12551324 'test_agent ' => [
12561325 'model ' => ['class ' => Gpt::class],
1257- 'memory ' => ' memory_alias ' , // This alias exists
1326+ 'memory ' => [ ' service ' => ' memory_alias '] , // Use new array syntax for service alias
12581327 'prompt ' => [
12591328 'text ' => 'You are a helpful assistant. ' ,
12601329 ],
@@ -1290,7 +1359,7 @@ public function testDifferentAgentsCanUseDifferentMemoryTypes()
12901359 'agent ' => [
12911360 'agent_with_service ' => [
12921361 'model ' => ['class ' => Gpt::class],
1293- 'memory ' => ' dynamic_memory_service ' , // Existing service
1362+ 'memory ' => [ ' service ' => ' dynamic_memory_service '] , // Use new array syntax for service
12941363 'prompt ' => [
12951364 'text ' => 'Agent with service. ' ,
12961365 ],
@@ -1312,6 +1381,7 @@ public function testDifferentAgentsCanUseDifferentMemoryTypes()
13121381
13131382 $ serviceMemoryProcessor = $ container ->getDefinition ('ai.agent.agent_with_service.memory_input_processor ' );
13141383 $ serviceArgs = $ serviceMemoryProcessor ->getArguments ();
1384+ $ this ->assertInstanceOf (Reference::class, $ serviceArgs [0 ]);
13151385 $ this ->assertSame ('dynamic_memory_service ' , (string ) $ serviceArgs [0 ]);
13161386
13171387 // Second agent uses StaticMemoryProvider
0 commit comments