Append-only JSONL logging creates a complete audit trail for debugging, replay testing, and cost analysis.
Mock Transport for Testing
Query JSONL logs with jq: jq 'select(.event == "tool_call") | {tool_name, latency_ms}' logs/agent.jsonl
Why mocked-model tests are folklore
The most common LLM testing pattern is to mock the model: mock_openai.return_value = "fake response". Tests pass forever. Production breaks anyway because the SDK changed a parameter, the prompt drifted, or the tool schema gained a required field. Mocks pin a fictional model to fictional behavior; reality moves out from under them.
Replay-based testing fixes this. Capture a real session as JSONL. In CI, replay the session events through your code (model output is mocked from the JSONL, not from a fixture). Assert on observable outcomes: final text, tool sequence, total cost. When the SDK or prompt changes, the test fails on the right line — the line that diverged from the captured truth.