Skip to main content

Framework-agnostic, OTel-native toolkit for reliable, evaluatable, debuggable, and self-healing LLM agents in production

Project description

๐Ÿ› ๏ธ SpecOps AI

Agent Reliability Kit

Framework-agnostic, OTel-native toolkit for reliable, evaluatable, debuggable, and self-healing LLM agents in production.

PyPI version Python versions CI Coverage License

Getting Started โ€ข Features โ€ข Examples โ€ข Simulation โ€ข Coordination โ€ข Roadmap โ€ข Contributing


The Problem

LLM agents fail silently. They hallucinate, loop, drift off-task, and degrade without warning. Teams building agentic systems today lack:

  • Observability โ€” No standardized way to trace agent reasoning, tool calls, and decision paths
  • Evaluation โ€” No framework-agnostic way to measure if agents actually do what they're supposed to
  • Debugging โ€” When agents fail, root-cause analysis is guesswork
  • Self-healing โ€” Agents crash and stay crashed; no recovery patterns exist
  • Simulation โ€” No way to test for emergent failures before they hit production

Getting Started

Installation

pip install specops-ai

With framework adapters:

pip install specops-ai[langgraph]   # LangGraph support
pip install specops-ai[crewai]      # CrewAI support
pip install specops-ai[strands]     # Strands support
pip install specops-ai[all]         # All adapters

One-Line Quickstart

from specops_ai import trace_agent

@trace_agent(name="my-agent")
def agent(task: str) -> str:
    return "done"  # Your agent logic โ€” now fully traced via OTel

Trace Any Agent

from specops_ai import trace_agent, trace_tool, trace_llm

@trace_tool(name="search")
def search(query: str) -> list[str]:
    return ["result1", "result2"]

@trace_llm(model="gpt-4o", provider="openai")
def call_llm(prompt: str) -> dict:
    return {"text": "...", "model": "gpt-4o", "input_tokens": 10, "output_tokens": 25}

@trace_agent(name="research-agent")
def agent(task: str) -> str:
    results = search(task)
    return call_llm(f"Summarize: {results}")["text"]

Record & Replay

from specops_ai import replayable, recording, replaying

@replayable
def call_llm(prompt: str) -> str:
    return "..."  # Your LLM call

# Record
with recording(session_id="session-1", seed=42) as session:
    result = call_llm("What is 2+2?")

# Replay deterministically
with replaying("session-1"):
    same_result = call_llm("What is 2+2?")  # Identical output

Self-Healing

from specops_ai import self_healing, RetryPolicy, FallbackPolicy

@self_healing(
    retry=RetryPolicy(max_retries=3, base_delay=0.5),
    fallback=FallbackPolicy(fallback_fn=backup_llm),
)
def call_llm(prompt: str) -> str:
    ...  # Auto-retries, falls back if exhausted

Simulation Sandbox

from specops_ai import simulation

with simulation("loop-test", max_steps=50, loop_threshold=3) as sim:
    for action in agent_actions:
        event = sim.record("my-agent", action)
        if event.anomaly:
            print(f"Detected: {event.anomaly.value}")
    result = sim.stop()
    assert result.passed

Multi-Agent Coordination

from specops_ai import check_consensus, check_divergence, AgentOutput, BehaviorTrace

# Consensus check
result = check_consensus([
    AgentOutput(agent="a", output="yes"),
    AgentOutput(agent="b", output="yes"),
    AgentOutput(agent="c", output="no"),
], quorum=0.6)

# Divergence detection
result = check_divergence([
    BehaviorTrace(agent="a", actions=["search", "summarize", "respond"]),
    BehaviorTrace(agent="b", actions=["search", "summarize", "respond"]),
], max_edit_distance=2)

Evaluation

from specops_ai import eval_golden_set, EvalCase, llm_judge

results = eval_golden_set(
    agent_fn=my_agent,
    cases=[EvalCase(input="2+2", expected="4")],
)

verdict = llm_judge(output, criteria="correctness", judge_fn=my_llm)

RCA Graph

from specops_ai import build_rca_graph, to_dot

graph = build_rca_graph(spans)
print(f"Root causes: {[n.name for n in graph.root_causes]}")
dot_output = to_dot(graph, title="Failure Analysis")

โš ๏ธ SpecOps is in early development (v0.2.0). APIs may change. See the Roadmap.

Features

