Skip to content

Commit

Permalink
Refactors AgentPromptGenerator
Browse files Browse the repository at this point in the history
  • Loading branch information
butschster committed Aug 31, 2024
1 parent 4269ef5 commit bf81797
Showing 1 changed file with 24 additions and 26 deletions.
50 changes: 24 additions & 26 deletions src/AgentPromptGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,21 +39,11 @@ public function generate(
- think before responding to user
PROMPT,
),
values: ['prompt' => $agent->getInstruction()],
),

// Agent memory
MessagePrompt::system(
prompt: 'Instructions about your experiences, follow them: {memory}',
values: [
'memory' => \implode(
"\n",
\array_map(
static fn(SolutionMetadata $metadata) => $metadata->content,
$agent->getMemory(),
),
),
],
prompt: 'Instructions about your experiences, follow them: {memory}. And also {dynamic_memory}',
),
];

Expand All @@ -74,26 +64,12 @@ public function generate(
Always follow rules:
- Don't make up the agent key. Use only the ones from the provided list.
PROMPT,
values: [
'associated_agents' => \implode(
PHP_EOL,
\array_map(
static fn(array $agent): string => \json_encode([
'key' => $agent['agent']->getKey(),
'description' => $agent['agent']->getDescription(),
'output_schema' => $agent['output_schema'],
]),
$associatedAgents,
),
),
],
);
}

if ($sessionContext !== null) {
$messages[] = MessagePrompt::system(
prompt: 'Session context: {active_context}',
values: ['active_context' => \json_encode($sessionContext)],
);
}

Expand All @@ -105,6 +81,28 @@ public function generate(

return new Prompt(
messages: $messages,
variables: [
'prompt' => $agent->getInstruction(),
'active_context' => \json_encode($sessionContext),
'associated_agents' => \implode(
PHP_EOL,
\array_map(
static fn(array $agent): string => \json_encode([
'key' => $agent['agent']->getKey(),
'description' => $agent['agent']->getDescription(),
'output_schema' => $agent['output_schema'],
]),
$associatedAgents,
),
),
'memory' => \implode(
"\n",
\array_map(
static fn(SolutionMetadata $metadata) => $metadata->content,
$agent->getMemory(),
),
),
],
);
}
}
}

0 comments on commit bf81797

Please sign in to comment.