Skip to content
Agent Field Notes
Course contentsExpand a topic to choose a lesson.

SYSTEMATIC LEARNING / FOUR-LEVEL COURSE

Combine deterministic workflows with bounded exploration

Choose a recoverable orchestration structure around defined processes, dynamic exploration, checkpoints, and manual approvals.

Learning objectives: Known business rules should determine which paths are allowed, and the model only explores unknown steps within the allowed range. Graphs improve process observability, and loops provide local adaptability; neither replaces the idempotency and version acceptance of external writes.

Content checked: 2026-10-30 · Each level has independent explanations, tasks and inspections

Choose a starting point based on your familiarity with this topic. Current level: Implementation · Build it. After completing the task, continue to the next level. Reading and self-checks alone do not establish mastery.

On this level

Review the prerequisites

Suitable for: Backend developers learning Agent applications.

Combine deterministic workflows with bounded exploration
Known business rules should determine which paths are allowed, and the model only explores unknown steps within the allowed range. Graphs improve process observability, and loops provide local adaptability; neither replaces the idempotency and version acceptance of external writes.

How does the mechanism work?

Step-by-step explanation
  1. Parallel nodes modify the evidence list at the same time. How should they be merged?

    Parallel graphs turn sequential reads and writes into a merge problem, requiring explicit semantics for shared fields.

  2. Recovery will rerun the node. What will happen if a notification is sent before approval?

    The recovery point determines which code is replayed. Persistence alone does not ensure that external actions execute only once.

  3. How to prevent the draft you see during approval from being different from the published content?

    Content may change between the review node and the publishing node.

Implementation · Build it

Implement and check the complete contract

Objectives of this level: Implement ordered control decisions and an approval checkpoint.

Visual guide · Where the next action is chosen

Where the next action is chosen

Both modes use the same authority and budget boundaries. This pure selector dispatches nothing; model_stop ends the loop without proving business completion. Select the figure to open it at full size.

Read the full contract before coding

The following preserves the existing local function, exact shape rules, output precedence and fixed inputs. Implement it in your own module, retain the first failed report, then explain what the adapter must additionally prove in a real deployment.

Derive the invariant

A workflow can fix business transitions while an Agent loop chooses exploratory work. Both need an outer contract: a model proposal cannot approve itself, exhaust unlimited turns, or turn a sent refund into a completed task.

Executable entry and responsibility

Same after-sales project: ticket-1 belongs to tenant A. Junior responsibility derives input/failure boundaries; intermediate responsibility implements and repairs the function; senior responsibility owns integration facts and recovery tradeoffs. These are responsibilities, not the four tracks or a calibrated hiring ladder. Python3.9+ standard library; extract the package and keep lab_runner.py beside cases/. Scaffold refuses overwrites.

  • https://ai.lwkjob.com/lab/extended-practice/README.md
  • https://ai.lwkjob.com/lab/extended-practice/lab_runner.py
  • https://ai.lwkjob.com/lab/extended-practice/cases/graph-vs-agent-loop.json
  • https://ai.lwkjob.com/downloads/extended-agent-practice-v1.zip
python3 lab_runner.py scaffold --course graph-vs-agent-loop --out control_action_student.py
python3 lab_runner.py grade --course graph-vs-agent-loop --module control_action_student.py --out graph-vs-agent-loop-report.json
def control_action(payload):
    """Implement the public contract; disclose assistance used."""
    raise NotImplementedError("graph-vs-agent-loop")

Complete function contract

control_action(payload) accepts exactly mode (graph/loop), tenant (nonempty string), principal, phase, proposal, budget, steps and max_steps. phase is retrieve/draft/approve/execute/reconcile/done. principal has exactly nonempty tenant and strict bool approved. proposal has exactly tool (search/draft/refund/finish) and args with exactly nonempty tenant plus operation_key (null/nonempty string). budget has exactly remaining/cost (strict nonnegative ints). steps is strict nonnegative int; max_steps strict positive int. Shape errors are ValueError("input_shape").

Return exactly decision, reason, next_phase and tool. Default next_phase is unchanged; tool defaults null. Reject tenant disagreement among principal/proposal/task first: deny/tenant_mismatch. finish in done→stop/completed; finish in other loop phases→stop/model_stop with phase unchanged (not business completion); graph finish before done→deny/invalid_transition. Next, steps>=max_steps→pause/step_limit. Non-finish work in done/reconcile is deny/invalid_transition.

