Skip to content

Python SDK

Commander provides a Python SDK for integrating multi-agent orchestration into Python applications. It is a thin HTTP client against a running Commander API server — not an in-process runtime.

Installation

bash
git clone https://github.com/PStarH/Commander.git
cd Commander/packages/python-sdk
pip install -e ".[dev]"

When published to PyPI

bash
pip install commander-ai

Package name: commander-ai · import: from commander import CommanderClient

Quick Start

python
import asyncio
from commander import CommanderClient

async def main():
    async with CommanderClient(
        api_key="cmd-...",
        base_url="http://localhost:4000",
    ) as client:
        # Zero-cost planning
        plan = await client.plan("audit repository for security vulnerabilities")
        print(f"Topology: {plan.topology}")
        print(f"Budget: ${plan.estimate.cost_budget_usd:.2f}")

        # Execute
        result = await client.run("list all Python files")
        print(f"Status: {result.status}")

asyncio.run(main())

API Reference

MethodDescription
client.run(prompt, ...)Execute an agent task
client.plan(task, ...)Zero-cost deliberation (no LLM call)
client.stream(session_id)SSE event stream for a running session
client.memory_write(content, ...)Write to memory
client.memory_query(...)Query memory
client.memory_stats()Memory statistics
client.health()Liveness probe
client.health_detailed()Detailed component health
client.system_status()System status
client.metrics()OpenMetrics text

Streaming

python
async for event in client.stream(session_id):
    if event.event == "output.delta":
        print(event.data["content"], end="", flush=True)
    elif event.event == "agent.status":
        print(f"\n[{event.data['status']}]")
    elif event.event == "tool_call.started":
        print(f"\n[Tool: {event.data['toolName']}]")

Event Types

EventDescription
output.deltaStreaming text output chunk
output.completedOutput stream finished
agent.statusAgent status change
reasoning.deltaAgent reasoning chunk
tool_call.startedTool call initiated
tool_call.completedTool call finished
tool_call.deltaTool call streaming output
tool_call.timeoutTool call timed out
tool_call.retryTool call retried
tool_call.blockedTool call blocked by approval gate
error.occurredError during execution
state.syncState synchronization
cost.updateToken cost update
compensation.updateCompensation status update

Sync Wrapper

For scripts and non-async contexts:

python
from commander import CommanderClientSync

client = CommanderClientSync(
    api_key="cmd-...",
    base_url="http://localhost:4000",
)
result = client.run("analyze this")
client.close()

Not for Jupyter/notebooks — use CommanderClient with asyncio there.

Configuration

Env varDefaultDescription
COMMANDER_API_KEYAPI key for Bearer auth
http://localhost:4000Commander server base URL

Architecture

Python SDK → HTTP → Commander Server → Runtime

The SDK is a thin httpx client — no Python-side runtime porting.

Development

bash
git clone https://github.com/PStarH/Commander.git
cd packages/python-sdk
pip install -e ".[dev]"
python -m pytest tests/ -v

MIT Licensed — Built for multi-agent orchestration.