Skip to content

Persist & Replay

Install

Install with storage and replay
pip install "briefcase-ai[storage,replay]"

Live observability (@capture + observe()) only needs the base package. Persistence and replay import briefcase.storage and briefcase.replay, which are gated behind extras — see Installation.

Persist a snapshot

Build a typed DecisionSnapshot, then save it with a storage backend. SqliteBackend.in_memory() is fine for a notebook; use a file path to keep decisions across runs.

  1. Build and save a DecisionSnapshot

    from briefcase import (
    DecisionSnapshot,
    Input,
    ModelParameters,
    Output,
    init,
    )
    from briefcase.storage import SqliteBackend
    init() # start the native runtime
    decision = DecisionSnapshot("classify_ticket")
    decision.add_input(Input("ticket_text", "My invoice is wrong", "string"))
    params = ModelParameters("gpt-4o-mini")
    params.with_provider("openai")
    params.with_parameter("temperature", 0.0)
    decision.with_model_parameters(params)
    output = Output("category", "billing", "string")
    output.with_confidence(0.93)
    decision.add_output(output)
    decision.with_execution_time(12.0)
    backend = SqliteBackend.in_memory() # or SqliteBackend("./decisions.db")
    decision_id = backend.save_decision(decision)
    print(f"Recorded decision {decision_id}")
  2. Replay and compare

    from briefcase.replay import ReplayEngine
    engine = ReplayEngine(backend)
    result = engine.replay(decision_id, "strict")
    print("status:", result.status)
    print("outputs match:", result.outputs_match)
    print("execution time (ms):", result.execution_time_ms)
  3. Verify the result

    ReplayResult exposes .status, .outputs_match, .replay_output, .execution_time_ms, and .policy_violations. Valid replay modes are "strict" and "tolerant".

What’s next

You now have a reloadable, replayable record. Continue into governance and audit when you need controls before the action or proof after the fact.