Skip to content

Commit 90741e9

Browse files
committed
bug #719 [AI Bundle] Preserve boolean options in agent/vectorizer model confguration (sonnymilton)
This PR was squashed before being merged into the main branch. Discussion ---------- [AI Bundle] Preserve boolean options in agent/vectorizer model confguration | Q | A | ------------- | --- | Bug fix? | no | New feature? | yes <!-- please update src/**/CHANGELOG.md files --> | Docs? | no <!-- required for new features --> | Issues | - <!-- prefix each issue number with "Fix #", no need to create an issue if none exist, explain below instead --> | License | MIT ## Problem When configuring models in `symfony/ai-bundle` via the `options` section, boolean values were **misrepresented**. This happens because `http_build_query()` converts booleans into integers: - `true` → `1` - `false` → `0` So configuration like: ```yaml ai: agent: my_agent: model: name: gpt-4o-mini options: stream: false ``` Converted to `gpt-4o-mini?stream=0` Expected: `gpt-4o-mini?stream=false` This makes it impossible to distinguish between a booleans and an integers during parsing. ## Changes - Inline normalization of options before calling `http_build_query()`. Booleans are explicitly converted to the strings `"true"` / `"false"`. - Added regression tests for both agents and vectorizers. Commits ------- f107a20 [AI Bundle] Preserve boolean options in agent/vectorizer model confguration
2 parents df0a2bd + f107a20 commit 90741e9

File tree

2 files changed

+64
-0
lines changed

2 files changed

+64
-0
lines changed

src/ai-bundle/config/options.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,12 @@
271271
return $model;
272272
}
273273

274+
array_walk_recursive($options, static function (mixed &$value): void {
275+
if (\is_bool($value)) {
276+
$value = $value ? 'true' : 'false';
277+
}
278+
});
279+
274280
return $model.'?'.http_build_query($options);
275281
})
276282
->end()
@@ -698,6 +704,12 @@
698704
return $model;
699705
}
700706

707+
array_walk_recursive($options, static function (mixed &$value): void {
708+
if (\is_bool($value)) {
709+
$value = $value ? 'true' : 'false';
710+
}
711+
});
712+
701713
return $model.'?'.http_build_query($options);
702714
})
703715
->end()

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

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2583,6 +2583,58 @@ public function testVectorizerConfigurationWithColonNotation(string $model)
25832583
$this->assertSame($model, $definition->getArgument(1));
25842584
}
25852585

2586+
public function testAgentModelBooleanOptionsArePreserved()
2587+
{
2588+
$container = $this->buildContainer([
2589+
'ai' => [
2590+
'agent' => [
2591+
'test' => [
2592+
'model' => [
2593+
'name' => 'qwen3',
2594+
'options' => [
2595+
'stream' => false,
2596+
'think' => true,
2597+
'nested' => [
2598+
'bool' => false,
2599+
],
2600+
],
2601+
],
2602+
],
2603+
],
2604+
],
2605+
]);
2606+
2607+
$agentDefinition = $container->getDefinition('ai.agent.test');
2608+
2609+
$this->assertSame('qwen3?stream=false&think=true&nested%5Bbool%5D=false', $agentDefinition->getArgument(1));
2610+
}
2611+
2612+
public function testVectorizerModelBooleanOptionsArePreserved()
2613+
{
2614+
$container = $this->buildContainer([
2615+
'ai' => [
2616+
'vectorizer' => [
2617+
'test' => [
2618+
'model' => [
2619+
'name' => 'text-embedding-3-small',
2620+
'options' => [
2621+
'normalize' => false,
2622+
'cache' => true,
2623+
'nested' => [
2624+
'bool' => false,
2625+
],
2626+
],
2627+
],
2628+
],
2629+
],
2630+
],
2631+
]);
2632+
2633+
$vectorizerDefinition = $container->getDefinition('ai.vectorizer.test');
2634+
2635+
$this->assertSame('text-embedding-3-small?normalize=false&cache=true&nested%5Bbool%5D=false', $vectorizerDefinition->getArgument(1));
2636+
}
2637+
25862638
private function buildContainer(array $configuration): ContainerBuilder
25872639
{
25882640
$container = new ContainerBuilder();

0 commit comments

Comments
 (0)