File tree 3 files changed +28
-13
lines changed
3 files changed +28
-13
lines changed Original file line number Diff line number Diff line change 11
11
use LLM \Agents \PromptGenerator \PromptGeneratorInput ;
12
12
use LLM \Agents \PromptGenerator \PromptInterceptorInterface ;
13
13
14
- final class InstructionGenerator implements PromptInterceptorInterface
14
+ final readonly class InstructionGenerator implements PromptInterceptorInterface
15
15
{
16
+ public function __construct (
17
+ private string $ outputFormat = 'markdown ' ,
18
+ ) {}
19
+
16
20
public function generate (
17
21
PromptGeneratorInput $ input ,
18
22
InterceptorHandler $ next ,
@@ -24,17 +28,23 @@ public function generate(
24
28
$ input ->prompt
25
29
->withAddedMessage (
26
30
MessagePrompt::system (
27
- prompt: <<<'PROMPT'
28
- {prompt}
29
- Important rules:
30
- - always response in markdown format
31
- - think before responding to user
32
- PROMPT,
31
+ prompt: '{instruction} ' ,
32
+ with: ['instruction ' ],
33
+ ),
34
+ )
35
+ ->withAddedMessage (
36
+ MessagePrompt::system (
37
+ prompt: 'Output format instruction: {output_format_instruction} ' ,
38
+ with: ['output_format_instruction ' ],
33
39
),
34
40
)
35
41
->withValues (
36
42
values: [
37
- 'prompt ' => $ input ->agent ->getInstruction (),
43
+ 'instruction ' => $ input ->agent ->getInstruction (),
44
+ 'output_format_instruction ' => \sprintf (
45
+ 'always response in `%s` format ' ,
46
+ $ this ->outputFormat ,
47
+ ),
38
48
],
39
49
),
40
50
),
Original file line number Diff line number Diff line change 20
20
public function __construct (
21
21
private AgentRepositoryInterface $ agents ,
22
22
private SchemaMapperInterface $ schemaMapper ,
23
+ private string $ agentKey = 'ask_agent ' ,
23
24
) {}
24
25
25
26
public function generate (
@@ -52,14 +53,16 @@ public function generate(
52
53
MessagePrompt::system (
53
54
prompt: <<<'PROMPT'
54
55
There are agents {linked_agents} associated with you. You can ask them for help if you need it.
55
- Use the `ask_agent ` tool and provide the agent key.
56
+ Use the `{ask_agent_tool} ` tool and provide the agent key.
56
57
Always follow rules:
57
58
- Don't make up the agent key. Use only the ones from the provided list.
58
59
PROMPT,
60
+ with: ['linked_agents ' , 'ask_agent_tool ' ],
59
61
),
60
62
)
61
63
->withValues (
62
64
values: [
65
+ 'ask_agent_tool ' => $ this ->agentKey ,
63
66
'linked_agents ' => \implode (
64
67
PHP_EOL ,
65
68
\array_map (
Original file line number Diff line number Diff line change @@ -22,10 +22,12 @@ public function generate(
22
22
return $ next (
23
23
input: $ input ->withPrompt (
24
24
$ input ->prompt ->withAddedMessage (
25
- MessagePrompt::user ('{user_prompt} ' )
26
- ->withValues ([
27
- 'user_prompt ' => (string ) $ input ->userPrompt ,
28
- ]),
25
+ MessagePrompt::user (
26
+ prompt: '{user_prompt} ' ,
27
+ with: ['user_prompt ' ],
28
+ )->withValues ([
29
+ 'user_prompt ' => (string ) $ input ->userPrompt ,
30
+ ]),
29
31
),
30
32
),
31
33
);
You can’t perform that action at this time.
0 commit comments