PythiloLesson 10 of 12 · progress kept in this browser

Practice in Lab: Project: validate, authorize and replay a dependency-aware tool plan →

Project: validate, authorize and replay a dependency-aware tool plan

A multi-step agent needs a deterministic execution boundary independent of model obedience. This project validates a dependency graph, checks current scopes and exact approved arguments, enforces a new-operation budget and reuses tenant-scoped receipts. The two tools really read and modify a copied local record store. A failure prevents publication of that copy. Approval hashes are lookup identities in a trusted externally supplied set, never self-issued permission. The exercise does not provide durable exactly-once remote effects, a distributed transaction or an actual approval user interface.

import hashlib, json
operation = {'tenant':'a','id':'set1','tool':'set',
             'args':{'key':'x','value':5},'deps':[]}
encoded = json.dumps(operation,sort_keys=True,separators=(',',':'))
print(hashlib.sha256(encoded.encode()).hexdigest()[:12])
Your task

Implement the closed local tools read(key) and set(key,JSON scalar value) on state.records[tenant]. Each plan operation has exactly id,tool,args,deps; IDs and dependencies are unique, all dependencies exist, no cycles. Prevalidate all schemas and current scopes (records:read/write), byte-limit canonical operation payloads to 4096, and require set approval membership. Approval identity is SHA256(canonical JSON {'tenant':tenant,**op}, sorted keys, compact separators, allow_nan=False); approved is a trusted controller-provided allowlist, not a secret or authority created by hashing. Topologically choose the lexicographically smallest ready ID. Verify tenant-scoped receipt fingerprints before reuse. Budget counts new operations only; reject before effects. Execute on a deep copy, return state,order,outputs,executed; exceptions preserve original state. Receipts store fingerprint,result by tenant and operation ID.