Skip to main content

Async Python SDK for AgentOS APIs.

Project description

AgentOS SDK for Python

Async Python SDK for AgentOS APIs. The package is a thin client over AgentOS HTTP and SSE endpoints with small compatibility helpers for bearer tokens, stream callbacks, Pythonic method names, and request defaults.

Install

pip install agentos-sdk-python

For local development:

python3 -m venv .venv
.venv/bin/python -m pip install -e ".[dev]"

Quickstart

from agentos_sdk import AgentOSSDK


async def main():
    async with AgentOSSDK(base_url="http://localhost:8888") as sdk:
        version = await sdk.agentos.get_version()
        print(version)

        await sdk.agentos.register_bundle(
            {"bundleId": "com.demo.app", "appGroupId": "com.demo.group"}
        )

        tasks = await sdk.cronkit.list_tasks(limit=10)
        print(tasks)

AgentOSSDK also exposes TS-style camelCase aliases for common migration paths, such as registerBundle, listTasks, chatSimple, listModels, and loadTool.

Transport

The SDK uses httpx.AsyncClient and defaults to http://localhost:8888.

from agentos_sdk import AgentOSSDK

sdk = AgentOSSDK(
    base_url="http://localhost:8888",
    connect_timeout=5.0,
    receive_timeout=10.0,
)

Use async with AgentOSSDK(...) or call await sdk.aclose() when done.

Token Handling

sdk.agentos.register_bundle(...) stores the active app token. Protected facade methods in sdk.agentkit and sdk.cronkit use that token automatically.

If a protected call fails with HTTP 401, HTTP 403, or recognizable invalid-token text, the SDK re-runs registration for the same bundle once and retries the call.

AgentOS Events

from agentos_sdk import AgentOSEventHandler, AgentOSSDK


class Handler(AgentOSEventHandler):
    async def on_welcome(self, welcome):
        print("welcome", welcome)

    async def on_call_app(self, call):
        print("call app", call)

    async def on_done(self):
        print("subscription ended")

    async def on_error(self, error):
        raise error


async with AgentOSSDK() as sdk:
    await sdk.agentos.register_bundle({"bundleId": "com.demo.app"})
    await sdk.agentos.subscribe(Handler())

AgentKit

from agentos_sdk import AgentMessageHandler, AgentOSSDK, ToolReturn


class ChatHandler(AgentMessageHandler):
    async def on_message(self, session_id, message):
        print("message", session_id, message)

    async def on_chunk(self, session_id, chunk):
        print("chunk", session_id, chunk)

    async def on_function_call(self, session_id, function_call):
        return ToolReturn(function_call["id"], {"ok": True})

    async def on_done(self):
        print("done")

    async def on_error(self, error):
        raise error


async with AgentOSSDK() as sdk:
    await sdk.agentos.register_bundle({"bundleId": "com.demo.app"})
    session = await sdk.agentkit.init_session()
    await sdk.agentkit.chat(
        session,
        {"content": [{"type": "text", "message": "Hello"}]},
        ChatHandler(),
    )

Direct AgentKit methods include get_agent, create_agent, update_agent, delete_agent, init_session, init_simple, chat, chat_simple, history, stop, clear, callback, and stream_callback.

CronKit

async with AgentOSSDK() as sdk:
    await sdk.agentos.register_bundle({"bundleId": "com.demo.app"})
    task = await sdk.cronkit.create_task(
        request={
            "name": "Daily summary",
            "schedule": "0 9 * * *",
            "spec": {
                "systemPrompt": "You are a scheduled agent.",
                "content": [{"type": "text", "message": "Summarize today."}],
            },
        }
    )
    await sdk.cronkit.run_task_now(cron_id=task["cronId"])

CronKit create requests default concurrency to skipIfRunning, enabled to True, and spec.timeoutSeconds to 3600.

ModelKit

async with AgentOSSDK() as sdk:
    models = await sdk.modelkit.list_models()
    chat_models = await sdk.modelkit.list_models_by_task("chat")

    completion = await sdk.modelkit.chat.create(
        {
            "model": "qwen3-1.7b",
            "messages": [{"role": "user", "content": "Hello"}],
            "maxTokens": 128,
        }
    )

    async for chunk in sdk.modelkit.chat.create_stream(
        {"model": "qwen3-1.7b", "messages": [{"role": "user", "content": "Stream"}]}
    ):
        print(chunk)

ModelKit also supports:

  • sdk.modelkit.embedding.create(...)
  • sdk.modelkit.asr.transcribe(...)
  • sdk.modelkit.tts.synthesize(...)
  • sdk.modelkit.tts.list_voices()

ToolKit

async with AgentOSSDK() as sdk:
    tools = await sdk.toolkit.list_tool()
    definition = await sdk.toolkit.load_tool("tool-id")
    raw_json = definition.to_json() if definition else None

    async for event in sdk.toolkit.subscribe_tool_events("daemon-api-key"):
        print(event)

load_tool() returns an OpenToolDefinition wrapper that preserves the raw JSON definition. It does not execute tools or implement browser/daemon OpenTool bridging.

Direct Clients

The low-level clients are available for explicit-token or custom transport usage:

from agentos_sdk.clients import AgentKitClient, CronKitClient, ModelKitClient
from agentos_sdk.transport import ApiClient

api = ApiClient(base_url="http://localhost:8888")
agentkit = AgentKitClient(api)
agent = await agentkit.get_agent("bearer-token", "agent-id")

Development

.venv/bin/python -m compileall agentos_sdk
.venv/bin/python -m pytest -q
.venv/bin/ruff check .

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

agentos_sdk_python-0.1.0.tar.gz (18.9 kB view details)

Uploaded Source

Built Distribution

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

agentos_sdk_python-0.1.0-py3-none-any.whl (18.3 kB view details)

Uploaded Python 3

File details

Details for the file agentos_sdk_python-0.1.0.tar.gz.

File metadata

  • Download URL: agentos_sdk_python-0.1.0.tar.gz
  • Upload date:
  • Size: 18.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for agentos_sdk_python-0.1.0.tar.gz
Algorithm Hash digest
SHA256 6b510bf25d9ca672170fca16209e092894534aae1b521786dcc265c7cc51bb8c
MD5 2c35199b2958fe9d961a3f10aef4cbc1
BLAKE2b-256 5002bf94bf06ce4455a30c1cf38878d501cbf88b92df206045c5df01dd30bc4f

See more details on using hashes here.

File details

Details for the file agentos_sdk_python-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for agentos_sdk_python-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5accaf3583eaae292500e12a918a5d6466deeb7c2b10be2fa0a8a35749922314
MD5 84683fdc4aa87d6bd3aa30f9e7817cb4
BLAKE2b-256 1d0989bc6fec675d601cd418f92dc318ab45f7d12ac25de3980e43b7a0c14211

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