Skip to main content

optio

Economic cost and outcome quality signals for agent runs — in the OpenTelemetry GenAI vocabulary.

CI PyPI Python License

Your agent framework tells you what happened. optio tells you what it cost, whether it was going in circles, and whether the answer was any good — as ordinary OTel span attributes, so every backend you already run can chart and alert on them.

from optio import instrument

instrument(agent)  # one line; spans now carry cost + behavior signals

That is the whole integration. optio never touches a request (ADR-001) — it reads the spans your framework already emits and writes numbers back onto them.


Install

pip install optio                # core: signals only, never touches a request
pip install "optio[langgraph]"   # + framework adapter
pip install "optio[optimize]"    # + optio_optimize: acts on the signals (see below)

Adapters: langgraph, openai, crewai, claude. Python 3.10 – 3.14, Linux/macOS/Windows.

Usage

from optio import meter, RunContext


@meter(budget="$0.50")
def run_agent(prompt: str) -> str: ...


# or scope it yourself
with RunContext(budget="$0.50") as run:
    ...  # spans emitted inside are governed

Enabling or disabling lanes never changes agent behavior, nothing blocks the agent, and configuration errors raise at setup — never on the hot path.

The signals

These attribute names are the integration contract — mirrored as constants in optio.semconv and asserted by contract tests. docs/signals.md is authoritative.

Signal Type Lane
gen_ai.run.actual_cost double (USD) cost
gen_ai.run.projected_cost double (USD) cost
gen_ai.run.budget_remaining double (USD) cost
gen_ai.run.cost_per_successful_task double (USD) cost × quality
gen_ai.run.loop_state enum string behavior
gen_ai.run.repeat_count int behavior
gen_ai.run.quality.groundedness double [0,1] quality (opt-in)
gen_ai.run.quality.task_success double [0,1] quality (opt-in)
gen_ai.run.success bool quality

Policies match the exact names, so they stay portable across backends:

deny if input.attributes["gen_ai.run.projected_cost"] > 0.50
deny if input.attributes["gen_ai.run.loop_state"] == "looping"

Overhead

Published rather than promised — generated by the CI benchmark job, not written by hand.

Measure Result Budget
Per-step, cost + behavior lanes mean ~70 µs, p99 ~130 µs < 5 ms p99
Behavior classification at 10k steps ~40 µs → ~50 µs flat in run length
Classification vs window size 37 µs at 50, 38 µs at 1000 flat in window
Ledger snapshot, 10k open reservations ~100 µs O(1)-ish
Both lanes disabled ~18 µs p99 —
import optio ~158 ms cold < 500 ms

Roughly 40× inside budget. Measured on one developer machine with an in-memory store and no exporter attached; read them as an order of magnitude, not a promise for your hardware. The window-size row is a structural guarantee rather than a measurement — classification is O(1) in the window, so raising behavior_window_size to catch longer cycles costs memory but not latency. It used to cost both, at 370 µs per step (docs/testing.md).

Detector accuracy on the synthetic corpus, both CI-gated:

Measure Result
False positives — healthy runs flagged 0 / 1200 (0.000%)
Detection — pathological runs caught 600 / 600 (100.0%)

The detection rate is gated alongside the false-positive rate, because a zero false-positive rate is trivially achievable by never detecting anything.

optio_optimize — acting on the signals

A separate, opt-in package that sits in the request path: caching, prefix markers, history trimming, deduplication, retrieval pruning (ADR-013). Installing optio alone never pulls it in.

from optio_optimize import Optimizer

optimizer = Optimizer()  # lossless by default
response = optimizer.call(request, provider_fn)  # or await optimizer.acall(...)

Cost reduction, live-API measured, not simulated:

Workload gpt-4o-mini claude-sonnet-4-5
retry_storm 93.5% 97.8%
tool_loop 80.8% 93.7%
multi_turn_chat_long — 86.2%
mcp_agent — 84.0%
fan_out 68.2% 83.7%
multi_turn_chat 8.4% 82.2%
rag_queries 16.5% 76.2%

Those two columns differ by 10× on multi_turn_chat, and that gap is the point. OpenAI populates its prefix cache automatically, so the biggest lever — placing explicit cache breakpoints — has nothing to do there. Anthropic caches only what you mark, which is where marking correctly is worth 80%+ on ordinary conversation traffic.

Three Anthropic figures come with 100% byte-identical output, and two of them reduce zero tokens — prefix caching changes the rate tokens are billed at, not the volume. A tool that reports only "tokens saved" scores those at 0.0%.

Full method, dates and per-stage detail: docs/optimize-benchmarks.md.

How it decides what to claim

Every number above is measured, dated and re-runnable — and several exist because a measurement contradicted an earlier claim and the claim lost:

  • Stages ship off when the evidence says so. 14 of 24 optimizations are disabled by default, including one that measured a cost increase of 14.8%.
  • Corrections stay in the record. optimize-benchmarks.md rewrites itself in place when a live run contradicts a simulated one — it has, twice.
  • Unfavourable numbers are published too. semantic_cache's live false-positive rate at the shipped default is recorded at 85.7%.

The reasoning behind each decision is in 46 ADRs.

Status

alpha (0.2.0). All three lanes work end to end and every signal in the contract is implemented, on 99% coverage with 100% on the ledger and the fail-open guard.

  • State is in-process only. store_backend="redis" is rejected at setup rather than silently ignored (ADR-005).
  • The signal names may still move. They are pinned to OTel GenAI semconv 1.37.0, which is itself marked Development-stability upstream (ADR-002).

1.0.0 waits for that vocabulary to stabilise — the reasoning and the three conditions are in ADR-046.

What is public

The top-level package, and nothing else (ADR-012):

from optio import instrument, meter, RunContext, current_run, Config, BudgetPolicy
from optio import __version__, GENAI_SEMCONV_VERSION
instrument attach to a framework object
meter decorator: scope a run, optionally with a budget
RunContext the same thing as a context manager
current_run the run in scope, or None
Config everything configurable, validated at setup
BudgetPolicy the limits a run is governed by
__version__, GENAI_SEMCONV_VERSION this release, and the semconv release it tracks

Plus optio.semconv, which holds the attribute names as constants.

optio.runtime, optio.lanes and friends are internal and may change without a major bump — if you need something from them, please open an issue rather than importing it. A test asserts every name above appears in this file, so an undocumented export cannot ship.

Docs

Signals contract every attribute, authoritative
Behavior detection what the corpus does and does not model
Testing how the numbers above are produced
Optimize benchmarks per-stage, per-workload, dated
ADRs why every decision went the way it did
Contributing the gate you need to pass
Changelog what changed, and why

Development

pip install -e ".[dev]"
pytest                       # 2,210 tests
ruff check . && mypy         # lint + types
lint-imports                 # architecture boundaries

License

Apache-2.0 — see LICENSE.

Metadata

Release files for optio 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 optio 0.2.0
File Size Uploaded Provenance Actions
optio-0.2.0.tar.gz 949.8 kB With provenance Details for optio-0.2.0.tar.gz

Built distribution (wheel)

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

Total release size: 1.3 MB

Release files / optio-0.2.0.tar.gz

Download URL optio-0.2.0.tar.gz
Size 949.8 kB
Tags Source
SHA-256 checksum
How to use checksums
258eadf169d5566cce641f600e711ddf2358323854d5bd083ed82c088307b367
BLAKE2b-256 checksum
How to use checksums
8d0ea5934344ffde5e929c869fafcd2a2a9c3f9408222dc7447fac28034920cf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 2, 2026.

Transparency log

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

Download URL optio-0.2.0-py3-none-any.whl
Size 369.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a9c082d1f624fc5f0073bf4c1a88dfcd2fff95dc69f3d3d9c3a83b585578034d
BLAKE2b-256 checksum
How to use checksums
484bf943efd1e0f532051731fe44d0c4ed124b11de618ab6b61e4a677ec2cb79
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 2, 2026.

Transparency log

Security for optio 0.2.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for optio-0.2.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 2, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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