tracedojo 0.1.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.
Files changed (45) hide show
  1. tracedojo-0.1.0/.gitignore +5 -0
  2. tracedojo-0.1.0/LICENSE +202 -0
  3. tracedojo-0.1.0/NOTICE +5 -0
  4. tracedojo-0.1.0/PKG-INFO +212 -0
  5. tracedojo-0.1.0/README.md +183 -0
  6. tracedojo-0.1.0/pyproject.toml +58 -0
  7. tracedojo-0.1.0/src/tracedojo/__init__.py +59 -0
  8. tracedojo-0.1.0/src/tracedojo/__main__.py +7 -0
  9. tracedojo-0.1.0/src/tracedojo/_json.py +211 -0
  10. tracedojo-0.1.0/src/tracedojo/cli.py +341 -0
  11. tracedojo-0.1.0/src/tracedojo/clock.py +226 -0
  12. tracedojo-0.1.0/src/tracedojo/compare.py +191 -0
  13. tracedojo-0.1.0/src/tracedojo/demo.py +77 -0
  14. tracedojo-0.1.0/src/tracedojo/errors.py +6 -0
  15. tracedojo-0.1.0/src/tracedojo/langgraph.py +127 -0
  16. tracedojo-0.1.0/src/tracedojo/privacy.py +88 -0
  17. tracedojo-0.1.0/src/tracedojo/py.typed +0 -0
  18. tracedojo-0.1.0/src/tracedojo/reports.py +36 -0
  19. tracedojo-0.1.0/src/tracedojo/runner.py +789 -0
  20. tracedojo-0.1.0/src/tracedojo/schema.py +856 -0
  21. tracedojo-0.1.0/src/tracedojo/signal.py +50 -0
  22. tracedojo-0.1.0/src/tracedojo/summary.py +66 -0
  23. tracedojo-0.1.0/src/tracedojo/templates/__init__.py +0 -0
  24. tracedojo-0.1.0/src/tracedojo/templates/booking/__init__.py +0 -0
  25. tracedojo-0.1.0/src/tracedojo/templates/booking/adapter.py +59 -0
  26. tracedojo-0.1.0/src/tracedojo/templates/booking/workflow.json +106 -0
  27. tracedojo-0.1.0/src/tracedojo/upload.py +146 -0
  28. tracedojo-0.1.0/tests/parity/fixtures/booking.mjs +45 -0
  29. tracedojo-0.1.0/tests/parity/fixtures/booking.py +42 -0
  30. tracedojo-0.1.0/tests/parity/fixtures/checks.mjs +88 -0
  31. tracedojo-0.1.0/tests/parity/fixtures/checks.py +106 -0
  32. tracedojo-0.1.0/tests/parity/fixtures/faults.mjs +87 -0
  33. tracedojo-0.1.0/tests/parity/fixtures/faults.py +83 -0
  34. tracedojo-0.1.0/tests/parity/fixtures/limits.mjs +102 -0
  35. tracedojo-0.1.0/tests/parity/fixtures/limits.py +118 -0
  36. tracedojo-0.1.0/tests/parity/js_bridge.mjs +155 -0
  37. tracedojo-0.1.0/tests/parity/workflows/checks.json +54 -0
  38. tracedojo-0.1.0/tests/parity/workflows/clock.json +14 -0
  39. tracedojo-0.1.0/tests/parity/workflows/limits.json +14 -0
  40. tracedojo-0.1.0/tests/test_cli.py +154 -0
  41. tracedojo-0.1.0/tests/test_json.py +66 -0
  42. tracedojo-0.1.0/tests/test_langgraph.py +148 -0
  43. tracedojo-0.1.0/tests/test_parity.py +455 -0
  44. tracedojo-0.1.0/tests/test_runner.py +198 -0
  45. tracedojo-0.1.0/tests/test_upload.py +76 -0
