Interactive and Long-Horizon Task Evaluation › Anatomy of a stateful environment
Language AI HandbookAll chapters A stateful environment that is usable for evaluation has five components. Writing them down as an explicit contract, before you write any code, is the single most important habit in this chapter.
-
The state schema. A closed enumeration of every field the environment tracks. "Closed" matters: if the state can grow free-form, you cannot reliably verify goals or diff trajectories. For an expense-filing task the state might be: the set of receipts, the set of reports (each with fields and a lifecycle status), a log of submitted actions, and a set of resources consumed (a budget).
-
The action space. A closed set of typed actions with validated arguments.
create_report(receipt_id=...),set_field(report_id=..., field=..., value=...),submit(report_id=...),noop(). Anything outside the set is a parse failure or invalid action, which is itself a signal about the agent. -
The transition semantics. For each (state, action) pair, the next state or an explicit error with a code. Errors are first-class:
REPORT_NOT_FOUND,FIELD_LOCKED,ALREADY_ACCEPTED,BUDGET_EXCEEDED. The evaluator will use these codes to score recovery. -
The goal predicate. A Boolean function of the final state. It should encode everything the task asks for and nothing it does not, which is harder than it sounds (we return to under-specification below).
-
The cost and safety ledger. Every transition may consume a resource (an API call, a token budget, a wall-clock second) and may be irreversible or externally visible (submitting, paying, sending). The ledger lets us compute efficiency and flag unsafe effects.
Each of these five components separates an environment you can trust from one you cannot. The closed state schema is a promise that the evaluator can enumerate every relevant fact; without it, a model could smuggle information through an unanticipated field and a goal check would silently miss it. The typed action space is a promise that "invalid" is a meaningful, detectable category rather than an excuse; a model that emits free-form text has no notion of a malformed action, and so you lose the ability to score whether it understood the interface. First-class error codes turn the environment's rejections into evidence, because an error the agent can read and respond to is a capability probe. The goal predicate is the specification of the task itself, and the ledger is the audit trail that lets you reconstruct what happened. Omit any one of these and the harness will eventually be unable to answer the central question: why did this trajectory fail?
A stateful evaluation environment is a tuple (S, A, T, G, C) where:
S: a closed state schemaA: a typed action spaceT: S × A → S ∪ Error: a deterministic transition function (for a fixed initial state and action sequence)G: S → {0,1}: a goal predicateC: a cost/safety ledger The agent is evaluated over a trajectory(s_0, a_1, ..., a_n), not over a single output.
We now build this for a concrete task. The task will deliberately include:
- ordered prerequisites (a report must be created before it is submitted)
- a recoverable validation error (submitting the default category fails and may be corrected and retried)
- an attempt-based safety rule (a request to accept a second report is denied and logged)
These together exercise all five scoring dimensions.
Comments
Add to the conversation
A question, a correction, or an example from your own work.
No comments yet. Be the first to share your thoughts!