Metadata-Version: 2.4
Name: agents24
Version: 0.2.0
Summary: Unified Python SDK for Agents24 agent runtime and control APIs.
License: MIT
Requires-Python: >=3.10
Description-Content-Type: text/markdown
Requires-Dist: httpx>=0.27.0
Requires-Dist: requests>=2.31.0
Provides-Extra: fastapi
Requires-Dist: fastapi>=0.110; extra == "fastapi"
Provides-Extra: starlette
Requires-Dist: starlette>=0.36; extra == "starlette"
Provides-Extra: flask
Requires-Dist: flask>=3.0; extra == "flask"
Requires-Dist: asgiref>=3.8; extra == "flask"
Provides-Extra: django
Requires-Dist: django>=5.0; extra == "django"
Provides-Extra: aiohttp
Requires-Dist: aiohttp>=3.9; extra == "aiohttp"
Provides-Extra: server
Requires-Dist: fastapi>=0.110; extra == "server"
Requires-Dist: starlette>=0.36; extra == "server"
Requires-Dist: flask>=3.0; extra == "server"
Requires-Dist: asgiref>=3.8; extra == "server"
Requires-Dist: django>=5.0; extra == "server"
Requires-Dist: aiohttp>=3.9; extra == "server"

# agents24

Last Updated: 2026-07-15

Unified Python SDK for Agents24.

Interrupted runs use the strict V2 resume envelope: `schema_version = "agents24.hitl.resume.v2"`, one exact `interrupt_id`, one `approve | reject | connect | skip` action, and an optional comment. Reattach after every successful or idempotent resolution.

Endpoint methods are generated from `packages/agents24-sdk-contract/agents24.sdk.json`.
Do not edit files under `agents24/generated/` directly. For SDK maintenance, see `docs/references/agents24_sdk_development_guide.md`.

```python
from agents24 import Agents24

client = Agents24(
    base_url="http://localhost:8000",
    api_key="tpk_...",
    organization_id="org-id",
)

agent = client.agent({
    "name": "Support Agent",
    "instructions": "Answer briefly.",
}).create()

client.agents.publish(agent["id"])
```

## Published-Agent Runtime

Use `client.embed` from server code to call a published agent through the public embed runtime:

```python
def on_event(event):
    print(event["event"])

result = client.embed.stream_agent(
    "published-agent-id",
    {
        "input": "Help me with my account.",
        "external_user_id": "customer-user-123",
    },
    on_event=on_event,
)
```

The namespace also includes thread detail/delete, run-context, cancel, and attachment-upload methods.

Thread history can be listed for one agent or across several agents:

```python
threads = client.embed.list_agent_threads(
    "published-agent-id",
    external_user_id="customer-user-123",
)

sidebar_threads = client.embed.list_agent_threads_multi({
    "agent_ids": ["agent-a", "agent-b"],
    "external_user_id": "customer-user-123",
})
```

Async backends can use `AsyncAgents24.embed.list_agent_threads_multi(agent_ids, external_user_id=...)`.

## Artifact Authoring

Artifact code imports lightweight helpers from `agents24.artifacts`:

```python
from pydantic import BaseModel, Field

from agents24.artifacts import tool


class EchoInput(BaseModel):
    text: str = Field(description="Text to echo.")


class EchoOutput(BaseModel):
    text: str


@tool(
    name="echo",
    input_schema=EchoInput,
    output_schema=EchoOutput,
)
async def echo(input, config, context):
    return {"text": input["text"]}
```

The `agents24.artifacts` module is transport-free and safe for artifact runtime code. If artifact code imports Pydantic, declare `pydantic` as an artifact dependency.

Self-hosted Python services can expose decorated tools through the framework-neutral server helper:

```python
from agents24.server import create_artifact_server

server = create_artifact_server(
    exports=[echo],
    signing_secret="shared-environment-secret",
)

manifest = server.manifest()
health = server.health()
response = await server.invoke(body=request_body, headers=request_headers)
```

Use a built-in adapter when the SDK should create the application and mount the protocol routes:

```python
from agents24.server_adapters import create_artifact_fastapi_app

app = create_artifact_fastapi_app(
    exports=[echo],
    signing_secret="shared-environment-secret",
)
```

Adapters are available for FastAPI, Starlette, Flask, Django `urlpatterns`, and aiohttp. Application adapters create a new app by default or mount into an existing app passed as `app=`. Install only the selected extra, for example `agents24[fastapi]`; `agents24[server]` installs every supported framework adapter.

For custom providers, keep using `ArtifactServer` directly or wrap `create_artifact_asgi_app()` / `create_artifact_wsgi_app()`. `server.routes()` exposes the canonical method/path list and `await server.dispatch(...)` provides framework-independent routing and normalized JSON responses.

## Development

```bash
pnpm run generate:sdk
pnpm run check:sdk-contract
pnpm run test:agents24-python
```

Generated endpoint methods must stay in parity with the TypeScript `@agents24/sdk` package.
