Read the long description: it is how the AI decides what is worth remembering.
New file · app/Ai/Tools/Memory.php
<?php
namespace App\Ai\Tools;
use App\Ai\Agents\Agent;
use App\Ai\Memory\Store;
use Illuminate\Support\Facades\Http;
class Memory implements Tool
{
public function __construct(protected Store $store = new Store) {}
public function definition(): array
{
return [
'type' => 'function',
'name' => 'remember',
'description' => <<<'DESC'
Save a stable, long-term fact about the user or their project.
Only use this for things that will still be useful in future sessions, such as:
- preferences ("prefers Pest over PHPUnit")
- project context ("works on a Laravel + Inertia app")
- identity ("goes by Jeffrey")
Do NOT use it for small talk, temporary state, secrets or API keys,
or anything already in the project guidelines or existing memories.
Write the fact as a short third-person sentence that makes sense on its own.
DESC,
'parameters' => [
'type' => 'object',
'properties' => [
'fact' => ['type' => 'string', 'description' => 'The fact to remember.'],
],
'required' => ['fact'],
'additionalProperties' => false,
],
'strict' => true,
];
}
public function use(array $arguments = []): string
{
$fact = $arguments['fact'];
$memory = $this->store->fetch();
$refreshed = $this->refresh($memory, $fact);
if (trim($refreshed) === trim($memory)) {
return "Fact already known: {$fact}";
}
$this->store->update($refreshed);
return "Fact remembered: {$fact}";
}
/**
* Ask the AI to merge the new fact into the existing memory file.
*/
protected function refresh(string $memory, string $fact): string
{
$response = Http::withToken(config('services.openai.key'))
->post('https://api.openai.com/v1/responses', [
'model' => config('services.openai.model'),
'instructions' => <<<'INSTR'
You maintain a short markdown list of long-term facts about a user.
You get the existing markdown and one new candidate fact. Return the full, updated markdown.
- If the fact is new, add it as a bullet point.
- If it is already covered, return the existing markdown unchanged.
- If it updates or contradicts an existing fact, replace the old fact.
- Do not add or remove anything else. Return only markdown, no code fences.
INSTR,
'input' => [
['role' => 'user', 'content' => "Existing memory:\n\n{$memory}\n\nNew fact:\n\n{$fact}"],
],
])
->throw()
->json();
// If something odd comes back, keep what we had.
return Agent::text($response) ?: $memory;
}
}

The remember tool’s description: what is worth remembering.

Instructions for merging a new fact into the memory file.