Skip to main content
The AgentOS SDKs serve the agent contract (GET /health and POST /invoke) and wrap every platform call an agent makes. You write one function per capability; the SDK calls it with the invocation and turns what it returns into the right answer. Everything the SDKs do is one of the documented HTTP calls, so an agent in any other language loses nothing by using plain HTTP. Check either way with the conformance kit.

A first handler

Putting the SDK in your bundle

The SDKs aren’t published on PyPI or npm yet. They ship with AgentOS as a Python wheel (agentos_sdk-0.1.0-py3-none-any.whl) and an npm tarball (agentos-sdk-0.1.0.tgz). Put the file in a vendor/ folder of your bundle and install it from there in your Dockerfile:
Dockerfile
With an extra, for example LangGraph: RUN pip install "$(ls vendor/*.whl)[langgraph]".For local development and tests, pip install vendor/agentos_sdk-0.1.0-py3-none-any.whl into your virtual environment.
Zip the folder with vendor/ in it and deploy as usual.

The invocation

A handler gets the invocation, inv, with input, capability, run_id / runId, session_id / sessionId, user, kind, id, seq, attempt, config, secrets, resume and eval, plus these helpers: Python’s platform calls are synchronous, each with an async twin (aask, astart, aevent, state.run.aget …), and async handlers work too. inv.eval is None / null on a normal run. On an experiment run it holds the holds recorded for the dataset item. Keeping side effects (payments, emails) out of eval runs is your code’s job: check it.

Answers and errors

A Fail code is lowercase letters, digits and _, starting with a letter, at most 63 characters, with a non-empty message (the platform would record anything else as agent_failed, so Python’s Fail refuses it with a ValueError). Platform refusals raise AgentOSError subclasses: InvalidRequest (and GuardrailBlocked, with guardrail, at, hit), Unauthorized, Forbidden, NotFound, Conflict (and VersionConflict, with current_version), TooLarge, and InvocationEnded when your code uses the invocation after it answered. agentos.guardrail_block(error) / guardrailBlocked(error) find a guardrail block inside another client’s error (see Guardrails).
There is no “run once” helper. Code before ask() runs again on the resume, so keep it idempotent and key side effects by run_id and a step name.

Serving

The run token in your own HTTP clients

The SDK sends the run token only to the platform and the model gateway, and only while the invocation runs; afterwards it raises InvocationEnded instead of sending it. Your own clients should follow the same rule:
  • Python: httpx.Client(event_hooks=agentos.httpx_event_hooks()) (async_httpx_event_hooks() for AsyncClient) adds the token to requests for the platform’s hosts and takes it off any request to another host, redirect hops included: once a request has left the platform, its later hops never get the token. A thread pool doesn’t inherit the invocation: submit agentos.bind(fn).
  • TypeScript: inv.fetch(url, init) or platformFetch(url, init) follow redirects themselves with the same rule. The invocation follows awaits and timers, not worker threads.

Frameworks

Adapters for the OpenAI Agents SDK, LangGraph, Agno, the Vercel AI SDK and Mastra turn each framework’s own pause into a hold and continue where it stopped on the resume. See Frameworks.