Category Status Description
OTel Tracing โœ… Trace agent runs, tool calls, LLM requests with OpenTelemetry spans
Replay Engine โœ… Record and replay agent sessions deterministically
Eval Harness โœ… Golden-set comparison + LLM-as-judge for behavioral evaluation
Self-Healing โœ… Retry with backoff, fallback chains, escalation, memory pruning
RCA Graphs โœ… Root-cause analysis from OTel spans, Graphviz DOT export
Simulation Sandbox โœ… Test for loops, drift, cascades, and token overflow in a sandbox
Coordination Checks โœ… Consensus, memory integrity, and divergence detection for multi-agent systems
Framework Adapters โœ… LangGraph, CrewAI, AutoGen, Strands adapters (auto-detected)

Simulation Sandbox

The simulation sandbox lets you test agent behaviors in a controlled environment before they hit production:

  • Loop detection โ€” Catch agents stuck repeating the same action
  • Budget enforcement โ€” Set max steps, duration, and token limits
  • Cascade testing โ€” Simulate failure propagation across agent pipelines
  • OTel integration โ€” All simulation events produce spans for analysis
from specops_ai import simulate, SimulationEnvironment

@simulate("my-scenario", max_steps=100, token_budget=10000)
def test_agent(sim: SimulationEnvironment):
    for task in tasks:
        sim.record("agent", task)
        sim.add_tokens(500)

Multi-Agent Coordination

Built-in checks for multi-agent systems:

Check Purpose
check_consensus() Verify agents agree on outputs (configurable quorum)
check_memory_integrity() Detect state divergence and stale reads
check_divergence() Flag behavioral drift via edit distance

Architecture

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚              Your Agent Code                 โ”‚
โ”‚  (LangChain / CrewAI / Custom / etc.)       โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚            SpecOps SDK Layer                 โ”‚
โ”‚  trace ยท eval ยท replay ยท heal ยท simulate    โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚         OpenTelemetry Protocol               โ”‚
โ”‚  spans ยท metrics ยท logs                      โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚           Any OTel Backend                   โ”‚
โ”‚  Jaeger ยท Grafana ยท Datadog ยท etc.          โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Project Structure

specops/
โ”œโ”€โ”€ src/specops_ai/       # Core library
โ”‚   โ”œโ”€โ”€ trace.py          # OTel tracing decorators
โ”‚   โ”œโ”€โ”€ replay.py         # Record/replay engine
โ”‚   โ”œโ”€โ”€ eval.py           # Evaluation harness
โ”‚   โ”œโ”€โ”€ heal.py           # Self-healing policies
โ”‚   โ”œโ”€โ”€ simulate.py       # Simulation sandbox
โ”‚   โ”œโ”€โ”€ coordinate.py     # Multi-agent coordination
โ”‚   โ”œโ”€โ”€ rca.py            # Root-cause analysis
โ”‚   โ””โ”€โ”€ adapters/         # Framework adapters
โ”œโ”€โ”€ tests/                # Test suite (120+ tests)
โ”œโ”€โ”€ examples/             # Usage examples
โ”‚   โ”œโ”€โ”€ providers/        # Provider-specific (require API keys)
โ”‚   โ”‚   โ”œโ”€โ”€ openai/       # OpenAI / LangGraph examples
โ”‚   โ”‚   โ”œโ”€โ”€ anthropic/    # Anthropic examples (coming soon)
โ”‚   โ”‚   โ””โ”€โ”€ grok/         # Grok examples (coming soon)
โ”‚   โ””โ”€โ”€ shared/           # Shared utilities (key loading, graceful skip)
โ”œโ”€โ”€ docs/specs/           # Specifications
โ””โ”€โ”€ pyproject.toml        # Build config (hatch + ruff + pytest)

Running the Examples

SpecOps ships with a rich set of examples covering every module. All examples run with a single command โ€” no complex setup required.

Quick Start

# 1. Install the package
uv sync

# 2. Run any core example immediately (no API keys needed)
uv run examples/plain_agent.py

Core Examples (No API Key Required)

These examples demonstrate SpecOps features using mocked LLM calls โ€” perfect for learning and CI:

