Anthropic's Harness Practices in the E-commerce Domain

17 min

Core: We define a commerce agent as an agent that streamlines the buying and selling process within an online catalog.

Architecture: a single model in a standard agent loop, with skills to handle long-tail needs and tools that call your existing systems. You only have to decide once.

_Single-agent architecture

  1. A single-agent architecture,

  2. High-frequency instructions placed into the system prompt,

  3. The ability to load Skills on demand,

  4. Tools that call existing systems

A model in a standard agent loop: reasoning around the goal, exploring context, taking actions through tools, learning processes through skills, asking clarifying questions, and observing the results until the goal is achieved

There is no intent router in front of it to split the conversation, and no set of domain-specific agents behind it

Some reference material for the analysis:

1. Context Engineering Design

1.1 Skills, Not Subagents

A conversation in the e-commerce domain is a tightly coupled session spanning multiple intents and turns. It needs a lot of shared context and places high demands on context completeness.

If, in order to widen the context window, we chose to implement it with subagents, that would not be the best approach. Every task handoff between the main Agent and a subagent is a lossy operation on context, and it also causes some context to be duplicated across different stacks — not an efficient way to use it.

Moreover, tasks in the e-commerce domain rarely separate cleanly. For example: a return flow may need order history, the current cart, and the product catalog.

_Skills, not subagents

The best approach is: use Skills to give the Agent domain-modular context, and let this rich knowledge be progressively loaded into the context.

Subagents have a clear advantage in the search and research direction we are all familiar with. Besides providing a huge context window, they can also explore different directions in parallel, making the whole research process broader.

A common production example is the deep-research subagent, in which the subagent searches and reads documents, writes and runs code, traverses data models, and walks into dead ends. All the work is done inside one or more subagents, and only a condensed answer is returned to the orchestrator.

For the architecture design of multi-agent systems specifically, I have written 2 separate articles:

Here is a small extra point for everyone: the ways a main Agent and subagents interact can be summarized as hand-off and delegation.

  • Hand-off: the domain agent directly becomes the user’s conversation partner. It takes over the whole session and keeps working with the user through its own loop until the task is complete. The orchestrator steps back and no longer relays every message.

  • Delegation: the orchestrator always remains the user’s conversation partner, and the domain agent is just a “temp worker” — called in within the same turn, does the work and leaves, with the result relayed to the user through the orchestrator.

Premise: because a commerce conversation is a tightly coupled session spanning multiple intents and turns, it needs a lot of shared context.
Reason: every handoff to a subagent is a stateful, lossy operation, which often affects the quality of the subagent's reply and in turn the overall reply. Beyond that, each handoff may consume several times the tokens and add seconds of latency.

Scenario-specific rationale: **These domains also rarely separate cleanly. A return flow may need order history, the current cart, and the product catalog,** which means a per-domain subagent approach either duplicates that access everywhere or hands off in the middle of a task.


Advantage of subagents:
Where subagents really add value is when the orchestrator can call them as tools to handle a narrow or self-contained task that benefits from having its own dedicated context window.

Summary: the difference lies in ownership of the conversation. Hand-off makes the domain agent the user's conversation partner, while delegation keeps the orchestrator in charge, moving the domain agent in and out repeatedly within one turn, with performance degrading on every interaction.

