Tools and human approval
Step 9 of 14. Let Store Assist act through narrow, checked tools, and keep people in charge of the actions that carry real consequences.
Tools and human approval in 60 seconds
- Core rule: the model proposes an action. Ordinary services validate it, authorise it, run it and report the real result.
- Contracts: each tool does one job, takes typed arguments, has its own checks, and states its timeout, errors and retry behaviour.
- Safety: least privilege per tool, idempotency keys built from the logical operation, and workflow state stored outside the model.
- Humans: write escalation conditions in advance, scaled to the cost of a mistake. Approvals are enforced records with an approver, a scope and an expiry.
- Measure: escalation rate, how many were truly needed, time to a human reply, time to resolution and return to automation.
The problem it solves
A store assistant that can only talk is limited. Colleagues want it to check live stock, look up an incident, raise a ticket for a scanner that will not sync, or start a till PIN reset. Those abilities are tools: functions your own services expose, which the model may ask the system to run.
The danger is that a model is fluent, not accountable. It can claim a refund was issued when nothing happened, or repeat a call that already worked. So consequential decisions stay in code you can test, and high-impact ones stay with a person who is answerable for them.
How a tool call really works
Take a colleague who writes: "Raise a ticket, my scanner has not synced since the update." The path through the system has seven stages, and the model is only involved at the start and the end.
- The model reads the message and judges that an incident ticket is the right next move.
- It emits a structured request that names the tool and proposes values for the arguments. Nothing has happened yet.
- The orchestrator checks the arguments against the schema, then against business rules, such as whether the fault category exists and whether the store code belongs to this colleague.
- The orchestrator checks what the colleague is permitted to do and whether the action needs approval.
- The owning ticketing service performs the action under its own credentials and writes its own audit entry.
- The service returns a real result, such as the identifier INC-5521, or a real error.
- Store Assist composes its reply from that result, never from its own expectation of what the result will be.
The firm rule is about wording. A confirmation such as "Your incident is INC-5521" must be assembled from the service reply. If no reply arrived, the honest message is that the outcome is not yet known. An invented success sentence is a defect, however polite.
Narrow contracts and least privilege
A tool should have one clear job and accept structured input. An incident tool might take a short description, a category from an approved list and one of three severities. It should never accept a free-form query or command string. Narrow tools are easier to test, to permission and to defend against prompt injection.
Write every contract in the same template, so reviewers know where to look:
- Purpose: what it does, and what it deliberately does not.
- Inputs: names, types, allowed values, length limits, optional fields.
- Caller identity and scope: whose authority it runs under.
- Validation: schema checks plus business rules.
- Output and errors: the success shape with identifiers, and a list separating retryable faults from permanent ones.
- Timeout: the longest the caller will wait.
- Idempotency: how a repeated call is recognised.
- Risk tier and approval rule: and who approves.
- Owner: the team paged when it misbehaves.
The tool must repeat validation itself. A schema catches malformed arguments, but only the owning service knows whether a category is still active or whether this colleague may act on this till.
Least privilege means each tool holds only the access its job needs. The stock lookup reads inventory and nothing else. The incident tool creates and comments on tickets but cannot close them. The till PIN tool starts the identity verification workflow but cannot set a PIN. Issue tokens valid for a few minutes, scoped to one tool and one colleague, so a leak or a manipulated model has little to work with.
Making repeated actions safe
Networks fail halfway. Store Assist asks for an incident, the ticketing service creates INC-5521, and the reply is lost on a flaky store Wi-Fi hop. A naive retry raises a second incident, and two engineers get dispatched.
The fix is an idempotency key on every state-changing call. Build it from the logical operation, never from the colleague's wording: join the tool name, store code, asset identifier, fault type and trading date, then hash them. If the colleague rephrases and asks again, the key is identical and the service returns the original result. Keep keys and results for at least 24 hours.
Retrying also needs a split between a known failure and an unknown outcome. A validation error is known, so fix and resend. A timeout is unknown, because the work may have finished. In that case:
- Mark the step unknown in workflow state, not failed.
- Ask the service about the operation by its key before anything else.
- If it confirms, record the result and carry on. If it has no record, retry with the same key.
- If it still cannot be settled, run reconciliation and tell the colleague plainly that confirmation is pending.
Keeping workflow state outside the model
A conversation can describe an intention, but the authoritative record of what has happened lives in a workflow store owned by the application. The model sees a short summary each turn and is never the only holder of the facts. If the process restarts, nothing is lost. Use a small state machine, changed only by the orchestrator:
| State | Meaning | Allowed next states |
|---|---|---|
| proposed | The model asked for the tool and nothing is checked yet. | validated, rejected |
| validated | Schema, business rules and permissions all passed. | awaiting approval, executing |
| awaiting approval | A named approver has been asked and the clock is running. | approved, rejected, expired |
| executing | The service call has been sent with its idempotency key. | succeeded, failed, unknown |
| unknown | The outcome is uncertain and is being reconciled. | succeeded, failed, escalated |
| succeeded, failed, rejected, expired | Terminal states, each with an identifier or a reason. | none |
Record which tools were requested and authorised, whether approval was needed and given, the state of each operation, and the identifiers returned. This matters most for multi-step requests. If the scanner flow checks the device, raises an incident and notifies area support, a crash after step two must resume at step three and never repeat step two.
When a human should take over
Full automation is not the goal. Some requests carry enough consequence that a person should decide, and handing them over places responsibility correctly. Decide the triggers before launch, so they are testable:
- Approved sources give too little evidence to answer.
- Sources disagree and nothing settles which is current.
- The action is sensitive or cannot be undone.
- The colleague asks for a person.
- The same workflow keeps failing.
- Company policy names an approver.
- A wrong answer would cost more than automation should carry.
Scale the policy to the cost of an error. A question about shelf-edge label sizes and a refund over £150 should not share rules:
| Risk tier | Store Assist example | Policy |
|---|---|---|
| Read-only | How many units of SKU 448812 are in the stockroom? | Automatic. Answer from the inventory service. |
| Personal read | What is my shift on Saturday? | Automatic, only for the signed-in colleague, never cached across people. |
| Reversible write | Raise an incident for a scanner that will not sync. | Automatic after the colleague confirms the summary. Idempotent. |
| Money or access | A refund over £150, a price override, a till PIN reset. | Store manager approval, or the identity verification workflow. Never generated instructions. |
| Irreversible or regional | Anything touching the regional store closure plan. | Out of scope for the assistant. Route to the owning team. |
Handoffs that help
A weak handoff says "please contact the support desk" and makes the colleague explain everything again at a busy till. A useful one lets the desk start work in seconds.
Define the case card as a schema, so desk tooling can render it and quality checks can test it:
- Case identifier, store code, colleague role and a conversation reference.
- A short summary of the problem, and the original question verbatim.
- Steps already tried and what each produced.
- Sources used, with document versions.
- Actions performed, with the identifiers returned.
- The reason for escalation, from a fixed list of codes.
- Urgency, and flags for sensitive content.
Include sensitive details only when the receiving team needs and is cleared for them, and pass a reference to a record rather than a copy of personal data. The desk should also be able to hand a case back, for example once a manager has approved a refund and only the confirmation remains.
Approval as a real control
For high-impact actions, the executor enforces approval. It is never just a polite request in the prompt. Rewording, or reaching for a different tool, cannot get round it, because the check sits in code on the path to the service. Store every approval as a record:
- Who: the approver's identity and role. A requester can never approve their own action.
- What: the exact operation and a hash of its parameters, for example one refund of £212.40 against one receipt.
- Scope: the single target the approval covers. Approving a price override for one SKU in one store does not cover another.
- When: the time given and an expiry, typically 15 minutes for a refund.
- Use: single use. Once executed, the record is closed.
- Outcome: the result of the execution, linked to the idempotency key.
If any parameter changes after approval, the hash no longer matches and the approval is void. If the clock runs out, the request expires and the colleague is told. Both are ordinary states, not errors.
Measuring the quality of escalation
Escalation has its own numbers. Read them together:
- Escalation rate: a starting range of 3% to 6% of requests is plausible for Store Assist, to tune on evidence.
- Accepted as necessary: at least 85% of escalations the desk agrees needed a human.
- Time to first human reply: under 5 minutes during trading hours.
- Time to resolution after handoff, by reason code.
- Return to automation: cases handed back once the human step is done.
- Top reasons: a ranked list showing where to fix knowledge, tools or policy.
A high rate can mean gaps in the manuals, a weak route or a task unsuited to automation. A very low rate is not automatically good, since it can mean risks are being taken. Check it against the target of at least 98% of sensitive requests correctly escalated.
Store Assist, worked through
Start from 36,000 requests a day. Suppose 20% involve a tool: 7,200 calls. About 6,000 are live lookups such as stock and incident status, around 1,000 raise incidents, and roughly 200 start sensitive flows such as a till PIN reset. These shares are assumptions to confirm with real traffic.
If 4% of requests escalate, that is 1,440 handoffs a day, or 3.6 per store, and the desk must be sized for the 08:00 opening, when volume can be ten times the average. A refund over £150 might occur around 60 times a day across the estate, each needing a manager approval with a 15 minute expiry.
Now follow one request. A colleague asks for the status of INC-5521. The orchestrator validates the identifier, checks the store, calls the ticketing service with a 3 second timeout and writes the answer from the returned status. On a timeout, Store Assist says it could not confirm and offers to retry. A three-tool flow takes around 7 seconds, which at 10 requests a second is 70 in flight, so tool timeouts must stop slow dependencies holding connections.
import hashlib, time
TOOL_TIMEOUT_S = 3 # hard limit for one tool call
APPROVAL_TTL_S = 15 * 60 # approval expires after 15 minutes
MAX_RETRIES = 1 # one retry, only after a status check
def idempotency_key(tool, store, asset, kind, trading_date):
# Built from the logical operation, never from the user's wording.
raw = "|".join([tool, store, asset, kind, trading_date])
return hashlib.sha256(raw.encode()).hexdigest()
def run_tool(request, user, services, state):
tool = services.catalogue.get(request.tool)
if tool is None:
return state.finish(request, "rejected", reason="unknown tool")
problems = tool.validate(request.args, user) # schema and business rules
if problems:
return state.finish(request, "rejected", reason=problems)
if not services.permissions.allows(user, tool.name, request.args):
return state.finish(request, "rejected", reason="not permitted")
if tool.needs_approval(request.args):
ok = services.approvals.check(
request.id, tool.name, args_hash=hash_args(request.args),
now=time.time(), ttl_s=APPROVAL_TTL_S) # who, what, scope, expiry
if not ok:
return state.finish(request, "awaiting approval")
key = idempotency_key(tool.name, user.store, request.args["asset"],
request.args["kind"], request.trading_date)
state.mark(request, "executing", key=key)
for attempt in range(MAX_RETRIES + 1):
try:
result = tool.call(request.args, key=key, timeout_s=TOOL_TIMEOUT_S,
token=services.tokens.short_lived(user, tool.name))
return state.finish(request, "succeeded", result=result)
except TimeoutError:
# Uncertain outcome: ask the service before repeating anything.
status = tool.lookup_by_key(key)
if status is not None:
return state.finish(request, "succeeded", result=status)
state.mark(request, "unknown", key=key)
except tool.PermanentError as err:
return state.finish(request, "failed", reason=str(err))
return state.finish(request, "unknown", reason="needs reconciliation")
The names are placeholders. The order matters: validate, authorise, approve, then execute with a key.
Design decisions
- Tool catalogue: a registry with owner, risk tier and contract version. Refuse to run anything unregistered.
- Where checks live: validation, permission and approval checks sit in the executor, not in prompts.
- State store: one workflow store with atomic transitions and retention matching your audit needs.
- Approver routing: who approves what, who covers absences, and what happens at expiry.
- Handoff schema: versioned, and agreed with the support desk.
- Failure wording: standard messages per outcome.
Measuring it
- Tool selection accuracy: on labelled cases, including those where no tool is right.
- False confirmation rate: replies that claim success when no success record exists. The target is zero.
- Duplicate action rate: actions executed twice for one logical request. The target is zero.
- Escalation precision and recall: against a labelled set, with at least 98% of sensitive cases correctly escalated.
- Unknown-outcome resolution time: how long operations stay in the unknown state.
When to use it, and how much of it
| Situation | How much machinery | Why |
|---|---|---|
| Answers only, no actions | None. Skip tools. | Retrieval and routing are enough. See model routing. |
| Live read-only lookups | Typed tools, short timeouts, caller identity | Low risk, but data scoping must still hold. |
| Reversible writes such as raising an incident | Idempotency keys, state machine, confirmation | Duplicates and uncertain outcomes are the main hazards. |
| Money, access or pricing changes | Enforced approval records or a verification workflow | The cost of one error is high enough to need a named person. |
| Actions with no safe undo | Do not automate | Hand to the owning team. |
Trade-offs
| Dimension | Effect | What to do about it |
|---|---|---|
| Speed | Each check and approval adds time. | Run independent lookups in parallel and keep approvals for actions that need them. |
| Safety | More gates mean fewer bad actions, and more friction for colleagues. | Tier by consequence so low-risk work stays smooth. |
| Staffing | Escalation moves work to the support desk and to managers. | Size the desk for the opening peak and track the escalation rate weekly. |
What this means for your role
Common mistakes
Step checklist
- Every tool has a written contract and a named owner.
- Tokens are short-lived, per tool and per colleague.
- State-changing tools take an idempotency key built from the logical operation.
- The unknown-outcome path is tested by forcing a timeout after a successful action.
- Workflow state lives in a store, not in the conversation.
- Escalation triggers are written down and tied to risk tiers.
- Approval records are single use and hold approver, action hash, scope and expiry.
- The handoff schema is agreed with the support desk.
- Escalation rate, acceptance, first reply time and resolution time are on a dashboard.
- False confirmations and duplicate actions are zero in tests.
Further reading
- Tool design for agents: how to shape tools so models use them well.
- Tool calling and MCP: the mechanics of exposing tools to a model.
- Human checkpoint: the orchestration pattern behind approvals.
- Idempotency: why repeated calls must be safe.
- Agentic failure modes: what goes wrong when agents act.
Approvals keep the help Store Assist gives inside clear limits. Next: Step 10: AI gateway and resilience.