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.4.tar.gz (355.7 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.4-py3-none-any.whl (83.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: nudgeops-0.2.4.tar.gz
  • Upload date:
  • Size: 355.7 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.4.tar.gz
Algorithm Hash digest
SHA256 9ca4846e583ab5dd8cfa66f7323fa39c1cfd187718b0d2c2408e73e4f94a3595
MD5 fb0704a58a7084acab24beda61f0f015
BLAKE2b-256 f3fcef56c10e974d0e8c04e76a147860b04f700eabf2033c4dc4ef8cfc3184bc

See more details on using hashes here.

File details

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

File metadata

  • Download URL: nudgeops-0.2.4-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.4-py3-none-any.whl
Algorithm Hash digest
SHA256 3a29df50e2b6acbb61c29e57064f561f7c7cbae7471bf26be7458e88942e5a04
MD5 abc5529bf2197c2cf18a1bb612ece662
BLAKE2b-256 7df23e0a72ce76ffc6fe65e9db245da89697744d6cf1fe6b286c72589686fe1a

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