Task statement 1.4 · Agentic architecture and orchestration
Implement multi‑step workflows with enforcement and handoff patterns
Before process_refund runs, the support agent must know whose account it is refunding, and when it escalates mid-case, the human taking over must be able to act without the transcript.
share
get_customer, lookup_order, process_refund and escalate_to_human. Its target is 80% first-contact resolution, and it may refund up to $500 on its own.When logs show the agent skipping get_customer, the natural fix is a firmer system prompt or few-shot examples of the right order. Both make the skip rarer but not impossible, because the model still chooses every tool call. A routing classifier that enables some tools changes which tools exist, not their order. Because the skipped step guards a refund, the rare miss sends money to the wrong account.
KnowledgePrompt guidance versus programmatic enforcement
Prompt-based guidance writes the ordering into the system prompt, so the model follows it most of the time. Programmatic enforcement puts the ordering in code outside the model: a hook, or a prerequisite gate, a check that refuses a tool call until an earlier step has returned its result. In the guide's production data, the guided agent skipped get_customer in 12% of cases and looked up orders by the customer's stated name, which occasionally refunded a misidentified account. When deterministic compliance is required, as with identity verification before financial operations, prompt instructions alone have a non-zero failure rate. Where a skipped step harms no one, a prompt instruction is proportionate and cheaper to change.
SkillWhere the prerequisite gate lives
Because the gate is your code, it keeps its own record. In an Agent SDK agent, PostToolUse, the hook that runs after a tool succeeds, records the verified customer ID that get_customer returned. PreToolUse, the hook that runs before a tool call executes, checks that record and blocks process_refund or lookup_order without it. The same check can live in the process_refund handler on the server, which also covers callers other than your agent.
- "J. Rivera" asks for a refund on order #12345.
- The model skips verification and calls
process_refund. - The
PreToolUsehook finds no verified ID for the session and denies the call. - The refund never runs; the denial tells the model to call
get_customer. get_customerreturnsC-88431, and thePostToolUsehook records it.- The retried
process_refundpasses the check.
verified = {} # session_id → verified customer ID
async def record_verified(input_data, tool_use_id, context):
customer = parse_customer(input_data["tool_response"])
if customer.get("verified"):
verified[input_data["session_id"]] = customer["customer_id"]
return {}
async def require_verified(input_data, tool_use_id, context):
if input_data["session_id"] in verified:
return {} # allow
return {"hookSpecificOutput": {"hookEventName": "PreToolUse",
"permissionDecision": "deny",
"permissionDecisionReason": "Call get_customer first."}}
hooks = {"PostToolUse": [HookMatcher(matcher="mcp__support__get_customer", hooks=[record_verified])],
"PreToolUse": [HookMatcher(matcher="mcp__support__process_refund|mcp__support__lookup_order",
hooks=[require_verified])]}
Interactive · the same skip under two enforcement models
Prompt guidance: the skip goes straight to the refund tool.
Programmatic gate: the same skip now ends at a denial.
get_customer; only some of those refund the wrong account. Programmatic gate: the model still skips get_customer as often as before, because nothing changed its choice. The gate changes the outcome: an unverified process_refund call is denied before it executes. SkillOne message, three concerns
Verified customer C-88431 writes that the blender from order #12345 arrived cracked, that #12377 was charged twice, and that a returned espresso machine from #12390 was never refunded. Answering the blender and ending the turn loses two concerns and costs first-contact resolution. The agent should decompose the request into three distinct items and investigate each in parallel using shared context: one get_customer result serves all three, and the three lookup_order calls go out in one turn. Then it synthesizes a unified resolution: $89 refunded, the duplicate $42 refunded, and the $640 refund sent to a human because it exceeds $500.
SkillA handoff a human can act on
That third item is a mid-process escalation. An escalation is the agent handing the case to a person, and human agents lack access to the conversation transcript, so a one-line reason forces them to rebuild the case with the customer. A structured handoff protocol instead sends customer details, root cause analysis, the refund amount and a recommended action, plus what the agent already resolved.
A reason the human cannot act on
escalate_to_human({
"reason": "Customer is unhappy about
a refund. Please assist."
})The human has to contact the customer again.
A structured handoff summary
escalate_to_human({
"customer_id": "C-88431",
"root_cause": "Espresso machine from
#12390 returned; refund never issued.",
"refund_amount": 640.00,
"recommended_action": "Approve full
refund. Over the $500 agent limit.",
"already_resolved": ["$89 refund #12345",
"$42 duplicate charge #12377"]
})The human can approve it without reopening the case.
PreToolUse gate, or a check in the tool itself. No → a prompt instruction is proportionate.- A firmer prompt makes a skip rarer; only code that runs before the tool call makes it impossible.
PostToolUserecords the verified ID, andPreToolUsedenies the refund without it.- A mid-process handoff carries customer ID, root cause, refund amount and recommended action, because the human has no transcript.