v0.1.1
π‘οΈ LongGuard v0.1.1 β Initial Public Release
We are excited to introduce the initial open-source release of LongGuard β a lightweight, in-flight circuit breaker and reasoning loop recovery middleware designed specifically for autonomous AI agents built with LangGraph, LangChain, or custom loops.
β‘ What is LongGuard?
When autonomous LLM agents encounter ambiguous tool responses, rate limits, or unexpected hurdles, they often get stuck in destructive loops β calling identical tools repeatedly, oscillating between conflicting decisions, or drifting aimlessly while burning thousands of tokens.
LangGraph's built-in recursion_limit is a hard crash (GraphRecursionError) that drops user state with zero chance of recovery.
LongGuard catches loops early, injects a dynamic "Reflect & Pivot" prompt to guide the agent back on track, and only halts gracefully if recovery fails.
π Key Features
π 4-State Circuit Breaker State Machine
CLOSEDβ Normal agent operation; every step is monitored with sub-millisecond overhead.REFLECTINGβ Loop detected; injects recovery prompt to force course-correction.HALF_OPENβ Monitoring recovery step to verify the agent successfully pivoted.OPENβ Graceful circuit trip (kill) with complete conversation state preserved.
π 4 Autonomous Loop Detectors
- Tool Repeat Detector: Catches identical tool calls with duplicate parameters using SHA256 argument fingerprinting.
- Semantic Oscillation Detector: Detects thought cycles and conceptual loops across a rolling window using embedding variance.
- Dead-End Drift Detector: Flags repeated uninformative, empty, or error-laden tool observations using Jaccard similarity.
- Token Velocity Detector: Monitors exponential token spikes per step against dynamic rolling baselines.
π Seamless Integrations
- LangGraph 1.0+: Wrap your graph nodes in a single line of code with
add_guard_to_graph(). - LangChain: Drop-in wrapper via
GuardedAgentExecutor. - Standalone Loops: Full control using
CircuitBreakerandAgentStepin custom Pythonwhileloops.
π Comprehensive Telemetry
- Detailed
GuardReporttracking step latency, token consumption, detection events, and circuit breaker transitions.
π¦ Install
pip install longguard
# or
uv add longguard
# With optional extras:
pip install "longguard[langgraph]" # For LangGraph 1.0+
pip install "longguard[langchain]" # For LangChain
pip install "longguard[embeddings]" # For fast local semantic embeddingsFull Changelog: https://github.com/ENDEVSOLS/LongGuard/commits/v0.1.1