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.

Download files

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

Source Distribution

maos_agent-0.1.2.tar.gz (7.7 kB view details)

Uploaded Source

Built Distribution

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

maos_agent-0.1.2-py3-none-any.whl (7.3 kB view details)

Uploaded Python 3

File details

Details for the file maos_agent-0.1.2.tar.gz.

File metadata

  • Download URL: maos_agent-0.1.2.tar.gz
  • Upload date:
  • Size: 7.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.6

File hashes

Hashes for maos_agent-0.1.2.tar.gz
Algorithm Hash digest
SHA256 a14270ce7e86104527b89d1bd0f5df7f0704e462468677e16194e868ddab1c60
MD5 52b71416d4236a947d4b9eeb108f7897
BLAKE2b-256 4e8fb85e1281b8dbe4cc34dbdbc9a6dec2be78b7409a58612d09bbcd35bea028

See more details on using hashes here.

File details

Details for the file maos_agent-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: maos_agent-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 7.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.6

File hashes

Hashes for maos_agent-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 b0d21057e2d3a4f0a00d54bc455a5a94a9070622f5c0b6ac2644b906aa361111
MD5 b88021c3ad06048071b5a2dea2c4f4a0
BLAKE2b-256 61c121aca820a0a0a40ddb2a9f5d97b225720422aa8abd576a57e9b249a3deb3

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