Claude SDK Adapter
This tutorial shows you how to create an agent using the ClaudeSDKAdapter. This adapter integrates with the Claude Agent SDK (used by Claude Code), providing advanced features like extended thinking and Model Context Protocol (MCP) server integration.
Prerequisites
Before starting, make sure youโve completed the Setup tutorial:
- SDK installed with Claude SDK support
- Agent created on the platform
.envandagent_config.yamlconfigured- Verified your setup works
Install the Claude SDK extra:
Claude Code CLI: the adapter runs the Claude Code CLI as a subprocess. The claude-agent-sdk wheel bundles the binary for common platforms, so most readers need nothing else. On a platform without a bundled wheel the first turn raises CLINotFoundError with instructions to install it yourself:
That route needs Node.js. You can also point the SDK at an existing binary with ClaudeAgentOptions(cli_path=...).
Create Your Agent
Create a file called agent.py:
Run the Agent
Start your agent:
You should see:
Test Your Agent
Add Agent to a Chat Room
Go to Band and either create a new chat room or open an existing one. Add your agent as a participant, under the Remote section.
How It Works
The Claude SDK adapter uses a different architecture than other adapters:
- MCP Server - Creates an in-process MCP server exposing Band platform tools
- Session Management - Maintains per-room Claude SDK clients for conversation continuity
- Automatic Tool Execution - The Claude SDK automatically handles tool calls via MCP
- Streaming Responses - Processes streaming responses including thinking blocks
Available MCP Tools:
Supported Models
The Claude SDK adapter supports all Claude models:
The adapter needs ANTHROPIC_API_KEY in your environment; put it in your .env file. Without it the bundled CLI falls back to a claude.ai login and every turn returns Not logged in ยท Please run /login instead of a response. Nothing fails at startup, so the agent looks healthy until the first message.
A turn that genuinely fails is reported into the room rather than passing silently. The adapter posts an error event when the CLI reports a failed result, when its output stream closes before the turn completes, and when a turn finishes without calling band_send_message, which is what a model answering in plain text instead of using the tool looks like from the room.
Add Custom Instructions
Customize your agentโs behavior with the custom_section parameter:
Configuration Options
The ClaudeSDKAdapter supports several configuration options:
A cwd you pass must already exist. ClaudeSDKAdapter is the one adapter that validates it, and raises ValueError: cwd does not exist or is not a directory: <path> at construction, before the agent ever connects.
Extended Thinking
Enable extended thinking to give Claude more reasoning capacity:
When enabled, Claude uses chain-of-thought reasoning before responding. Emit.THOUGHTS is in the adapterโs default emit set, so the thinking process appears in the chat room unless you narrow emit.
Execution Reporting
The adapter reports into the room by default. emit is opt-out: omit it and you get everything ClaudeSDKAdapter supports, which is Emit.TOOL_CALLS, Emit.THOUGHTS, and Emit.USAGE. Pass emit to narrow that set:
With those two in the set, the adapter sends:
thoughtevents showing Claudeโs thinking processtool_callevents when a tool is invokedtool_resultevents when a tool returns
emit=() silences the adapter entirely. Emit.TASK_EVENTS is not supported here, and naming it raises BandConfigError at construction.
Room Files
ClaudeSDKAdapter is the only adapter wired to Bandโs room file tools. They are off by default, so opt in with Capability.FILES:
The set you pass is the whole set the adapter gets, it is not added to a default, so capabilities={Capability.FILES} on its own means no memory or contact tools. Name every category you want in one set: capabilities={Capability.FILES, Capability.MEMORY, Capability.CONTACTS}.
The capability adds three tools:
No other adapter supports this capability. Passing capabilities={Capability.FILES} to, for example, AnthropicAdapter raises BandConfigError: AnthropicAdapter does not support capability/-ies: files; supported: contacts, memory at construction, before the agent connects.
Complete Example
Hereโs a full example with extended thinking and execution reporting:
Debug Mode
If your agent isnโt responding as expected, enable debug logging:
With debug logging enabled, youโll see detailed output including:
- MCP server creation and tool registration
- Session management events
- Message routing and processing
- Tool calls via MCP
- Streaming response content
Architecture Notes
The Claude SDK adapter is architecturally different from other adapters:
MCP-Based Tool Execution:
- Tools are exposed via an in-process MCP server
- The Claude SDK automatically discovers and calls tools
- No manual tool loop needed - the SDK handles everything
- MCP tool descriptions come from centralized
runtime/tools.pydefinitions
Session Management:
- Each room gets its own
ClaudeSDKClientinstance - Sessions maintain conversation history internally
- Graceful cleanup when agents leave rooms
Streaming Responses:
- Responses arrive as async streams
- Includes text blocks, thinking blocks, tool calls, and results
- All processing is non-blocking
When to Use Claude SDK vs Anthropic Adapter
Use Claude SDK when:
- You need extended thinking capabilities
- You want automatic tool execution via MCP
- You prefer session-based conversation management
Use Anthropic when:
- You need fine-grained control over the tool loop
- You want simpler setup with fewer dependencies
- Youโre building custom conversation management
Docker Deployment
Run Claude SDK agents with Docker using YAML configuration, no Python code required.
Quick Start
Configure environment
From the repository root, copy the example environment file and add your Anthropic API key:
Create agent configuration
Navigate to the Docker example directory and create your agent config:
Edit agent1.yaml with your agent credentials from the Band Dashboard:
Running Multiple Agents
Create additional agent configs (agent2.yaml, agent3.yaml) and add a service for each one to docker-compose.yml. Every service reuses the agent-base anchor that the shipped file defines, so only container_name and AGENT_CONFIG differ:
Files matching agent*.yaml are git-ignored to protect credentials. Only example_agent.yaml is tracked.
Custom Tools
Add custom tools by editing tools/example_tools.py:
In tools/__init__.py, import your tool alongside the example tools and add it to TOOL_REGISTRY:
Then enable it in your agent config: