Skip to main content

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_worker for threads
  • tracer.py — start/end spans, build tree, fail-open, route to sink
  • span.py — OTel-shaped Span + SpanType
  • redact.py — scrub secrets + truncate (on by default)
  • cost.py — per-model token→$ price map (override with am.cost.set_prices)
  • decorators.py@meter, with meter.span(...), @meter.tool
  • instrument/openai.py — sync + async + streaming, enrich-not-duplicate
  • instrument/anthropic.py — sync + async
  • instrument/langchain.py — callback handler, run_id tree, global register
  • sinks/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 ui local 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.

Release files for agenticmeter-cli 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for agenticmeter-cli 0.2.0
File Size Uploaded
agenticmeter_cli-0.2.0.tar.gz 25.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for agenticmeter-cli 0.2.0
File Interpreter ABI Platform
agenticmeter_cli-0.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 55.5 kB

Release files / agenticmeter_cli-0.2.0.tar.gz

Download URL agenticmeter_cli-0.2.0.tar.gz
Size 25.8 kB
Tags Source
SHA-256 checksum
How to use checksums
d7cbb2c43b565438ba1745a4bc86cce7333ff18c9cd826631118b8205e71afef
BLAKE2b-256 checksum
How to use checksums
08819d86a047199979848ca32e82424888a53f643ebada30c2a9123cbd6f63c4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.11

Release files / agenticmeter_cli-0.2.0-py3-none-any.whl

Download URL agenticmeter_cli-0.2.0-py3-none-any.whl
Size 29.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
eb6ff6c065ac119ee7dd84093a0216e70e09d76c4619199bb6e84cee8466ea4e
BLAKE2b-256 checksum
How to use checksums
0c1084db2a0090035009e336e13b9baf67dd4d9ac2825107aa307bf5ad553eaa
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.11

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files

0.0.1

2 release 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