MeshAI Python SDK — Agent Control Plane client
Project description
MeshAI Python SDK
Python client for the MeshAI Agent Control Plane. Register agents, send telemetry, query anomalies, manage governance policies, and track EU AI Act compliance.
Install
pip install meshai-sdk
With framework auto-tracking:
pip install meshai-sdk[openai] # OpenAI auto-tracking
pip install meshai-sdk[anthropic] # Anthropic auto-tracking
pip install meshai-sdk[crewai] # CrewAI auto-tracking
pip install meshai-sdk[langchain] # LangChain/LangGraph auto-tracking
pip install meshai-sdk[autogen] # AutoGen auto-tracking
Quick Start
from meshai import MeshAI
client = MeshAI(api_key="msh_...", agent_name="my-agent")
client.register(framework="crewai", model_provider="openai", model_name="gpt-4o")
# Automatic heartbeats every 60s
client.start_heartbeat()
# Track token usage (buffered, batched automatically)
client.track_usage(
model_provider="openai",
model_name="gpt-4o",
input_tokens=1500,
output_tokens=800,
)
# Graceful shutdown (also registered via atexit)
client.shutdown()
Auto-Tracking Integrations
OpenAI
from meshai import MeshAI
from meshai.integrations.openai import wrap_openai
import openai
meshai = MeshAI(api_key="msh_...", agent_name="my-agent")
meshai.register(model_provider="openai", model_name="gpt-4o")
oai = wrap_openai(openai.OpenAI(), meshai=meshai)
response = oai.chat.completions.create(
model="gpt-4o",
messages=[{"role": "user", "content": "Hello"}],
)
# Usage automatically tracked!
Anthropic
from meshai import MeshAI
from meshai.integrations.anthropic import wrap_anthropic
import anthropic
meshai = MeshAI(api_key="msh_...", agent_name="my-agent")
meshai.register(model_provider="anthropic", model_name="claude-sonnet-4-6")
ant = wrap_anthropic(anthropic.Anthropic(), meshai=meshai)
response = ant.messages.create(
model="claude-sonnet-4-6",
max_tokens=1024,
messages=[{"role": "user", "content": "Hello"}],
)
CrewAI
from meshai import MeshAI
from meshai.integrations.crewai import track_crewai
meshai = MeshAI(api_key="msh_...", agent_name="my-crew")
meshai.register(framework="crewai")
# Enable global tracking — all crews auto-track usage
track_crewai(meshai)
# Run your crew as normal — model extracted from each LLM call
crew.kickoff()
LangChain / LangGraph
from meshai import MeshAI
from meshai.integrations.langchain import MeshAICallbackHandler
from langchain_openai import ChatOpenAI
meshai = MeshAI(api_key="msh_...", agent_name="my-agent")
meshai.register(framework="langchain")
handler = MeshAICallbackHandler(meshai)
# Use with any LangChain model — model extracted automatically
llm = ChatOpenAI(model="gpt-4o", callbacks=[handler])
# Or with LangGraph
config = {"callbacks": [handler]}
result = graph.stream(input, config=config)
AutoGen
from meshai import MeshAI
from meshai.integrations.autogen import track_autogen
meshai = MeshAI(api_key="msh_...", agent_name="my-agent")
meshai.register(framework="autogen")
# Enable global tracking
track_autogen(meshai)
# Run agents as normal — all LLM calls tracked
Agent Queries
# List all agents
agents = client.list_agents(status="healthy", page=1, limit=50)
# Get single agent
agent = client.get_agent("01AGENT_ID_HERE")
# Update agent
client.update_agent("01AGENT_ID", description="Updated description")
# Delete agent (soft delete)
client.delete_agent("01AGENT_ID")
Cost Intelligence
# Cost summary
summary = client.get_cost_summary(start="2026-03-01T00:00:00Z", end="2026-03-17T00:00:00Z")
# Breakdown by agent or model
by_agent = client.get_cost_by_agent()
by_model = client.get_cost_by_model()
Anomaly Detection
# List active anomalies
anomalies = client.list_anomalies(severity="critical")
# Get summary
summary = client.get_anomaly_summary()
# Acknowledge or resolve
client.acknowledge_anomaly(event_id=42)
client.resolve_anomaly(event_id=42)
Governance
Risk Classification
# AI-assisted risk suggestion
suggestion = client.get_risk_suggestion("01AGENT_ID")
# Classify agent risk (EU AI Act Article 6)
client.classify_risk(
agent_id="01AGENT_ID",
risk_level="high",
justification="Handles PII in production",
assessed_by="security-team",
)
# Get classification
risk = client.get_risk_classification("01AGENT_ID")
Policies
# Create a policy
client.create_policy(
name="Production models only",
policy_type="model_allowlist",
rules={"allowed_models": ["gpt-4o", "claude-3-sonnet"]},
conditions={"environments": ["production"]},
)
# List policies
policies = client.list_policies(enabled=True)
# Dry-run evaluate
results = client.evaluate_policies(
agent_id="01AGENT_ID",
provider="openai",
model="gpt-4o",
)
# Update or delete
client.update_policy(policy_id=1, enabled=False)
client.delete_policy(policy_id=1)
Approvals (HITL)
# Check pending approvals
count = client.get_pending_count()
# List pending
pending = client.list_approvals(status="pending")
# Approve or deny
client.decide_approval(
request_id=1,
decision="approved",
reviewer_id="admin",
reason="Reviewed and approved",
)
Compliance (EU AI Act)
# Readiness score (0-120)
readiness = client.get_readiness_score()
# FRIA template (Article 27)
fria = client.get_fria("01AGENT_ID")
# Transparency card
card = client.get_transparency_card("01AGENT_ID")
Incident Reporting (Article 73)
# Report incident
client.create_incident(
agent_id="01AGENT_ID",
title="Data leak detected",
description="Agent exposed PII in response",
severity="critical",
reported_by="security-team",
is_widespread=False, # True = 2-day deadline, False = 15-day
)
# List and update
incidents = client.list_incidents(status="reported")
client.update_incident(
incident_id=1,
root_cause="Model hallucination",
corrective_actions="Added PII filter policy",
authority_notified=True,
)
Billing
# Current plan and agent usage
billing = client.get_billing_info()
# Returns: {plan, price_usd, max_agents, current_agents, at_limit}
Configuration
client = MeshAI(
api_key="msh_...", # Required
agent_name="my-agent", # Agent name (or pass to register())
base_url="https://api.meshai.dev",
environment="production", # production, staging, dev
batch_size=100, # Events per batch
flush_interval_seconds=5.0, # Auto-flush interval
heartbeat_interval_seconds=60, # Background heartbeat interval
max_retries=3, # Retry count on failure
timeout_seconds=10.0, # HTTP request timeout
)
Design Principles
- Never crashes the host — all SDK errors are caught and logged
- Buffered batching — events flush every 5s or 100 events
- Background heartbeat — daemon thread, auto-stops on shutdown
- Minimal dependencies — only
httpx
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file meshai_sdk-0.2.1.tar.gz.
File metadata
- Download URL: meshai_sdk-0.2.1.tar.gz
- Upload date:
- Size: 14.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5d8ad443075a3a236ac0d636b2c92c482f9d9073ecbe117a02a30d9ea3f808ec
|
|
| MD5 |
5c3500e4c6e84fcf3c3f49fd1c9b5248
|
|
| BLAKE2b-256 |
58c7ad6f60c4c36a71179b01694e6169a89855798317846d5d1863c35152b9c4
|
Provenance
The following attestation bundles were made for meshai_sdk-0.2.1.tar.gz:
Publisher:
publish.yml on meshailabs-org/meshai-sdk-python
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
meshai_sdk-0.2.1.tar.gz -
Subject digest:
5d8ad443075a3a236ac0d636b2c92c482f9d9073ecbe117a02a30d9ea3f808ec - Sigstore transparency entry: 1116817936
- Sigstore integration time:
-
Permalink:
meshailabs-org/meshai-sdk-python@bbcf2a772a219d0e16fe4d9ea618b43911dd1fd4 -
Branch / Tag:
refs/tags/v0.2.1 - Owner: https://github.com/meshailabs-org
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@bbcf2a772a219d0e16fe4d9ea618b43911dd1fd4 -
Trigger Event:
release
-
Statement type:
File details
Details for the file meshai_sdk-0.2.1-py3-none-any.whl.
File metadata
- Download URL: meshai_sdk-0.2.1-py3-none-any.whl
- Upload date:
- Size: 17.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cec25602a8ddb1b9b0834fa61c3222dfd4b5042be07e6f901e11bce6a2cfe501
|
|
| MD5 |
d4566431165218366250f35098d3a282
|
|
| BLAKE2b-256 |
27ab840bb07747a209b10dd699b195d6ad12f71aa03a61e4990b3d0828be0df2
|
Provenance
The following attestation bundles were made for meshai_sdk-0.2.1-py3-none-any.whl:
Publisher:
publish.yml on meshailabs-org/meshai-sdk-python
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
meshai_sdk-0.2.1-py3-none-any.whl -
Subject digest:
cec25602a8ddb1b9b0834fa61c3222dfd4b5042be07e6f901e11bce6a2cfe501 - Sigstore transparency entry: 1116817959
- Sigstore integration time:
-
Permalink:
meshailabs-org/meshai-sdk-python@bbcf2a772a219d0e16fe4d9ea618b43911dd1fd4 -
Branch / Tag:
refs/tags/v0.2.1 - Owner: https://github.com/meshailabs-org
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@bbcf2a772a219d0e16fe4d9ea618b43911dd1fd4 -
Trigger Event:
release
-
Statement type: