AI Foundations for Developers COURSE·LESSON 28 OF 410 completed

Workflows, Agents, and State

Decide where flexibility belongs

A fixed workflow defines the next step in code: classify, retrieve, draft, validate. An agentic workflow delegates some step selection to a model, such as deciding which tool to call next. These terms overlap in industry use; describe the actual control flow rather than relying on the label.

Use a fixed workflow when steps are known and predictable. Add model-directed choices where requests genuinely vary and the benefit justifies added failure modes. More autonomy is not automatically more useful.

A bounded agent loop

text
PSEUDOCODE
state = {request, evidence: [], actions: [], status: "working"}
for step in range(5):
    proposal = model.choose_next_action(state)
    if proposal.type == "finish":
        return validate_final_answer(proposal.answer, state)
    validate_and_authorize(proposal)
    outcome = execute_with_timeout(proposal)
    state.actions.append({proposal, outcome})
return hand_off("Step budget reached", state)

The limit of five is an illustrative configuration. Also bound wall-clock time, token use, tool cost, retries, and output size. A loop can otherwise repeatedly retrieve the same missing fact or retry an impossible action.

Rendering diagram…
stateDiagram-v2
  [*] --> Planning
  Planning --> Executing: Valid authorized proposal
  Executing --> Planning: Tool result
  Planning --> AwaitingApproval: Consequential action
  AwaitingApproval --> Executing: User confirms
  Planning --> Complete: Valid final answer
  Planning --> Review: Budget or uncertainty
  Executing --> Review: Unrecoverable failure

State, memory, and checkpoints

Store durable workflow state independently of model-generated text. A checkpoint should record completed actions, tool-call IDs, artifact versions, and pending approvals. Resuming after a crash must not repeat a completed write.

Separate planning from permission. A model can suggest an action without being authorized to perform it. Multi-agent arrangements can divide work, but also multiply coordination, cost, inconsistent assumptions, and data exposure. Start with one measurable workflow.

Checkpoint with answers

What makes an agent loop safe to retry? Durable action state, idempotent tools or idempotency keys, explicit retry rules, and authorization at execution.

Why can “keep trying until successful” be a bad instruction? It has no resource boundary and can hide uncertainty or amplify side effects.

Exercise: A document assistant only needs retrieval followed by an answer. Does it need autonomous planning? Answer: often no. A simple pipeline is easier to evaluate; add planning only for demonstrated requirements.

Learn at your own pace0 / 41 lessons complete