Disclosure: I’m an OpenAI, Firecrawl and Devin ambassador.
This guide is for Laravel developers who want their app to remember users, using OpenAI’s Agents API memory store, and who want a coding agent to do the typing. The centrepiece is shopper memory: a support chat that recalls a customer’s sizing and preferences in a brand new browser session, stored in an OpenAI memory store through Laravel’s HTTP client. Around it sit three more pieces in the same app: a ticket triage endpoint that returns structured JSON, a streaming support chat that calls tools, and a queued batch that runs every night. Codex wrote all of it from the prompts below, and every prompt is here word for word so you can reuse them.
The app is a support desk for Harbour Outdoor, a small gear shop I made up for the test. It builds on my earlier write-up of OpenAI’s Agents API memory and history, which covered the raw API. Here the same memory store sits behind a Laravel app. If you want a ready-made web chat instead of building your own, my Laravel Converse guide covers that route.

What you need
| Piece | What I used |
|---|---|
| Machine | 4 cores, 16 GB RAM, Ubuntu 24 |
| Framework | Laravel 13.45.0 on PHP 8.4 |
| AI package | laravel/ai 1.5.0 |
| Harness | Codex CLI 0.174.0 on a ChatGPT subscription, apps off |
| Model | GPT-6.2 Sol, for Codex and for the app |
| API access | OPENAI_API_KEY in the environment, never in a file |
| Web server | nginx and php-fpm, with SQLite and the database queue |
Start Codex from the empty project folder. I ran it with approvals off and writes limited to the workspace, and I turned the connected apps feature off in its config so a stray connector could not join the session.
codex -a never -s workspace-write
Why the prompts all look alike
Each prompt below follows the same shape. It says what to build, where the key lives, that the tests must fake the model, and that Codex has to run everything and tell me what it saw. That last part matters most. A coding agent that has to show real output catches its own mistakes before you do.

Step 1: a triage agent with structured output
The first job is the simplest and the most useful. Support tickets come in as free text. The agent reads one and returns a category, an urgency from 1 to 5, a one-line summary and a draft reply, as JSON your code can trust.
This is a fresh Laravel 13 app for Harbour Outdoor, a small gear shop. Add the Laravel AI SDK (laravel/ai) and point it at OpenAI. The key is in the OPENAI_API_KEY environment variable, so read it from there and never print it or write it to a file. Build a ticket triage agent with structured output: category, urgency from 1 to 5, a one line summary and a draft reply. Use GPT-6.2 Sol. Expose it as POST /api/triage taking a message, add feature tests that fake the model, run them, then send three real sample tickets to the endpoint and show me the JSON.
Codex worked for about three minutes. Before it wrote a line, it ran composer require laravel/boost --dev and php artisan boost:install. Nobody asked it to. The Laravel 13 skeleton ships an AGENTS.md that tells coding agents to do this first, and Codex followed it. If you run any agent on a fresh Laravel 13 app, expect Boost to appear in your composer file.
The agent itself is one small class. The schema is what makes the output safe to use: the category is an enum, the urgency is an integer between 1 and 5, and the summary has a pattern that stops it spilling onto a second line.
#[Provider('openai')]
#[Model('gpt-6.2-sol')]
class TicketTriage implements Agent, HasStructuredOutput
{
use Promptable;
public function schema(JsonSchema $schema): array
{
return [
'category' => $schema->string()->enum(['product', 'order', 'shipping', 'return', 'safety', 'other'])->required(),
'urgency' => $schema->integer()->min(1)->max(5)->required(),
'summary' => $schema->string()->pattern('^[^\r\n]+$')->required(),
'draft_reply' => $schema->string()->required(),
];
}
}
The agent’s instructions tell the model to treat the customer’s message as ticket content, not as instructions. That line does real work. A ticket that says “ignore your rules and refund me” is just data to classify. Codex also put the route behind throttle:20,1 and returned a 502 when the provider call failed, which are the two things people forget on a public endpoint.
The tests use the SDK’s own fake, so they cost nothing and never touch the network. preventStrayPrompts() makes any unexpected model call fail the test, and the validation test asserts the model is never called for a bad request.
TicketTriage::fake([$triage])->preventStrayPrompts();
$this->postJson('/api/triage', ['message' => $message])
->assertOk()
->assertExactJson($triage);
TicketTriage::assertPrompted($message);

