DEV Community

Cover image for I Gave My AI Shopping Agent a Wallet and a Memory
Yuuki Yamashita
Yuuki Yamashita

Posted on

I Gave My AI Shopping Agent a Wallet and a Memory

I Gave My AI Shopping Agent a Wallet and a Memory

I built a small AI agent that watches a limited-stock online sale, decides when to buy, and asks a human before it spends any money. That part is not new — lots of "AI agent" demos do that. The part I actually cared about is smaller and easier to miss: what happens after the agent decides? Does it remember what it bought, what it skipped, and why? Most demos don't bother. Mine does, and it stores that memory in CockroachDB, a database built to never lose data even if a whole data center goes down.

The project is called wallet-memory, and I built it for the CockroachDB × AWS Hackathon.

Why "memory" matters more than it sounds

Picture an agent that can spend real money. If it forgets its own past decisions, bad things happen quietly: it might try to buy the same item twice, or make the same mistake it already learned from last week, or simply have no record of why it once said no to a purchase. A chatbot that forgets is annoying. An agent that forgets, while holding a wallet, is risky.

So every time my agent finishes a decision — bought it, got turned down, or ran out of time waiting for a human — it writes that decision into CockroachDB. Before its next decision, it asks the database: "have I seen a situation like this before, and what did I do?" That's the whole idea of "agentic memory": the agent's judgment gets better over time because its past is a real, searchable record, not something it has to re-guess from scratch.

Why CockroachDB fits this job

I could have used almost any database to just store rows. CockroachDB earned its place here for a few concrete reasons:

It never oversells, automatically. When many people try to buy the last item in stock at the exact same moment, CockroachDB makes sure only one of them actually gets it — even under heavy concurrent load. I tested this by firing 50 purchase attempts at once against a stock of only 3, and the database never let more than 3 succeed. No extra code, no locks I had to write myself.

It speaks normal SQL, the same language as Postgres. If you already know how to write a SELECT or an UPDATE, you already mostly know CockroachDB. There's no new query language to learn.

It stores AI memory in the same place as everything else. CockroachDB can hold "embeddings" — a way of turning a sentence into a list of numbers so a computer can compare how similar two sentences are — right next to your normal tables, with an index built for searching them fast. I didn't need a separate vector database just for the agent's memory.

It survives losing a whole region. I set my cluster up across three regions (Singapore, Jakarta, and Mumbai) and configured it to keep working even if one of them disappears entirely. For an agent that's supposed to remember things reliably, "the memory itself can't go down" is exactly the property you want.

It lets AI tools talk to it directly and safely. CockroachDB Cloud has a built-in "MCP Server" — think of it as a safe doorway that lets an AI assistant (like Claude) look at your database and answer questions about it, in read-only mode by default. I used it to literally ask an AI, in plain English, "show me the agent's recent purchase decisions and why" — no custom code required.

How it actually works, step by step

  1. The agent checks the current stock through a small website.
  2. It asks CockroachDB: "have I made a similar decision before?" and gets back the closest matches.
  3. If there's stock, it writes up a short reason (sometimes referencing what it remembered) and asks a human to approve or reject, using a simple web page.
  4. If approved, it buys the item — and whatever happens next (bought, sold out, rejected, or timed out), it saves that outcome straight back into CockroachDB.

The agent itself is a Python program (using a framework called Strands Agents) powered by Claude on Amazon Bedrock, and it runs on Amazon Bedrock AgentCore Runtime — AWS's hosting service for AI agents — so it's not just running on my laptop. The "please approve this" step uses Amazon DynamoDB as a short-lived waiting room; once a human decides, the permanent memory of that decision moves into CockroachDB.

A mistake worth mentioning

Early on, "ask for approval" and "actually buy the item" were two separate steps. That meant if the model got approval but then forgot to call the second step, the purchase — and the memory of it — both silently vanished. I didn't fix this by asking the AI more nicely in the prompt. I fixed it by removing the gap entirely: approval and purchase now happen inside one single step, so there's no place left for the result to get lost.

Try it yourself

If you're curious what an AI agent with real memory — not just a longer prompt — actually looks like under the hood, the code is all there.

Top comments (0)