An Agent That Shops, and Survives a Crash
Shopify and Google published UCP, the Universal Commerce Protocol, back in January. The pitch is that a program rather than a person with a browser can discover and buy from a merchant. I wanted to know what that actually feels like to build against, so I spent a couple of days wiring up a shopping agent on my own machine. No cloud model, no API bill, a local llama.cpp server doing the thinking.
The short version is that the protocol part was easy and the agent part was not, and almost everything I learned was about the second half.
Two layers, and the trap in between Direct link to this section
The first thing worth knowing is that catalog search over UCP is unauthenticated. You can query the global catalog right now, today, and get real listings from real merchants. That is why this was a weekend project and not a quarter.
The second thing is less obvious and it shapes the whole design. Product discovery is global: one catalog, every merchant, and you can filter by where the buyer is and where stock is held. But physical store locations are not in that catalog at all. Proximity lives on the individual merchant, behind a separate capability, at the merchant's own endpoint. The reference CLI has no command for it.
So "find me waterproof boots I can try on in Montreal" is necessarily two phases. Search globally, then go ask specific merchants whether they have a shop near you. An agent that does not know this will either invent store locations or tell you there is nothing available locally.
Only merchants with an active retail location answer at all. I scanned 24 of them across four product queries and 7 exposed store data. Roughly a third, and heavily skewed toward actual outdoor retailers, which is exactly the category where trying something on matters.
Then I hit the good part. SAIL Plein Air has four stores around Montreal. I asked for stores matching "Montreal" and got zero.
query "Montreal" -> 0 stores
query "Laval" -> 2 stores
no query -> 10 stores: Laval, Beloeil, Quebec, Brossard,
Ottawa, Oshawa, Burlington, Cambridge,
Vaudreuil-Dorion, Chicoutimi
The matching is literal. There is no geocoding. The branches are named after the suburbs they are in, so the city name appears nowhere, and a faithful agent would have reported "no stores near you" in the most misleading way possible. It only got the right answer because it happened to follow up with a second call that had no filter at all.
I did not fix that with a better prompt. The tool now notices that a city query returned nothing while the merchant does have stores, asks again without the filter, and hands back the full list with a note explaining that matching is literal and the model should judge proximity from the addresses.
Stop asking the model to behave Direct link to this section
That turned out to be the theme. Three separate times I wrote a rule into the prompt, watched it get ignored, and then had the same rule hold perfectly once it was ordinary TypeScript.
The envelope. My first version handed the model the raw UCP tools and told it to write a script to pull the products out of the response, which runs about 180 KB. It worked on toy queries and fell over on a real one: eight turns fighting a JSON parsing edge case, context ballooned to 19,000 tokens, killed by a timeout seconds before it would have answered. I moved the search, the parsing, the colour and size matching and the price sorting into a plain function. Same query, 111 seconds, correct answer. The model now gets parameters, not a parser.
The budget. Asking a merchant for its stores costs a network round trip, so the policy said "check at most three merchants". It checked nine. On another run, twelve. I moved the cap into code, where it holds at four and then returns a refusal that also tells the model to describe the merchants it did not check as unknown rather than as online-only. Runtime dropped from 187 seconds to 139.
The city matching, above.
I am not claiming this is a deep insight. It is the oldest lesson in software, which is that a constraint you can enforce beats a constraint you have to request. But I had to learn it three times in two days, and the budget one is the sharpest version: a perfectly capable model, given a plain instruction with a number in it, swept nine merchants anyway.
Worth being honest about the limit too. The budget bounds the work reliably but it cannot stop the model overstating what the work showed. On one run it still wrote "no Montreal stores carry these" when two merchants had been refused unchecked.
What the catalog cannot tell you Direct link to this section
A smaller trap, but it cost me a run and nearly a wrong conclusion. Global catalog search returns exactly one representative variant per product. Forty products come back as forty variants, and asking for a specific product returns that same single variant rather than the full matrix.
So "blue, in large" is sampling, not an inventory check. An early run looked like it worked and surfaced two matching jackets, which was pure luck about which variant those two listings happened to expose. Adding a location filter returned forty products with zero matches, which read as "no stock in Canada" and was simply wrong.
Merchants also name their options however they please. From a single page of ten results I got French option names, a field called "Colour" containing a size, one field called "Color/size" holding both, and listings where the colour appeared only in the product title. The code now matches option names in five languages, falls back to scanning the title, and when it cannot confirm a colour or size it says so out loud instead of returning nothing.
The part I did not expect to care about Direct link to this section
The agent runs on a durable harness, and that turned out to be the most interesting piece.
Most agent frameworks persist your conversation. That is history. This one commits every model turn and every tool call to storage before showing it, which is execution. The difference is invisible until something dies mid-run, and then it is the whole ballgame.
I tested it the rude way. Killed the process 25 seconds into a run, then restarted it:
entry 7 user message committed BEFORE the kill
entry 11 model turn committed BEFORE the kill 7.5s
entry 13 catalog round trip committed BEFORE the kill
entry 16 store lookups after the kill
entry 32 the answer after the kill
The resumed process picked up at entry 16. It did not re-ask the model for that first turn and did not re-run the catalog search. The 180 KB fetch and seven and a half seconds of generation had already been committed, so they were reused.
The subtle bit came later, when I moved that merchant budget into durable storage so a crash could not hand the agent a fresh allowance. Claiming a merchant you have already claimed has to succeed. A tool that is safe to re-run will, after a crash, ask again for something it already paid for, and refusing it there throws away the work that survived. I got this right by accident and only understood why when a test killed the run with two merchants claimed and four lookups pending: two were correctly refused, and the two already paid for ran and returned real data. Had I made the re-claim fail, all four would have been refused and the agent would have finished with nothing.
Where it stops Direct link to this section
It cannot buy anything. That is not a prompt instruction, it is that no cart or checkout tool is registered at all, so there is no code path to one. Catalog access is open but checkout needs a Catalog JWT and an agent profile published at an HTTPS URL, neither of which I set up.
I am also in no hurry. The interesting question is not how to make an agent spend money, it is where the human approval goes when it tries. The harness I am using has no permission system of its own, which means that decision has to live somewhere deliberate rather than somewhere convenient.
For now it does research and handoff: find the thing, compare prices, work out whether there is a shop near me that stocks it, and give me the link. On the boots query it picked a more expensive pair than the cheapest result, specifically because it was the only one I could go and try on. That is a recommendation a price sorter cannot make, and it is the first time any of this felt like it was actually worth the electricity.
The code is at resistorsoftware/pi-ucp-shop, MIT licensed. It is a two-day prototype rather than anything polished, and it sits on a library whose API is still moving, so treat it as a worked example rather than something to depend on. The README leads with the UCP findings, which are the part most likely to save someone else the afternoon I spent.