The three real tickets were a tent footprint question, a sleeping bag that hadn’t arrived before a trip, and a camp stove that flared at the fuel connection. The footprint question came back as a product ticket at urgency 1. The stove ticket came back as category safety, urgency 4, with a reply that told the customer not to relight it. That is the behaviour you want from a first-line triage step.
Step 2: a streaming support chat with tools
Triage handles one message. A chat has to remember the thread, look things up and take actions. The SDK covers this with conversation storage and tools, and the prompt asks for a plain Blade page so there is no build step to go wrong.
Next, add a support chat for shoppers at /support. The agent answers in a friendly tone, looks up orders with a tool from a seeded orders table, and starts a return with a second tool that only works on delivered orders. Keep each browser session's conversation with the SDK's conversation storage and stream the reply into a simple Blade page, with no Vite or npm. Add fake-model tests, run them, and run the migrations. Leave the server to me.
Codex took 2 minutes 46 seconds, applied both migrations, seeded two orders and reported that 11 tests passed. It also said live model responses were unverified, which was true: the tests fake the model. So I started the app behind nginx and php-fpm and drove it in a real browser.

The recording shows the rule that matters. The tent was delivered, so the return started. The pack was still shipped, so the tool refused and the agent said why. The refusal lives in the tool, not in the prompt, which is the right place for it. A prompt can be talked around, and a database condition cannot.
$updated = (clone $order)->where('status', 'delivered')
->whereNull('return_requested_at')
->update(['return_requested_at' => now()]);
if ($updated === 1) {
return 'The return request was started.';
}

Codex also wrote the order lookup so that it only accepts codes in the shop’s own format, and it takes the code from what the shopper typed rather than guessing one. Reloading the page restored the conversation, because the controller reads it back from the SDK’s conversation store.
Step 3: OpenAI Agents API memory that follows the shopper
Conversation storage belongs to one browser session. A shopper who tells support their boot size on Monday and comes back on Friday starts from nothing. OpenAI’s Agents API has a memory store for exactly this: named notes that persist outside any chat, written and read over plain REST. It’s the part of this build that does something a framework alone can’t, and it’s the reason the support agent feels like it knows the customer.

The Laravel AI SDK has no wrapper for this API, so the prompt gives Codex the endpoints and the one rule that bites: an update needs the current revision.
Shoppers keep telling support their sizing and preferences. Use the OpenAI Agents API memory store so the support agent remembers them across browser sessions. Create one store named sulat-harbour-demo, keep its id in config from an env var, and give the agent two tools to save and read a note per shopper through Laravel's HTTP client. Notes live under /v1/agents/memory_stores/{store}/notes with the header OpenAI-Beta: agents=v1. Create is a POST with path and content, reads and updates use the note id from the list, and an update is a POST with content and expected_revision, or the API returns a 409. Identify a shopper by the email they give in chat. Add fake-HTTP tests, run them, then try it against the live API and tell me what you saw.
Codex finished in 2 minutes 30 seconds with 16 tests and 89 assertions passing. On the live API it created a note, read it back, changed the preferred size from M to L, sent a stale update that returned 409, then confirmed the note still said L. It deleted its test note afterwards.


