1.4 Multi-step workflows with enforcement and handoff patterns
Programmatic enforcement vs prompt-based guidance
| Programmatic (hooks, prerequisite gates) | Prompt-based guidance | |
|---|---|---|
| Compliance | Deterministic — 100% | Probabilistic — non-zero failure rate |
| Cost | Code to write and maintain | A paragraph |
| Use when | Financial operations, identity verification, policy limits, regulated ordering | Style, preference, soft defaults |
When deterministic compliance is required, prompt instructions alone have a non-zero failure rate. Few-shot examples and a stronger system prompt are both prompt-based — neither is an answer to "12% of the time it skips verification".
Prerequisite gates
Block downstream tool calls until prerequisites have completed — for example, block process_refund until get_customer has returned a verified customer ID:
- TypeScript
- Python
// Illustrative: a pre-tool-use interception with server-side state.
const verifiedCustomerId = new Map<string, string>(); // sessionId -> customerId
function gate(sessionId: string, toolName: string, input: unknown) {
const requiresVerification = ["lookup_order", "process_refund"];
if (requiresVerification.includes(toolName) && !verifiedCustomerId.has(sessionId)) {
return {
allow: false,
reason:
"Customer identity is not verified. Call get_customer first and use the returned customer_id.",
};
}
return { allow: true };
}
# Illustrative: a pre-tool-use interception with server-side state.
verified_customer_id: dict[str, str] = {} # session_id -> customer_id
REQUIRES_VERIFICATION = ("lookup_order", "process_refund")
def gate(session_id: str, tool_name: str, tool_input: object) -> dict:
if tool_name in REQUIRES_VERIFICATION and session_id not in verified_customer_id:
return {
"allow": False,
"reason": (
"Customer identity is not verified. Call get_customer first and "
"use the returned customer_id."
),
}
return {"allow": True}
The denial reason matters: it is fed back to the model, which then self-corrects by calling get_customer. A silent block produces a confused agent.
Multi-concern decomposition
For a message raising several issues ("my order arrived damaged, I was double-charged, and I want to change my address"):
- Decompose into distinct items.
- Investigate each in parallel using shared context.
- Synthesise a unified resolution — one reply, not three.
Structured handoff protocols
Human agents receiving an escalation have no access to the conversation transcript. A handoff summary must be self-contained:
{
"customer_id": "cus_8842",
"order_id": "12345",
"root_cause": "Carrier damage confirmed by photo evidence; item out of stock for replacement.",
"refund_amount": 649.0,
"policy_reference": "returns.damaged.v3 — silent on out-of-stock replacements",
"recommended_action": "Approve full refund plus expedited shipping credit.",
"attempted": ["get_customer", "lookup_order", "process_refund (blocked: >$500)"]
}
Include customer details, root cause analysis, and recommended actions — this is the checklist the exam uses.
Quiz
- Question 1
Production data shows that in 12% of cases your agent skips get_customer entirely and calls lookup_order using only the customer’s stated name, occasionally leading to misidentified accounts and incorrect refunds. What change would most effectively address this reliability issue?
- Question 2
A customer writes: "My order arrived damaged, I was charged twice, and I never got the discount code your rep promised me." Your agent investigates the damage claim properly with tool calls, then answers the other two from whatever context it already has, getting the duplicate charge wrong. Which workflow change matches the decomposition pattern for multi-concern requests?
- Question 3
When the agent escalates, the human agent receives the full conversation transcript. Handling time has risen: humans read 40 turns to reconstruct what happened, and they have no access to the agent’s tool results — only to the text it wrote. What should the escalation produce instead?
- Question 4
Identity verification must precede any account mutation. Compliance sampling across 50,000 conversations finds a 2% violation rate despite an explicit, prominent system prompt rule, and the regulator requires zero. Which implementation meets the requirement?