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.2.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.2-py3-none-any.whl (83.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: nudgeops-0.2.2.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.2.tar.gz
Algorithm Hash digest
SHA256 8a371abbacdd2a44c33a6f58dbb7c7b1d95cd4bb6a04370011a24b293834bbfb
MD5 48d3bfc236bc79a16c9afb21d167c580
BLAKE2b-256 7cc8b50ec57db35e0af909e5da6e81cf1f665f4b2ff10a18ff7176f463c7fe0b

See more details on using hashes here.

File details

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

File metadata

  • Download URL: nudgeops-0.2.2-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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 8fcbb01bdff34c454c27d6a347f1389e7fec3d0b7efb2b8cb07192abaa88e9e7
MD5 2c9241ddbb22737af0785b5530e2f09c
BLAKE2b-256 b0175743c193865ceee68e8242d282b336ee2cb36ffe1b9c45f32a25ca7ad44d

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