Skip to main content

ai-agent-gateway

Deploy an AI agent as an HTTP/SSE service without rebuilding session, tool, approval, and execution infrastructure around the model loop. Requires Python 3.10 or newer.

Ownership

This package owns the generic FastAPI chat surface, sessions and JWTs, SSE event stream, provider/run loop, tool dispatch, approvals, code execution, skills, sub-agents, autonomous execution, and heartbeat support.

It does not own an embedding product's profiles, prompts, channel policy, domain tools, research data, or business schemas. Applications supply those through create_gateway_app() or the higher-level create_agent() inputs.

Main entrypoints

Source Primary symbol Use it for
agent_gateway/easy.py create_agent() A small server from a prompt, tools, skills, and provider configuration
agent_gateway/server.py create_gateway_app() Product-owned runtime factories, auth, policy, and lifecycle integration
agent_gateway/autonomous.py run_autonomous() / run_autonomous_sync() A prebound headless one-shot with no HTTP server
agent_gateway/heartbeat.py HeartbeatLoop Repeated prebound autonomous work with quiet windows and backoff
agent_gateway/cli.py main() (agent init / agent run) Scaffold and run a package project

The package does not infer a new model or credential inside autonomous execution. The application resolves and passes the exact bound capability, session, billing mode, and skill limits before calling run_autonomous().

Quick start

Install a provider extra and set its credential:

pip install "ai-agent-gateway[anthropic]"
export ANTHROPIC_API_KEY="your-anthropic-api-key"
export USER_DATA_DIR="$PWD/.agent-data"
mkdir -p "$USER_DATA_DIR/gateway"
chmod 700 "$USER_DATA_DIR" "$USER_DATA_DIR/gateway"

Create and run a project:

agent init my-agent
cd my-agent
agent run

Or create a FastAPI app directly:

from agent_gateway import create_agent

app = create_agent(
    "You are a concise research assistant.",
    skills_dir="skills",
)

Serve the module with uvicorn agent:app. The default is the stable session.driver entry in the configured model registry; applications can pass another eligible stable model_key.

For OpenAI, install ai-agent-gateway[openai] and set OPENAI_API_KEY. Managed provider login flows are available through agent auth login anthropic, agent auth login codex, and agent auth login xai. Use agent auth status <provider> for all built-ins. Gateway token-store logout applies to Anthropic and XAI; Codex credentials are managed by the Codex CLI, and OpenAI uses OPENAI_API_KEY.

The complete session-token, chat request, and SSE walkthrough is in the quickstart.

Request shape

HTTP client
  -> create_agent() or create_gateway_app()
  -> ChatRuntime
  -> AgentRunner.run() (provider stream and model/tool loop)
  -> ToolDispatcher.dispatch()
       |-- local Python handler
       |-- MCP stdio server
       |-- approval policy
       |-- code execution
       `-- run_agent sub-agent
  -> EventLog -> SSE response

Headless calls use the same runner, tools, skills, and provider abstractions, but return RunOutput instead of exposing an HTTP/SSE session.

Develop and verify

From the package root, run:

pytest tests

Use the focused test for the boundary you change. Runnable examples live under examples/; the production-style assembly example is examples/07-full-production/, and the headless fixture is examples/09-autonomous/.

Documentation

License

MIT

Metadata

Release files for ai-agent-gateway 0.18.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ai-agent-gateway 0.18.0
File Size Uploaded
ai_agent_gateway-0.18.0.tar.gz 2.6 MB Details

Built distribution (wheel)

Table of built distributions (wheels) for ai-agent-gateway 0.18.0
File Interpreter ABI Platform
ai_agent_gateway-0.18.0-py3-none-any.whl Python 3 none any Details

Total release size: 4.7 MB

Release files / ai_agent_gateway-0.18.0.tar.gz

Download URL ai_agent_gateway-0.18.0.tar.gz
Size 2.6 MB
Tags Source
SHA-256 checksum
How to use checksums
b8280989d838afd88f61f89447751fff919b10e65ddce58c676b06c1e2670fa3
BLAKE2b-256 checksum
How to use checksums
540071b224b920cf888c60cab16b79a31ca63fed06a215d2719e864cbc6ef834
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.2

Release files / ai_agent_gateway-0.18.0-py3-none-any.whl

Download URL ai_agent_gateway-0.18.0-py3-none-any.whl
Size 2.1 MB
Tags Python 3
SHA-256 checksum
How to use checksums
06c07bc6ab4760b6d2eb231af786cdd9d4bee60448da2a0910fe527792517e5d
BLAKE2b-256 checksum
How to use checksums
19f9b2d1ebf2f15c140dc3c6e10569fa2a89c93a5954b5ef387a84a3bece5dc1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.2

Release history Release notifications | RSS feed

0.27.1

2 release files

0.26.0

2 release files

0.25.0

2 release files

0.24.2

2 release files

0.22.1

1 release file

0.22.0

1 release file

0.21.1

2 release files

0.21.0

2 release files

0.20.1

2 release files

0.20.0

2 release files

0.19.0

2 release files

0.18.4

2 release files

0.18.3

2 release files

0.18.1

2 release files

This release

0.18.0 This release

2 release files

0.17.4

2 release files

0.17.3

2 release files

0.17.2

2 release files

0.17.1

2 release files

0.17.0

2 release files

0.16.2

2 release files

0.16.1

2 release files

0.16.0

2 release files

0.15.9

2 release files

0.15.8

2 release files

0.15.7

2 release files

0.15.6

2 release files

0.15.3

2 release files

0.15.2

2 release files

0.15.1

2 release files

0.15.0

2 release files

0.13.1

2 release files

0.13.0

2 release files

0.12.1

2 release files

0.12.0

2 release files

0.11.1

2 release files

0.11.0

2 release files

0.10.0

2 release files

0.9.0

2 release files

0.8.1

2 release files

0.8.0

2 release files

0.7.0

2 release files

0.6.0

2 release files

0.5.3

2 release files

0.5.2

2 release files

0.5.1

2 release files

0.5.0

2 release files

0.4.2

2 release files

0.4.1

2 release files

0.4.0

2 release files

0.3.0

2 release files

0.2.3

2 release files

0.2.2

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page