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/


💬 Community & Support


📜 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.2.0.tar.gz (34.1 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.2.0-py3-none-any.whl (35.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: moven_sdk-0.2.0.tar.gz
  • Upload date:
  • Size: 34.1 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.2.0.tar.gz
Algorithm Hash digest
SHA256 dcdd533b76722d282080fee463b8b13fded28c183fd480377f7dee4994848109
MD5 7b9b15cb84e9bb98886632acb4cc0cbf
BLAKE2b-256 8a3a1b024b655bc51c235bdcc5d9d917004e706dc3208e5d2097174f59503943

See more details on using hashes here.

File details

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

File metadata

  • Download URL: moven_sdk-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 35.0 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.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 92bd43fbb8e2adaf0a7ff5c974908ae0cbe7163f9210521b47b1520edbf48d53
MD5 37bae7cadfdb51d670c63d8d145bb576
BLAKE2b-256 0cabf1b9d99240ad7f3d12edef44dfdaf5f53bd4794970acb80ae3177329c32b

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 files

0.1.0

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