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.1.tar.gz (7.1 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.1-py3-none-any.whl (9.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pyagentos_sdk-0.2.1.tar.gz
  • Upload date:
  • Size: 7.1 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.1.tar.gz
Algorithm Hash digest
SHA256 2d352ec3a6d2abbdba9b98a2558b118494cc772b51ee475e1504707946afdbd0
MD5 757b276b8a0ee081e6e29e4653a9a485
BLAKE2b-256 025c252c5952ac38fb65ac7051fcc1fbba4b4272ab86c0741736685eaea4ab90

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pyagentos_sdk-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 9.2 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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 15d76dba48b06efb002de3c1f37beac9e1fbd6890d7af88e23c06a232a54f34a
MD5 1ce65ab6e05fc410006f4051810528d3
BLAKE2b-256 76b21ce3e76224b0e93c4ca84d981f5575e48e21dcdb9d5656623f7de2d89f62

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