agentix.cassette¶
cassette ¶
Record/replay cassettes for deterministic real-model tests.
Hitting a live model in tests is slow, costly, and flaky. :class:CassetteModel
wraps any model: the first run records each model call's response to a JSON
file; later runs replay from the file with no network. Same idea as VCR —
record once, replay forever (delete the file to re-record).
model = CassetteModel("tests/cassettes/weather.json", model=AnthropicModel())
agent = Agent(model=model, system_prompt="...", tools=[...])
outcome = await agent.run("...")
model.save() # writes the cassette in record mode (no-op when replaying)
With mode="auto" (the default) it records when the file is missing and
replays when it exists. Replay is sequential: responses are returned in the
order they were recorded, matching a deterministic loop.
CassetteModel ¶
A :class:~agentix.model.ModelFn that records/replays model responses.
mode: "auto" (record if the file is missing, else replay), "record"
(wrap model and capture), or "replay" (read from the file; no model
needed). Call :meth:save after a recording run to write the file.