An explicit, local-first Python recorder for actual agent/tool execution evidence. It records tool boundaries and retry identity; developers can attach external observations and postcondition requirements. It exports the canonical Traser AgentRun v0.1 and a separate MCP 0.3-compatible request. The separate TypeScript engine performs investigations. This package never asserts root cause or independently authenticates external state. Developers may opt into their own authorized API/database read callbacks through the new verification helpers; there is no SDK-managed network client, background polling or cloud dependency.
Status: v0.1.0 is published on PyPI; the v0.2.0 verification helpers described here are in development and not yet released. The Python SDK is Apache-2.0 licensed; see LICENSE and NOTICE. This repository contains only the Python SDK; the separate Traser analysis engine and npm MCP package are not relicensed.
python -m pip install -e .
python examples/refund.py
python
from traser_sdk import Traser
traser = Traser()
with traser.run("customer-refund") as run:
with run.operation("issue_refund", operation_id="refund-request-42") as op:
response = op.call(lambda: {"refund_id": "r42", "status": "pending"}, attempt=1)
op.observe(kind="write_receipt", source_kind="api", locator="refund-provider/r42",
value=response)
op.require(kind="terminal_state", required_for="refund reaches completed state")
run.record_step("Tell customer", kind="agent", status="success",
output={"message": "Your refund is complete"})
run.context(expected_outcome="Refund completed", actual_outcome="Refund still pending")
run.export_run("refund-run.json") # Canonical run for /investigate browser upload.
run.export_request("refund-request.json") # Pass full object to MCP traser_investigate.
The SDK records function returned as step success, never external operation completed. A receipt or external read is evidence for an engineer to inspect, not authenticated proof the postcondition succeeded. Requirements are user-declared and MCP review keeps postconditionVerified: false.
A verification that reads back its own tool response is not an independent postcondition check. Explicitly annotate the actual verification step:
with Traser().run("refund") as run:
with run.operation("issue_refund") as op:
receipt = op.call(lambda: {"refund_id": "r42", "status": "accepted"})
claim = run.record_step("Verify refund", kind="evaluator", status="success",
input_value=receipt, output={"verified": True})
op.mark_verification(claim, basis="tool_response") # Not an external read!
def get_refund(refund_id):
return {"status": "pending"} # Synthetic API result for illustration.
matches = op.verify_external(
get_refund, "r42", source_kind="api", locator="provider/refunds/r42",
expected_path="status", expected_value="completed")
assert not matches
Use await op.averify_external(async_reader, ...) for async provider/database clients. The SDK calls the exact callback you supply once, records its response as a post_write_state observation, links it to the originating write step, and declares evidence.verificationChecks. It compares an explicit dot-separated JSON field against a scalar expected value. A False result means the supplied observation did not match or lacked the field; it does not establish permanent failure during an eventual-consistency window. It never retries, takes credentials, invents state, polls or executes a write by itself. Exceptions propagate and are recorded by type only.
The matching MCP investigation release will return verificationReview statuses, such as self_report_only, external_state_mismatch and external_state_matches_expected_unverified. An API/database source label is caller-supplied, not independently authenticated by Traser. The currently published MCP package @maas-dorian/traser@0.3.1 does not accept these new verificationChecks fields; install a compatible MCP release before sending the new request format.
Inspired by engineering feedback about APIs returning HTTP 200 before the
external write is visible, the SDK now has an opt-in in-process polling helper.
It repeats only the application's authorized read callback, never the
write. Each check uses verify_external() internally, so each observed
state and verification basis is recorded in the exported MCP request.
with Traser().run("update-customer") as run:
with run.operation("update_address") as op:
op.call(lambda: {"http_status": 200, "accepted": True}) # Synthetic write
def read_customer():
return {"status": "completed"} # Replace with your real GET/query.
result = op.poll_external(
read_customer, source_kind="api", locator="customers/42",
expected_path="status", expected_value="completed",
timeout_s=30, interval_s=2, max_attempts=10)
print(result.status, result.attempts, result.elapsed_ms)
Use await op.apoll_external(async_reader, ...) for asynchronous clients.
Run python examples/external_polling.py for a local, network-free example.
Possible statuses are observed_match, unconfirmed_timeout, and
unconfirmed_attempt_limit. observed_match means the caller-supplied read
reported the expected value; Traser does not independently authenticate
that source. Unconfirmed does not mean the original write failed. Read
exceptions are re-raised and recorded by exception type, with no fabricated
success claim. The SDK does not retry read errors in this first version.
This first version uses fixed intervals and a maximum of 50 attempts, bounded by the SDK's existing per-run evidence limits. It does not include background polling, persistent jobs, backoff/jitter, provider-specific retry logic, rate-limit management, or automatic provider credentials. Slow or hung reads must be bounded by the application's own client timeout; the wall-clock polling deadline cannot interrupt an in-flight blocking read. Sensitive data still requires deliberate minimization and redaction before export.
Release note: this code is under development and is not yet on PyPI. The latest published Python SDK remains v0.1.0 until release checks finish. Use an editable checkout of the repository for evaluation.
-
Browser: upload the
export_run()canonical JSON toTraser browser investigator . -
MCP: using the published
@maas-dorian/traser@0.3.1server, calltraser_investigatewith the JSON object fromexport_request(), includingexecution,evidence, and optionalcontext. The file is an MCPargument object , not a complete browser trace;tracePathexpectsexport_run()instead. The SDK does not call MCP on your behalf. -
No comparison run is required. A reference run can be supplied separately, but is not ground truth.
-
with Traser().run(name, run_id=...) as run:captures a bounded in-memory run. Without an exception, runstatus=successmeans local control flow completed,not that the agent achieved the requested real-world result. Userun.set_status(...)to label partial/unknown states. -
with run.operation(name, operation_id=..., idempotency_key=..., side_effect_target=...) as operation:groups logical retries. If omitted, operation ID is SDK-generated and cannot prove cross-process identity. -
operation.call(func, *args, attempt=1, **kwargs)andawait operation.acall(async_func, ...)record actual called inputs, observed return values, exception** type** (not message), start/end timestamps, stable logical operation ID and unique attempt ID. Exceptions are re-raised. Instrumentation is opt-in; it is not an automatic framework integration. -
run.record_step(...)records an explicitly supplied agent/LLM/other execution step; never invent recorded steps from source code. -
operation.observe(kind=..., value=..., source_kind=..., locator=..., observed_at=...)adds a separately attributed observation linked to the latest recorded step;operation.require(kind=..., required_for=..., consistency_deadline=...)declares a question or postcondition. Neither changes historical tool outputs. External reads cannot establish what the agent saw earlier. -
operation.mark_verification(claim_step_id, basis=...)labels a recorded check astool_response,agent_output,external_stateorunknown.operation.verify_external(...)/await operation.averify_external(...)invoke your authorized read callback, record its state and explicitly compare one scalar field; they are not general-purpose provider integrations. -
run.export_run(path)writes canonical run JSON;run.export_request(path)includes provenance and evidence as separate fields. Exports writeonly when called and will not overwrite a file withoutoverwrite=True. On POSIX, new exports use mode 0600. -
No global instrumentation, analytics, background threads, cloud uploads, database dependencies, SDK-managed API credentials, automatic state reads or recovery actions. The optional external verification callback can make a real network request only when your code explicitly calls it .
-
Capture is opt-in and may record private data . Common secret-looking object keys (e.g.
authorization,password,api_key,access_token,cookie) are replaced with[REDACTED]; this is not a comprehensive PII/secret scrubber. Do not record credentials or customer data without explicit authorization. Audit the exportbefore sharing it with a coding agent or third-party model provider. Avoid credentials inlocator,idempotency_key,side_effect_target, context text and free-form strings; the SDK does not sanitize those. -
Only JSON-native values (and tuples represented as arrays) can be captured. Unsupported/oversize tool values are omitted and marked with capture warnings , never converted into guessed
repr()strings.Traser(max_value_bytes=...)defaults to 128 KiB per value. Oversize or unsupportedobservations raise, since silently discarding explicit evidence would be misleading. -
Evidence
coverage=partialby default because opt-in recording cannot establish full trace coverage.origin=recordedis acaller assertion , not source authentication. Source locators link relevant recorded steps but are not independently verified. No observation changes candidate ranking in the current MCP release. -
Maximum 5,000 steps/run, 100 sources, 100 observations, 50 requirements and 10 MiB/run export. The outer MCP request has its own combined request limit; keep captures small and scoped.
-
No automatic thread/async context propagation. Concurrent steps are ordered by call entry , which is not necessarily causal order. Custom integration and full async framework coverage need separate validation.
From a local checkout, run the following after installing the SDK with python -m pip install -e .:
python -m unittest discover -s tests -v
python -m pip wheel . --no-deps -w /tmp/traser-wheels
Before publishing v0.2.0, run the cross-repository MCP integration test with the matching MCP release, validate real authorized read-only integrations, check package metadata and approve the release. The npm MCP package is separate and not covered by the SDK license.
All code, tests, examples and documentation in this repository are licensed under Apache-2.0, with the license and attribution included in published archives. You may use, modify, and redistribute this SDK under those terms. The Traser analysis engine, website, and npm MCP package are separate projects and are not included here.
Please use synthetic reproductions for issues and pull requests. Never submit credentials, customer traces, or sensitive production logs.