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

SYSTEMATIC LEARNING / FOUR-LEVEL COURSE

Separate natural-language requests from transaction state

Examine intent understanding, business rules, authorization and traceable execution.

Learning objectives: Models explain appeals and policies, and controlled business facts are required for qualifications, amounts, and transaction completion. Commitment text, generated reply, and real money effects must remain distinct.

Content checked: 2026-10-03 · 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.

Separate natural-language requests from transaction state
Models explain appeals and policies, and controlled business facts are required for qualifications, amounts, and transaction completion. Commitment text, generated reply, and real money effects must remain distinct.

How does the mechanism work?

Step-by-step explanation
  1. The user said that customer service promised a refund last time. Do you believe it?

    A model interprets user statements; explain when those statements can become facts that justify execution.

  2. What should I do if the policy document is inconsistent with the rule service?

    Conflicts between policy explanations and executable rules can affect eligibility decisions.

  3. What content should be passed during manual takeover?

    After pausing automation, retain state that allows the process to continue.

Implementation · Build it

Implement the contract · Separate natural-language requests from transaction state

Objectives of this level: Implement a bounded refund decision with exact approval and amount guards.

Visual guide · Ledger state changes the next step

Ledger state changes the next step

These are fictional refund-planning states, not executed payments. Current tenant and ownership checks precede ledger decisions; a receipt is not settlement. Select the figure to open it at full size.

Same after-sales project

The same after-sales Agent receives a refund request. The model may propose an action, but the trusted principal, current order, merchant rule, approval and ledger decide whether it is permitted. A refund request/receipt is distinct from money arriving; Stripe’s refund lifecycle illustrates why an API acknowledgement is insufficient. These integer-cent fixtures do not contact a payment provider.

The existing capstone main-return creates a return application; it does not execute a refund. These manifests are independent fictional extensions or policy/evidence/counting exercises. They do not add real refunds, publication, model calls or Java execution to the capstone runtime.

Complete function contract

Implement decide_service_action(payload). principal has nonempty tenant/user; order has nonempty tenant/owner, state paid/cancelled/refunded and nonnegative integer amount. payload.amount is a positive integer, operation_key nonempty, now nonnegative integer. rule.eligible is bool and max_auto nonnegative integer. ledger.status is none/unknown/succeeded and ledger.operation_key must equal the request operation_key. approval is null or contains nonempty operation_key, nonnegative integer amount/expires_at. All missing/malformed fields or wrong ledger key raise ValueError:input; no bool is an integer; extras ignored. Return exactly action/reason/operation_key. Priority: principal tenant/user mismatch → deny/identity; succeeded ledger → done/confirmed_effect; unknown → reconcile/unknown_effect; unpaid order, rule ineligible or requested amount > order.amount → reject/business_rule. Otherwise amount > max_auto requires an approval matching operation_key AND amount AND expires_at > now, else request_approval/amount_limit. Remaining case → refund/eligible_authorized. Amount equal to max_auto is eligible for automatic dispatch. No sorting. This planner does not create an effect and assumes current trusted inputs; a web request cannot supply its own principal or ledger.

Every listed input key must exist; explicit null is not an absent key. All returns must be JSON-compatible fresh containers, with exact bool/int distinctions, and leave the input unchanged. Every invalid declared field uses exactly ValueError("input"); this includes malformed nested fields. Do not swallow NotImplementedError or return a self-declared passed flag.

Own blank implementation

Download the full local package, extract it and work in its lab_runner.py directory. Runner and this case manifest are alternatives: save the runner and cases/customer-service-action-design.json with that exact directory layout. The manifest contains all public fixed inputs/expected outputs; it contains no general solution. It is not an unseen assessment. Python 3.9+ and standard library only; no model keys or network calls are needed while grading.

def decide_service_action(payload):
    raise NotImplementedError("Implement the documented contract yourself")
python3 lab_runner.py scaffold --course customer-service-action-design --out student.py
python3 lab_runner.py grade --course customer-service-action-design --module student.py --out report.json

The untouched scaffold must exit 1. Fill the function yourself and rerun; all 13 public checks must pass for exit 0. Submit student.py, the generated report.json, your source diff and one additional condition-changing test. The runner imports and calls your function on each actual payload, compares exact output/error, checks input preservation and container independence, and records runner/cases/student SHA. A manual passed flag is not accepted. Its 5-second process timeout is a hang guard, not an enterprise latency requirement.

code example

Deliver your own function and report

Implement decide_service_action(payload). principal has nonempty tenant/user; order has nonempty tenant/owner, state paid/cancelled/refunded and nonnegative integer amount. payload.amount is a positive integer, operation_key nonempty, now nonnegative integer. rule.eligible is bool and max_auto nonnegative integer. ledger.status is none/unknown/succeeded and ledger.operation_key must equal the request operation_key. approval is null or contains nonempty operation_key, nonnegative integer amount/expires_at. All missing/malformed fields or wrong ledger key raise ValueError:input; no bool is an integer; extras ignored. Return exactly action/reason/operation_key. Priority: principal tenant/user mismatch → deny/identity; succeeded ledger → done/confirmed_effect; unknown → reconcile/unknown_effect; unpaid order, rule ineligible or requested amount > order.amount → reject/business_rule. Otherwise amount > max_auto requires an approval matching operation_key AND amount AND expires_at > now, else request_approval/amount_limit. Remaining case → refund/eligible_authorized. Amount equal to max_auto is eligible for automatic dispatch. No sorting. This planner does not create an effect and assumes current trusted inputs; a web request cannot supply its own principal or ledger.

The exact function and complete inputs are in the main body. Implement from the blank starter, not by copying expected outputs into branches.

Acceptance task for this level

Implement the blank function and submit the real generated report, own code/diff and one changed-condition test; Java candidates additionally deliver their real Java patch/build. Contract: decide_service_action(payload).

Acceptance self-checks

Reading this browser’s record…

Hide the answer and check your understanding

Does an expired approval pass at expires_at == now?

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.