Skip to main content

⚡ Moven Python SDK (moven-sdk)

The Synchronous Circuit Breaker for Autonomous AI Agents in Python. Real-time, in-process safety fuses that detect runaway tool loops, hallucinated parameters, and cost spikes before your credit card burns.

PyPI version Python Version license Zero Latency


💡 Why Moven?

Observability platforms (LangSmith, Langfuse, Helicone) record what happened after your agent finishes. If your agent enters an unhandled 150-step loop at 2 AM, traditional tools show you a $300 bill in the morning.

Moven sits synchronously in the execution loop. It evaluates deterministic heuristics in < 0.8ms on every tool call and trips the fuse mid-flight before money burns.


✨ Core Capabilities

  • Zero-Latency In-Memory Hot-Path: In-memory static heuristics evaluate in < 0.8ms without network proxies.
  • 🔁 Canonical Deep Parameter Hashing: SHA-256 canonical serialization detects duplicate parameter loops regardless of dict key order.
  • 💸 Dynamic Live Pricing Engine: Real-time token math synced from https://api.moven.dev/v1/models calculates exact dollar savings when loops are intercepted.
  • 🛡️ Zero-Trust Hallucination Guard: Intercepts unpopulated placeholder arguments (TODO_..., REPLACE_ME, None) and non-existent schema parameters.
  • Ctrl+Z Step Checkpoints: Automatically snapshots agent state & prompts before every tool execution for instant time-travel rewinds.
  • 🤖 Multi-Model Dynamic Auto-Fallback: Automatically tracks token burn rates and provides in-memory model tiering.
  • 🌐 Python Framework Adapters: Native support for LangChain, LangGraph, CrewAI, AutoGen, OpenAI Python SDK, Anthropic Python SDK, and custom functions via @breaker.protect.

📦 Installation

pip install moven-sdk

🚀 Quick Start Examples

1. Protect Agent Tools with Decorator

from moven_sdk import MovenCircuitBreaker, BreakerConfig

# Initialize in-memory circuit breaker
breaker = MovenCircuitBreaker(
    BreakerConfig(
        project_id="a263283f-2d0b-4ce1-a40d-37103f09a160",
        max_repeats=3,               # Trip fuse after 3 identical tool calls
        spend_ceiling_usd=2.00,       # Stop runaway spend at $2.00
        max_turns=15,                 # Max recursion depth
        model_name="openai/gpt-4o",   # Used for real-time dollar calculation
    )
)

# Decorate any tool function
@breaker.protect
def query_vector_db(query: str, top_k: int = 5):
    # Your agent's tool execution logic
    return vector_store.similarity_search(query, k=top_k)

2. LangChain & LangGraph Callback Integration

from moven_sdk import MovenCircuitBreaker, BreakerConfig
from moven_sdk.adapters.langchain import MovenLangChainCallbackHandler
from langchain_openai import ChatOpenAI

# Initialize circuit breaker and callback handler
breaker = MovenCircuitBreaker(
    BreakerConfig(
        project_id="my-langgraph-project",
        max_repeats=3,
        spend_ceiling_usd=1.50,
    )
)
handler = MovenLangChainCallbackHandler(breaker)

# Attach callback handler to your LLM or LangGraph workflow
llm = ChatOpenAI(model="gpt-4o", callbacks=[handler])

3. CrewAI Tool Integration

from crewai import Agent, Task, Crew
from crewai.tools import tool
from moven_sdk import MovenCircuitBreaker, BreakerConfig

breaker = MovenCircuitBreaker(BreakerConfig(project_id="my-crewai-fleet"))

@tool("Search Internet")
@breaker.protect
def search_internet(query: str) -> str:
    """Searches the internet for relevant news."""
    return search_api.run(query)

4. Dynamic Live Model Pricing & Dollar Savings

Moven syncs live rates directly from https://api.moven.dev/v1/models and calculates accurate token and dollar savings when an infinite loop is aborted:

from moven_sdk import MovenDynamicPricingEngine

# 0ms in-memory lookup synced with OpenRouter catalog
rates = MovenDynamicPricingEngine.get_model_rates("anthropic/claude-3.5-sonnet")
print(f"Claude Sonnet Input Rate: ${rates['prompt']}/1M tokens")

# Exact dollar savings calculation on tripped loops
savings = MovenDynamicPricingEngine.calculate_money_saved(
    model_name="openai/gpt-4o",
    total_tool_calls_made=5
)

print(f"Prevented Spend: ${savings['money_saved']} USD ({savings['prevented_tokens']:,} tokens prevented)")

🛠️ Python Framework Adapters Reference

Framework Exported Adapter
Universal Function Decorator @breaker.protect
LangChain / LangGraph MovenLangChainCallbackHandler(breaker)
CrewAI wrap_crewai_tool(breaker, func)
OpenAI Python SDK MovenOpenAIWrapper(client, breaker)

⚙️ Configuration Reference (BreakerConfig)

from moven_sdk import BreakerConfig

config = BreakerConfig(
    project_id="default",                       # Moven project ID
    agent_name="production_agent",             # Agent identifier
    max_repeats=3,                              # Trip on N consecutive identical tool invocations
    spend_ceiling_usd=2.00,                     # Maximum hard dollar spend ceiling
    max_turns=50,                               # Maximum execution steps per session
    model_name="openai/gpt-4o",                 # Model used for pricing calculation
    endpoint="https://api.moven.dev/events",    # Telemetry streaming endpoint
    strict_placeholders=True,                   # Block unpopulated template args (TODO_...)
    auto_heal_github=False,                     # Dispatch automated AST GitHub pull request
)

🧪 Running Tests

python -m pytest tests/

📜 License

MIT © Moven AI

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

moven_sdk-0.1.0.tar.gz (15.9 kB view details)

Uploaded Source

Built Distribution

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

moven_sdk-0.1.0-py3-none-any.whl (15.7 kB view details)

Uploaded Python 3

File details

Details for the file moven_sdk-0.1.0.tar.gz.

File metadata

  • Download URL: moven_sdk-0.1.0.tar.gz
  • Upload date:
  • Size: 15.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.13.6

File hashes

Hashes for moven_sdk-0.1.0.tar.gz
Algorithm Hash digest
SHA256 3a62590599d0d7484702527e6a3d19bce1b2dea0d7b5f043851760f452b1c50f
MD5 a10467b1d7444434cde95bf61dae26ab
BLAKE2b-256 7adae9f84b2e21975854609c1867c671b2930d6e9de701e5efd85e946dd0b45c

See more details on using hashes here.

File details

Details for the file moven_sdk-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: moven_sdk-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 15.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.13.6

File hashes

Hashes for moven_sdk-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9dd7b0785aaf6fd04be44e9156679a0c24a5d5a8a0c1821174212b37f60d7342
MD5 c0c5a0f460dbaf4a2473a28cd30e53ef
BLAKE2b-256 8898017033a3b6813d96ad5843e3705989b91e52eec864483b50752245644453

See more details on using hashes here.

Release history Release notifications | RSS feed

0.2.0

2 files

This release

0.1.0 This release

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page