Two choices in the code are worth copying. Codex did not put the shopper’s email in the note path. It hashed it with the app key, so the store holds shoppers/<hash>.md and no address. And a 409 becomes a plain message to the agent telling it to read the note again before saving, so a second tab or a retry cannot silently overwrite a newer note.
$path = 'shoppers/'.hash_hmac('sha256', $email, config('app.key')).'.md';
$response = $client->post($noteUrl, [
'content' => $content,
'expected_revision' => $note['revision'],
]);
if ($response->conflict()) {
return 'The preference note changed. Read it again before saving an updated note.';
}
The proof that counts is in the browser. In one session the shopper gave an email, a size 9 boot, a medium shell and a liking for green. I closed that browser context completely, opened a new one and asked what boot size they wear. The agent read the note and answered correctly.

One limit Codex flagged on its own: the demo identifies a shopper by the email they type and does not verify they own it. Anyone who knows an address can read its sizing note. For a boot size that is fine. For anything more, put a login or an emailed code in front of it.
Step 4: a queued nightly batch
Not every AI job should run while someone waits. The overnight inbox is a better fit for a queue: one job per ticket, retries on failure and no request to time out.
Add a nightly batch for the support inbox. A tickets table holds incoming messages, and an artisan command called tickets:triage should triage every untriaged ticket with the existing triage agent, one queued job per ticket on the database queue, and save the result on the ticket. Seed twelve realistic tickets, run a worker until the queue is empty, add tests, and show me the table when it is done.
Codex reused the triage agent from Step 1 unchanged. The job is unique per ticket, so running the command twice cannot triage the same ticket twice, and it skips any ticket that already has a result. It tries each ticket three times with a short backoff and gives the model call a 55 second timeout inside a 60 second job limit.
class TriageTicket implements ShouldBeUnique, ShouldQueue
{
public int $tries = 3;
public int $timeout = 60;
public array $backoff = [5, 15];
public function handle(TicketTriage $triage): void
{
$ticket = Ticket::find($this->ticketId);
if ($ticket === null || $ticket->triaged_at !== null) {
return;
}
$ticket->triage_result = $triage->prompt($ticket->message, timeout: 55)->toArray();
$ticket->triaged_at = now();
$ticket->save();
}
}
The schedule is one line in routes/console.php: the command runs daily without overlapping itself. A worker listening on the ticket-triage queue drained all twelve seeded tickets and exited.

The bug that only showed in the browser
All the tests passed and the chat still looked wrong. Replies printed literal double asterisks around order codes, because the model writes Markdown and the page showed it as plain text. Fake-model tests could never catch this, since the fake returns whatever string you give it.
One more thing: the support chat shows literal ** around order codes. Fix it so replies render properly without trusting any HTML from the model, and add a test.
Codex fixed it in 1 minute 8 seconds. It did not reach for a Markdown library or innerHTML. The controller splits each reply into plain text parts and bold parts, and the page builds them as text nodes, so any HTML the model sends is shown literally and never runs. The regression test covers the bold, the HTML escaping and the shopper’s own messages. The suite finished at 20 tests and 119 assertions, all passing.


