Skip to content

Commit 2220387

Browse files
committed
[AI Bundle] Rename system_prompt to prompt and prompt key to text
- Renamed system_prompt configuration key to prompt for clearer naming - Renamed nested 'prompt' key to 'text' in array configuration to avoid confusion - Updated all configuration examples in demo - Updated documentation with new configuration structure - Updated all tests to use new configuration structure - Maintained backward compatibility through configuration normalization
1 parent c31ae98 commit 2220387

File tree

5 files changed

+46
-46
lines changed

5 files changed

+46
-46
lines changed

demo/config/packages/ai.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ ai:
1818
model:
1919
class: 'Symfony\AI\Platform\Bridge\OpenAi\Gpt'
2020
name: !php/const Symfony\AI\Platform\Bridge\OpenAi\Gpt::GPT_4O_MINI
21-
system_prompt: |
21+
prompt: |
2222
You are an example chat application where messages from the LLM are streamed to the user using
2323
Server-Sent Events via `symfony/ux-turbo` / Turbo Streams. This example does not use any custom
2424
javascript and solely relies on the built-in `live` & `turbo_stream` Stimulus controllers.
@@ -35,16 +35,16 @@ ai:
3535
name: !php/const Symfony\AI\Platform\Bridge\OpenAi\Gpt::GPT_4O_MINI
3636
options:
3737
temperature: 0.5
38-
system_prompt:
39-
prompt: 'Please answer the users question based on Wikipedia and provide a link to the article.'
38+
prompt:
39+
text: 'Please answer the users question based on Wikipedia and provide a link to the article.'
4040
include_tools: true
4141
tools:
4242
- 'Symfony\AI\Agent\Toolbox\Tool\Wikipedia'
4343
audio:
4444
model:
4545
class: 'Symfony\AI\Platform\Bridge\OpenAi\Gpt'
4646
name: !php/const Symfony\AI\Platform\Bridge\OpenAi\Gpt::GPT_4O_MINI
47-
system_prompt: 'You are a friendly chatbot that likes to have a conversation with users and asks them some questions.'
47+
prompt: 'You are a friendly chatbot that likes to have a conversation with users and asks them some questions.'
4848
tools:
4949
# Agent in agent 🤯
5050
- agent: 'blog'