Graph allows retrieve→search, draft→draft, approve/execute→refund; other pairs deny/invalid_transition. Loop permits repeated search/draft before execute; search/draft in execute are invalid. For refund, only approve/execute are valid, then require a key (deny/write_key_required), then current approved=True (otherwise pause/approval_required). Approved approve advances to execute as advance/approval_checkpoint with tool=null; it dispatches no write and is not charged against cost. For any actual tool candidate, cost>remaining pauses/budget_exhausted. Otherwise allow/dispatch_candidate with the proposed tool; graph search advances to draft, graph draft to approve, loop search/draft keeps phase, refund advances only to reconcile, never directly to done.

principal and phase are trusted current server facts, not model-created approval. This pure function selects candidates; it neither decrements actual budgets, commits state, calls tools nor rechecks permissions atomically at a remote write. The same hard authority/budget boundaries apply to both modes. The control policy is authored here, not a verbatim LangGraph runtime implementation.

Three public inputs and exact expectations

graph-search-progress

{
  "input": {
    "mode": "graph",
    "tenant": "A",
    "principal": {
      "tenant": "A",
      "approved": true
    },
    "phase": "retrieve",
    "proposal": {
      "tool": "search",
      "args": {
        "tenant": "A",
        "operation_key": null
      }
    },
    "budget": {
      "remaining": 5,
      "cost": 2
    },
    "steps": 0,
    "max_steps": 4
  },
  "expected": {
    "decision": "allow",
    "reason": "dispatch_candidate",
    "next_phase": "draft",
    "tool": "search"
  },
  "error": null
}

unapproved-write-pauses

{
  "input": {
    "mode": "graph",
    "tenant": "A",
    "principal": {
      "tenant": "A",
      "approved": false
    },
    "phase": "execute",
    "proposal": {
      "tool": "refund",
      "args": {
        "tenant": "A",
        "operation_key": "refund-1"
      }
    },
    "budget": {
      "remaining": 5,
      "cost": 2
    },
    "steps": 0,
    "max_steps": 4
  },
  "expected": {
    "decision": "pause",
    "reason": "approval_required",
    "next_phase": "execute",
    "tool": null
  },
  "error": null
}

loop-stop-is-not-completion

{
  "input": {
    "mode": "loop",
    "tenant": "A",
    "principal": {
      "tenant": "A",
      "approved": true
    },
    "phase": "retrieve",
    "proposal": {
      "tool": "finish",
      "args": {
        "tenant": "A",
        "operation_key": null
      }
    },
    "budget": {
      "remaining": 5,
      "cost": 2
    },
    "steps": 0,
    "max_steps": 4
  },
  "expected": {
    "decision": "stop",
    "reason": "model_stop",
    "next_phase": "retrieve",
    "tool": null
  },
  "error": null
}

Scope and evidence

All cases are public fixed local simulations. The grader imports and calls your function, checks exact JSON types (bool is not int), immutable input and no dict/list aliases in the return. Return0 only when all cases pass; return1 for contract failures; malformed CLI/overwrite returns2. It records input, expected/actual/error, source/module/case hashes and Python version. Five seconds is a hang guard, not performance evidence. No model, remote tool, production load, cryptographic receipt validation or real learner outcomes were measured. Submit your source, initial red report, personal diff, rerun report and a short tradeoff note; published expected values and author calibration do not prove independent mastery.

code example

Implement the function contract · unapproved-write-pauses

A workflow can fix business transitions while an Agent loop chooses exploratory work. Both need an outer contract: a model proposal cannot approve itself, exhaust unlimited turns, or turn a sent refund into a completed task.

{
  "input": {
    "mode": "graph",
    "tenant": "A",
    "principal": {
      "tenant": "A",
      "approved": false
    },
    "phase": "execute",
    "proposal": {
      "tool": "refund",
      "args": {
        "tenant": "A",
        "operation_key": "refund-1"
      }
    },
    "budget": {
      "remaining": 5,
      "cost": 2
    },
    "steps": 0,
    "max_steps": 4
  },
  "expected": {
    "decision": "pause",
    "reason": "approval_required",
    "next_phase": "execute",
    "tool": null
  },
  "error": null
}

Acceptance task for this level

Implement control_action in control_action_student.py without copying a public solver; run every fixed case and retain the first failed report before repair.

Acceptance self-checks

Reading this browser’s record…

Hide the answer and check your understanding

Why does an allowed refund move only to reconcile?

Further explanations and practice

When encountering unfamiliar principles, first read the implementation, continuous questioning and migration cases, and then independently explain the premise and boundaries. Answers and notes are saved to the original account record.

All linked explanations and exercises (1 )

Sources and verification scope

The principles are based on public information; the numbers, cases and tasks are the teaching design of this website. Offline experiments verify the range noted on this page, and the learning effect still needs to be judged through independent tasks and feedback.