AI Agents Course · Reliability method

How to Design a Reliable AI Agent Workflow

Design an AI agent workflow with explicit step boundaries, state, retries, idempotency and manual escalation.

Learn the design method, inspect a worked scenario, and test a fresh variation.

AGENT WORKFLOW PREVIEW
Reliability methodDesign → test

Core idea

A timeout is a state to resolve, not permission to repeat a write.

receive → classify → review
execute_once(key)
trace result or escalate
Action needs a boundary.Verify the proposed step before any consequential tool call.

The direct answer

Define each state before connecting the tools.

A reliable AI agent workflow separates classification from action, records state between steps and treats uncertain tool outcomes explicitly. The design should say what happens when an event repeats, an API times out after writing, a reviewer rejects a proposal or the model cannot classify an input. Without those branches, a successful demo can hide a fragile production process.

This page works through inbound request classification with manual escalation. It includes a sequence, failure cases, a state table and a fresh design check. The method is platform-neutral; verify the chosen platform’s persistence and approval capabilities before implementation. Course pricing follows this overview.

Course access

Choose your next step in AI agents.

Review the current course options and access details here.

Heycademy Courses · Coming Soon

Master AI Agents with Heycademy

We’re preparing an interactive learning experience with practical exercises, skill assessments and personalized learning to help you build confidence and master new skills.

Launching soon!
We’re putting the finishing touches on this course. Please check back for updates.

Step boundaries

Make every transition observable.

State model for inbound requests
StateOwnerAllowed workExit condition
receivedIntake serviceValidate event id and source.Unique run created.
classifiedModel plus validatorPropose category and evidence.Accepted confidence/rule or escalation.
pending_reviewWorkflowWait; no consequential write.Exact approval or rejection.
executingAction executorRecheck policy and call bounded tool.Recorded result or uncertain outcome.
completed / escalatedWorkflowStore final trace or handoff.Reviewer can inspect outcome.

State is more than a log line. The workflow must be able to resume after a restart without forgetting whether approval happened or whether a side effect may already have occurred. Microsoft’s agent behavior guidance discusses approval state and idempotent action execution.

Worked sequence

Inbound request with manual escalation.

Input request R-31 says “Please update my delivery address.” The customer identity is verified, but the order has already shipped. The model might classify it as an address change, yet the business rule prohibits an automatic update after dispatch. The workflow should not give the model a general update-order tool.

1. TriggerR-31 with event id.
2. ReadOrder status, scoped.
3. ClassifyPropose address-change.
4. RuleShipped → no auto update.
5. EscalateHuman reviews options.

Expected result: no order mutation, a review ticket with the request and order status, and an audit record explaining why the automatic path stopped. If the same event arrives again, the existing ticket is reused. An implementation can use a deterministic status check after classification, so the model cannot override the shipped-order rule.

Failure table

Plan for what happens when a step fails.

Failure and recovery map
FailureUnsafe responseReliable response
Event delivered twiceStart two runs and create two tickets.Deduplicate using R-31 event id.
Read API times outInvent order status or proceed.Retry bounded read or escalate with unknown status.
Ticket API times out after createBlindly create another ticket.Lookup or retry with same idempotency key.
Reviewer approves then payload changesExecute the changed payload.Invalidate approval and request new review.
Model returns an unrecognised categoryGuess the closest permitted action.Escalate with source context.

Retry policy depends on the tool. A read-only lookup may be retried within a bounded budget. A write needs idempotent execution or a reconciliation lookup. Even an idempotency key requires the downstream service to enforce it; simply putting a key in a prompt does nothing.

Keep building this skill

Turn the design into a tested workflow.

Return to the course options whenever you are ready.

Explore course options →

Repeatable design method

Write the workflow contract before coding.

  1. Define the single job, input schema and expected output.
  2. List tools and give each the smallest useful permission.
  3. Mark which step is model-driven and which checks are deterministic.
  4. Draw the normal, rejected, duplicate and uncertain-completion paths.
  5. Bind approvals to exact action arguments and reviewer identity.
  6. Define bounded retries, idempotency keys and terminal escalation states.
  7. Write acceptance tests for outcome and allowed tool path.

Use a mock executor to test the control flow before connecting live systems. A trace should include event id, state transitions, model proposal, policy check, approval and executor result. The final message alone cannot prove that an external action happened.

Try the changed case

What if the order is still unshipped?

Request R-32 is identical, but the order is not dispatched. A policy allows an address update after an authenticated customer request and human approval. Draft the proposed new address, show old and new values to the reviewer, and require exact approval. Do not let a later model revision silently change the postal code.

Show the design answer

The workflow verifies identity, reads order status, classifies the request and checks the policy. It stores an exact proposed address-change payload in pending_review. On approval, it rechecks current order status and payload version, then calls the constrained update tool once with an idempotency key. A rejection or changed status escalates without write. The audit trace records who approved what and the executor result.

This exercise exposes a subtle point: an approval at time A may not remain valid if the order changes before time B. Revalidate the relevant state immediately before the action.

Measure reliability

Test the trace, not the claim.

Minimum scenario set
TestEvidence of pass
Normal eligible caseOne approved update; correct old and new values.
Shipped orderNo mutation; escalation ticket.
Duplicate eventNo second update or ticket.
Lost write responseOne action after reconciliation.
Changed approval payloadNo execution under stale approval.

Track failures by state and cause so the next design revision is precise. The exercise collection provides more changed-input cases; Microsoft’s agent behavior guidance, OWASP’s excessive-agency guidance and the NIST Generative AI Profile provides current external design guidance.

A compact implementation contract

Make the executor’s promise explicit.

Input: event_id, proposal_version, approved_action, reviewer_id
Preconditions: current policy allows action; approval matches exact args
Executor key: event_id + proposal_version + action_type
On success: persist external_result_id and completed state
On timeout: reconcile by key; never create a new action identity
On denial: record reason and move to escalated state

This is a design contract, not executable code. It clarifies what the action service must guarantee. A model can propose fields, but it cannot define a new executor key or change an approval record after the fact. The application should reject a call that lacks a valid reviewer, action version or current policy check.

For request R-31, the status rule blocks address mutation and produces an escalation. For R-32, approval of the proposed address is only one precondition; the executor must also confirm that the order is still eligible when the call runs. If the order ships while the request is awaiting review, the workflow should stop. This second check prevents a stale approval from silently overriding a changed business state.

FAQ

Questions about this skill.

What is idempotency?

An idempotent action can be repeated with the same identity without creating an additional side effect. The executor must enforce the rule.

Should a model decide whether to retry?

The workflow should own retry limits and side-effect safety. The model can help classify an error, but it should not bypass the executor’s policy.

Why keep a pending-review state?

It makes the exact proposed action durable and allows approval or rejection to be tied to a particular version.

Continue with the course

Build with clear boundaries and evidence.

Review the course options and choose your next learning step.

Take the next step →
Scroll to Top