Example Module Description
plain_agent.py Tracing Simple research agent with search + LLM tracing
async_pipeline.py Tracing Async multi-agent pipeline with nested spans
langgraph_agent.py Adapters StateGraph-style agent with tool routing
crewai_agent.py Adapters Multi-agent crew (researcher + writer)
replay_basic.py Replay Record and replay agent sessions deterministically
replay_async_eval.py Replay + Eval Async replay with evaluation harness
eval_golden_set.py Eval Golden-set evaluation with LLM-as-judge
self_healing_basic.py Heal Retry and fallback policies
self_healing_advanced.py Heal Escalation and memory pruning strategies
rca_analysis.py RCA Root-cause analysis graph from OTel spans
simulation_loops.py Simulation Detect agent loops in a sandbox
simulation_cascade.py Simulation Test cascading failures across agents
simulation_demo.py Simulation Full simulation sandbox walkthrough
multi_agent_coordination.py Coordination Consensus voting and divergence detection
# Run any core example
uv run examples/replay_basic.py
uv run examples/self_healing_advanced.py
uv run examples/simulation_demo.py

Provider Examples (API Key Required)

Provider examples connect to real LLM APIs. Each provider directory contains the same five examples for easy comparison:

Example Framework Description
basic_agent.py Direct API Simple traced agent call
langgraph_agent.py LangGraph StateGraph agent with tool routing
crewai_agent.py CrewAI Multi-agent crew orchestration
autogen_agent.py AutoGen Multi-agent conversation
strands_agent.py Strands Tool-use agent with Strands SDK

Available Providers

Provider Directory Required Key
OpenAI examples/providers/openai/ OPENAI_API_KEY
Anthropic examples/providers/anthropic/ ANTHROPIC_API_KEY
Grok (xAI) examples/providers/grok/ GROK_API_KEY

Setup

# 1. Copy the environment template
cp .env.example .env

# 2. Add your API key(s) โ€” only the providers you need
#    OPENAI_API_KEY=sk-...
#    ANTHROPIC_API_KEY=sk-ant-...
#    GROK_API_KEY=xai-...

# 3. Run a provider example
uv run examples/providers/openai/basic_agent.py
uv run examples/providers/anthropic/langgraph_agent.py
uv run examples/providers/grok/crewai_agent.py
uv run examples/providers/openai/strands_agent.py

๐Ÿ’ก Provider examples exit gracefully with a helpful message if the required API key is missing.

Mock Mode (No API Key Needed)

Run any provider example without a real API key using mock mode โ€” ideal for CI pipelines and quick testing:

SPECOPS_EXAMPLE_MODE=mock uv run examples/providers/openai/langgraph_agent.py
SPECOPS_EXAMPLE_MODE=mock uv run examples/providers/anthropic/autogen_agent.py
SPECOPS_EXAMPLE_MODE=mock uv run examples/providers/grok/strands_agent.py

Viewing Traces

By default, traces are printed to the console. To send traces to an OTel-compatible backend like Jaeger:

export OTEL_EXPORTER_OTLP_ENDPOINT=http://localhost:4317
uv run examples/plain_agent.py

Contributing

We use spec-driven development โ€” every feature starts as a specification before code is written. See CONTRIBUTING.md for the full workflow.

# Setup
uv sync

# Run tests
uv run pytest

# Lint & format
uv run ruff check src/ tests/
uv run ruff format src/ tests/

# Type check
uv run mypy src/

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

specops_ai-0.3.0.tar.gz (426.0 kB view details)

Uploaded Source

Built Distribution

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

specops_ai-0.3.0-py3-none-any.whl (33.3 kB view details)

Uploaded Python 3

File details

Details for the file specops_ai-0.3.0.tar.gz.

File metadata

  • Download URL: specops_ai-0.3.0.tar.gz
  • Upload date:
  • Size: 426.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.12 {"installer":{"name":"uv","version":"0.11.12","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for specops_ai-0.3.0.tar.gz
Algorithm Hash digest
SHA256 4755e91048559690be0a7db7621a7aaa6d2ce200a8298456dda4ca872572b487
MD5 a597000b7f6ac61d914a7388aea0196e
BLAKE2b-256 53dc6a1301ebed2a9c85eed5c584287d5548315da76e796eca8ee3d31910c0f5

See more details on using hashes here.

File details

Details for the file specops_ai-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: specops_ai-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 33.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.12 {"installer":{"name":"uv","version":"0.11.12","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for specops_ai-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0d8b48d257f7c72726f4f95a1ad83a14b4261237517d13ea64ecf5d1d37695b2
MD5 b892bdd51b47aa5f86c5da4abc96e8f8
BLAKE2b-256 d94202fa378aa7397e042307afb4891e0ceac33f59cd3dd21e9055c1b3fcb719

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