src/ai-bundle/config/options.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -130,32 +130,32 @@
130130
->end()
131131
->end()
132132
->booleanNode('structured_output')->defaultTrue()->end()
133-
->arrayNode('system_prompt')
133+
->arrayNode('prompt')
134134
->info('The system prompt configuration')
135135
->beforeNormalization()
136136
->ifString()
137137
->then(function (string $v) {
138-
return ['prompt' => $v];
138+
return ['text' => $v];
139139
})
140140
->end()
141141
->beforeNormalization()
142142
->ifArray()
143143
->then(function (array $v) {
144-
if (!isset($v['prompt']) && !isset($v['include_tools'])) {
145-
throw new \InvalidArgumentException('Either "prompt" must be configured for system_prompt.');
144+
if (!isset($v['text']) && !isset($v['include_tools'])) {
145+
throw new \InvalidArgumentException('Either "text" must be configured for prompt.');
146146
}
147147

148148
return $v;
149149
})
150150
->end()
151151
->validate()
152152
->ifTrue(function ($v) {
153-
return \is_array($v) && '' === trim($v['prompt'] ?? '');
153+
return \is_array($v) && '' === trim($v['text'] ?? '');
154154
})
155-
->thenInvalid('The "prompt" cannot be empty.')
155+
->thenInvalid('The "text" cannot be empty.')
156156
->end()
157157
->children()
158-
->scalarNode('prompt')
158+
->scalarNode('text')
159159
->info('The system prompt text')
160160
->end()
161161
->booleanNode('include_tools')

src/ai-bundle/doc/index.rst

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ Configuration
7171
model:
7272
class: 'Symfony\AI\Platform\Bridge\OpenAi\Gpt'
7373
name: !php/const Symfony\AI\Platform\Bridge\OpenAi\Gpt::GPT_4O_MINI
74-
system_prompt: # The system prompt configuration
75-
prompt: 'You are a helpful assistant that can answer questions.' # The prompt text
74+
prompt: # The system prompt configuration
75+
text: 'You are a helpful assistant that can answer questions.' # The prompt text
7676
include_tools: true # Include tool definitions at the end of the system prompt
7777
tools:
7878
# Referencing a service with #[AsTool] attribute
@@ -158,7 +158,7 @@ For basic usage, specify the system prompt as a simple string:
158158
model:
159159
class: 'Symfony\AI\Platform\Bridge\OpenAi\Gpt'
160160
name: !php/const Symfony\AI\Platform\Bridge\OpenAi\Gpt::GPT_4O_MINI
161-
system_prompt: 'You are a helpful assistant.'
161+
prompt: 'You are a helpful assistant.'
162162
163163
**Advanced Configuration**
164164

@@ -172,13 +172,13 @@ For more control, such as including tool definitions in the system prompt, use t
172172
model:
173173
class: 'Symfony\AI\Platform\Bridge\OpenAi\Gpt'
174174
name: !php/const Symfony\AI\Platform\Bridge\OpenAi\Gpt::GPT_4O_MINI
175-
system_prompt:
176-
prompt: 'You are a helpful assistant that can answer questions.'
175+
prompt:
176+
text: 'You are a helpful assistant that can answer questions.'
177177
include_tools: true # Include tool definitions at the end of the system prompt
178178
179179
The array format supports these options:
180180

181-
* ``prompt`` (string, required): The system prompt text that will be sent to the AI model
181+
* ``text`` (string, required): The system prompt text that will be sent to the AI model
182182
* ``include_tools`` (boolean, optional): When set to ``true``, tool definitions will be appended to the system prompt
183183

184184

src/ai-bundle/src/AiBundle.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -604,12 +604,12 @@ private function processAgentConfig(string $name, array $config, ContainerBuilde
604604
}
605605

606606
// SYSTEM PROMPT
607-
if (isset($config['system_prompt'])) {
608-
$includeTools = isset($config['system_prompt']['include_tools']) && $config['system_prompt']['include_tools'];
607+
if (isset($config['prompt'])) {
608+
$includeTools = isset($config['prompt']['include_tools']) && $config['prompt']['include_tools'];
609609

610610
$systemPromptInputProcessorDefinition = (new Definition(SystemPromptInputProcessor::class))
611611
->setArguments([
612-
$config['system_prompt']['prompt'],
612+
$config['prompt']['text'],
613613
$includeTools ? new Reference('ai.toolbox.'.$name) : null,
614614
new Reference('logger', ContainerInterface::IGNORE_ON_INVALID_REFERENCE),
615615
])

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

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,7 @@ public function testProcessorTagsUseFullAgentId()
389389
['service' => 'some_tool', 'description' => 'Test tool'],
390390
],
391391
'structured_output' => true,
392-
'system_prompt' => 'You are a test assistant.',
392+
'prompt' => 'You are a test assistant.',
393393
],
394394
],
395395
],
@@ -440,14 +440,14 @@ public function testMultipleAgentsWithProcessors()
440440
'tools' => [
441441
['service' => 'tool_one', 'description' => 'Tool for first agent'],
442442
],
443-
'system_prompt' => 'First agent prompt',
443+
'prompt' => 'First agent prompt',
444444
],
445445
'second_agent' => [
446446
'model' => ['class' => 'Symfony\AI\Platform\Bridge\Anthropic\Claude'],
447447
'tools' => [
448448
['service' => 'tool_two', 'description' => 'Tool for second agent'],
449449
],
450-
'system_prompt' => 'Second agent prompt',
450+
'prompt' => 'Second agent prompt',
451451
],
452452
],
453453
],
@@ -656,8 +656,8 @@ public function testSystemPromptWithArrayStructure()
656656
'agent' => [
657657
'test_agent' => [
658658
'model' => ['class' => 'Symfony\AI\Platform\Bridge\OpenAi\Gpt'],
659-
'system_prompt' => [
660-
'prompt' => 'You are a helpful assistant.',
659+
'prompt' => [
660+
'text' => 'You are a helpful assistant.',
661661
],
662662
'tools' => [
663663
['service' => 'some_tool', 'description' => 'Test tool'],
@@ -683,8 +683,8 @@ public function testSystemPromptWithIncludeToolsEnabled()
683683
'agent' => [
684684
'test_agent' => [
685685
'model' => ['class' => 'Symfony\AI\Platform\Bridge\OpenAi\Gpt'],
686-
'system_prompt' => [
687-
'prompt' => 'You are a helpful assistant.',
686+
'prompt' => [
687+
'text' => 'You are a helpful assistant.',
688688
'include_tools' => true,
689689
],
690690
'tools' => [
@@ -704,16 +704,16 @@ public function testSystemPromptWithIncludeToolsEnabled()
704704
$this->assertSame('ai.toolbox.test_agent', (string) $arguments[1]);
705705
}
706706

707-
#[TestDox('System prompt with only prompt key defaults include_tools to false')]
708-
public function testSystemPromptWithOnlyPromptKey()
707+
#[TestDox('System prompt with only text key defaults include_tools to false')]
708+
public function testSystemPromptWithOnlyTextKey()
709709
{
710710
$container = $this->buildContainer([
711711
'ai' => [
712712
'agent' => [
713713
'test_agent' => [
714714
'model' => ['class' => 'Symfony\AI\Platform\Bridge\OpenAi\Gpt'],
715-
'system_prompt' => [
716-
'prompt' => 'You are a helpful assistant.',
715+
'prompt' => [
716+
'text' => 'You are a helpful assistant.',
717717
],
718718
'tools' => [
719719
['service' => 'some_tool', 'description' => 'Test tool'],
@@ -756,8 +756,8 @@ public function testValidSystemPromptCreatesProcessor()
756756
'agent' => [
757757
'test_agent' => [
758758
'model' => ['class' => 'Symfony\AI\Platform\Bridge\OpenAi\Gpt'],
759-
'system_prompt' => [
760-
'prompt' => 'Valid prompt',
759+
'prompt' => [
760+
'text' => 'Valid prompt',
761761
'include_tools' => true,
762762
],
763763
'tools' => [
@@ -777,38 +777,38 @@ public function testValidSystemPromptCreatesProcessor()
777777
$this->assertSame('ai.toolbox.test_agent', (string) $arguments[1]);
778778
}
779779

780-
#[TestDox('Empty prompt in array structure throws configuration exception')]
781-
public function testEmptyPromptInArrayThrowsException()
780+
#[TestDox('Empty text in array structure throws configuration exception')]
781+
public function testEmptyTextInArrayThrowsException()
782782
{
783783
$this->expectException(InvalidConfigurationException::class);
784-
$this->expectExceptionMessage('The "prompt" cannot be empty.');
784+
$this->expectExceptionMessage('The "text" cannot be empty.');
785785

786786
$this->buildContainer([
787787
'ai' => [
788788
'agent' => [
789789
'test_agent' => [
790790
'model' => ['class' => 'Symfony\AI\Platform\Bridge\OpenAi\Gpt'],
791-
'system_prompt' => [
792-
'prompt' => '',
791+
'prompt' => [
792+
'text' => '',
793793
],
794794
],
795795
],
796796
],
797797
]);
798798
}
799799

800-
#[TestDox('System prompt array without prompt key throws configuration exception')]
801-
public function testSystemPromptArrayWithoutPromptKeyThrowsException()
800+
#[TestDox('System prompt array without text key throws configuration exception')]
801+
public function testSystemPromptArrayWithoutTextKeyThrowsException()
802802
{
803803
$this->expectException(InvalidConfigurationException::class);
804-
$this->expectExceptionMessage('The "prompt" cannot be empty.');
804+
$this->expectExceptionMessage('The "text" cannot be empty.');
805805

806806
$this->buildContainer([
807807
'ai' => [
808808
'agent' => [
809809
'test_agent' => [
810810
'model' => ['class' => 'Symfony\AI\Platform\Bridge\OpenAi\Gpt'],
811-
'system_prompt' => [
811+
'prompt' => [
812812
'include_tools' => true,
813813
],
814814
],
@@ -825,7 +825,7 @@ public function testSystemPromptWithStringFormat()
825825
'agent' => [
826826
'test_agent' => [
827827
'model' => ['class' => 'Symfony\AI\Platform\Bridge\OpenAi\Gpt'],
828-
'system_prompt' => 'You are a helpful assistant.',
828+
'prompt' => 'You are a helpful assistant.',
829829
'tools' => [
830830
['service' => 'some_tool', 'description' => 'Test tool'],
831831
],
@@ -1270,8 +1270,8 @@ private function getFullConfig(): array
12701270
],
12711271
'structured_output' => false,
12721272
'track_token_usage' => true,
1273-
'system_prompt' => [
1274-
'prompt' => 'You are a helpful assistant.',
1273+
'prompt' => [
1274+
'text' => 'You are a helpful assistant.',
12751275
'include_tools' => true,
12761276
],
12771277
'tools' => [
@@ -1285,7 +1285,7 @@ private function getFullConfig(): array
12851285
],
12861286
'another_agent' => [
12871287
'model' => ['class' => 'Symfony\AI\Platform\Bridge\Anthropic\Claude', 'name' => 'claude-3-opus-20240229'],
1288-
'system_prompt' => 'Be concise.',
1288+
'prompt' => 'Be concise.',
12891289
],
12901290
],
12911291
'store' => [

0 commit comments

Comments
 (0)