@@ -0,0 +1,5 @@
1
+ .venv/
2
+ __pycache__/
3
+ .pytest_cache/
4
+ dist/
5
+ *.egg-info/
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
tracedojo-0.1.0/NOTICE ADDED
@@ -0,0 +1,5 @@
1
+ TraceDojo SDK
2
+ Copyright 2026 Syed Arman
3
+
4
+ The SDK and its starter templates are licensed under the Apache License,
5
+ Version 2.0. TraceDojo dashboard code and branding are not included in this grant.
@@ -0,0 +1,212 @@
1
+ Metadata-Version: 2.5
2
+ Name: tracedojo
3
+ Version: 0.1.0
4
+ Summary: Controlled tool failures and state assertions for AI agents
5
+ Project-URL: Homepage, https://tracedojo.com/docs
6
+ Project-URL: Repository, https://github.com/syedarman1/tracedojo-sdk
7
+ Project-URL: Issues, https://github.com/syedarman1/tracedojo-sdk/issues
8
+ Author: Syed Arman
9
+ License-Expression: Apache-2.0
10
+ License-File: LICENSE
11
+ License-File: NOTICE
12
+ Keywords: ai-agents,chaos-engineering,llm-testing,prompt-injection,regression-testing
13
+ Classifier: Development Status :: 3 - Alpha
14
+ Classifier: Intended Audience :: Developers
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Programming Language :: Python :: 3 :: Only
17
+ Classifier: Programming Language :: Python :: 3.10
18
+ Classifier: Programming Language :: Python :: 3.11
19
+ Classifier: Programming Language :: Python :: 3.12
20
+ Classifier: Programming Language :: Python :: 3.13
21
+ Classifier: Programming Language :: Python :: 3.14
22
+ Classifier: Topic :: Software Development :: Testing
23
+ Classifier: Typing :: Typed
24
+ Requires-Python: >=3.10
25
+ Provides-Extra: langgraph
26
+ Requires-Dist: langchain-core>=1.0; extra == 'langgraph'
27
+ Requires-Dist: langgraph>=1.0; extra == 'langgraph'
28
+ Description-Content-Type: text/markdown
29
+
30
+ # TraceDojo for Python
31
+
32
+ **Chaos testing for AI agent tools.**
33
+
34
+ The booking succeeded. The response timed out. Your agent booked it again.
35
+
36
+ TraceDojo runs your agent against tools you simulate in memory, makes a tool call
37
+ fail on purpose, and checks what actually changed in your application's state. Every
38
+ test runs a no-fault control first, a fault the agent never reaches is reported as
39
+ inconclusive instead of passing, and `compare` gates pull requests on regressions
40
+ against the base commit.
41
+
42
+ This is the Python SDK. It writes the same report format as the JavaScript SDK
43
+ (`@tracedojo/sdk`), so the TraceDojo dashboard, `compare`, and the CI gate accept
44
+ reports from either language, and a Python report compares cleanly against a
45
+ JavaScript one for the same workflow.
46
+
47
+ Python 3.10 or later. No runtime dependencies.
48
+
49
+ > Not yet published to PyPI. Install from a checkout:
50
+ > `pip install ./packages/python` (add `[langgraph]` for the LangGraph adapter).
51
+
52
+ ## See a failure and its fix
53
+
54
+ ```sh
55
+ tracedojo demo
56
+ ```
57
+
58
+ It runs a scripted booking agent twice against a lost confirmation. The version
59
+ that makes a new operation key per retry books twice and fails; the version that
60
+ reuses its key passes. Both reports are saved in a new directory under `.tracedojo/`.
61
+
62
+ ## Test your agent
63
+
64
+ A workflow (`workflow.json`) holds the task, the starting state, outcome checks, and
65
+ fault scenarios. It is the same `workflow/1` file the JavaScript SDK reads; see
66
+ [`docs/WORKFLOWS.md`](../../docs/WORKFLOWS.md) for every field. An adapter module
67
+ defines the simulated tools and a factory for your agent:
68
+
69
+ ```python
70
+ # dojo/adapter.py
71
+ from tracedojo import tool
72
+
73
+
74
+ @tool("write")
75
+ def reserve_slot(args, state, context):
76
+ """Only successful writes commit. Mutate the state draft, return a result."""
77
+ key = args.get("operationKey")
78
+ if not key:
79
+ return {"ok": False, "error": {"code": "INVALID_ARGUMENTS", "message": "Provide operationKey.", "retryable": False}}
80
+ if key in state["operations"]:
81
+ return {"ok": True, "data": state["operations"][key]}
82
+ booking = {"id": f"booking_{len(state['bookings']) + 1}", "customerId": args["customerId"], "slot": args["slot"]}
83
+ state["bookings"].append(booking)
84
+ state["operations"][key] = booking
85
+ return {"ok": True, "data": booking}
86
+
87
+
88
+ tools = {"reserve_slot": reserve_slot}
89
+
90
+
91
+ class BookingAgent:
92
+ id = "booking-agent"
93
+ version = "1"
94
+
95
+ async def run(self, context):
96
+ for _attempt in range(3):
97
+ # Route every tool call through context.call and always await it.
98
+ # Reuse one operation key so a retry cannot book twice.
99
+ result = await context.call(
100
+ "reserve_slot", {"customerId": "customer_7", "slot": "slot_42", "operationKey": "one-booking"}
101
+ )
102
+ if isinstance(result, dict) and result["ok"]:
103
+ return {"status": "completed", "message": "Meeting booked.", "output": {"bookingId": result["data"]["id"]}}
104
+ if isinstance(result, dict) and not result["error"]["retryable"]:
105
+ return {"status": "blocked", "message": result["error"]["message"]}
106
+ return {"status": "blocked", "message": "The booking could not be confirmed."}
107
+
108
+
109
+ def create_agent():
110
+ return BookingAgent() # a fresh agent, with fresh conversation state, per trial
111
+ ```
112
+
113
+ ```sh
114
+ tracedojo test --config dojo/workflow.json --adapter dojo/adapter.py --trials 3 --out .tracedojo/report.json
115
+ ```
116
+
117
+ The complete booking starter is in
118
+ [`src/tracedojo/templates/booking`](src/tracedojo/templates/booking).
119
+
120
+ Or from Python:
121
+
122
+ ```python
123
+ from tracedojo import run_workflow, run_workflow_sync, workflow_exit_code
124
+
125
+ batch = run_workflow_sync(workflow_dict, adapter_module, trials=3, commit_sha=None)
126
+ # inside an event loop: batch = await run_workflow(workflow_dict, adapter_module)
127
+ ```
128
+
129
+ ### Faults and checks
130
+
131
+ Faults: `timeout_before`, `timeout_after`, `unavailable`, `malformed`,
132
+ `permission_revoked`, `duplicate_delivery`, `stale_read`, `prompt_injection`, each
133
+ with `occurrence` and `repeat`. Checks: `count`, `equals` (state or completion),
134
+ `unchanged`, `forbidden_tool`, `tool_calls`, `tool_order`. Semantics, limits, and
135
+ statuses are identical to the JavaScript SDK.
136
+
137
+ Model faults (`rate_limited`, `server_error`, `model_timeout`, `stream_cut`,
138
+ `stream_stall`, with `target: "model"`) sit between an agent process and its model
139
+ API, so only the JavaScript proxy runner (`npx tracedojo proxy`) injects them.
140
+ `run_workflow` rejects them, as the JavaScript `runWorkflow` does. The Python SDK
141
+ reads, validates, compares, summarizes, and uploads proxy reports that contain them.
142
+
143
+ ### The agent context
144
+
145
+ | Member | Purpose |
146
+ | --- | --- |
147
+ | `await context.call(tool, args)` | Simulated tool call. Returns `{"ok": True, "data": ...}`, `{"ok": False, "error": {...}}`, or a string for a malformed response. |
148
+ | `context.record_model(detail, payload=None)` | Evaluator-only model telemetry. Never include credentials or private reasoning. |
149
+ | `context.clock.now()`, `await context.clock.sleep(ms)` | Real time, or virtual time when the workflow sets `"clock": {"mode": "virtual"}`. |
150
+ | `context.signal` | Cancellation flag: `aborted`, `throw_if_aborted()`. |
151
+ | `context.task` | The workflow task text. |
152
+ | `context.with_call(fn)` | A copy whose `call` is wrapped, for retry or backoff wrappers. |
153
+
154
+ Tools and `run` may be sync or async. `context.call` starts the call immediately
155
+ and returns an awaitable; a call still pending when the agent finishes is recorded
156
+ as `unawaited_calls`. Use `context.clock.sleep` (not `asyncio.sleep`) so virtual
157
+ time applies. Deadlines are cooperative: a synchronous handler that blocks the event
158
+ loop cannot be interrupted, and adapters are trusted code, not sandboxed.
159
+
160
+ ## Compare, gate, and upload
161
+
162
+ ```sh
163
+ tracedojo compare --base base-report.json --candidate pr-report.json --out comparison.json --summary comparison.md
164
+ TRACEDOJO_UPLOAD_TOKEN=... tracedojo upload report.json --url https://tracedojo.com --project PROJECT_UUID
165
+ ```
166
+
167
+ Exit codes: 0 passed, 1 failed checks or regressions, 2 invalid input, 3 incomplete
168
+ or inconclusive evidence. Output files must be new; existing evidence is never
169
+ overwritten. Reports are redacted with the same patterns as the JavaScript SDK
170
+ before they are written.
171
+
172
+ The base and candidate reports can come from either SDK. The JavaScript
173
+ `npx tracedojo compare` and this `tracedojo compare` produce identical results.
174
+
175
+ ## LangGraph
176
+
177
+ ```python
178
+ from tracedojo.langgraph import LangGraphAgent
179
+
180
+ def create_agent():
181
+ return LangGraphAgent(
182
+ "support-agent",
183
+ "2026-11-15",
184
+ [reserve_slot_tool], # your real LangChain tools; only name, description, and schema are used
185
+ build_graph=lambda tools: my_graph_builder(model, tools), # returns a compiled graph
186
+ to_completion=lambda state: {"status": "completed", "message": state["messages"][-1].text},
187
+ )
188
+ ```
189
+
190
+ `create_tools(context, tools)` returns simulated stand-ins for your LangChain tools
191
+ that route through `context.call`; the live tool functions are never invoked.
192
+ Invoke graphs asynchronously (`ainvoke`). Model requests made by your graph use your
193
+ provider account and may incur charges.
194
+
195
+ ## How parity is tested
196
+
197
+ `tests/test_parity.py` runs 38 workflow cases through both SDKs (the booking
198
+ starter, all eight faults, every check type, run limits, protocol violations, and
199
+ virtual time) and requires byte-identical reports after removing random IDs and
200
+ timings. It also checks that each SDK's schema accepts the other's batches and
201
+ rejects the same tampered ones, that `compare` gives identical results on mixed
202
+ pairs, and that fingerprints, imported report IDs, redaction, workflow parsing,
203
+ and Markdown summaries match. It needs Node and the built JavaScript SDK:
204
+
205
+ ```sh
206
+ npm ci && npm run build # repository root
207
+ cd packages/python && pip install -e ".[langgraph]" pytest && pytest
208
+ ```
209
+
210
+ ## License
211
+
212
+ Apache-2.0. See [LICENSE](LICENSE) and [NOTICE](NOTICE).
@@ -0,0 +1,183 @@
1
+ # TraceDojo for Python
2
+
3
+ **Chaos testing for AI agent tools.**
4
+
5
+ The booking succeeded. The response timed out. Your agent booked it again.
6
+
7
+ TraceDojo runs your agent against tools you simulate in memory, makes a tool call
8
+ fail on purpose, and checks what actually changed in your application's state. Every
9
+ test runs a no-fault control first, a fault the agent never reaches is reported as
10
+ inconclusive instead of passing, and `compare` gates pull requests on regressions
11
+ against the base commit.
12
+
13
+ This is the Python SDK. It writes the same report format as the JavaScript SDK
14
+ (`@tracedojo/sdk`), so the TraceDojo dashboard, `compare`, and the CI gate accept
15
+ reports from either language, and a Python report compares cleanly against a
16
+ JavaScript one for the same workflow.
17
+
18
+ Python 3.10 or later. No runtime dependencies.
19
+
20
+ > Not yet published to PyPI. Install from a checkout:
21
+ > `pip install ./packages/python` (add `[langgraph]` for the LangGraph adapter).
22
+
23
+ ## See a failure and its fix
24
+
25
+ ```sh
26
+ tracedojo demo
27
+ ```
28
+
29
+ It runs a scripted booking agent twice against a lost confirmation. The version
30
+ that makes a new operation key per retry books twice and fails; the version that
31
+ reuses its key passes. Both reports are saved in a new directory under `.tracedojo/`.
32
+
33
+ ## Test your agent
34
+
35
+ A workflow (`workflow.json`) holds the task, the starting state, outcome checks, and
36
+ fault scenarios. It is the same `workflow/1` file the JavaScript SDK reads; see
37
+ [`docs/WORKFLOWS.md`](../../docs/WORKFLOWS.md) for every field. An adapter module
38
+ defines the simulated tools and a factory for your agent:
39
+
40
+ ```python
41
+ # dojo/adapter.py
42
+ from tracedojo import tool
43
+
44
+
45
+ @tool("write")
46
+ def reserve_slot(args, state, context):
47
+ """Only successful writes commit. Mutate the state draft, return a result."""
48
+ key = args.get("operationKey")
49
+ if not key:
50
+ return {"ok": False, "error": {"code": "INVALID_ARGUMENTS", "message": "Provide operationKey.", "retryable": False}}
51
+ if key in state["operations"]:
52
+ return {"ok": True, "data": state["operations"][key]}
53
+ booking = {"id": f"booking_{len(state['bookings']) + 1}", "customerId": args["customerId"], "slot": args["slot"]}
54
+ state["bookings"].append(booking)
55
+ state["operations"][key] = booking
56
+ return {"ok": True, "data": booking}
57
+
58
+
59
+ tools = {"reserve_slot": reserve_slot}
60
+
61
+
62
+ class BookingAgent:
63
+ id = "booking-agent"
64
+ version = "1"
65
+
66
+ async def run(self, context):
67
+ for _attempt in range(3):
68
+ # Route every tool call through context.call and always await it.
69
+ # Reuse one operation key so a retry cannot book twice.
70
+ result = await context.call(
71
+ "reserve_slot", {"customerId": "customer_7", "slot": "slot_42", "operationKey": "one-booking"}
72
+ )
73
+ if isinstance(result, dict) and result["ok"]:
74
+ return {"status": "completed", "message": "Meeting booked.", "output": {"bookingId": result["data"]["id"]}}
75
+ if isinstance(result, dict) and not result["error"]["retryable"]:
76
+ return {"status": "blocked", "message": result["error"]["message"]}
77
+ return {"status": "blocked", "message": "The booking could not be confirmed."}
78
+
79
+
80
+ def create_agent():
81
+ return BookingAgent() # a fresh agent, with fresh conversation state, per trial
82
+ ```
83
+
84
+ ```sh
85
+ tracedojo test --config dojo/workflow.json --adapter dojo/adapter.py --trials 3 --out .tracedojo/report.json
86
+ ```
87
+
88
+ The complete booking starter is in
89
+ [`src/tracedojo/templates/booking`](src/tracedojo/templates/booking).
90
+
91
+ Or from Python:
92
+
93
+ ```python
94
+ from tracedojo import run_workflow, run_workflow_sync, workflow_exit_code
95
+
96
+ batch = run_workflow_sync(workflow_dict, adapter_module, trials=3, commit_sha=None)
97
+ # inside an event loop: batch = await run_workflow(workflow_dict, adapter_module)
98
+ ```
99
+
100
+ ### Faults and checks
101
+
102
+ Faults: `timeout_before`, `timeout_after`, `unavailable`, `malformed`,
103
+ `permission_revoked`, `duplicate_delivery`, `stale_read`, `prompt_injection`, each
104
+ with `occurrence` and `repeat`. Checks: `count`, `equals` (state or completion),
105
+ `unchanged`, `forbidden_tool`, `tool_calls`, `tool_order`. Semantics, limits, and
106
+ statuses are identical to the JavaScript SDK.
107
+
108
+ Model faults (`rate_limited`, `server_error`, `model_timeout`, `stream_cut`,
109
+ `stream_stall`, with `target: "model"`) sit between an agent process and its model
110
+ API, so only the JavaScript proxy runner (`npx tracedojo proxy`) injects them.
111
+ `run_workflow` rejects them, as the JavaScript `runWorkflow` does. The Python SDK
112
+ reads, validates, compares, summarizes, and uploads proxy reports that contain them.
113
+
114
+ ### The agent context
115
+
116
+ | Member | Purpose |
117
+ | --- | --- |
118
+ | `await context.call(tool, args)` | Simulated tool call. Returns `{"ok": True, "data": ...}`, `{"ok": False, "error": {...}}`, or a string for a malformed response. |
119
+ | `context.record_model(detail, payload=None)` | Evaluator-only model telemetry. Never include credentials or private reasoning. |
120
+ | `context.clock.now()`, `await context.clock.sleep(ms)` | Real time, or virtual time when the workflow sets `"clock": {"mode": "virtual"}`. |
121
+ | `context.signal` | Cancellation flag: `aborted`, `throw_if_aborted()`. |
122
+ | `context.task` | The workflow task text. |
123
+ | `context.with_call(fn)` | A copy whose `call` is wrapped, for retry or backoff wrappers. |
124
+
125
+ Tools and `run` may be sync or async. `context.call` starts the call immediately
126
+ and returns an awaitable; a call still pending when the agent finishes is recorded
127
+ as `unawaited_calls`. Use `context.clock.sleep` (not `asyncio.sleep`) so virtual
128
+ time applies. Deadlines are cooperative: a synchronous handler that blocks the event
129
+ loop cannot be interrupted, and adapters are trusted code, not sandboxed.
130
+
131
+ ## Compare, gate, and upload
132
+
133
+ ```sh
134
+ tracedojo compare --base base-report.json --candidate pr-report.json --out comparison.json --summary comparison.md
135
+ TRACEDOJO_UPLOAD_TOKEN=... tracedojo upload report.json --url https://tracedojo.com --project PROJECT_UUID
136
+ ```
137
+
138
+ Exit codes: 0 passed, 1 failed checks or regressions, 2 invalid input, 3 incomplete
139
+ or inconclusive evidence. Output files must be new; existing evidence is never
140
+ overwritten. Reports are redacted with the same patterns as the JavaScript SDK
141
+ before they are written.
142
+
143
+ The base and candidate reports can come from either SDK. The JavaScript
144
+ `npx tracedojo compare` and this `tracedojo compare` produce identical results.
145
+
146
+ ## LangGraph
147
+
148
+ ```python
149
+ from tracedojo.langgraph import LangGraphAgent
150
+
151
+ def create_agent():
152
+ return LangGraphAgent(
153
+ "support-agent",
154
+ "2026-11-15",
155
+ [reserve_slot_tool], # your real LangChain tools; only name, description, and schema are used
156
+ build_graph=lambda tools: my_graph_builder(model, tools), # returns a compiled graph
157
+ to_completion=lambda state: {"status": "completed", "message": state["messages"][-1].text},
158
+ )
159
+ ```
160
+
161
+ `create_tools(context, tools)` returns simulated stand-ins for your LangChain tools
162
+ that route through `context.call`; the live tool functions are never invoked.
163
+ Invoke graphs asynchronously (`ainvoke`). Model requests made by your graph use your
164
+ provider account and may incur charges.
165
+
166
+ ## How parity is tested
167
+
168
+ `tests/test_parity.py` runs 38 workflow cases through both SDKs (the booking
169
+ starter, all eight faults, every check type, run limits, protocol violations, and
170
+ virtual time) and requires byte-identical reports after removing random IDs and
171
+ timings. It also checks that each SDK's schema accepts the other's batches and
172
+ rejects the same tampered ones, that `compare` gives identical results on mixed
173
+ pairs, and that fingerprints, imported report IDs, redaction, workflow parsing,
174
+ and Markdown summaries match. It needs Node and the built JavaScript SDK:
175
+
176
+ ```sh
177
+ npm ci && npm run build # repository root
178
+ cd packages/python && pip install -e ".[langgraph]" pytest && pytest
179
+ ```
180
+
181
+ ## License
182
+
183
+ Apache-2.0. See [LICENSE](LICENSE) and [NOTICE](NOTICE).
@@ -0,0 +1,58 @@
1
+ [build-system]
2
+ requires = ["hatchling>=1.25"]
3
+ build-backend = "hatchling.build"
4
+
5
+ [project]
6
+ name = "tracedojo"
7
+ version = "0.1.0"
8
+ description = "Controlled tool failures and state assertions for AI agents"
9
+ readme = "README.md"
10
+ license = "Apache-2.0"
11
+ license-files = ["LICENSE", "NOTICE"]
12
+ authors = [{ name = "Syed Arman" }]
13
+ requires-python = ">=3.10"
14
+ dependencies = []
15
+ keywords = [
16
+ "ai-agents",
17
+ "llm-testing",
18
+ "chaos-engineering",
19
+ "prompt-injection",
20
+ "regression-testing",
21
+ ]
22
+ classifiers = [
23
+ "Development Status :: 3 - Alpha",
24
+ "Intended Audience :: Developers",
25
+ "Programming Language :: Python :: 3",
26
+ "Programming Language :: Python :: 3 :: Only",
27
+ "Programming Language :: Python :: 3.10",
28
+ "Programming Language :: Python :: 3.11",
29
+ "Programming Language :: Python :: 3.12",
30
+ "Programming Language :: Python :: 3.13",
31
+ "Programming Language :: Python :: 3.14",
32
+ "Topic :: Software Development :: Testing",
33
+ "Typing :: Typed",
34
+ ]
35
+
36
+ [project.optional-dependencies]
37
+ langgraph = ["langchain-core>=1.0", "langgraph>=1.0"]
38
+
39
+ [project.scripts]
40
+ tracedojo = "tracedojo.cli:main"
41
+
42
+ [project.urls]
43
+ Homepage = "https://tracedojo.com/docs"
44
+ Repository = "https://github.com/syedarman1/tracedojo-sdk"
45
+ Issues = "https://github.com/syedarman1/tracedojo-sdk/issues"
46
+
47
+ [dependency-groups]
48
+ dev = ["pytest>=8", "langchain-core>=1.0", "langgraph>=1.0"]
49
+
50
+ [tool.hatch.build.targets.wheel]
51
+ packages = ["src/tracedojo"]
52
+
53
+ [tool.hatch.build.targets.sdist]
54
+ include = ["src/tracedojo", "tests", "README.md", "LICENSE", "NOTICE"]
55
+
56
+ [tool.pytest.ini_options]
57
+ testpaths = ["tests"]
58
+ pythonpath = ["src"]