Skip to main content

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 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.

Links

Project details


Download files

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

Source Distribution

ag_ui_claude_sdk-0.1.4.tar.gz (44.6 kB view details)

Uploaded Source

Built Distribution

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

ag_ui_claude_sdk-0.1.4-py3-none-any.whl (28.2 kB view details)

Uploaded Python 3

File details

Details for the file ag_ui_claude_sdk-0.1.4.tar.gz.

File metadata

  • Download URL: ag_ui_claude_sdk-0.1.4.tar.gz
  • Upload date:
  • Size: 44.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.19 {"installer":{"name":"uv","version":"0.11.19","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

Hashes for ag_ui_claude_sdk-0.1.4.tar.gz
Algorithm Hash digest
SHA256 ed14fe4231e2c23d73a6cc97205fcd7190983118182f606ad8499eea515ae864
MD5 e7f159bf5329cf16ca375ad80b9c6ee6
BLAKE2b-256 5bb88fadad82fa6cc76c759ce83f8cf9bdd0d5a133a50d6f9ea1210fd7609c1e

See more details on using hashes here.

File details

Details for the file ag_ui_claude_sdk-0.1.4-py3-none-any.whl.

File metadata

  • Download URL: ag_ui_claude_sdk-0.1.4-py3-none-any.whl
  • Upload date:
  • Size: 28.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.19 {"installer":{"name":"uv","version":"0.11.19","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

Hashes for ag_ui_claude_sdk-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 94d19fbc2c5a8e82a8d5ffe8cd18594e385679f2492468e766a43c06c233a4dd
MD5 0e469ec1c2ab81344b8d6cbccb300e39
BLAKE2b-256 c3054042f1a64e00a14d25074c2678cc780230543ffd23fd9df61014edd1b0e5

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