Review the prerequisites
Suitable for: Backend developers learning Agent applications.
- Task contracts and independent acceptance checks
- A harness turns goals into executable boundaries and verifiable artifacts. The model may change the solution, but cannot manufacture success by changing permissions or acceptance criteria. Recovery rebuilds the working view from facts rather than treating a progress summary as authoritative system state.
How does the mechanism work?
Step-by-step explanation
- How to prevent the Agent from modifying the acceptance criteria to pass itself?
When the model controls the candidate implementation, check again whether it also controls the grader.
- A constraint is lost after context compression. How to find out the details at runtime?
Summarization is lossy and hard limits cannot rely solely on model memory.
- What should I do if the recovery record is inconsistent with the current repository version?
Persisted state may lag behind the actual environment, so reconcile facts before resuming.
Implementation · Build it
Implement and check the complete contract
Objectives of this level: Implement a strictly typed outcome contract and stable diagnostic order.
Visual guide · Facts outrank a pass flag
The checker binds terminal state, tenant/task receipts and cost. Fixture labels are trusted inputs here; real receipt provenance needs an independent authority. 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 returned success sentence and a model pass flag do not prove the business task finished. A harness must bind an independent terminal state, tenant/task-scoped receipts and bounded consumption to explicit expected outcomes.
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/harness-contract.json
- https://ai.lwkjob.com/downloads/extended-agent-practice-v1.zip
python3 lab_runner.py scaffold --course harness-contract --out check_harness_student.py
python3 lab_runner.py grade --course harness-contract --module check_harness_student.py --out harness-contract-report.json
def check_harness(payload):
"""Implement the public contract; disclose assistance used."""
raise NotImplementedError("harness-contract")
Complete function contract
check_harness(payload) accepts exactly expected and actual. expected has exactly tenant/task_id (nonempty strings), required_receipts (unique nonempty-string list), max_cost (strict nonnegative int). actual has exactly tenant/task_id, status (success/partial/failed), receipts (list), cost (strict nonnegative int), claimed_passed (strict bool). Each receipt has exactly id/tenant/task_id (nonempty strings), valid (strict bool); receipt IDs must be unique. Every shape error is ValueError("input_shape").
Build matched_receipts from every valid receipt bound to expected tenant/task_id, sorting IDs lexically, including valid extras. claimed_passed is ignored. Return exactly passed, failures and matched_receipts. Accumulate failure codes in this exact order: tenant_mismatch (actual tenant differs), task_mismatch, status_not_success, foreign_receipt (any receipt bound elsewhere), invalid_receipt (any valid=False), missing_receipt (any required ID absent from matched), cost_exceeded (actual.cost>max_cost). Each code appears at most once. passed is true exactly when failures is empty. max_cost equality is allowed. A foreign extra receipt still fails even with all required receipts present.
The fixture's actual/receipt.valid values represent an independent server ledger adapter's facts. This function checks consistency, not remote signature authenticity, semantic answer quality or model self-verification. A model-supplied valid=True must not become an adapter fact. Budget units are teaching integers; this lab does not measure real token invoices or calibrate a statistical evaluator.
Three public inputs and exact expectations
facts-win-over-claimed-false
{
"input": {
"expected": {
"tenant": "A",
"task_id": "ticket-1",
"required_receipts": [
"refund-r1"
],
"max_cost": 5
},
"actual": {
"tenant": "A",
"task_id": "ticket-1",
"status": "success",
"receipts": [
{
"id": "refund-r1",
"tenant": "A",
"task_id": "ticket-1",
"valid": true
}
],
"cost": 3,
"claimed_passed": false
}
},
"expected": {
"passed": true,
"failures": [],
"matched_receipts": [
"refund-r1"
]
},
"error": null
}
claimed-true-missing-receipt
{
"input": {
"expected": {
"tenant": "A",
"task_id": "ticket-1",
"required_receipts": [
"refund-r1"
],
"max_cost": 5
},
"actual": {
"tenant": "A",
"task_id": "ticket-1",
"status": "success",
"receipts": [],
"cost": 3,
"claimed_passed": true
}
},
"expected": {
"passed": false,
"failures": [
"missing_receipt"
],
"matched_receipts": []
},
"error": null
}
foreign-extra-receipt-rejected
{
"input": {
"expected": {
"tenant": "A",
"task_id": "ticket-1",
"required_receipts": [
"refund-r1"
],
"max_cost": 5
},
"actual": {
"tenant": "A",
"task_id": "ticket-1",
"status": "success",
"receipts": [
{
"id": "refund-r1",
"tenant": "A",
"task_id": "ticket-1",
"valid": true
},
{
"id": "foreign-r2",
"tenant": "B",
"task_id": "other",
"valid": true
}
],
"cost": 3,
"claimed_passed": false
}
},
"expected": {
"passed": false,
"failures": [
"foreign_receipt"
],
"matched_receipts": [
"refund-r1"
]
},
"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 · claimed-true-missing-receipt
A returned success sentence and a model pass flag do not prove the business task finished. A harness must bind an independent terminal state, tenant/task-scoped receipts and bounded consumption to explicit expected outcomes.
{
"input": {
"expected": {
"tenant": "A",
"task_id": "ticket-1",
"required_receipts": [
"refund-r1"
],
"max_cost": 5
},
"actual": {
"tenant": "A",
"task_id": "ticket-1",
"status": "success",
"receipts": [],
"cost": 3,
"claimed_passed": true
}
},
"expected": {
"passed": false,
"failures": [
"missing_receipt"
],
"matched_receipts": []
},
"error": null
}
Acceptance task for this level
Implement check_harness in check_harness_student.py without copying a public solver; run every fixed case and retain the first failed report before repair.
Reading this browser’s record…
Hide the answer and check your understanding
What is the exact failure list for missing evidence with otherwise valid facts?
Expand reference derivation
Only missing_receipt. Failure ordering and specificity help reproduce a diagnosis without replacing the whole report by a score.
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.