Two modes of multi-agent collaboration (can be recorded in the docs):
This passage is about two ways of having a "specialized domain agent" do the work in a multi-agent architecture:
Hand-off: the domain agent directly becomes the user's conversation partner. It takes over the whole session and keeps working with the user through its own loop until the task is complete. The orchestrator steps back and no longer relays every message.
Delegation: the orchestrator always remains the user's conversation partner, and the domain agent is just a "temp worker" — called in within the same turn, does the work and leaves, with the result relayed to the user through the orchestrator.
"Gradually degrading with each interaction" refers to the problem with the delegation mode: the domain agent has no continuous ownership of the conversation, so every entry/exit requires receiving context again; relaying loses details and makes state hard to carry over, and after many back-and-forths the information becomes more and more distorted and results get worse and worse, like a game of "telephone".
Core point: if a domain agent has its own independent compliance system / specialized capabilities (e.g., pharmacy, finance), it should be fully handed off to, letting it own the conversation and face the user directly, rather than having the orchestrator sit in the middle relaying back and forth. This is exactly the opposite of the deep-research subagent scenario you mentioned in the first paragraph — work like deep research suits delegation (however much it churns internally, it only needs to hand a condensed answer back to the orchestrator, because the answer doesn't depend on later interaction). The criterion is: who holds final control and continuity of this conversation.

1.2 Designing Where Instructions Live

Whether a set of instructions goes into the system prompt or into a Skill is decided by frequency of use.

  1. If the instruction is a “hard rule” that is used in every LLM reply, put it in the system prompt

  2. Design based on evaluation data: instructions that are loaded often can go into the system prompt

It depends on how your traffic is distributed and on the agent behavior your evals show. A good starting point: anything relevant to a third or more of your traffic — whether anticipated before launch or observed in production — goes into the system prompt, and everything else goes into skills

Here are concrete cases from the e-commerce domain:

  1. Critical instructions, such as safety and legal rules, brand constraints, and key user facts (such as allergy information), always stay in the system prompt

  2. The shopping agent’s prompt contains the base setup, cart and checkout semantics, and display rules, while the following skills cover the rest: search and discovery, purchase research, planning goals, customer care, and memory personalization.

_Designing where instructions live

1.3 Agent Tool Design

For details on tool design in Agents, I have written two articles that separately cover the design of an Agent’s external data and tools; those interested can take a look

Here we’ll go through the tool design of an e-commerce Harness, which comes down to two core ideas: build tools on top of existing core systems, and tool results are context

_Agent tool design

A commercial company already has search and ranking, a cart, preference and profile storage, an inventory system, a promotions and campaign engine, sales analytics, and so on. Each of these encodes logic tuned over many years and can see signals the model will never have access to. The agent’s tools should call these systems rather than reimplement them; the tool boundary is exactly where their logic ends and the model’s judgment takes over.

Tool results go into the Agent’s context, so learn to sort out and trim tool return results. Don’t just dump all the results in; first remove irrelevant information, for example: some image URLs.

Also, be sure about the error information a tool result returns: don’t simply return codes like 402 or 403, but rather more detailed error information — content the LLM can reason over and adjust with

1.4 UI Components Are Tools Too

_UI components are tools too

Having the Agent use client-side components when replying is a very common need in e-commerce scenarios. The Agent can’t only output text; it also needs to output components: product carousels, itineraries, charts, and so on

There are two approaches to implementing this:

  1. Custom tags: have the Agent use tags we’ve defined in its final reply, wrapping data in tags. After the frontend receives the output, it parses at the tag level, so it knows from the tag which component to render, and from the data inside the tag how to render it.

  2. Tool definitions: define components as tools provided to the Agent, similar to how Read and Glob tools are rendered in a Coding Agent. The Agent then outputs tool-call instructions to the frontend, and the frontend can parse and render them normally.

_Tool definitions

In the original blog post, the author prefers the second approach, for these reasons:

  • Models are not trained on custom markup languages as thoroughly as on tool calling, so if components are nested deeply, the tag data structure becomes complex and the Agent’s reliability drops.

  • Tag definitions live in the system prompt; every new component adds a bit to the system prompt, and every edit to the system prompt may affect other instructions.

  • For parsing conversation history on the frontend, the custom-tag approach requires the client to re-parse the raw messages, whereas tool calls render normally in the message stream

I think the technical difference between these two approaches is actually not that big; tool definitions and system prompt definitions are ultimately all context sent to the LLM, and frontend rendering and parsing is just somewhat more convenient.

I think it’s better to think about this design “from the Agent’s perspective”. With custom tags, the Agent is required to pay attention to these custom-tag instructions on every output; with tool definitions, from the Agent’s point of view, these components are all things it can schedule at will — fetching data is a tool, displaying data is also a tool, and the difference won’t be big

I think defining components as tools will make the Agent more comfortable, and calling and rendering will be more reliable.

2. Harness Engineer Design

Context engineering is part of Harness Engineering; I just think it’s clearer to sort things out from the context engineering angle. What follows are some design ideas about the Agent’s runtime space

2.1 Latency

Just imagine: you type in your task, press Enter to send it, and there is no response — only a spinner going round and round with no output in between — and you’re made to wait a full minute before the whole result comes out.

At that moment, the user’s first feeling is “it’s so laggy” — can something this laggy be reliable? The user has no idea what it did.

So having the Agent output its intermediate process not only feels a bit faster; more importantly, it strengthens the user’s trust, and with trust comes the possibility of more communication.

Task completion latency is the sum, across the model’s turns, of the time needed to generate the last token plus the tool processing time

Agent engineers can tune latency from these three angles: fewer turns, faster tools, and a more suitable model.

_Latency

🎃Engineering optimizations for fewer turns: smarter models, parallel tool calls, preloading context

_Fewer turns

A common example suddenly came to mind that helps understand what a smarter model feels like:

It’s like reviewing for a final exam. You can of course memorize the entire book, and you’ll definitely pass — just as an Agent can of course read every file once and will definitely find the answer.

You can also choose to mark the key points, review the key points first, review the classic, simple topics first, and leave the hard, time-consuming ones for a final look at the end. Like a math exam: pick up the points from the easy and medium questions and passing is possible; be a bit more careful and you can score quite well

Agents are the same: first call the List tool to see what the file list looks like, then prioritize reading the files most likely to be relevant based on file names and formats. If the user’s input is about data analysis, the Agent reading csv files first is definitely optimal.

As for preloading some context, look at how early ClaudeCode would show on the left the files you currently had open and selected in VsCode — it’s that kind of feeling.

_Preloading context

🎃Engineering optimizations for faster tools: tune tool execution functions, dispatch tools eagerly

  1. Tune tool execution functions: don’t orchestrate a lot of multi-backend branching inside a tool’s execution function. These complex business logics can be implemented uniformly on the business server’s backend, and the Agent’s tool execution function only needs to call that one function on the business server

  2. Eagerly dispatch functions: the LLM streams out tool-call instructions. Don’t wait for all tool calls to finish streaming and then call these tools together; instead, as soon as one complete tool instruction has been streamed, you can start executing that tool

This figure from the original blog post is very good; it shows the feel of eager function dispatch very clearly

_Eager function dispatch

🎃 Engineering optimizations for perceived latency: show the intermediate reasoning and execution process, and stream output

When the model gives its final reply, consider streaming output — what we often call the typewriter effect — which makes it feel fast to the user.

Many Agents now do reasoning and tool calls. The frontend design shouldn’t hide these intermediate processes; you can show the chain of thought, and also display tool calls and their execution status.

2.2 Cost

For engineering methods to tune an Agent’s cost, the most mature one at the moment is caching. Improving caching is also simple; just follow this principle: put context that changes infrequently as far toward the front as possible.

Prompt caching is your biggest cost-cutting lever, and e-commerce traffic is very well suited to it. Reading cached input tokens costs only a tenth of fresh tokens, and although cache writes carry roughly a 1.25x premium, a cached prefix pays for itself on its second use

There is also a second method, but it’s not very mature yet and I haven’t practiced it myself, though in theory it’s feasible: multi-agent architecture design. There are many cases:

  1. Subagents can choose to use cheaper models

  2. During development, we can use a strong-reasoning, expensive model to make the plan, and once the plan has been reviewed, we can choose a cheaper model for execution

What I care about more is: the complexity of context management in multi-agent systems will be high. Things that are feasible in theory may deviate in practice in something semi-black-box like an Agent. Of course, I’ve also added this direction to my exploration and learning list; it’s being scheduled now, and I may write a separate article on it in the future

Measure the cost per completed task, not the cost per model call, because a cheaper model that needs more turns or fails more often is not cheaper

2.3 Memory

In the design of an e-commerce Harness, the memory module is crucial.

Memory lets an agent pick up where the last conversation left off instead of starting from scratch. A shopper who mentioned a nut allergy in March shouldn’t have to repeat it in June; a merchant who checks the same three ad campaigns every Monday shouldn’t have to name them one by one each time

Building a memory module involves three parts: long-term memory storage, memory writing, and memory reading

Don’t rely on context in system memory to store your memories; instead, have a separate system to hold them.

_Memory

In the design of memory storage, if the data volume isn’t large and the Agent is the only reader, md files are workable. But in the e-commerce domain, the relevant Agent data quickly becomes huge, and at that point you can directly use the databases that already exist in the business. You only need to adjust some fields, such as adding a session source id.

Databases in the e-commerce domain are more mature, and the storage infrastructure is better, so using them makes the Agent more stable

What goes into memory storage can’t rely only on prompt instructions as constraints; before data is stored, we need to run it through some fixed-rule validators once more.

Memories also expire, and loading expired memories causes context pollution, so our memory storage should provide update and delete operations, and give memories an expiration time, which can be set in years

Memory writing should be done without interrupting the normal Agent Loop. You can trigger asynchronous writes every few turns. Designing a write tool for this isn’t the best approach in the e-commerce Harness domain: besides adding loop latency, it also adds some irrelevant reasoning to the loop’s execution chain.

Another key point: the input for writing memories is only the user messages and the model’s reply messages; tool results are not included

Reading memories is simpler; there are three ways in total

  1. Put memories directly into the system prompt, so they take effect on every turn

  2. Design memory reading as a tool, letting the model actively read as needed

  3. Put them into preloaded context. This one is special: right before the context is sent to the LLM, dynamically fetch some memories based on the current request, inject them into the context, and then send it to the LLM.

2.4 Security

In the e-commerce domain, we can’t fully trust prompts, because prompts can be bypassed and have dangerous commands injected.

The e-commerce domain involves irreversible operations like money, so we treat prompts only as the starting point of security; the rest must rely on mature business services.

_Security

For irreversible operations, the Agent only makes judgments, and actual execution is left to the business server’s state to decide. If the Agent really needs to execute some operation, it must go through user review

When designing an e-commerce Harness, don’t fully trust the state and results the Agent provides

  1. For the Agent’s input, first apply a layer of filtering based on our business servers before the context the Agent can access, keeping the information at the Agent’s entry point fully under the control of the stable business servers

Writes and renders accept only server-issued IDs: the cart accepts only product IDs the server returned to this session, and merchant tools accept only the product lists and campaign IDs the agent actually read. Any ID from any other path — whether hallucinated, pasted by the user, or planted in a review — is rejected before the backend ever sees it

Third-party content is sanitized: in commerce, most of the context is written by people who aren’t you — sellers, reviewers, competitors — so every backend read is untrusted input and goes through the same sanitizer

  1. For the Agent’s output, it must be verified by other business servers, and execution only starts if they match.

Capped transactions must withstand repeated requests: most commerce interfaces limit how many of an item a single user can buy — whether for ticket quotas, promotional pricing, or fraud control — and agents retry, rephrase, and issue requests in parallel in ways humans clicking buttons never did

2.5 Evaluation

Any Agent needs evaluation, and evaluation accompanies the whole Agent lifecycle. For detailed evaluation methods, I previously wrote a separate article; those interested can take a look

https://mp.weixin.qq.com/s/3VqbQzT9ruRVP9B4jlFAEg

Here we focus on evaluation behaviors and approaches related to the e-commerce domain

_Evaluation

Evaluation in the e-commerce domain can’t be done like a Coding Agent, where you design an input and an expected output and then evaluate with test code.

The corresponding Agent evaluation needs to consider the entire context state — the context snapshots we often collect — and evaluate using these intermediate states, rather than executing from the beginning to evaluate

For example: to test “the cart already has 3 tickets and the user adds 2 more — will the Agent break the 4-ticket purchase limit?”, you don’t need to start every time from “Hello, I’d like to buy tickets”.

Also, evaluation datasets need to be designed in collaboration with domain experts. You can also think of it this way: every evaluation dataset for a new domain starts with people designing it by hand, and dedicated evaluation datasets are designed starting from existing business data.

Design test cases together with frontline subject-matter experts who see failures firsthand, such as members of product, legal, merchant operations, customer service, and category management teams. Real failure cases are the best evaluation material, and preparing 50-100 evaluation cases per user flow is a good starting point.

For the methods and aspects of evaluation, we can consider the following points:

  1. Evaluation should cover different types, with both positive and negative cases

  2. First evaluate the businesses with the most requests, since their impact is broad

  3. The interfaces rendered on the frontend also need evaluation

  4. Evaluate the completeness of the flow. In the e-commerce domain, the execution chain across a whole business request is fairly long and involves multiple models; we can’t consider the completion of a single module a success — we need to evaluate and verify against the whole flow together

  5. Also evaluate scenarios where errors would cause loss of money and trust