Skip to main content

meterbility-agent (Python SDK)

The Python counterpart to @meterbility/agent. Wire any Python LLM agent into Meterbility by capturing one Step per model call. Runs land in the same ~/.meter/meterbility.db store the TypeScript SDK, the CLI, and the web UI read from — so a Python agent shows up in meter list and meter web immediately, with no separate ingest step.

Install

pip install -e packages/agent-py        # core only (stdlib)
pip install -e 'packages/agent-py[anthropic]'  # add the Anthropic helper

Requires Python 3.9+. Core has zero runtime dependencies (it uses sqlite3, hashlib, json, pathlib from the standard library).

Minimal usage

from meterbility_agent import MeterbilityTracer

with MeterbilityTracer(project="my-app", agent="support") as tracer:
    step = tracer.start_step(
        model="claude-opus-4-7",
        system_prompt="you are helpful",
        history=[{"role": "user", "content": "hello"}],
    )
    # ... call your model, then record what it did ...
    step.record_message("hi back!").record_tokens(
        input=10, output=2, cached_read=0, cache_creation=0
    )
    step.end()

Then in another terminal:

meter list
meter inspect <run-id>
meter web   # see it live alongside any Claude Code / Codex runs

Anthropic shortcut

If you already use the official anthropic Python SDK, wrap the client once and every messages.create() call is captured automatically:

from anthropic import Anthropic
from meterbility_agent import MeterbilityTracer, trace_anthropic

with MeterbilityTracer(project="my-app", agent="support") as tracer:
    client = trace_anthropic(tracer, Anthropic())  # API-compatible wrapper

    resp = client.messages.create(
        model="claude-opus-4-7",
        max_tokens=512,
        system="you are helpful",
        messages=[{"role": "user", "content": "hello"}],
    )
    # one Meterbility Step captured per call — including tool_use, tokens, latency.

The wrapped client behaves identically to the underlying Anthropic client — it returns the same Message object, exposes the same attributes, and re-raises the same exceptions (recording them as error outcomes before the throw bubbles).

Multi-step agent loop

For multi-step agents that call tools, drive each step manually:

from meterbility_agent import MeterbilityTracer, tool_call_action

with MeterbilityTracer(project="my-app", agent="rag") as tracer:
    history = [{"role": "user", "content": "what's the weather in NYC?"}]

    # turn 1: model picks a tool
    step1 = tracer.start_step(model="claude-opus-4-7", history=history)
    step1.record_action(tool_call_action("weather", {"city": "NYC"}, "tu_1"))
    step1.record_tokens(input=120, output=20)
    step1.end()

    # run the tool yourself ...
    tool_result = {"temp_f": 68, "conditions": "clear"}

    # turn 2: feed the tool result back, model produces a message
    history += [
        {"role": "assistant", "content": "[tool_call weather]"},
        {"role": "tool", "content": str(tool_result)},
    ]
    step2 = tracer.start_step(model="claude-opus-4-7", history=history)
    step2.record_message("It's 68°F and clear in NYC.")
    step2.record_tokens(input=150, output=15)
    step2.end()

What's captured per step

Field Source
model required arg to start_step()
system_prompt, tool_definitions, history, retrieved_docs optional context components (blob-stored, content-addressed)
action record_message() / record_tool_call() / record_action()
outcome record_tool_result() / record_outcome()
tokens (input / output / cached_read / cache_creation [5m] / cache_creation_1h) record_tokens()
cost_cents computed from tokens via the same pricing table the TS side uses
latency_ms wall-clock since start_step(), or explicit via record_tokens(latency_ms=...)
tags step.tag("x")cost:approx auto-applied for unknown models

Configuration

Env var Effect
METERBILITY_HOME Override the data directory (default ~/.meter)
METERBILITY_REDACT=off Disable regex redaction of API keys / bearer tokens / private keys

Run the tests

cd packages/agent-py
python -m unittest discover -s tests -v

Tests redirect METERBILITY_HOME to a tempdir per test, so they never touch your real ~/.meter store.

Download files

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

Source Distribution

meterbility_agent-0.6.1.tar.gz (60.2 kB view details)

Uploaded Source

Built Distribution

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

meterbility_agent-0.6.1-py3-none-any.whl (30.0 kB view details)

Uploaded Python 3

File details

Details for the file meterbility_agent-0.6.1.tar.gz.

File metadata

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

File hashes

Hashes for meterbility_agent-0.6.1.tar.gz
Algorithm Hash digest
SHA256 3509d72cf03ea49d62fadf6868d9e64539bd571c51ac32619c4ab3a63b414775
MD5 63efb02d4a6fb8768b49d67ce43c1a0a
BLAKE2b-256 56c01859bcfb4c6af13046b97b042552e88ade7d59b7baf8a1ff860fcb625ec0

See more details on using hashes here.

Provenance

The following attestation bundles were made for meterbility_agent-0.6.1.tar.gz:

Publisher: publish-pypi.yml on HoneycombHairDevelopers/Meterbility

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

File details

Details for the file meterbility_agent-0.6.1-py3-none-any.whl.

File metadata

File hashes

Hashes for meterbility_agent-0.6.1-py3-none-any.whl
Algorithm Hash digest
SHA256 0f75a70c0eca39cce2a8740ae8909a693160254d0da22345180d8a09800ae6b7
MD5 10473b436a4101f7acefd63f65fc15fc
BLAKE2b-256 fb04996b27ae07690999e39e969d63ba1362381bf9ed5c11d845098cd42b9aab

See more details on using hashes here.

Provenance

The following attestation bundles were made for meterbility_agent-0.6.1-py3-none-any.whl:

Publisher: publish-pypi.yml on HoneycombHairDevelopers/Meterbility

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

Release history Release notifications | RSS feed

This release

0.6.1 This release

2 files

0.6.0

2 files

0.5.1

2 files

0.5.0

2 files

0.4.0

2 files

0.3.1

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page