Agent-centric, local-first observability: understand what your AI agents do, not just trace them.
Project description
agenticmeter — capture layer (prototype)
Agent-centric, local-first observability. Wrap your agent; get a trace tree of every step, tool call, and loop with token + cost usage.
Quick start
import agenticmeter as am
sink = am.configure() # scrub redaction on, auto-patches OpenAI/Anthropic/LangChain
@am.meter # wrap the run
def agent(task):
with am.span("plan", am.SpanType.LLM):
...
return do_work(task)
agent("plan my launch week")
# inspect the trace tree
root, children = sink.tree(sink.spans[0].trace_id)
What's implemented
context.py— contextvars spine (current run/span) +bind_workerfor threadstracer.py— start/end spans, build tree, fail-open, route to sinkspan.py— OTel-shaped Span + SpanTyperedact.py— scrub secrets + truncate (on by default)cost.py— per-model token→$ price map (override witham.cost.set_prices)decorators.py—@meter,with meter.span(...),@meter.toolinstrument/openai.py— sync + async + streaming, enrich-not-duplicateinstrument/anthropic.py— sync + asyncinstrument/langchain.py— callback handler, run_id tree, global registersinks/base.py— Sink interface + MemorySink (+ tree builder)
Capture surfaces & the double-counting rule
LLM call usage is captured by SDK patching. When a framework (LangChain) already
opened an LLM span, the SDK patch enriches that span with exact token usage
instead of emitting a duplicate — driven by context.in_framework_llm.
Not yet built (next steps)
- SQLite sink + background async flush queue (
flush.py) agenticmeter uilocal viewer- loop / cycle detection (
analysis/loops.py) - cloud exporter
Run the tests
python3 smoke_test.py
Behavior layer (the product)
analysis/insights.py — six pure detectors over the span tree, each returning
Insights with evidence (span ids) + an action. Assert-only-what-you-can-prove:
| code | tier | fires when |
|---|---|---|
| silent_tool_failures | fact | a tool errored but the run returned ok |
| cost_concentration | fact | one step >= 60% of run cost (>= 3 priced steps) |
| repeated_llm_calls | fact | identical prompt billed >= 2x |
| context_growth | fact | peak prompt >= 3x first (and >= 2k extra tokens) |
| repeated_tool_calls | pattern | same tool + same args >= 3x (the provable "loop") |
| time_concentration | fact | >= 70% of step time in retrieval/tool/custom |
from agenticmeter.analysis.insights import analyze, format_insights
print(format_insights(analyze(spans))) # spans = one trace's span list
Run the demo / tests:
python3 behavior_demo.py # messy run -> all six warnings
python3 behavior_test.py # messy fires all six, clean fires none
Seeing the output (Level 0 + 1)
Level 0 — every @meter run prints its behavior summary when it closes (warnings
only by default, so clean runs stay silent):
import agenticmeter as am
am.configure(sink="sqlite", summary="auto") # "auto" | True | False
@am.meter
def agent(task): ...
agent("...") # -> prints ▸ run header + any ⚠ warnings to stderr
Level 1 — runs persist to ~/.agenticmeter/traces.db; replay them from the terminal:
agenticmeter runs # list recent runs (or: python -m agenticmeter runs)
agenticmeter show # latest run: trace tree + warnings
agenticmeter show <id> # a specific run (prefix ok)
Try it: python3 level01_demo.py, then python3 -m agenticmeter --db /tmp/agenticmeter_demo.db show.
Install (editable)
pip install -e . # registers the `agenticmeter` command
This also avoids the import-shadowing trap: run from anywhere, edits picked up live.
Local web viewer (Level 2)
agenticmeter ui # opens http://127.0.0.1:4319 in your browser
agenticmeter ui --port 8080 --no-open
Single page: live-polling run list (left), selected run's behavior findings + trace tree (right). Click any ⚠ finding and it highlights + scrolls to the offending steps in the trace — diagnosis you can verify in one click. Stdlib only, no deps.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file agenticmeter_cli-0.2.0.tar.gz.
File metadata
- Download URL: agenticmeter_cli-0.2.0.tar.gz
- Upload date:
- Size: 25.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d7cbb2c43b565438ba1745a4bc86cce7333ff18c9cd826631118b8205e71afef
|
|
| MD5 |
f77aeacdc8229b8a36af522889631df4
|
|
| BLAKE2b-256 |
08819d86a047199979848ca32e82424888a53f643ebada30c2a9123cbd6f63c4
|
File details
Details for the file agenticmeter_cli-0.2.0-py3-none-any.whl.
File metadata
- Download URL: agenticmeter_cli-0.2.0-py3-none-any.whl
- Upload date:
- Size: 29.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
eb6ff6c065ac119ee7dd84093a0216e70e09d76c4619199bb6e84cee8466ea4e
|
|
| MD5 |
2e3fc2713c09dcd4248b8ab35e1c26a1
|
|
| BLAKE2b-256 |
0c1084db2a0090035009e336e13b9baf67dd4d9ac2825107aa307bf5ad553eaa
|