Skip to main content

Agent reliability layer: circuit breakers, dead letter queues, cost guards, and verification loops for any AI agent framework

Project description

lore-agents

PyPI Python License: MIT

Agent reliability layer. Adds circuit breakers, dead letter queues, cost guards, model routing, and execution tracing to any AI agent framework.

Install

pip install lore-agents

Quick Start

from lore import CircuitBreaker, CostGuard, DeadLetterQueue, LoreTrace, lore_wrap

# Wrap any LLM call with full reliability stack
safe_call = lore_wrap(
    my_llm_function,
    name="openai",
    failure_threshold=3,
    session_limit_usd=5.0,
)
result = safe_call("Hello, world!")

Features

Circuit Breaker

Prevents cascading failures when LLM providers go down.

from lore import CircuitBreaker

cb = CircuitBreaker(name="openai", failure_threshold=3, recovery_timeout=30)
result = cb.call(openai_chat, prompt="hello")

# Or use as a decorator
from lore import circuit_breaker

@circuit_breaker(name="anthropic", threshold=5)
def call_claude(prompt: str) -> str:
    return client.messages.create(...)

States: CLOSED (normal) -> OPEN (rejecting) -> HALF_OPEN (probing) -> CLOSED

Dead Letter Queue

SQLite-backed queue that captures failed tasks with automatic error classification.

from lore import DeadLetterQueue

dlq = DeadLetterQueue()

try:
    result = agent.run(task)
except Exception as e:
    dlq.push("task-123", e, context='{"model": "gpt-4o"}')

# Replay transient failures
entries = dlq.replay_transient(rate=10)

Classification: Transient (retry) | Permanent (park) | Ambiguous (one retry)

Cost Guard

Per-task and per-session spending limits with alerting.

from lore import CostGuard

guard = CostGuard(session_limit_usd=5.00, task_limit_usd=0.50)
guard.check_budget("task-1")  # Pre-flight check
guard.record("gpt-4o", input_tokens=1000, output_tokens=500, task_id="task-1")
print(guard.get_summary())

Model Router

3-tier routing (budget/mid/frontier) with latency tracking and fallback cascades.

from lore import ModelRouter, ModelTier

router = ModelRouter(
    task_type_map={"crud": ModelTier.BUDGET, "architecture": ModelTier.FRONTIER}
)
model = router.route("crud")  # -> cheapest healthy model

Execution Tracing

Step-level cost and duration tracking, exportable to JSON.

from lore import LoreTrace

tracer = LoreTrace("customer_support")
with tracer.step("classify", model="gpt-4o-mini") as s:
    result = classify(query)
    s.input_tokens = 150
    s.output_tokens = 20

tracer.finish()
print(tracer.to_json())

Audit Scanner

Scans agent code for missing reliability patterns.

from lore import LoreAudit

audit = LoreAudit("/path/to/project")
report = audit.scan()
print(report.to_json())

CLI

lore install .          # Install reliability rules + pre-commit hooks
lore audit .            # Scan for missing patterns
lore audit . -j         # JSON output
lore trace trace.json   # View a trace file
lore wrap               # Show wrap usage examples

Optional Dependencies

pip install lore-agents[redis]  # Redis-backed circuit breaker persistence
pip install lore-agents[dev]    # Development tools (pytest, mypy, ruff)

License

MIT

Project details


Download files

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

Source Distribution

lore_agents-0.1.0.tar.gz (31.9 kB view details)

Uploaded Source

Built Distribution

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

lore_agents-0.1.0-py3-none-any.whl (33.8 kB view details)

Uploaded Python 3

File details

Details for the file lore_agents-0.1.0.tar.gz.

File metadata

  • Download URL: lore_agents-0.1.0.tar.gz
  • Upload date:
  • Size: 31.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for lore_agents-0.1.0.tar.gz
Algorithm Hash digest
SHA256 f4a96312d0e60742fb7624a60ebce333b4a3e1fbabe6ce12e97f7c296f7e76f0
MD5 077652db273243906ab6984e2fb610ea
BLAKE2b-256 f4676f5f6346309901defeb2940c70d23799f3cc03667de422ee701cfd576309

See more details on using hashes here.

File details

Details for the file lore_agents-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: lore_agents-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 33.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for lore_agents-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d30c128662642a9787deb97f8cd6b4bd487aef9b5be37ce0344a4df1b4f18bee
MD5 395abc011b85dd661e3ae4706404affc
BLAKE2b-256 370aa965a472c57371bb75c296b95a2a75079595aa0b654ec2f172475fd51e89

See more details on using hashes here.

Supported by

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