Async-aware runtime primitives for multi-step LLM agent loops.
Project description
Runtime
Author: Techrevati doo
Runtime primitives for multi-step LLM agent loops: sync and async sessions, retry classification, circuit-breaker protection, usage tracking, optional budget enforcement, role-based tool gating, guardrails, handoffs, policy evaluation, checkpointing, rate limiting, streaming, hooks, and telemetry integration.
The package is currently 0.4.0. The 0.x
API surface is still unstable, so pin exact versions when you depend on a
specific behavior.
pip install techrevati-runtime
pip install 'techrevati-runtime[otel]'
Quick Start
from techrevati.runtime import (
AgentSession,
ModelPricing,
UsageSnapshot,
register_pricing,
)
register_pricing(
"model-a",
ModelPricing(input_per_million=3.0, output_per_million=15.0),
)
agent = AgentSession(
role="writer",
phase="draft",
project_id=1,
budget_usd=10.0,
enforce_budget=True,
max_iterations=25,
)
with agent.session() as session:
result, usage = session.run_turn(
lambda: call_model(prompt),
model="model-a",
usage=UsageSnapshot(input_tokens=5000, output_tokens=1200),
timeout=30.0,
)
print(session.summary())
The session moves through INITIALIZING -> RUNNING -> COMPLETED, classifies
exceptions into typed failure scenarios, attempts recovery once, enforces the
configured budget, gates tool calls behind permissions and guardrails, and emits
structured events to the configured sinks.
For async code, use async with, asession(), and arun_turn() with the same
parameters. Cancellation transitions the worker to CANCELLED.
Design Goals
- Zero runtime dependencies; optional extras are opt-in.
- Type-safe public API with
py.typed. - Composable primitives that work standalone or through
AgentSession. - Thread-safe sync paths and async-safe async paths.
- Caller-owned configuration for pricing, thresholds, roles, sinks, and policy.
Main Primitives
| Module | Provides |
|---|---|
orchestrator |
AgentSession, sync and async sessions |
circuit_breaker |
Sync and async circuit breakers |
retry_policy |
Failure classification and recovery recipes |
usage_tracking |
Usage snapshots, pricing registration, limits, budgets |
agent_lifecycle |
Worker registry and validated lifecycle transitions |
agent_events |
Typed lifecycle events |
permissions |
Deny-first role and tool authorization |
guardrails |
Pre-call and post-call content checks |
handoffs |
Agent-to-agent delegation records |
policy_engine |
Declarative policy conditions and actions |
checkpoint |
In-memory and SQLite checkpoint savers |
rate_limit |
Token buckets and rate limiters |
streaming |
Structured async stream events |
hooks |
Mutating lifecycle hook chain |
sinks |
Event and usage sink protocols |
persistence |
SQLite-backed durable sinks |
otel |
Optional telemetry sinks |
compliance |
EU AI Act primitives (audit log, oversight, risk registry, incidents, transparency) |
EU AI Act compliance
The techrevati.runtime.compliance subpackage provides technical primitives that
map to EU AI Act (Regulation (EU) 2024/1689) Articles 9, 12, 13, 14, 15, 26, and
73 — a tamper-evident hash-chained audit log, human-oversight pause/override, a
risk registry, incident detection with 15-day deadline tracking, and a
transparency report — bundled behind the EUAIActComplianceKit facade:
from techrevati.runtime import AgentSession
from techrevati.runtime.compliance import EUAIActComplianceKit, AuditLogSink, SqliteAuditBackend
kit = EUAIActComplianceKit.standard(audit_log=AuditLogSink(SqliteAuditBackend("audit.db")))
session = AgentSession(role="loan_assessor", phase="decide", compliance=kit)
with session.session() as s:
s.run_tool("score", lambda: assess(application))
assert kit.audit_log.verify_chain().valid
⚠️ Not legal advice. The runtime is not itself an AI system; it provides building blocks. The deployer remains responsible for classification, conformity assessment, and operation. See the EU AI Act docs for the article-by-article guidance and the audit-log threat model.
Example: Async Handoff
import asyncio
from techrevati.runtime import (
AgentSession,
AllowAllGuardrail,
AsyncCircuitBreaker,
UsageSnapshot,
)
cb = AsyncCircuitBreaker(
"model-api",
failure_threshold=3,
recovery_timeout_seconds=30.0,
)
async def main():
agent = AgentSession(
role="writer",
phase="draft",
async_circuit_breaker=cb,
guardrails=[AllowAllGuardrail()],
max_iterations=10,
)
async with agent.asession() as session:
text, _ = await session.arun_turn(
lambda: acall_model(prompt),
model="model-a",
usage=UsageSnapshot(input_tokens=5000, output_tokens=1200),
timeout=30.0,
)
handoff = session.handoff_to(
"editor",
reason="review",
context={"draft": text},
)
print(f"handed off to {handoff.target_role}")
asyncio.run(main())
Limits
- Pricing is caller-provided. Unknown models are tracked with zero cost and a warning.
- Budget enforcement is opt-in with
enforce_budget=True. - Permissions and guardrails are runtime gates, not process sandboxes.
- Durable execution is opt-in through a
CheckpointSaverand stablethread_id. - Default sinks are in-memory ring buffers; long-running sessions should plug in durable sinks.
- Circuit breaker state is per process.
License
MIT. Copyright 2026 Techrevati doo. See LICENSE.
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 techrevati_runtime-0.4.0.tar.gz.
File metadata
- Download URL: techrevati_runtime-0.4.0.tar.gz
- Upload date:
- Size: 392.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
13d16dba3b2a2939ec33510c78632af8b14acee4f131c396aff36f2ac3dffa78
|
|
| MD5 |
611441f32112b387424eabf6366cc58d
|
|
| BLAKE2b-256 |
2971e81070600ee80d84e9840ed67ff461932b15ba650c2de9db1c1110741d4e
|
Provenance
The following attestation bundles were made for techrevati_runtime-0.4.0.tar.gz:
Publisher:
release.yml on Techrevati/runtime
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
techrevati_runtime-0.4.0.tar.gz -
Subject digest:
13d16dba3b2a2939ec33510c78632af8b14acee4f131c396aff36f2ac3dffa78 - Sigstore transparency entry: 1891329910
- Sigstore integration time:
-
Permalink:
Techrevati/runtime@eaece4a87e0224573db3e778d702f5b1099c0243 -
Branch / Tag:
refs/tags/v0.4.0 - Owner: https://github.com/Techrevati
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@eaece4a87e0224573db3e778d702f5b1099c0243 -
Trigger Event:
push
-
Statement type:
File details
Details for the file techrevati_runtime-0.4.0-py3-none-any.whl.
File metadata
- Download URL: techrevati_runtime-0.4.0-py3-none-any.whl
- Upload date:
- Size: 131.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
442f4303624e9ce5a639d7e64275b735588e2912b6ff960ebb4124b8d15720c5
|
|
| MD5 |
68ed307195cc97a1785437f455dbd78e
|
|
| BLAKE2b-256 |
4c196ecaca5697ebb9940565e69cc65935020ec1866c9d1180027bf54e75ec23
|
Provenance
The following attestation bundles were made for techrevati_runtime-0.4.0-py3-none-any.whl:
Publisher:
release.yml on Techrevati/runtime
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
techrevati_runtime-0.4.0-py3-none-any.whl -
Subject digest:
442f4303624e9ce5a639d7e64275b735588e2912b6ff960ebb4124b8d15720c5 - Sigstore transparency entry: 1891330107
- Sigstore integration time:
-
Permalink:
Techrevati/runtime@eaece4a87e0224573db3e778d702f5b1099c0243 -
Branch / Tag:
refs/tags/v0.4.0 - Owner: https://github.com/Techrevati
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@eaece4a87e0224573db3e778d702f5b1099c0243 -
Trigger Event:
push
-
Statement type: