Reproduce the failure. Find the broken invariant. Prove the recovery.
AgentFault Lab is an open-source, local-first laboratory for controlled fault injection and recovery experiments in multi-step agent workflows. It records structured execution events, checks explicit invariants, compares recovery policies, and saves experiment results for inspection and regression testing.
Status: Initial working implementation / research prototype. The benchmark uses a small deterministic simulator. Results are not evidence of production-wide reliability or universal LLM behavior .Try it Live here: https://agentfault-lab-web.vercel.app/
Tracing and LLM evaluation platforms already cover substantial parts of debugging and evaluation. AgentFault Lab focuses on a narrower workflow:
- Define a workflow and its invariants.
- Inject a known failure at a controlled point.
- Record tool calls, results, state transitions, and recovery decisions.
- Compare no-recovery, retry, and state-aware recovery policies.
- Export and rerun the scenario as a regression test.
The initial implementation deliberately uses simulated tools and does not require an LLM or a paid API. This makes it possible to validate the test harness before introducing model nondeterminism.
- Deterministic tool simulator for example workflows.
- Fault injection: timeout, exception, malformed response, and repeated-response marker.
- Structured event traces with sequence numbers and timestamps.
- Explicit invariant checking.
- Three policies:
none,retry, andstate_aware. - Experiment runner with repeated trials.
- JSON summary, JSONL run records, per-run trace files, and SQLite persistence.
- FastAPI endpoints and command-line interface.
- Unit, API, integration, regression, and execution-bound tests.
- Dockerfile, Docker Compose, GitHub Actions, and contributor/security documentation.
Requirements: Python 3.10+.
python -m venv .venv
# Windows PowerShell:
.venv\Scripts\Activate.ps1
# macOS/Linux:
# source .venv/bin/activate
python -m pip install -e ".[dev]"
pytestList scenarios:
agentfault list --scenarios-dir scenariosRun one scenario:
agentfault run \
--scenario order_malformed_response \
--policy state_aware \
--scenarios-dir scenarios \
--output results/one-run.jsonOn Windows Command Prompt, put the command on one line or use ^ for line continuation.
Run the benchmark:
agentfault benchmark \
--scenarios order_malformed_response notification_timeout malformed_transform \
--policies none retry state_aware \
--trials 5 \
--scenarios-dir scenarios \
--output-dir results \
--experiment-id baseline-v1Or run the supplied configuration from the repository root:
python benchmarks/run_benchmark.pyOutputs include:
results/<experiment-id>_summary.jsonresults/<experiment-id>_runs.jsonlresults/traces/<run-id>.jsonlresults/agentfault.db
A sample 45-run baseline report and its run records are included in results/.
The observed policy comparison and its interpretation are documented in
docs/benchmark-methodology.md.
The SQLite database stores run metadata and event rows. Do not commit generated traces or databases if they contain sensitive data.
scenarios/order_processing/order_malformed_response.json models a state-changing order update that succeeds internally but returns a malformed response. A blind retry can perform the operation twice. The state-aware policy checks the simulated state before retrying.
Run the example:
python examples/run_one_scenario.pyExpected qualitative behavior:
none: stops after the malformed response.retry: retries the update; the simulated update count becomes 2 and the duplicate-operation invariant is violated.state_aware: detects the already-applied status update and resumes without applying the update again.
This is a designed simulator scenario, not an empirical claim about arbitrary agent frameworks.
Start the local API from the repository root:
uvicorn agentfault.api.app:app --host 127.0.0.1 --port 8000Open the interactive API docs at http://127.0.0.1:8000/docs.
Endpoints:
GET /healthGET /scenariosPOST /runsPOST /experiments
Example run request:
{
"scenario_id": "notification_timeout",
"policy": "retry",
"seed": 7
}The API resolves the shipped scenarios/ directory from the working repository by default; set AGENTFAULT_SCENARIOS_DIR explicitly when deploying from a different working directory or an installed package. For a public deployment, set APP_ENV=production and configure a strong AGENTFAULT_API_KEY. Protected routes require the X-API-Key header; /health remains public for hosting health checks. The web frontend attaches the key server-side. This MVP still needs shared rate limiting, durable managed database storage, user-level authorization, and a security review before production customer use.
docker compose up --buildThe API is exposed on port 8000. Results are written to the mounted results/ directory. This container does not execute arbitrary user-provided agent code; do not add that capability without a dedicated sandbox design.
flowchart TD
A[Experiment Configuration] --> B[Scenario Loader]
B --> C[Agent Runner]
C --> D[Simulated Tools]
E[Fault Injector] --> D
D --> C
C --> F[Execution Recorder]
F --> G[JSONL Event Trace]
F --> H[SQLite Run Store]
G --> I[Invariant Checker]
G --> J[Failure Analyzer]
I --> K[Experiment Evaluator]
J --> K
K --> L[Policy Comparison and Metrics]
L --> M[JSON Report]
L --> N[Regression Scenario Workflow]
models.py: validated scenario, event, and result schemas.runner/engine.py: deterministic workflow runner.faults/injector.py: call-count-based deterministic faults.invariants/checker.py: invariant checks.recovery/policies.py: bounded recovery policy definitions.recorder/recorder.py: append-only structured event recorder.evaluation/metrics.py: aggregate metrics and Wilson confidence interval utility.store.py: SQLite persistence.experiment.py: repeated experiment orchestration.analysis/report.py: JSON, JSONL, trace, and database outputs.api/app.py: FastAPI interface.cli.py: command-line interface.
Included scenarios cover:
- A malformed response after a state-changing order update.
- A transient notification timeout.
- A malformed transformation response.
Policies:
none: no retry.retry: bounded blind retry.state_aware: inspect known simulated state before retrying an order update.
Metrics currently reported:
- Task success rate.
- Fault injection rate.
- Invariant violation rate.
- Mean tool calls.
- Mean retries.
- Median duration.
- Total invariant violations.
Run the benchmark with multiple trials and retain the configuration with the results. The current scenarios are deterministic, so repeated trials primarily validate repeatability and output handling; they are not independent stochastic samples. Do not interpret a confidence interval from repeated identical deterministic runs as evidence of generalization.
Measured by the current implementation:
- Whether a configured fault was triggered.
- Whether the workflow reached its configured expected final state.
- Whether explicit supported invariants were violated.
- Tool-call and retry counts.
- Runtime of the local simulation.
- Whether a known duplicate-operation scenario is caught.
Not yet established:
- General root-cause diagnosis for arbitrary LLM behavior.
- Reliability across external agent frameworks.
- Production latency or throughput.
- Security of executing arbitrary user code.
- Generalization to real production workloads.
- Superiority over existing observability platforms.
Scenarios are JSON documents validated with Pydantic. They include a task, initial state, ordered action list, optional fault, invariants, and execution bounds. The simulator currently supports these tools:
validate_orderupdate_order_statussend_notificationread_filetransform_datamark_complete
Supported fault kinds:
timeoutexceptionmalformedrepeat_response
Supported invariant kinds:
required_final_stateunique_operationno_false_completionno_malformed_result_used
Add a new tool or invariant only with tests and an updated scenario example.
- The project runs simulated tools and does not require credentials.
- The API supports a shared
AGENTFAULT_API_KEYand fails closed in production if it is not configured. This is not end-user authentication or tenant isolation. - Traces may include tool arguments and state snapshots. Avoid secrets and personal data in scenarios.
- Do not execute arbitrary submitted Python code in the API process.
- If you add real tools, use explicit allowlists and safe test environments.
See docs/threat-model.md.
python -m pip install -e ".[dev]"
pytestOptional style check:
ruff check src testsThe project targets Python 3.10+. CI tests Python 3.10, 3.11, and 3.12.
- Harden event semantics and scenario schema.
- Add scenario-level expected-result validation.
- Add scenario minimization for failing runs.
- Add optional local LLM adapter, with prompts/model metadata captured.
- Add bootstrap comparisons for stochastic runs.
- Add one framework adapter after verifying the core interface.
- Add a lightweight trace viewer only if users need it.
This project is not a replacement for general tracing or evaluation products. Useful comparison points include:
The proposed distinction is a small, reproducible workflow connecting injected failures, observable invariant violations, recovery-policy comparison, and regression scenarios. That distinction should be validated against current releases before making originality claims.
MIT. Check third-party dependency and model licenses before redistributing optional components.
A Next.js dashboard lives in frontend/. It includes an experiment configuration UI, scenario library, policy comparison, and event trace explorer. The frontend uses a server-side API proxy so the backend API key is not exposed to browser JavaScript.
Requirements: Node.js 20.9 or newer.
-
Start the Python API from the repository root in one terminal:
$env:APP_ENV = "development" python -m uvicorn agentfault.api.app:app --reload --port 8000
-
In a second terminal:
cd frontend npm install Copy-Item .env.example .env.local -
Set
AGENTFAULT_API_URL=http://127.0.0.1:8000infrontend/.env.local. In local development, the API does not require a key unlessAGENTFAULT_API_KEYis configured. -
Run
npm run devand openhttp://localhost:3000.
- API: use the included
render.yamlBlueprint, or create a Render Web Service from this repository. The API starts withuvicorn agentfault.api.app:app --host 0.0.0.0 --port $PORTand uses/healthas its health check. - Frontend: import this GitHub repository into Vercel and set the Root Directory to
frontend. - Frontend environment variables: set
AGENTFAULT_API_URLto the deployed API URL andAGENTFAULT_API_KEYto the exact backend secret. Do not name itNEXT_PUBLIC_*; it must remain server-side. - Backend environment: set
APP_ENV=productionand configure a strongAGENTFAULT_API_KEY. Protected API routes fail closed if the key is missing./healthstays public for hosting health checks.
See docs/deployment.md for step-by-step hosting setup and the current MVP limitations.