Skip to main content

Python SDK for defining durable Amber AI agent workflows

Project description

Amber SDK

amber-sdk is the Python library for defining durable Amber agent workflows in your agent applications. It provides the runtime object used by API and worker processes, plus decorators for durable workflows and steps.

Install

If you are deploying with Amber, install the full product package:

pip install amber-runtime

amber-runtime includes the amber CLI and depends on amber-sdk, so application code can use from amber import ....

Install amber-sdk directly only when you need the Python library without the CLI:

pip install amber-sdk

DB URL

Durable execution requires a Postgres database. Amber uses this database to store workflow state so queued runs, steps, and sleeps can recover cleanly after restarts. Set DB_URL in both the API and worker environments.

Public API

Most agent applications use these imports from the amber module:

from amber import (
    AgentRuntime,
    agent_runner,
    register_agent,
    sleep,
    step,
    workflow,
)

AgentRuntime is the recommended entry point for agent applications. The API process uses it to enqueue agent runs, and the worker process uses it to execute those queued runs.

agent_runner runs OpenAI Agents SDK agents inside Amber workflows. Use it from registered agents or workflow/step code when invoking an OpenAI agent. Amber wraps the call so agent execution fits the same durable workflow model as the rest of the app.

@register_agent, @workflow, and @step mark durable units of work, while sleep provides durable sleeps that recover cleanly after restarts.

Application Shape

Amber applications define a normal Python app and an agent runtime target, then deploy with the amber CLI.

from fastapi import FastAPI
from amber import AgentRuntime, register_agent, step

agent_runtime = AgentRuntime(
    queue_name="agent-runs",
)

app = FastAPI(lifespan=agent_runtime.api_lifespan())


@step()
async def draft_answer(prompt: str) -> str:
    return f"Draft answer for: {prompt}"


@register_agent(name="support-agent")
async def support_agent(prompt: str) -> str:
    return await draft_answer(prompt)


@app.post("/runs")
async def start_run(payload: dict[str, str]) -> dict[str, str]:
    handle = await agent_runtime.agents.start(
        "support-agent",
        payload["input"],
    )
    return {"workflow_id": handle.workflow_id}

If agents are defined in the same module as agent_runtime, no agent_modules setting is needed. If agents live in separate files, import those modules in the backend module so @register_agent runs before API requests enqueue work, and list the same modules in AgentRuntime(agent_modules=[...]) so the worker imports them when it starts.

# my_app/agents.py
from amber import register_agent


@register_agent(name="research-assistant")
async def research(topic: str) -> str:
    ...
# my_app/main.py
from fastapi import FastAPI
from amber import AgentRuntime
from . import agents  # registers @register_agent workflows

agent_runtime = AgentRuntime(
    agent_modules=["my_app.agents"],
    queue_name="agent-runs",
)

app = FastAPI(lifespan=agent_runtime.api_lifespan())

Use agent_runner inside registered agents when calling an OpenAI agent. This code usually lives in the separate agent module:

# my_app/separate_agent_file.py
from agents import Agent
from amber import agent_runner, register_agent

research_agent = Agent(
    name="Research Agent",
    instructions="Research the user request and return a concise answer.",
)


@register_agent(name="research-assistant")
async def research(topic: str) -> str:
    result = await agent_runner(
        starting_agent=research_agent,
        input=f"Research this topic: {topic}",
    )
    return str(result.final_output)

Run the API process with your ASGI server:

uvicorn my_app.main:app

Run a worker process against the same AgentRuntime target:

python -m amber.worker my_app.main:agent_runtime

Worker Concurrency

worker_concurrency defaults to 8. To change how many workflows each worker process can run at once, set worker_concurrency=<number> on AgentRuntime.

queue_concurrency defaults to None, meaning there is no global cap for the queue. Set queue_concurrency=<number> only when you need a maximum concurrency across workers.

The number of worker processes is controlled by however you run or deploy workers, not by SDK queue settings.

agent_runtime = AgentRuntime(
    queue_name="agent-runs",
    worker_concurrency=16,
    queue_concurrency=64,
)

Deploying

Use amber-runtime for the end-to-end product workflow:

pip install amber-runtime
amber init
amber deploy

See the amber-runtime package documentation for deployment, dashboard access, and workflow visibility.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

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

amber_sdk-0.1.1-py3-none-any.whl (18.9 kB view details)

Uploaded Python 3

File details

Details for the file amber_sdk-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: amber_sdk-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 18.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.27 {"installer":{"name":"uv","version":"0.9.27","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for amber_sdk-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 4b8264bda4956559c5c8e6c4ed5cefc38b817156750e4e4a983530d66bc16b19
MD5 16ccca3cd70e30fb65ce3cd5bd9b30e7
BLAKE2b-256 ca08e9cfa47cd7bf621dcfb8210da2cade07305ae805430a5f9133cc0cf48ef5

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