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.1.tar.gz (42.9 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.1-py3-none-any.whl (35.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: wardhook_observability-0.1.1.tar.gz
  • Upload date:
  • Size: 42.9 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.1.tar.gz
Algorithm Hash digest
SHA256 6137aa4fbf5e3a395f0a0e9c03840fcffa7f54a11f9cdec6da86f4ec2ce6ea86
MD5 b474ca806515c6f097b3071b771b37b3
BLAKE2b-256 9d593ed9543d33e6dfa82df33b97235e9c7c258c9f87faf59cb8a74095f191b1

See more details on using hashes here.

Provenance

The following attestation bundles were made for wardhook_observability-0.1.1.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.1-py3-none-any.whl.

File metadata

File hashes

Hashes for wardhook_observability-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 b2fb1f25d221b906c88d5434a5f66fd9147dedae2bec97134e1be5c90973f04a
MD5 0dcc7ea332dc166071d690c8b1d5afe0
BLAKE2b-256 2481e8940649e72f2d6fc396104da8df9aea92810d55f43220abddd9f9fab026

See more details on using hashes here.

Provenance

The following attestation bundles were made for wardhook_observability-0.1.1-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

This release

0.1.1 This release

2 files

0.1.0

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