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

Uploaded Python 3

File details

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

File metadata

  • Download URL: nudgeops-0.2.1.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.1.tar.gz
Algorithm Hash digest
SHA256 42e1edd57a51a37a7b57ee0891386c50ed0656d87066f888314978915e038085
MD5 f9dcbf097141fac2f4085dfe266cc394
BLAKE2b-256 01b3e03f53489e21455267fb44c62d5145f5544403eb1a5f306694a2c98968b1

See more details on using hashes here.

File details

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

File metadata

  • Download URL: nudgeops-0.2.1-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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 3ba1589d08ab854fabe17791f09036d39b80e1d095254bbedb6956143c60eecb
MD5 7f4b8b3795d2d27a14630fce1b8a3a91
BLAKE2b-256 c1b08466b09564786efcf6e1ce81432c8faf5ca7845873c0c5d16f3ea1542bd8

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