Skip to main content

Maos Agent SDK

The official Python SDK for building resilient, observable AI Agents on the Maos Platform.

maos-agent provides the "Day 2" primitives required to run autonomous agents in production:

  1. Zero-Config Telemetry: Automatically emits Prometheus metrics for every tool call, token used, and cognitive step.
  2. Spot Instance Resilience: Handles SIGTERM signals from Kubernetes to allow graceful state checkpointing before node termination.

Installation

pip install maos-agent

Quick Start

Wrap your existing agent code with the Maos decorators to instantly get Grafana dashboards and Spot interruption protection.

import time
import random
from maos_agent import MaosAgent, SpotInterruptionError

# 1. Initialize (Starts Prometheus server on port 8000)
agent = MaosAgent(service_name="financial-analyst", version="v1.2")

# 2. Define Tools (Auto-tracked for success/failure rates)
@agent.tool(name="stock_lookup")
def get_stock_price(ticker: str):
    # Simulate work
    if random.random() < 0.05:
        raise ConnectionError("API Timeout") # Recorded as 'error' in Grafana
    return 150.00

# 3. The Agent Loop
def run_job():
    # Track duration, steps, and success automatically
    with agent.task("analyze_portfolio") as task:
        print("Starting analysis...")
        
        for i in range(5):
            # --- THE MAOS GUARANTEE ---
            # Checks if K8s sent a termination signal (Spot reclaim).
            # Raises SpotInterruptionError if node is draining.
            agent.check_health() 
            
            # Record a "cognitive step" (thinking loop)
            task.step() 
            
            price = get_stock_price("AAPL")
            time.sleep(1)

if __name__ == "__main__":
    try:
        run_job()
    except SpotInterruptionError:
        print("🚨 SPOT RECLAIM DETECTED! SAVING STATE TO REDIS...")
        # Checkpoint your agent's memory here so it can resume on a new node
        exit(0)

Key Features

1. Automatic Telemetry (The "Brain Scan")

Stop guessing if your agent is working. The SDK automatically exposes a /metrics endpoint on port 8000 (configurable) with standard Prometheus metrics:

Metric Name Type Description
maos_agent_tool_calls_total Counter Tracks tool usage + Success/Error rates.
maos_agent_steps_per_goal Histogram Detects "Loops of Death" (agents spinning in circles).
maos_agent_token_usage_total Counter Tracks cost (Input vs Output tokens).
maos_agent_task_duration_seconds Histogram End-to-end latency of jobs.

Compatible with the Maos Agent Quality Dashboard.

2. Graceful Shutdown (The "Money Saver")

Maos runs agents on Spot Instances to save you 90% on compute. However, Spot nodes can disappear with a 2-minute warning.

The agent.check_health() method abstracts the complexity of Kubernetes signal handling.

  • Normal operation: Returns immediately.
  • During Drain: Raises SpotInterruptionError.

Best Practice: Call check_health() inside your main while loop or before every LLM call.


Configuration

You can configure the agent via environment variables or constructor arguments.

Environment Variable Default Description
MAOS_SERVICE_NAME unknown-agent The name of your agent (for filtering in Grafana).
MAOS_METRICS_PORT 8000 Port to expose Prometheus metrics.
MAOS_LOG_LEVEL INFO Logging verbosity.

Contributing

We welcome contributions! Please see CONTRIBUTING.md for details.

  1. Fork the repo.
  2. Create a feature branch (git checkout -b feature/langchain-integration).
  3. Commit your changes.
  4. Open a Pull Request.

Built by Maosproject Platform — The Control Plane for Autonomous Compute.

Metadata

Release files for maos-agent 0.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for maos-agent 0.1.2
File Size Uploaded Provenance
maos_agent-0.1.2.tar.gz 7.7 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for maos-agent 0.1.2
File Interpreter ABI Platform
maos_agent-0.1.2-py3-none-any.whl Python 3 none any Details

Total release size: 15.0 kB

Release files / maos_agent-0.1.2.tar.gz

Download URL maos_agent-0.1.2.tar.gz
Size 7.7 kB
Tags Source
SHA-256 checksum
How to use checksums
a14270ce7e86104527b89d1bd0f5df7f0704e462468677e16194e868ddab1c60
BLAKE2b-256 checksum
How to use checksums
4e8fb85e1281b8dbe4cc34dbdbc9a6dec2be78b7409a58612d09bbcd35bea028
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.6

Release files / maos_agent-0.1.2-py3-none-any.whl

Download URL maos_agent-0.1.2-py3-none-any.whl
Size 7.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b0d21057e2d3a4f0a00d54bc455a5a94a9070622f5c0b6ac2644b906aa361111
BLAKE2b-256 checksum
How to use checksums
61c121aca820a0a0a40ddb2a9f5d97b225720422aa8abd576a57e9b249a3deb3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.6

Security for maos-agent 0.1.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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