State-harness detects LLM agent instability using control theory
Open-source state-harness library uses a Lyapunov energy function to catch token spirals in multi-turn LLM agents and explain failures without extra LLM calls.
State-harness is a new Python library that monitors multi-turn LLM agent loops for instability. It applies a Lyapunov energy function to track token usage against a warmup baseline, classifying failure patterns — context accumulation spirals, retry storms, policy drift, early token explosions — purely from token trajectories, with no additional LLM calls. When growth exceeds a threshold over consecutive turns, it trips the loop and produces a report with evidence, cost estimates, and concrete fixes like history compression, lower thresholds, or sliding-window context.
The author is explicit that the tool doesn't improve raw task success rates over a naive budget cap; its value lies in diagnostics rather than resolution. Where it does help is compute efficiency in search-tree agents (MCTS, beam search), cutting search nodes and wall-clock time on benchmarks like SWE-bench by terminating dead-end branches early. The project claims validation across roughly 3,175 runs and multiple models with zero false positives.
Integrations are provided for LangGraph, CrewAI, and vanilla Python agent loops, along with OpenTelemetry-compatible exports for observability at scale. The tool targets platform teams running production agents and search-based agent architectures, while noting that simple chatbots, RAG pipelines, or short ReAct loops are already well served by standard iteration and budget caps.