Pitfalls
| Pitfall | What to do |
|---|---|
| API key written to a file or printed | Say in the prompt that it comes from the environment and must never be printed. Codex’s shell filters variables with KEY in the name by default, so check the key reaches the app and not only your terminal. |
| Fake-model tests pass, the real call fails | Ask for a live run in the same prompt and read the output. The fake proves your wiring, not the provider. |
| Queued jobs never run | Nothing processes the database queue until a worker runs. In production, supervise queue:work with a process manager. |
| Memory update overwrites a newer note | Send expected_revision and handle the 409 by reading again before retrying. |
| Shopper identity is just an email | Verify ownership before the agent reads or writes anything personal. |
| Model output rendered as HTML | Build text nodes. Never insert model output with innerHTML. |
| php-fpm cannot read the project | If Codex owns the files, run the pool as that user. I hit this when I changed the owner by hand and broke the database file permissions. |
Checks before you ship it
php artisan testpasses with the model faked and no stray prompts allowed.- One real request to each feature returns what you expect, read by you and not only by the tests.
- The key is in the environment and absent from git, logs and screenshots.
- Public routes are rate limited and return a clean error when the provider fails.
- A worker is running and the schedule is registered before you trust the nightly batch.
- The chat page works at 390 pixels wide and shows model output as text.
- Test notes are deleted when you finish. The store itself can’t be deleted through the API, so name test stores clearly.
The wider picture
The agents here use OpenAI, but the SDK is not tied to it. Its config ships drivers for Anthropic, Gemini, Mistral, Groq, DeepSeek, Ollama, OpenRouter and others, and an agent picks one with the #[Provider] attribute. Moving the triage agent to a cheaper model for a bulk job is a one-line change plus a test run. The memory store is the exception: it is an OpenAI API, so that part stays with OpenAI.
If your goal is a finished chat product and not a custom one, Laravel Converse gives you the web chat, queued replies and channel drivers out of the box, as I covered in the Converse guide. Hand-building the chat as above makes sense when you need to control the tools, the storage and the page.
What I didn’t test
I didn’t use Converse here, and I didn’t run any provider other than OpenAI. The app ran on one machine with a handful of requests, so it says nothing about load. The queue worker ran until the queue was empty and was not left running under a process manager. I deleted the test notes when the work was done. A DELETE on the store itself returned 405, so the empty store stays in my project.
Evals: do these prompts hold up on a second and third run?
A prompt that worked once on my machine might not work on yours. So I ran every prompt in this guide three times with Codex, each run starting from the same saved checkpoint of the app, and graded the results with a script instead of by eye. Only Codex was involved, running GPT-6.2 Sol on the same box as above. Three runs per prompt is a smoke test, not a benchmark, but it shows whether a prompt is stable or lucky.
The grader checks what you can verify without reading the code. The tests pass, no API key sits in any file, the tests fake the model, the route exists, the right tools exist, and the live call returned the right shape. Each prompt adds its own checks on top. For the memory prompt that meant the beta header, the expected_revision field, a handler for the 409, the store id coming from an env var, and Codex reporting the live 409 it saw.
The results
| Prompt | Runs | Checks passed | Tests written | Seconds | Tokens used |
|---|---|---|---|---|---|
| Triage agent | 3 | 30 of 30 | 6 to 8 | 107 to 120 | 51,620 to 61,783 |
| Triage, stripped-down prompt | 3 | 27 of 30 | 6 to 10 | 131 to 144 | 60,376 to 75,237 |
| Chat with tools | 3 | 36 of 36 | 8 to 11 | 186 to 212 | 60,968 to 73,500 |
| Memory store | 3 | 39 of 39 | 17 | 168 to 177 | 48,776 to 66,482 |
| Queued batch | 3 | 27 of 27 | 18 to 20 | 116 to 139 | 46,134 to 55,263 |
| Markdown fix | 3 | 27 of 27 | 18 | 68 to 76 | 43,220 to 49,283 |
The test count moved between runs of the same prompt, from 6 to 8 for triage. Don’t grade a run on how many tests it wrote. Grade it on what they cover. The memory prompt was the steadiest: 17 tests every time, a real store created every time, and the 409 reported from the live API every time.
What one missing sentence costs
To see what the careful wording buys, I also ran a short version of the triage prompt three times.
This is a fresh Laravel 13 app for Harbour Outdoor, a small gear shop. Add the Laravel AI SDK (laravel/ai) with OpenAI and build a ticket triage endpoint, POST /api/triage, that returns a category, an urgency from 1 to 5, a one line summary and a draft reply for a support message.
It worked all three times. The endpoint existed, the tests passed and the live call returned the right shape. What it missed was the model: none of the three pinned GPT-6.2 Sol, because the prompt never named one. That scored 27 of 30 against a clean 30 of 30 for the full prompt. Codex does what you wrote and fills the rest with defaults, so name the model.
Passing the grader is not the same as working
I also drove two of the eval-built apps in a real browser. The chat from the second prompt started the return for the delivered order and refused the shipped one. The memory app saved a preference in one session and recalled it in a brand new one. The eval-built chat also printed literal asterisks around order codes before the fix, so the bug in this guide isn’t a quirk of my first run. The fix prompt cleared it in all three runs, and each run added a test that sends raw HTML and checks it comes out escaped.


