Agent reliability layer: circuit breakers, dead letter queues, cost guards, and verification loops for any AI agent framework
Project description
lore-agents
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)
CI/CD Integration
Run lore audit automatically on every PR with GitHub Actions.
Quick Setup
mkdir -p .github/workflows
curl -o .github/workflows/lore-audit.yml \
https://raw.githubusercontent.com/Miles0sage/lore-agents/main/.github/workflows/lore-audit.yml
git add .github/workflows/lore-audit.yml
git commit -m "ci: add lore agent reliability audit"
git push
This will:
- Audit every PR that changes Python files and post a comment with the reliability score
- Run on every push to
main - Run weekly (Monday 6am UTC) to catch drift
See examples/github-actions-setup.md for customization options.
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
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 lore_agents-0.2.0.tar.gz.
File metadata
- Download URL: lore_agents-0.2.0.tar.gz
- Upload date:
- Size: 357.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0818a1fac1c96780737f4bdf9ee683b92c7b7e46cb5cd850cf6f150b078cfd63
|
|
| MD5 |
74ca72f86aa1dd796a33bbf30b1aa796
|
|
| BLAKE2b-256 |
b08deb67e2ef4449f0ce3bc043494ac0e79069d7d66ae324a429e6559798c0cc
|
File details
Details for the file lore_agents-0.2.0-py3-none-any.whl.
File metadata
- Download URL: lore_agents-0.2.0-py3-none-any.whl
- Upload date:
- Size: 70.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ccd3cd3c90e8ceafb35d80bab3256a97faeb66adecae5672e4930e613adf7857
|
|
| MD5 |
79230c3a51d39af7337ba89bf4a63968
|
|
| BLAKE2b-256 |
063698d4eaf508d6978cf9d323eeed997c333315641eac63c716fb41d2549987
|