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

Uploaded Python 3

File details

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

File metadata

  • Download URL: nudgeops-0.2.5.tar.gz
  • Upload date:
  • Size: 88.6 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.5.tar.gz
Algorithm Hash digest
SHA256 6506b9f29943bb477d88020a235d137623a57cc8b41408c21f5c3263dc12a2e0
MD5 773bfdbb1c408ccdfdb8c1286c38e6ac
BLAKE2b-256 7b1f6aeffacb7dfe2be082dc9d32693fd33bd7b9017ed5c8dc65e8c8a69d4544

See more details on using hashes here.

File details

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

File metadata

  • Download URL: nudgeops-0.2.5-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.5-py3-none-any.whl
Algorithm Hash digest
SHA256 1b357820f56e3f20fe1f292e0bf64cb69322b5f65ae6b5ec2e10580cf8f9a000
MD5 0060840a8c8a5244fcdef8cd54afae54
BLAKE2b-256 4b51fce1ae3d4dc43b68775d35741bed7289975d5a587db732198396a491f4a2

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