tapedeck-llm 0.2.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 E'Angelo
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,227 @@
1
+ Metadata-Version: 2.4
2
+ Name: tapedeck-llm
3
+ Version: 0.2.0
4
+ Summary: Flight recorder for LLM agents: record once, replay forever, diff what drifted. Zero dependencies.
5
+ Author: E'Angelo
6
+ License: MIT
7
+ Project-URL: Repository, https://github.com/EAnge1o/tapedeck
8
+ Project-URL: Issues, https://github.com/EAnge1o/tapedeck/issues
9
+ Keywords: llm,agent,replay,testing,observability,regression
10
+ Classifier: Development Status :: 4 - Beta
11
+ Classifier: Intended Audience :: Developers
12
+ Classifier: License :: OSI Approved :: MIT License
13
+ Classifier: Programming Language :: Python :: 3
14
+ Classifier: Framework :: Pytest
15
+ Classifier: Topic :: Software Development :: Testing
16
+ Requires-Python: >=3.10
17
+ Description-Content-Type: text/markdown
18
+ License-File: LICENSE
19
+ Provides-Extra: openai
20
+ Requires-Dist: openai>=1.40; extra == "openai"
21
+ Provides-Extra: anthropic
22
+ Requires-Dist: anthropic>=0.34; extra == "anthropic"
23
+ Provides-Extra: pytest
24
+ Requires-Dist: pytest>=8; extra == "pytest"
25
+ Dynamic: license-file
26
+
27
+ # tapedeck
28
+
29
+ <img src="docs/logo.svg" alt="tapedeck" width="420" align="center" />
30
+
31
+ [![ci](https://github.com/EAnge1o/tapedeck/actions/workflows/ci.yml/badge.svg)](https://github.com/EAnge1o/tapedeck/actions/workflows/ci.yml)
32
+ [![PyPI](https://img.shields.io/pypi/v/tapedeck-llm)](https://pypi.org/project/tapedeck-llm/)
33
+ [![Python](https://img.shields.io/badge/Python-3.10%2B-blue.svg)](https://python.org/)
34
+ [![Dependency](https://img.shields.io/badge/dependencies-0-informational.svg)]()
35
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](LICENSE)
36
+
37
+ **tapedeck** is a **flight recorder** for LLM agents: record a run once (REC ⏺), replay it offline forever (PLAY ▶), and diff exactly where behavior drifted (⏩).
38
+
39
+ > Everyone who has shipped an agent knows the same night: **the agent worked yesterday, you changed one line of prompt today, and now it's broken.** Rerunning costs money, ten reruns still don't reproduce it, and the logs are a wall of prints. tapedeck records the whole run — every model call, every tool call, every usage block — as versioned JSONL. From then on, replay costs $0.00 and is byte-for-byte deterministic, and one command diffs two runs to tell you **which step, which call, which value changed**.
40
+
41
+ Zero dependencies: pure Python standard library (even the tests are `unittest`). Nothing is uploaded anywhere — a trace is a local file you can commit, `cat`, and `rsync`.
42
+
43
+ ![tapedeck demo: record / replay / diff, rendered from real command output](docs/demo.svg)
44
+
45
+ *(The screenshot is rendered from real command output by `docs/make_demo_svg.py` — not staged.)*
46
+
47
+ 中文文档:[README.zh-CN.md](README.zh-CN.md)
48
+
49
+ ## How it works
50
+
51
+ ```mermaid
52
+ flowchart LR
53
+ A["Your agent<br/>tape.call(...)"] -->|"live run"| B["RecordingTape<br/>REC ⏺"]
54
+ A -->|"after a code change"| C["ReplayingTape<br/>PLAY ▶<br/>0 API calls"]
55
+ B --> D["trace.jsonl<br/>+ meta.json"]
56
+ C -.->|"byte-for-byte"| D
57
+ B --> E["tapedeck diff<br/>first drifted step"]
58
+ F["second recording"] --> E
59
+ E -->|"exit 0 / 1 / 2"| G["CI ✅ ❌"]
60
+ ```
61
+
62
+ ## 30 seconds
63
+
64
+ ```bash
65
+ pip install tapedeck-llm # or drop the tapedeck/ folder into your project
66
+ python examples/demo_agent.py --mode record --scenario stable
67
+ python examples/demo_agent.py --mode record --scenario drift # someone changed the discount policy
68
+ python examples/demo_agent.py --mode replay # offline replay, $0.00
69
+ python -m tapedeck diff demo-stable demo-drift
70
+ ```
71
+
72
+ Real output (paste the commands above and you get this verbatim):
73
+
74
+ ```
75
+ === replay ===
76
+ Your coffee is $3.50; with the 10% member discount you pay $6.30.
77
+
78
+ [replayed '20261026-151919-demo-stable': served 4 steps, 0 live calls, $0.00 spent]
79
+
80
+ === diff demo-stable demo-drift ===
81
+ run A: demo-stable (4 steps)
82
+ run B: demo-drift (4 steps)
83
+ step 2 (tool:compute_total) output:
84
+ A: 6.3
85
+ B: 5.6
86
+ context (steps 0..1):
87
+ step 0 (model:model.plan) input: []
88
+ step 1 (tool:get_price) input: []
89
+ run A: $0.0001
90
+ run B: $0.0001
91
+ ```
92
+
93
+ `diff` exit codes are designed for CI: `0` identical, `1` output drift, `2` structural drift (steps added or removed).
94
+
95
+ ## Watch your SDK client (no code changes)
96
+
97
+ Refactoring every call into `tape.call` is honest but invasive. If your agent talks to a provider SDK directly, hand the client to the tape instead — the code keeps reading like plain SDK calls:
98
+
99
+ ```python
100
+ import tapedeck, openai
101
+
102
+ client = openai.OpenAI() # DeepSeek/vLLM/Ollama: same client, your base_url
103
+ with tapedeck.record("chat-v3") as tape:
104
+ client = tape.watch(client) # REC ⏺ -- traced live
105
+ resp = client.chat.completions.create(model="deepseek-chat", messages=msgs)
106
+
107
+ with tapedeck.play("chat-v3") as tape:
108
+ client = tape.watch(client) # PLAY ▶ -- served from tape, no network
109
+ resp = client.chat.completions.create(model="deepseek-chat", messages=msgs)
110
+ ```
111
+
112
+ Intercepted method paths: `chat.completions.create` (the OpenAI SDK, which covers every OpenAI-compatible endpoint — **DeepSeek, vLLM, Ollama** — via `base_url`), `responses.create` (OpenAI Responses API), and `messages.create` (Anthropic), including `stream=True` (recorded chunk by chunk, replayed chunk by chunk). Install per provider: `pip install "tapedeck-llm[openai]"` / `"tapedeck-llm[anthropic]"`. The SDK is imported only here; the core stays dependency-free.
113
+
114
+ Replay rebuilds the SDK's own response objects from the trace (`model_validate`), so `resp.choices[0].message.content` and `resp.usage.prompt_tokens` work exactly as before. If the installed SDK has drifted from the recording, replay degrades to an attribute shim instead of crashing — content access survives, and strict input matching still flags the request drift.
115
+
116
+ ## In pytest
117
+
118
+ ```python
119
+ def test_agent_replies(tape): # pip install "tapedeck-llm[pytest]"
120
+ reply = my_agent(tape, "what's the price?")
121
+ assert "3.50" in reply
122
+ ```
123
+
124
+ Every test that asks for `tape` leaves a trace under `.tapedeck/runs/` (saved even if the test fails — crashes are data). `tapedeck ls` lists them, `tapedeck diff` compares two of them.
125
+
126
+ ## In CI — the regression test
127
+
128
+ Record once locally, commit the trace (or cache it as an artifact), then make replay a pull-request check:
129
+
130
+ ```yaml
131
+ # .github/workflows/agent-regression.yml
132
+ steps:
133
+ - uses: actions/checkout@v4
134
+ - uses: actions/setup-python@v5
135
+ with: { python-version: "3.12" }
136
+ - run: pip install tapedeck-llm
137
+ - run: python my_agent.py --replay demo-stable # your code, tape.play inside
138
+ - run: |
139
+ python -m tapedeck replay demo-stable
140
+ python -m tapedeck diff demo-stable demo-drift --fail-on-drift # or assert the exit code
141
+ ```
142
+
143
+ `replay` serves recorded outputs — the job spends $0.00 and never touches the network. A diff that drifts fails the check and prints the first diverging step.
144
+
145
+ ## Why not LangSmith / LangFuse
146
+
147
+ | | Cloud observability platforms | **tapedeck** |
148
+ |---|---|---|
149
+ | Position | look at runs (dashboard) | **reproduce runs (recorder)** |
150
+ | Replay | re-calls the LLM (costly, nondeterministic) | **replays recorded outputs (free, deterministic)** |
151
+ | Regression tests | not applicable | `replay` + `diff` exit codes in CI |
152
+ | Data | uploaded to a third party | **local files only** |
153
+ | Integration | SDK + reporting config | two function calls, zero dependencies |
154
+
155
+ The two are complementary, not competing: platforms show trends, tapedeck does forensics. When the question is "what was the exact call sequence of that incident, and how does it differ from last Friday's run", a local file beats a web snapshot.
156
+
157
+ ## Three lines to integrate
158
+
159
+ Agent code faces one interface: `tape.call(kind, name, fn, *args)` — when recording, it executes `fn` and files the result; when replaying, it **returns the recorded value and never calls `fn`** (so replays cost nothing and cannot fail).
160
+
161
+ ```python
162
+ import tapedeck
163
+
164
+ def run_agent(tape, message): # take a tape instead of calling openai yourself
165
+ reply = tape.call("model", "deepseek.chat", chat, messages) # fn = your real call
166
+ return tape.call("tool", "postprocess", lambda: reply.strip())
167
+
168
+ with tapedeck.record("chat-v3", redact=tapedeck.Redactor()) as tape: # REC: saved on exit
169
+ run_agent(tape, "hello")
170
+
171
+ with tapedeck.play("chat-v3") as tape: # PLAY: free regression test
172
+ run_agent(tape, "hello") # step count verified on exit
173
+ ```
174
+
175
+ Integration principle: **model calls and side-effectful tool calls go through the tape; pure functions don't.** Usage is recorded with each model call (whatever the provider returned), and cost is converted through a price table you own.
176
+
177
+ ## CLI
178
+
179
+ ```text
180
+ tapedeck ls # all runs: steps / tokens / cost (newest first)
181
+ tapedeck report RUN # per-step table for one run
182
+ tapedeck diff A B # first drift + context + usage/cost comparison
183
+ tapedeck prune --keep 20 # keep only the 20 newest runs
184
+ ```
185
+
186
+ ![tapedeck ls and report, rendered from real command output](docs/report.svg)
187
+
188
+ ## Trace format
189
+
190
+ One directory per run, two plain files (`DESIGN.md` has the full schema):
191
+
192
+ ```
193
+ .tapedeck/runs/20261026-151919-demo-stable/
194
+ meta.json # name, time, host, step count, redaction flag
195
+ trace.jsonl # one step per line: kind/name/input/output/error/usage/wall_ms
196
+ ```
197
+
198
+ ```json
199
+ {"v": 1, "i": 0, "kind": "model", "name": "model.plan",
200
+ "input": [], "output": {"tool": "get_price", "args": "coffee"},
201
+ "usage": {"prompt_tokens": 118, "completion_tokens": 24, "model": "deepseek-chat"},
202
+ "wall_ms": 0.142}
203
+ ```
204
+
205
+ ## Honest boundaries
206
+
207
+ - **Drift captured in closures is invisible.** Replay matches call sites by their inputs; if drift hides in a variable captured by a closure (never passing through parameters), input matching won't flag it — that is exactly what `diff` between two real recordings is for, and why the README suggests passing side-effectful parameters explicitly.
208
+ - **Deterministic replay holds only up to the I/O layer.** If the agent has unseeded randomness or reads the clock internally, replay may diverge from the recording — the shared boundary of every record/replay tool (VCR.py, respx).
209
+ - **SDK interception has limits.** Requests must be JSON-able (messages, tools, sampling params are; pydantic classes and binary payloads are not — those record as `repr` and replay as an input-mismatch drift, which is the honest signal). Streaming calls land on tape only after the stream is consumed. And if the installed SDK no longer validates a recording, replay serves an attribute shim — response-shape access works, `isinstance` checks don't.
210
+ - **No monkeypatching behind your back.** `tape.watch(client)` is explicit, scoped, and returns a proxy — the original client is never mutated.
211
+
212
+ ## Roadmap
213
+
214
+ - [x] OpenAI / DeepSeek / Anthropic auto-interception (`tape.watch`, optional extras)
215
+ - [x] pytest fixture (`tapedeck-llm[pytest]`)
216
+ - [ ] `tapedeck replay` lenient mode on the CLI (resume live from the first drift)
217
+ - [ ] trace signing (tamper-evident hash chain)
218
+
219
+ ## Design trade-offs
220
+
221
+ See [DESIGN.md](DESIGN.md): why traces are JSONL instead of SQLite, why steps are aligned by position instead of content, why redaction defaults off while replay defaults strict.
222
+
223
+ ## Same series
224
+
225
+ [nimbus-infer](https://github.com/EAnge1o/nimbus-infer) · [nimbus-infer-rs](https://github.com/EAnge1o/nimbus-infer-rs) · [nimbus-vm](https://github.com/EAnge1o/nimbus-vm) · [nimbus-kv](https://github.com/EAnge1o/nimbus-kv) — tapedeck is the first tool in the series aimed at **product and workflow** rather than an engine: the same zero-dependency stance, delivering a smoother workflow instead of a runtime.
226
+
227
+ Sister project [mocktape](https://github.com/EAnge1o/mocktape): the same "record once, replay offline" idea applied to the **HTTP layer** — real APIs recorded into readable YAML cassettes for frontend/integration testing, with closest-match diagnostics on 404. mocktape handles HTTP traffic, tapedeck handles agent decisions; neither knows the other exists, but they often show up in the same test suite.
@@ -0,0 +1,201 @@
1
+ # tapedeck
2
+
3
+ <img src="docs/logo.svg" alt="tapedeck" width="420" align="center" />
4
+
5
+ [![ci](https://github.com/EAnge1o/tapedeck/actions/workflows/ci.yml/badge.svg)](https://github.com/EAnge1o/tapedeck/actions/workflows/ci.yml)
6
+ [![PyPI](https://img.shields.io/pypi/v/tapedeck-llm)](https://pypi.org/project/tapedeck-llm/)
7
+ [![Python](https://img.shields.io/badge/Python-3.10%2B-blue.svg)](https://python.org/)
8
+ [![Dependency](https://img.shields.io/badge/dependencies-0-informational.svg)]()
9
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](LICENSE)
10
+
11
+ **tapedeck** is a **flight recorder** for LLM agents: record a run once (REC ⏺), replay it offline forever (PLAY ▶), and diff exactly where behavior drifted (⏩).
12
+
13
+ > Everyone who has shipped an agent knows the same night: **the agent worked yesterday, you changed one line of prompt today, and now it's broken.** Rerunning costs money, ten reruns still don't reproduce it, and the logs are a wall of prints. tapedeck records the whole run — every model call, every tool call, every usage block — as versioned JSONL. From then on, replay costs $0.00 and is byte-for-byte deterministic, and one command diffs two runs to tell you **which step, which call, which value changed**.
14
+
15
+ Zero dependencies: pure Python standard library (even the tests are `unittest`). Nothing is uploaded anywhere — a trace is a local file you can commit, `cat`, and `rsync`.
16
+
17
+ ![tapedeck demo: record / replay / diff, rendered from real command output](docs/demo.svg)
18
+
19
+ *(The screenshot is rendered from real command output by `docs/make_demo_svg.py` — not staged.)*
20
+
21
+ 中文文档:[README.zh-CN.md](README.zh-CN.md)
22
+
23
+ ## How it works
24
+
25
+ ```mermaid
26
+ flowchart LR
27
+ A["Your agent<br/>tape.call(...)"] -->|"live run"| B["RecordingTape<br/>REC ⏺"]
28
+ A -->|"after a code change"| C["ReplayingTape<br/>PLAY ▶<br/>0 API calls"]
29
+ B --> D["trace.jsonl<br/>+ meta.json"]
30
+ C -.->|"byte-for-byte"| D
31
+ B --> E["tapedeck diff<br/>first drifted step"]
32
+ F["second recording"] --> E
33
+ E -->|"exit 0 / 1 / 2"| G["CI ✅ ❌"]
34
+ ```
35
+
36
+ ## 30 seconds
37
+
38
+ ```bash
39
+ pip install tapedeck-llm # or drop the tapedeck/ folder into your project
40
+ python examples/demo_agent.py --mode record --scenario stable
41
+ python examples/demo_agent.py --mode record --scenario drift # someone changed the discount policy
42
+ python examples/demo_agent.py --mode replay # offline replay, $0.00
43
+ python -m tapedeck diff demo-stable demo-drift
44
+ ```
45
+
46
+ Real output (paste the commands above and you get this verbatim):
47
+
48
+ ```
49
+ === replay ===
50
+ Your coffee is $3.50; with the 10% member discount you pay $6.30.
51
+
52
+ [replayed '20261026-151919-demo-stable': served 4 steps, 0 live calls, $0.00 spent]
53
+
54
+ === diff demo-stable demo-drift ===
55
+ run A: demo-stable (4 steps)
56
+ run B: demo-drift (4 steps)
57
+ step 2 (tool:compute_total) output:
58
+ A: 6.3
59
+ B: 5.6
60
+ context (steps 0..1):
61
+ step 0 (model:model.plan) input: []
62
+ step 1 (tool:get_price) input: []
63
+ run A: $0.0001
64
+ run B: $0.0001
65
+ ```
66
+
67
+ `diff` exit codes are designed for CI: `0` identical, `1` output drift, `2` structural drift (steps added or removed).
68
+
69
+ ## Watch your SDK client (no code changes)
70
+
71
+ Refactoring every call into `tape.call` is honest but invasive. If your agent talks to a provider SDK directly, hand the client to the tape instead — the code keeps reading like plain SDK calls:
72
+
73
+ ```python
74
+ import tapedeck, openai
75
+
76
+ client = openai.OpenAI() # DeepSeek/vLLM/Ollama: same client, your base_url
77
+ with tapedeck.record("chat-v3") as tape:
78
+ client = tape.watch(client) # REC ⏺ -- traced live
79
+ resp = client.chat.completions.create(model="deepseek-chat", messages=msgs)
80
+
81
+ with tapedeck.play("chat-v3") as tape:
82
+ client = tape.watch(client) # PLAY ▶ -- served from tape, no network
83
+ resp = client.chat.completions.create(model="deepseek-chat", messages=msgs)
84
+ ```
85
+
86
+ Intercepted method paths: `chat.completions.create` (the OpenAI SDK, which covers every OpenAI-compatible endpoint — **DeepSeek, vLLM, Ollama** — via `base_url`), `responses.create` (OpenAI Responses API), and `messages.create` (Anthropic), including `stream=True` (recorded chunk by chunk, replayed chunk by chunk). Install per provider: `pip install "tapedeck-llm[openai]"` / `"tapedeck-llm[anthropic]"`. The SDK is imported only here; the core stays dependency-free.
87
+
88
+ Replay rebuilds the SDK's own response objects from the trace (`model_validate`), so `resp.choices[0].message.content` and `resp.usage.prompt_tokens` work exactly as before. If the installed SDK has drifted from the recording, replay degrades to an attribute shim instead of crashing — content access survives, and strict input matching still flags the request drift.
89
+
90
+ ## In pytest
91
+
92
+ ```python
93
+ def test_agent_replies(tape): # pip install "tapedeck-llm[pytest]"
94
+ reply = my_agent(tape, "what's the price?")
95
+ assert "3.50" in reply
96
+ ```
97
+
98
+ Every test that asks for `tape` leaves a trace under `.tapedeck/runs/` (saved even if the test fails — crashes are data). `tapedeck ls` lists them, `tapedeck diff` compares two of them.
99
+
100
+ ## In CI — the regression test
101
+
102
+ Record once locally, commit the trace (or cache it as an artifact), then make replay a pull-request check:
103
+
104
+ ```yaml
105
+ # .github/workflows/agent-regression.yml
106
+ steps:
107
+ - uses: actions/checkout@v4
108
+ - uses: actions/setup-python@v5
109
+ with: { python-version: "3.12" }
110
+ - run: pip install tapedeck-llm
111
+ - run: python my_agent.py --replay demo-stable # your code, tape.play inside
112
+ - run: |
113
+ python -m tapedeck replay demo-stable
114
+ python -m tapedeck diff demo-stable demo-drift --fail-on-drift # or assert the exit code
115
+ ```
116
+
117
+ `replay` serves recorded outputs — the job spends $0.00 and never touches the network. A diff that drifts fails the check and prints the first diverging step.
118
+
119
+ ## Why not LangSmith / LangFuse
120
+
121
+ | | Cloud observability platforms | **tapedeck** |
122
+ |---|---|---|
123
+ | Position | look at runs (dashboard) | **reproduce runs (recorder)** |
124
+ | Replay | re-calls the LLM (costly, nondeterministic) | **replays recorded outputs (free, deterministic)** |
125
+ | Regression tests | not applicable | `replay` + `diff` exit codes in CI |
126
+ | Data | uploaded to a third party | **local files only** |
127
+ | Integration | SDK + reporting config | two function calls, zero dependencies |
128
+
129
+ The two are complementary, not competing: platforms show trends, tapedeck does forensics. When the question is "what was the exact call sequence of that incident, and how does it differ from last Friday's run", a local file beats a web snapshot.
130
+
131
+ ## Three lines to integrate
132
+
133
+ Agent code faces one interface: `tape.call(kind, name, fn, *args)` — when recording, it executes `fn` and files the result; when replaying, it **returns the recorded value and never calls `fn`** (so replays cost nothing and cannot fail).
134
+
135
+ ```python
136
+ import tapedeck
137
+
138
+ def run_agent(tape, message): # take a tape instead of calling openai yourself
139
+ reply = tape.call("model", "deepseek.chat", chat, messages) # fn = your real call
140
+ return tape.call("tool", "postprocess", lambda: reply.strip())
141
+
142
+ with tapedeck.record("chat-v3", redact=tapedeck.Redactor()) as tape: # REC: saved on exit
143
+ run_agent(tape, "hello")
144
+
145
+ with tapedeck.play("chat-v3") as tape: # PLAY: free regression test
146
+ run_agent(tape, "hello") # step count verified on exit
147
+ ```
148
+
149
+ Integration principle: **model calls and side-effectful tool calls go through the tape; pure functions don't.** Usage is recorded with each model call (whatever the provider returned), and cost is converted through a price table you own.
150
+
151
+ ## CLI
152
+
153
+ ```text
154
+ tapedeck ls # all runs: steps / tokens / cost (newest first)
155
+ tapedeck report RUN # per-step table for one run
156
+ tapedeck diff A B # first drift + context + usage/cost comparison
157
+ tapedeck prune --keep 20 # keep only the 20 newest runs
158
+ ```
159
+
160
+ ![tapedeck ls and report, rendered from real command output](docs/report.svg)
161
+
162
+ ## Trace format
163
+
164
+ One directory per run, two plain files (`DESIGN.md` has the full schema):
165
+
166
+ ```
167
+ .tapedeck/runs/20261026-151919-demo-stable/
168
+ meta.json # name, time, host, step count, redaction flag
169
+ trace.jsonl # one step per line: kind/name/input/output/error/usage/wall_ms
170
+ ```
171
+
172
+ ```json
173
+ {"v": 1, "i": 0, "kind": "model", "name": "model.plan",
174
+ "input": [], "output": {"tool": "get_price", "args": "coffee"},
175
+ "usage": {"prompt_tokens": 118, "completion_tokens": 24, "model": "deepseek-chat"},
176
+ "wall_ms": 0.142}
177
+ ```
178
+
179
+ ## Honest boundaries
180
+
181
+ - **Drift captured in closures is invisible.** Replay matches call sites by their inputs; if drift hides in a variable captured by a closure (never passing through parameters), input matching won't flag it — that is exactly what `diff` between two real recordings is for, and why the README suggests passing side-effectful parameters explicitly.
182
+ - **Deterministic replay holds only up to the I/O layer.** If the agent has unseeded randomness or reads the clock internally, replay may diverge from the recording — the shared boundary of every record/replay tool (VCR.py, respx).
183
+ - **SDK interception has limits.** Requests must be JSON-able (messages, tools, sampling params are; pydantic classes and binary payloads are not — those record as `repr` and replay as an input-mismatch drift, which is the honest signal). Streaming calls land on tape only after the stream is consumed. And if the installed SDK no longer validates a recording, replay serves an attribute shim — response-shape access works, `isinstance` checks don't.
184
+ - **No monkeypatching behind your back.** `tape.watch(client)` is explicit, scoped, and returns a proxy — the original client is never mutated.
185
+
186
+ ## Roadmap
187
+
188
+ - [x] OpenAI / DeepSeek / Anthropic auto-interception (`tape.watch`, optional extras)
189
+ - [x] pytest fixture (`tapedeck-llm[pytest]`)
190
+ - [ ] `tapedeck replay` lenient mode on the CLI (resume live from the first drift)
191
+ - [ ] trace signing (tamper-evident hash chain)
192
+
193
+ ## Design trade-offs
194
+
195
+ See [DESIGN.md](DESIGN.md): why traces are JSONL instead of SQLite, why steps are aligned by position instead of content, why redaction defaults off while replay defaults strict.
196
+
197
+ ## Same series
198
+
199
+ [nimbus-infer](https://github.com/EAnge1o/nimbus-infer) · [nimbus-infer-rs](https://github.com/EAnge1o/nimbus-infer-rs) · [nimbus-vm](https://github.com/EAnge1o/nimbus-vm) · [nimbus-kv](https://github.com/EAnge1o/nimbus-kv) — tapedeck is the first tool in the series aimed at **product and workflow** rather than an engine: the same zero-dependency stance, delivering a smoother workflow instead of a runtime.
200
+
201
+ Sister project [mocktape](https://github.com/EAnge1o/mocktape): the same "record once, replay offline" idea applied to the **HTTP layer** — real APIs recorded into readable YAML cassettes for frontend/integration testing, with closest-match diagnostics on 404. mocktape handles HTTP traffic, tapedeck handles agent decisions; neither knows the other exists, but they often show up in the same test suite.
@@ -0,0 +1,43 @@
1
+ [build-system]
2
+ requires = ["setuptools>=68"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ # PyPI note: the name "tapedeck" has been taken on PyPI since 2015 by an
7
+ # unrelated music player. The project is "tapedeck", the distribution is
8
+ # "tapedeck-llm"; `pip install tapedeck-llm` still gives you the
9
+ # `tapedeck` package and the `tapedeck` CLI.
10
+ name = "tapedeck-llm"
11
+ version = "0.2.0"
12
+ description = "Flight recorder for LLM agents: record once, replay forever, diff what drifted. Zero dependencies."
13
+ readme = "README.md"
14
+ requires-python = ">=3.10"
15
+ license = { text = "MIT" }
16
+ authors = [{ name = "E'Angelo" }]
17
+ keywords = ["llm", "agent", "replay", "testing", "observability", "regression"]
18
+ classifiers = [
19
+ "Development Status :: 4 - Beta",
20
+ "Intended Audience :: Developers",
21
+ "License :: OSI Approved :: MIT License",
22
+ "Programming Language :: Python :: 3",
23
+ "Framework :: Pytest",
24
+ "Topic :: Software Development :: Testing",
25
+ ]
26
+
27
+ [project.urls]
28
+ Repository = "https://github.com/EAnge1o/tapedeck"
29
+ Issues = "https://github.com/EAnge1o/tapedeck/issues"
30
+
31
+ [project.scripts]
32
+ tapedeck = "tapedeck.cli:main"
33
+
34
+ [project.optional-dependencies]
35
+ openai = ["openai>=1.40"]
36
+ anthropic = ["anthropic>=0.34"]
37
+ pytest = ["pytest>=8"]
38
+
39
+ [project.entry-points.pytest11]
40
+ tapedeck = "tapedeck.pytest_plugin"
41
+
42
+ [tool.setuptools.packages.find]
43
+ include = ["tapedeck*"]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,74 @@
1
+ """tapedeck -- a flight recorder for LLM agents.
2
+
3
+ Record a live agent run once, then replay it offline forever: deterministic,
4
+ free, CI-friendly. Diff any two runs to find the first step where behavior
5
+ drifted, with token and cost accounting per model.
6
+
7
+ import tapedeck
8
+
9
+ with tapedeck.record("chat-v3") as tape:
10
+ answer = my_agent(tape, user_message) # every tape.call is traced
11
+
12
+ # ... later, on a changed codebase, in CI, with zero API spend:
13
+ with tapedeck.play("chat-v3") as tape:
14
+ answer = my_agent(tape, user_message) # serves recorded outputs
15
+ """
16
+
17
+ from .costs import total_cost
18
+ from .diff import diff_runs
19
+ from .redact import Redactor
20
+ from .session import Event, RecordingTape, ReplayDrift, ReplayingTape
21
+ from .store import DEFAULT_ROOT, RunStore
22
+
23
+ __version__ = "0.2.0"
24
+
25
+ __all__ = [
26
+ "record", "play", "load_run", "Redactor", "RecordingTape", "ReplayingTape",
27
+ "ReplayDrift", "Event", "RunStore", "diff_runs", "total_cost",
28
+ "DEFAULT_ROOT", "__version__",
29
+ ]
30
+
31
+
32
+ def record(name: str, root=None, redact: Redactor | None = None) -> RecordingTape:
33
+ """Start recording a run named ``name`` into ``root`` (default .tapedeck/runs).
34
+
35
+ Usable as a context manager -- the run is saved on clean exit::
36
+
37
+ with tapedeck.record("chat-v3") as tape:
38
+ my_agent(tape, message)
39
+ """
40
+ store = RunStore(root)
41
+ run_dir = store.new_run_dir(name)
42
+ tape = RecordingTape(redact=redact)
43
+ tape._run_dir = run_dir
44
+ tape._name = name
45
+ tape._root = root
46
+ tape._saved = False
47
+ return tape
48
+
49
+
50
+ def play(ref: str, root=None, strict: bool = True, lenient: bool = False) -> ReplayingTape:
51
+ """Load a recorded run (exact dir, path, or unique name prefix) for replay.
52
+
53
+ Also a context manager; on exit it verifies every recorded step was
54
+ reached, so ``with tapedeck.play("run") as tape:`` *is* the regression test.
55
+ """
56
+ store = RunStore(root)
57
+ run_dir = store.resolve(ref)
58
+ events, _meta = RunStore.read_run(run_dir)
59
+ return ReplayingTape(events=events, strict=strict, lenient=lenient)
60
+
61
+
62
+ def save(tape: RecordingTape, root=None, meta_extra: dict | None = None):
63
+ """Persist a finished recording session to disk."""
64
+ if getattr(tape, "_saved", False):
65
+ return tape._run_dir
66
+ store = RunStore(root if root is not None else getattr(tape, "_root", None))
67
+ tape._saved = True
68
+ return store.write_run(tape._run_dir, tape, tape._name, meta_extra)
69
+
70
+
71
+ def load_run(ref: str, root=None):
72
+ """Read one run as (events, meta) -- the data behind ls/report/diff."""
73
+ store = RunStore(root)
74
+ return RunStore.read_run(store.resolve(ref))
@@ -0,0 +1,4 @@
1
+ from .cli import main
2
+ import sys
3
+
4
+ sys.exit(main())