Skip to main content

ag-ui-claude-agent-sdk

Implementation of the AG-UI protocol for the Anthropic Claude Agent SDK (Python).

Installation

pip install -e .

Usage

The adapter manages the SDK lifecycle internally — just call adapter.run(input_data):

from ag_ui_claude_sdk import ClaudeAgentAdapter, add_claude_fastapi_endpoint

adapter = ClaudeAgentAdapter(name="my_agent", options={"model": "claude-haiku-4-5"})
add_claude_fastapi_endpoint(app=app, adapter=adapter, path="/my_agent")

Features

  • Full lifecycle management - Handles client pooling, message extraction, and event translation internally
  • Interrupt support - Call adapter.interrupt() to stop a running query
  • Dynamic frontend tools - Client-provided tools automatically added as MCP server with auto-granted permissions
  • Frontend tool halting - Streams pause after frontend tool calls for client-side execution (human-in-the-loop)
  • Streaming tool arguments - Real-time TOOL_CALL_ARGS emission as JSON arguments stream in
  • Bidirectional state sync - Shared state management via ag_ui_update_state tool
  • Context injection - Context and state injected into prompts for agent awareness
  • Event cleanup - Hanging events (tool calls, reasoning blocks) automatically closed on stream end
  • Custom tools via MCP - Define custom tools using Claude SDK's @tool decorator
  • Forwarded props - Per-run option overrides with security whitelist

Examples

The integration includes 5 example agents:

Route Description Features
/agentic_chat Basic conversational assistant Simple chat
/backend_tool_rendering Weather tool (backend MCP) Backend tool execution, tool rendering
/shared_state Recipe collaboration Bidirectional state sync, ag_ui_update_state
/human_in_the_loop Task planning with approval Frontend tools, step tracking, approval workflow
/tool_based_generative_ui Frontend tool rendering Dynamic frontend tools, generative UI

Running the Examples

# Install dependencies
cd integrations/claude-agent-sdk/python
pip install -e .

# Start server (port 8019)
cd examples
ANTHROPIC_API_KEY=sk-ant-xxx python server.py

# Start Dojo (in another terminal)
cd apps/dojo
pnpm dev

Visit http://localhost:3000 and select "Claude Agent SDK (Python)"

Session Persistence

Claude SDK maintains conversation state in the .claude/ directory. For production deployments:

  • Development: Sessions persist locally in .claude/{session_id}/
  • Production: Mount .claude/ as a persistent volume in your container
  • Resumption: Pass resume=<session_id> via the options dict or forwarded_props

See Claude SDK Hosting Guide for deployment patterns.

Metadata

Release files for ag-ui-claude-sdk 0.2.1

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

Source distribution (sdist)

Source distribution for ag-ui-claude-sdk 0.2.1
File Size Uploaded
ag_ui_claude_sdk-0.2.1.tar.gz 69.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for ag-ui-claude-sdk 0.2.1
File Interpreter ABI Platform
ag_ui_claude_sdk-0.2.1-py3-none-any.whl Python 3 none any Details

Total release size: 105.7 kB

Release files / ag_ui_claude_sdk-0.2.1.tar.gz

Download URL ag_ui_claude_sdk-0.2.1.tar.gz
Size 69.2 kB
Tags Source
SHA-256 checksum
How to use checksums
c322da7068f5759c7219f2b65109f40059a1e80c4ae74825e2c58058e3a1a6b1
BLAKE2b-256 checksum
How to use checksums
0887c0b6c7a77683b8886571ad66700759dc8677177f07f537e58bc57c806f15
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.12.1 {"installer":{"name":"uv","version":"0.12.1","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / ag_ui_claude_sdk-0.2.1-py3-none-any.whl

Download URL ag_ui_claude_sdk-0.2.1-py3-none-any.whl
Size 36.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
6b9ce6ea15e850987568a488da562d7e2665d99e52e3d34f7922a34ee8dbaba6
BLAKE2b-256 checksum
How to use checksums
2d6b2a135cf435811f7d0d86ac0af841965902113f2f2b22a8188be3b365d64a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.12.1 {"installer":{"name":"uv","version":"0.12.1","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release history Release notifications | RSS feed

0.2.2

2 release files

This release

0.2.1 This release

2 release files

0.2.0

2 release files

0.1.5

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

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