Replay a bounded agent lifecycle
Implement replay_run(events, max_calls) with a single pending call, correlated observations, a tool budget, evidence-required completion, and terminal-state protection.
Your task
- Start in ready with zero calls. Accept a list of dictionaries and a nonnegative exact integer max_calls.
- Support start {type}, call {type,id}, result {type,id,value}, finish {type,answer}, cancel {type}, and error {type,message}; all named data fields must be nonempty strings.
- start moves ready to running. call is allowed only while running, must use a previously unseen ID, consumes budget, and moves to waiting.
- result is allowed only while waiting and must match the pending ID; store its string value and return to running.
- finish is allowed only while running with at least one stored observation, then enters completed. cancel is allowed from any nonterminal state. error is allowed while running or waiting.
- Reject invalid shapes, illegal transitions, budget overflow, and any event after a terminal state with ValueError. Return state, calls, pending, observations, and answer; incomplete traces preserve their current state.
Examples
EXAMPLE 1
Inputstart, call(c1), result(c1,"A7=8"), finish("A7 has 8")
Outputstate=completed, calls=1, pending=None
EXAMPLE 2
Inputstart, call(c1)
Outputstate=waiting, calls=1, pending="c1"
Implement the function, then run the tests.
Ctrl / ⌘ + Enter to test · Shift + Tab leaves editor