Orchestration of AI agents for a retail task
Define the roles, shared records and action boundaries in a retail AI-agent workflow, then check handovers, retries and the final customer outcome.
- Published
- Last updated
Orchestration of AI agents coordinates who handles a task, which records each agent can use and when an action can proceed. For a retail workflow, that means keeping product advice consistent with the catalogue while making order changes only through an authorised service. One coordinator must own the final customer answer.
Start with one task and a clear completion rule. Add specialised agents where they handle distinct work, and keep fixed rules in ordinary automation.
Assign one retail task and its record owners
Choose the simplest workflow that can finish the task correctly. Deterministic automation follows predefined rules. A single tool-using agent chooses among tools as it interprets a request. A multi-agent system divides work between specialised agents and adds a coordinator to combine their results.
In a fictional camera store, a customer asks, “Does adapter AD-8 fit camera C-2, and can you replace the adapter in my unshipped order?” This task combines compatibility advice with a possible order change. It needs product evidence and verified authority to change that customer’s order.
Assign authority before assigning agents. The catalogue owns product identifiers and the supported compatibility relationship. Store policy owns substitution conditions. The order service owns fulfilment status and the saved order contents. The coordinator owns the final answer, but it cannot override those records.
A product specialist checks whether AD-8 supports C-2. An order specialist checks whether the identified order can still change. A fixed action step applies the permitted substitution only after the customer confirms the exact replacement and any price difference.
A subagent is an agent given a bounded part of the task by another agent. It doesn’t need permission to do everything its parent can do. In this example, the product specialist receives the camera and adapter identifiers. It has no reason to receive the customer’s delivery address or payment details.
The agent harness is the surrounding software that runs the agents and controls tool access. It also manages execution limits and saved task state. Calling a system a swarm doesn’t establish who can change an order or how conflicting results are resolved.
Design the handover and action contract
Give every role an explicit input and completion result. A handover must carry enough evidence for the next step to proceed without asking another agent to guess what happened.
For the camera-store task, use a shared case identifier, CASE-62. Keep customer identity verification outside the product specialist’s context. Pass only an authorised order reference to the role that needs it.
| Role | Inputs and allowed tools | Required result | Action boundary |
|---|---|---|---|
| Product specialist | AD-8, C-2 and read-only catalogue lookup | Compatible, incompatible or unknown, with supporting record identifiers and versions | Cannot change stock, orders or policy |
| Order specialist | Authorised order reference, requested line and read-only order lookup | Current order version, line contents and whether fulfilment blocks a change | Cannot approve a different customer’s order |
| Policy check | Proposed substitution, relevant product facts and store policy lookup | Applicable conditions and whether staff assistance is needed | Cannot invent an exception |
| Action step | Validated proposal, current order version and recorded customer confirmation | Operation identifier and confirmed saved order result | Only the approved substitution, with no separate charge unless authorised |
| Coordinator | Specialist results and confirmed action result | Customer answer that matches the evidence and saved order | Cannot describe a pending change as completed |
The product specialist’s contract can be short: “Read compatibility records for AD-8 and C-2. Return the decision, source record identifier and source version. Return unknown when evidence is missing.” Validate those fields before the next step uses them. An instruction in a prompt is insufficient access control, so restrict the connected tools and credentials too.
Context orchestration means selecting the information each step receives. Pass the product specialist’s compatibility evidence to the coordinator. Keep unrelated conversation history out of the handover. Preserve the source version so later changes don’t silently alter the basis of the decision.
Use sequential handovers when a later step depends on an earlier result. Check compatibility before preparing the substitution. Record customer confirmation before the write. Verify the saved order before announcing completion.
Catalogue and order lookups can be independent reads, but their results must refer to the same case and requested products. Combine them only after both finish. Parallel execution is a design option when the orchestrator supports it. Two agents writing to the same order introduce a conflict that faster reads cannot solve.
Handle retries, disagreement and interruption
Before retrying, establish whether the first attempt changed anything. An application programming interface (API) call can time out after the service saves the change. Repeating the write at that point can create a second action.
Save the task state outside the conversation. For CASE-62, retain the proposed substitution and source versions, together with the customer’s confirmation reference. Record the write operation identifier, its status and the last verified order version. Restrict this record to the staff and services handling the case.
| Situation | Check before continuing | Next action |
|---|---|---|
| Stale context | Does the order version still match the version used for the proposal? | Refresh the order and reassess the change |
| Duplicate event | Has this event identifier already completed its operation? | Return the recorded result instead of starting another write |
| Contradictory compatibility records | Which record applies to the exact camera revision and adapter variant? | Stop the proposal and send the conflicting evidence to staff |
| Partial failure | Did advice finish while the order lookup or policy check failed? | Keep the advice, but hold the substitution until its conditions are known |
| Uncertain write result | Does the order service show a completed operation or changed line? | Reconcile the first attempt before considering a retry |
| Customer interruption | Is the proposal still current, and does confirmation cover it? | Resume from saved state or ask for renewed confirmation |
Use a stable idempotency identifier for an action where the receiving service supports one. It lets that service recognise a repeated request as the same operation. The workflow must preserve the identifier across retries. An orchestrator cannot create this guarantee for a service that doesn’t enforce it.
Slow API responses can leave the coordinator with incomplete evidence. A timeout must move the task into a pending or failed state, with a bounded retry policy. It must not turn missing evidence into permission to proceed. Recheck stock and order state when a delay could invalidate the proposal.
Route unresolved cases to a named staff queue. Include the safe case reference, the requested outcome and the evidence that needs a decision. Assign one person ownership of the next action. When staff resume the case, they must see whether a write already completed before approving another one.
Verify the completed workflow
Use isolated records to walk the camera-store task through the orchestrator and inspect the resulting order. The following is a hypothetical n8n design with explicit expected results. It uses read-only specialist agents followed by controlled workflow steps for the order change.
The n8n AI Agent Tool documentation describes a parent agent calling specialist agents as tools. Its Description and Prompt fields define each specialist’s job. Keep the product specialist’s connected tools read-only, regardless of what its prompt says.
To build the example, you need an n8n workspace and a configured chat model. Use isolated catalogue and order services with restricted test credentials. The order service must expose the lookup and substitution operations your workflow calls. A generic HTTP connection doesn’t establish that a particular store supports those operations.
- Create CASE-62 with test order TEST-42 containing adapter AD-3. Give the fixture an unshipped status and order version 12. Set the compatibility fixture to show that AD-8 supports C-2.
- Connect an AI Agent coordinator to a chat model and the read-only specialist tools. Give each specialist one case per invocation. n8n sub-node expressions resolve against the first input item, so avoid sending several customers’ cases together.
- Validate the returned product identifiers and evidence. Check that AD-8 supports C-2 and that TEST-42 remains eligible under the store’s substitution policy. Route missing evidence to assistance.
- Capture confirmation for replacing AD-3 with AD-8 under the fixture’s stated price conditions. Send the approved operation through a dedicated sub-workflow. Enable Wait for Sub-Workflow Completion in the calling Execute Sub-workflow node.
- In that sub-workflow, re-read TEST-42 and apply the authorised substitution against the expected order version. Use an HTTP Request node only with the test service’s documented method and request fields. Save its operation identifier.
- Read TEST-42 again. Require the saved line to contain AD-8 and the operation to show completion. Return those facts from the sub-workflow’s final node, then produce the customer answer.
The Execute Sub-workflow guide explains input mapping and completion waiting. The HTTP Request guide covers request methods and authentication. Keep credentials in the connection configuration, outside agent messages.
For the successful fixture, compare the final order lookup with the answer. TEST-42 must contain AD-8 exactly once, and the answer must describe the saved substitution. A green workflow execution alone doesn’t establish either outcome.
Repeat the case with incompatible products, then with the order already shipping. Both must block the write. Finally, interrupt the response after a successful substitution and replay the same event. Confirm the existing operation is recovered and no second change or charge occurs.
Compare this design with a simpler route before adopting it. Fixed compatibility fields and clear substitution rules might need only lookups and deterministic checks. One agent can interpret the customer’s request without separate specialists. Keep multiple agents when their separate responsibilities justify the extra handovers and monitoring work, and require the same final-record checks whichever design you choose.
Give your store its own shopping agent
Customers ask in their own words. Your agent finds, compares and checks out from your catalogue, right on your site.