Skip to main content

AgentOS Python SDK — instrument agents with runs, events, and tasks

Project description

pyagentos-sdk

Official Python SDK for AgentOS — instrument your AI agents with runs, events, and tasks.

The PyPI package is pyagentos-sdk (the agentos-* namespace was already claimed on PyPI by an unrelated project). The Python import name stays agentos for clean code.

The SDK is a thin client over the AgentOS API. Your agent code runs wherever you want; AgentOS observes it.

Install

pip install pyagentos-sdk

For LangChain integration:

pip install "pyagentos-sdk[langchain]"

Quick start

Generate an API key from your agent's page in the AgentOS dashboard, then pick a path:

Calling a hosted agent

For agents you've defined in AgentOS — invoke() runs the agent server-side and returns its output:

import os
from agentos import AgentOS

aos = AgentOS(
    api_key=os.environ["AGENTOS_API_KEY"],
    agent_id=os.environ["AGENTOS_AGENT_ID"],
)

result = aos.invoke({"prompt": "Hello"})
print(result["output"])

Instrumenting your own agent

For agents that run in your own code — start_run / emit / complete reports them to AgentOS for observability:

import os
from agentos import AgentOS

aos = AgentOS(
    api_key=os.environ["AGENTOS_API_KEY"],
    agent_id=os.environ["AGENTOS_AGENT_ID"],
)

run = aos.start_run(input={"prompt": "Hello"})

try:
    run.emit("step.completed", {"step": 1})

    # ... do work ...

    run.complete(output={"result": "Done"})
except Exception as e:
    run.fail(error_message=str(e))
    raise

emit(type, payload, level) is non-blocking — events are buffered and flushed on a timer (default 500 ms) or when the buffer fills (50 events). Call run.flush() if you need to be sure pending events are sent before the process exits. run.complete() and run.fail() flush automatically.

LangChain integration

Drop in AgentOSCallbackHandler to mirror LangChain runs into AgentOS automatically:

from agentos import AgentOS
from agentos.langchain import AgentOSCallbackHandler
from langchain_anthropic import ChatAnthropic

aos = AgentOS(api_key=..., agent_id="...")
run = aos.start_run()

model = ChatAnthropic(callbacks=[AgentOSCallbackHandler(run)])
model.invoke("What's the weather in SF?")

run.complete()

langchain-core is an optional dependency — only install it if you use the LangChain handler (pip install "pyagentos-sdk[langchain]").

Configuration

AgentOS(
    api_key="aos_...",
    agent_id="...",
    base_url="https://agentos-ai.dev",  # optional — production default; override for self-hosted / local dev
    batch_interval_ms=500,              # flush events every 500 ms
    batch_size=50,                      # max events per batch
    disabled=False,                     # set True in tests for a no-op client
    timeout_seconds=10.0,               # httpx request timeout
)

Errors

from agentos import (
    AgentOSError,            # base class
    AgentOSAuthError,        # 401 — invalid/revoked key
    AgentOSValidationError,  # 400 — server-side validation failed
    AgentOSRateLimitError,   # 429 — ingest rate limit exceeded
)

Requirements

  • Python 3.10+
  • An AgentOS workspace with an agent + API key (sign up)

License

Apache-2.0

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

pyagentos_sdk-0.2.0.tar.gz (7.0 kB view details)

Uploaded Source

Built Distribution

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

pyagentos_sdk-0.2.0-py3-none-any.whl (9.1 kB view details)

Uploaded Python 3

File details

Details for the file pyagentos_sdk-0.2.0.tar.gz.

File metadata

  • Download URL: pyagentos_sdk-0.2.0.tar.gz
  • Upload date:
  • Size: 7.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.6

File hashes

Hashes for pyagentos_sdk-0.2.0.tar.gz
Algorithm Hash digest
SHA256 f47d1d1b2d572e9c12885a890a59b593e4a18dc20a4a4f4b42267f2104af344e
MD5 e693c62cd7b6e47742b9067841ebe0ae
BLAKE2b-256 e34d15917d5dbe13373cf6a661ea646264807ea76df5bf601aef0f5ebe01a195

See more details on using hashes here.

File details

Details for the file pyagentos_sdk-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: pyagentos_sdk-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 9.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.6

File hashes

Hashes for pyagentos_sdk-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9efd03e89c5b1a25d5e386071ea7a4eece8c2ef9a3aa0d6b8f6d5df00a8e2e4b
MD5 c7f94bd4de85b403d1ded9b0cf5d778d
BLAKE2b-256 10d647a221416d9944a02150f6cd45dc07dae37c027ec275ae1f2032401e5786

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