Skip to main content

Runtime semantic guardrails for AI agents. Detect loops. Nudge agents back on track.

Project description

NudgeOps

PyPI version License: MIT Tests

Runtime semantic guardrails for AI agents.

Detect loops. Nudge agents back on track. Stop runaway costs.

Features

  • Pattern Detection: Stutter, insanity, phantom progress, ping-pong loops
  • Intent-Level Protection: LLM-based thought normalization to detect strategy repetition
  • Two-Level Blocking: Block exact action repeats AND exhausted strategies
  • LangGraph Integration: Drop-in guard for LangGraph workflows
  • Observability: Track blocks, saves, and ROI

Installation

pip install nudgeops

# With LangGraph support
pip install nudgeops[langgraph]

# With OpenAI for thought normalization
pip install nudgeops[openai]

# Everything
pip install nudgeops[all]

Quick Start

Basic Usage (Pattern Detection)

from nudgeops import UniversalGuard

guard = UniversalGuard()

# In your agent loop
result = guard.check(state)
if result.blocked:
    print(f"Loop detected! {result.reason}")

Smart Guard (Intent-Level)

from nudgeops import SmartNudgeOps, MockLLMClient

# Create guard
nudgeops = SmartNudgeOps(llm_client=MockLLMClient())

# Check before each action
result = nudgeops.check(
    state={"page": "search"},
    thought="I should search for XYZ-9999",
    tool_name="search",
    args={"query": "XYZ-9999"}
)

if result.blocked:
    print(f"Blocked: {result.reason}")
    print(f"Nudge: {result.nudge_message}")

LangGraph Integration

from nudgeops import SmartNudgeOps
from langgraph.graph import StateGraph

# Build your graph
builder = StateGraph(AgentState)
builder.add_node("agent", agent_node)
builder.add_node("tools", tool_node)

# Apply NudgeOps - wraps tool nodes with guard
nudgeops = SmartNudgeOps(llm_client=my_llm)
nudgeops.apply(builder)

graph = builder.compile()

How It Works

Two-Level Protection

Level 1 (Action): Block exact action repeats after 2 attempts

search({q:"XYZ-9999"}) → fails
search({q:"XYZ-9999"}) → BLOCKED (same action twice)

Level 2 (Intent): Block exhausted strategies after 3 variations

"search XYZ-9999"  → "find product by ID" (intent)
"try XYZ9999"      → "find product by ID" (same intent!)
"try XYZ 9999"     → "find product by ID" (same intent!)
"try XYZ--9999"    → BLOCKED (intent exhausted)

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

nudgeops-0.2.0.tar.gz (357.5 kB view details)

Uploaded Source

Built Distribution

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

nudgeops-0.2.0-py3-none-any.whl (83.0 kB view details)

Uploaded Python 3

File details

Details for the file nudgeops-0.2.0.tar.gz.

File metadata

  • Download URL: nudgeops-0.2.0.tar.gz
  • Upload date:
  • Size: 357.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.14

File hashes

Hashes for nudgeops-0.2.0.tar.gz
Algorithm Hash digest
SHA256 9a5df29bd6fe308433f5170587334926f2e644d8c776575716487b28a6edbb3e
MD5 6c8e60eee48956bbdad6cfce844410df
BLAKE2b-256 8cf859a40bf65765e2a00376662b26be28bf197b755b2b18dc2ddf237dbb0cc6

See more details on using hashes here.

File details

Details for the file nudgeops-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: nudgeops-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 83.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.14

File hashes

Hashes for nudgeops-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4794c934cad6f3a4b6f5e48845972c0664f854a3070e9bc71faf0709ae42f323
MD5 7c4053ca4625c71174cb3820bf5b9e40
BLAKE2b-256 246f4ff4d5530199f6b56efb027b8f367ecd097f87361c7a7b5a42143cb53ade

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