Skip to main content

wardhook-observability

License: MIT Python 3.10+

Per-node token count, cost estimate, and latency tracking for LangGraph agents, with a self-contained HTML trace viewer.

Part of Wardhook.

Install

pip install wardhook-observability

No account, no API key, no collector process, no sidecar. Nothing is sent anywhere.

Usage

With wardhook-core, tracing is one keyword argument:

from wardhook.core import AgentGraph

agent = AgentGraph(model="claude-opus-5", telemetry=True)
agent.invoke("What excess applies to storm damage?")

trace = agent.trace()
for step in trace.steps:
    print(f"{step.node:14s} {step.latency_ms:6.0f}ms  {step.tokens_out:5d} tok  ${step.cost:.4f}")
guard_input        2ms      0 tok  $0.0000
retrieve          18ms      0 tok  $0.0000
call_model       412ms    120 tok  $0.0057
guard_output       3ms      0 tok  $0.0000

Standalone, against a graph you already built:

from wardhook.observability import Tracer, instrument, render_html

instrument(my_existing_graph, tracer := Tracer())
my_existing_graph.invoke({"messages": [...]})
open("trace.html", "w").write(render_html(tracer.get_trace()))

And from the command line:

wardhook-trace view traces/run-42.jsonl -o trace.html
wardhook-trace summary traces/run-42.jsonl

Keeping history

Point a tracer at a store and every completed run is appended to a JSON Lines file. Memory stays bounded; the file does not.

from wardhook.observability import JSONLTraceStore, Tracer

tracer = Tracer(store=JSONLTraceStore("traces/agent.jsonl"), max_runs=50)

Correcting a price

The built-in table carries a PRICES_AS_OF date and is rendered on every generated page, so a stale number is visible rather than silently trusted. Unknown models cost $0 and warn once. Override any rate without forking:

from wardhook.observability import ModelPrice, register_price

register_price("claude-opus-5", ModelPrice(input_per_1m=4.50, output_per_1m=22.50))

Design notes

  • Real usage, not estimates. A LangChain callback handler reads usage_metadata off the provider response rather than re-tokenising. Local re-tokenisation cannot see the system prompt the provider prepends, tool schema overhead, or which tokens were served from cache.
  • Cache multipliers, applied once. Cache reads bill at roughly 0.1× and writes at 1.25×. LangChain reports input_tokens as the total, cached tokens included, so the uncached remainder is derived before pricing — adding the cache buckets on top would bill them twice. A fully cached prompt costs 0.1× the input rate here, not 1.1×.
  • instrument() reads callbacks, it does not patch nodes. Replacing a compiled graph's node callables would depend on LangGraph internals and break on upgrade. The callback stream is a public interface and carries the node name on every step.
  • The viewer is one static HTML file with inlined CSS and JS. No CDN, no web font, no network requests, no dashboard server to run. Every interpolated value is escaped — a trace carries user-influenced text, so that is a security control, not formatting.
  • Safe in a long-lived process. Traces are held in a bounded ring, shared state is locked, node attribution is per-thread, and no callback can raise into your agent. Telemetry failing is never worth failing a request over.

Links

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

wardhook_observability-0.1.0.tar.gz (39.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

wardhook_observability-0.1.0-py3-none-any.whl (34.9 kB view details)

Uploaded Python 3

File details

Details for the file wardhook_observability-0.1.0.tar.gz.

File metadata

  • Download URL: wardhook_observability-0.1.0.tar.gz
  • Upload date:
  • Size: 39.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for wardhook_observability-0.1.0.tar.gz
Algorithm Hash digest
SHA256 66a6447ec3dd92284bbea9b57d60aedfe6979fdfac2aa7108e79c15f88a51267
MD5 b8dced9d86977f75293be5fc8e148454
BLAKE2b-256 3adf88170723011a64717d3c6f1485508115ad8ae506e3a910e015eed59add2b

See more details on using hashes here.

Provenance

The following attestation bundles were made for wardhook_observability-0.1.0.tar.gz:

Publisher: release.yml on justicebajaj161/wardhook

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file wardhook_observability-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for wardhook_observability-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ef1d07d6f8aad3eb2c1966b726c3e8304df6c8b715a57688bdd900d64666516e
MD5 8406b81622049aaef78b9edd1d04d4f5
BLAKE2b-256 3b7c7b843a747db8f1ff92f83b53e180c8f546635ecee5b273aeae8cd249101f

See more details on using hashes here.

Provenance

The following attestation bundles were made for wardhook_observability-0.1.0-py3-none-any.whl:

Publisher: release.yml on justicebajaj161/wardhook

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

0.2.0

2 files

0.1.1

2 files

This release

0.1.0 This release

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page