AG-UI integration for Anthropic Claude Agent SDK
Project description
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 8888)
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 orforwarded_props
See Claude SDK Hosting Guide for deployment patterns.
Links
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file ag_ui_claude_sdk-0.1.0.tar.gz.
File metadata
- Download URL: ag_ui_claude_sdk-0.1.0.tar.gz
- Upload date:
- Size: 20.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.11.3 {"installer":{"name":"uv","version":"0.11.3","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}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4f3044b8daab02397fe097a5ceaed5f1b5417781ab302d2f96c6cef812fead12
|
|
| MD5 |
48512c87a2ec3f621a8629c140be73cb
|
|
| BLAKE2b-256 |
053d65d65a349561df7f1e82fc431ac2eab5b41e5d52bc99b63d29b590afc619
|
File details
Details for the file ag_ui_claude_sdk-0.1.0-py3-none-any.whl.
File metadata
- Download URL: ag_ui_claude_sdk-0.1.0-py3-none-any.whl
- Upload date:
- Size: 22.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.11.3 {"installer":{"name":"uv","version":"0.11.3","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}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bd83b095e508328820d7464e514b7b64def0555521706e2b47800f4d4df0dc67
|
|
| MD5 |
a85d3290e81d2a37773dac02b0585b15
|
|
| BLAKE2b-256 |
a66716c99927015af31d3e69e127021a8c05a72391a288acd7dc7199b7c9be1c
|