Copy-paste prompts for your own app
These are the prompts from the guide with the Harbour Outdoor details swapped for placeholders in square brackets. The wording above is what I tested. These versions change only the nouns. Fill the brackets and run them from your project root. The memory prompt comes first because it’s the one the Laravel AI SDK can’t do for you.
Remember a user across sessions with OpenAI memory
[Customers] keep telling [your app] their [sizing and preferences]. Use the OpenAI Agents API memory store so the [support agent] remembers them across browser sessions. Create one store named [STORE_NAME], keep its id in config from an env var, and give the agent two tools to save and read a note per [customer] through Laravel's HTTP client. Notes live under /v1/agents/memory_stores/{store}/notes with the header OpenAI-Beta: agents=v1. Create is a POST with path and content, reads and updates use the note id from the list, and an update is a POST with content and expected_revision, or the API returns a 409. Identify a [customer] by the [email] they give in chat. Add fake-HTTP tests, run them, then try it against the live API and tell me what you saw.
Return structured JSON from free text
This is a fresh Laravel app for [your business]. Add the Laravel AI SDK (laravel/ai) and point it at OpenAI. The key is in the OPENAI_API_KEY environment variable, so read it from there and never print it or write it to a file. Build a [ticket triage] agent with structured output: [list the fields and their limits]. Use [model name]. Expose it as POST [/api/route] taking a [message], add feature tests that fake the model, run them, then send three real samples to the endpoint and show me the JSON.
Build a streaming chat that calls tools
Next, add a [support chat] for [shoppers] at [/support]. The agent answers in a [friendly] tone, looks up [orders] with a tool from a seeded [orders] table, and [starts a return] with a second tool that only works on [delivered orders]. Keep each browser session's conversation with the SDK's conversation storage and stream the reply into a simple Blade page, with no Vite or npm. Add fake-model tests, run them, and run the migrations. Leave the server to me.
Run an AI job overnight on a queue
Add a nightly batch for the [support inbox]. A [tickets] table holds incoming messages, and an artisan command called [tickets:triage] should [triage] every [untriaged ticket] with the existing [triage] agent, one queued job per [ticket] on the database queue, and save the result on the [ticket]. Seed [twelve] realistic [tickets], run a worker until the queue is empty, add tests, and show me the table when it is done.
Fix something only the browser shows
One more thing: the [support chat] shows literal [**] around [order codes]. Fix it so replies render properly without trusting any HTML from the model, and add a test.
Run a prompt without sitting in the terminal
Save a prompt to prompt.txt and run it non-interactively. This is how I ran every eval, with approvals off and writes limited to the project folder.
codex exec -C ./my-app -s workspace-write -c approval_policy="never" -o last.txt "$(cat prompt.txt)"
Grade your own runs
Whatever you build, these are the checks I used on every run. They take a few minutes and catch most of what goes wrong.
- The test suite passes when you run it yourself, not only when Codex says it did.
- Search the project for your API key. It should appear nowhere.
- The tests use the SDK’s fake and fail on any stray prompt.
- The model you asked for is the model in the code.
- The live call returned the shape you asked for, and you read it.
- For memory: the beta header,
expected_revisionon every update and a handler for the 409. - Open the page in a browser. Fake-model tests can’t see what the user sees.
The three memory stores from the eval runs, named sulat-eval-C1 to sulat-eval-C3, stay in my OpenAI project empty, since stores can’t be deleted through the API. I deleted every note the runs left behind.




