agrex (Python)
Record agent execution traces for the agrex viewer. Same trace format as the TypeScript @ppazosp/agrex/trace package — write a trace from Python, drop it on the viewer, get the same scrubbing replay.
Install
uv add agrex # or: pip install agrex
Requires Python 3.10+.
Quick start
from agrex import create_tracer
trace = create_tracer()
trace.agent("root", "Researcher", metadata={"input": query})
trace.stage("Search phase")
trace.tool("s1", "web_search", parent="root", args={"q": query})
# … do the work …
trace.done("s1", output=hits)
trace.done("root", output=summary)
# Drop on agrex.ppazosp.dev:
with open("run.jsonl", "w") as f:
f.write(trace.to_jsonl())
Async scopes — span()
Wraps any block. Emits node_add on entry and done / error on settle:
with trace.span(id="s1", label="web_search", parent="root"):
hits = search(query)
# async too
async with trace.span(id="s1", label="web_search", parent="root"):
hits = await search(query)
Default node type is tool. Pass type="sub_agent" etc. to override. On exception the span emits node_update with status="error" and a serialized exception in metadata.error, then re-raises.
Streaming for long runs
Pipe events directly to a file — the viewer reads JSONL natively.
with open("run.jsonl", "w") as f:
trace = create_tracer(out=f, buffer=False)
# ... emit events ...
trace.close() # flushes and closes the sink
buffer=False skips the in-memory log. events() / to_json() / to_jsonl() raise in that mode.
API summary
| Method | Emits |
|---|---|
agent(id, label, **kw) |
node_add (type: agent) |
sub_agent(id, label, **kw) |
node_add (type: sub_agent) |
tool(id, label, args=None, **kw) |
node_add (type: tool). args folds into metadata.args. |
file(id, label, **kw) |
node_add (type: file) |
node(partial) |
node_add — escape hatch, no validation |
update(id, status=, label=, metadata=) |
node_update |
done(id, output=None, metadata=None) |
node_update (status: done). output folds into metadata.output. |
error(id, error=None, metadata=None) |
node_update (status: error). Exceptions are serialized into metadata.error. |
remove(id) |
node_remove |
edge(id=, source=, target=, type=, label=) |
edge_add |
stage(label, color=None) |
stage |
marker(kind, label=None, color=None) |
marker |
clear() |
clear |
span(id=, label=, type='tool', **kw) |
sync/async context manager — node_add + done/error |
All node helpers accept parent, reads, writes, metadata, and status as keyword-only arguments.
Loading traces back
parse_trace auto-detects three input shapes — JSONL, {events: [...]}, or {nodes, edges} snapshots:
from agrex import parse_trace
with open("run.jsonl") as f:
events = parse_trace(f.read())
Raises TraceParseError with a format attribute on parse failure.
Thread safety
emit() is wrapped in a threading.Lock — concurrent calls from a ThreadPoolExecutor produce well-formed JSONL. asyncio-only callers pay no real cost (the lock is uncontended). The on_event callback runs outside the lock so user code never serializes across all emits.
Trace format
See the trace format spec. The Python and TypeScript packages emit the same canonical shape; the cross-language fixture round-trip test in CI guards against drift.
Metadata
Release files for agrex 0.7.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| agrex-0.7.0.tar.gz | 50.8 kB | With provenance | Details for agrex-0.7.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| agrex-0.7.0-py3-none-any.whl | Python 3 | none | any | Details for agrex-0.7.0-py3-none-any.whl |
Total release size: 62.7 kB
Release files / agrex-0.7.0.tar.gz
| Download URL | agrex-0.7.0.tar.gz |
|---|---|
| Size | 50.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
8382887994d2fc5e3c0ad0d91cbb4f4b67b1b54ed9a807a0fbcd4540390d8e12
|
|
BLAKE2b-256 checksum How to use checksums |
c1d4d162416e7a8b4d106569c3c79debb876e576ac68ff959a686f0d5e2c3330
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Apr 29, 2026.
Transparency logRelease files / agrex-0.7.0-py3-none-any.whl
| Download URL | agrex-0.7.0-py3-none-any.whl |
|---|---|
| Size | 11.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
46c130b68266673ab07ed7dc2c5163d91ab9099e5cc21ecc929a6c2053b24565
|
|
BLAKE2b-256 checksum How to use checksums |
fcced85605231af4ca21fd2a4a44ba24854f8edcc003fdb551969a9e96af72c9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Apr 29, 2026.
Transparency logSecurity for agrex 0.7.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for agrex-0.7.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Apr 29, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.