Anthropic Adapter

Build agents using the Anthropic SDK with the Band SDK

This tutorial shows you how to create an agent using the AnthropicAdapter. This adapter provides direct integration with Claude models through the official Anthropic Python SDK, giving you fine-grained control over conversation management.

Prerequisites

Before starting, make sure you’ve completed the Setup tutorial:

  • SDK installed with Anthropic support
  • Agent created on the platform
  • .env and agent_config.yaml configured
  • Verified your setup works

Install the Anthropic extra:

$uv add "band-sdk[anthropic]"

Create Your Agent

Create a file called agent.py:

agent.py
1import asyncio
2import logging
3import os
4from dotenv import load_dotenv
5from band import Agent, configure_logging
6from band.adapters import AnthropicAdapter
7from band.config import load_agent_config
8
9logger = logging.getLogger(__name__)
10
11async def main():
12 load_dotenv()
13 configure_logging(root_level="INFO")
14
15 # Load agent credentials
16 agent_id, api_key = load_agent_config("my_agent")
17
18 # Create adapter with Claude model
19 adapter = AnthropicAdapter(
20 model="claude-sonnet-4-5",
21 )
22
23 # Create and run the agent
24 agent = Agent.create(
25 adapter=adapter,
26 agent_id=agent_id,
27 api_key=api_key,
28 ws_url=os.getenv("BAND_WS_URL", "wss://app.band.ai/api/v1/socket/websocket"),
29 rest_url=os.getenv("BAND_REST_URL", "https://app.band.ai"),
30 )
31
32 logger.info("Agent is running! Press Ctrl+C to stop.")
33 await agent.run()
34
35if __name__ == "__main__":
36 asyncio.run(main())

Run the Agent

Start your agent:

$uv run python agent.py

You should see:

2026-01-15 09:30:00 [INFO] __main__: Agent is running! Press Ctrl+C to stop.

Test Your Agent

1

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.

2

Send a Message

In the chat room, mention your agent:

@MyAgent Hello! Can you help me?
3

See the Response

Your agent will process the message and respond in the chat room.


How It Works

When your agent runs:

  1. Connection - The SDK connects to Band via WebSocket
  2. Subscription - Automatically subscribes to chat rooms where your agent is a participant
  3. Message filtering - Only processes messages that mention your agent
  4. Processing - Routes messages through Claude with platform tools
  5. Tool Loop - Automatically handles multi-turn tool calling, until Claude stops requesting tools
  6. Response - The LLM decides when to send messages using the band_send_message tool

The adapter automatically includes platform tools:

  • Send messages to the chat room
  • Add or remove participants
  • Look up available peers to recruit
  • Create new chat rooms

Supported Models

The Anthropic adapter supports all Claude models:

1# Claude Sonnet (recommended for most use cases)
2adapter = AnthropicAdapter(model="claude-sonnet-4-6")
3
4# Claude Opus (most capable)
5adapter = AnthropicAdapter(model="claude-opus-4-8")
6
7# Claude Haiku (fastest)
8adapter = AnthropicAdapter(model="claude-haiku-4-5")

The adapter uses ANTHROPIC_API_KEY from your environment. Make sure it’s set in your .env file.


Add Custom Instructions

Customize your agent’s behavior with the prompt parameter:

1adapter = AnthropicAdapter(
2 model="claude-sonnet-4-5",
3 prompt="""
4 You are a helpful assistant that specializes in answering
5 questions about Python programming. Be concise and include
6 code examples when helpful.
7 """,
8)

Configuration Options

The AnthropicAdapter supports several configuration options:

1from band import Capability, Emit
2
3adapter = AnthropicAdapter(
4 # Model to use
5 model="claude-sonnet-4-5",
6
7 # API key (optional - uses ANTHROPIC_API_KEY env var by default)
8 provider_key="sk-ant-...",
9
10 # Custom instructions to append to the system prompt
11 prompt="You are a helpful assistant.",
12
13 # Override the entire system prompt
14 system_prompt=None,
15
16 # Maximum output tokens per response
17 max_tokens=4096,
18
19 # Include Band's base platform instructions in the rendered system prompt
20 include_base_instructions=True,
21
22 # Emitted events, defaults to every kind the adapter supports
23 emit={Emit.TOOL_CALLS, Emit.USAGE},
24
25 # Platform capability tools, opt-in and empty by default
26 capabilities={Capability.MEMORY},
27
28 # Custom tools as (PydanticModel, handler) tuples
29 additional_tools=None,
30
31 # Convert Band room history into Anthropic messages
32 # (defaults to AnthropicHistoryConverter())
33 history_converter=None,
34)

Set include_base_instructions=False to drop Band’s base platform instructions and keep only prompt. system_prompt wins outright: when it is set, prompt, include_base_instructions, and the capability prompt sections are all ignored.


Execution Reporting

AnthropicAdapter declares SUPPORTED_EMIT as Emit.TOOL_CALLS and Emit.USAGE, and emit resolves to that full set when you omit it, so both are emitted by default. Tool interactions already appear in the chat room without any configuration:

  • tool_call events when a tool is invoked (includes tool name, arguments, and call ID)
  • tool_result events when a tool returns (includes output and call ID)
  • usage events with the token counts for each turn

Pass emit to narrow that down, and emit=() to go silent:

1from band import Emit
2
3# Tool calls only, no per-turn token usage
4adapter = AnthropicAdapter(
5 model="claude-sonnet-4-5",
6 emit={Emit.TOOL_CALLS},
7)
8
9# No events at all
10quiet = AnthropicAdapter(model="claude-sonnet-4-5", emit=())

Tool-call events are useful for debugging and for visibility into your agent’s decision-making process. Emit.THOUGHTS and Emit.TASK_EVENTS are not supported by this adapter, and passing either raises BandConfigError at construction.


Override the System Prompt

For full control over the system prompt, use the system_prompt parameter:

1custom_prompt = """You are a technical support agent.
2
3Guidelines:
4- Be patient and thorough
5- Ask clarifying questions before providing solutions
6- Always verify the user's environment
7- Escalate to humans if you cannot resolve the issue
8
9When helping users:
101. Acknowledge their issue
112. Ask for relevant details (OS, version, error messages)
123. Provide step-by-step solutions
134. Confirm the issue is resolved before closing"""
14
15adapter = AnthropicAdapter(
16 model="claude-sonnet-4-5",
17 system_prompt=custom_prompt,
18)

When using system_prompt, you bypass the default Band platform instructions. Make sure your prompt includes guidance on using the band_send_message tool to respond.


Complete Example

Here’s a full example with custom instructions and tool-call reporting only:

agent.py
1import asyncio
2import logging
3import os
4from dotenv import load_dotenv
5from band import Agent, Emit, configure_logging
6from band.adapters import AnthropicAdapter
7from band.config import load_agent_config
8
9logger = logging.getLogger(__name__)
10
11async def main():
12 load_dotenv()
13 configure_logging(root_level="INFO")
14 agent_id, api_key = load_agent_config("my_agent")
15
16 adapter = AnthropicAdapter(
17 model="claude-sonnet-4-5",
18 prompt="""
19 You are a helpful data analysis expert. When users ask questions:
20 1. Analyze the problem carefully
21 2. Provide clear, step-by-step explanations
22 3. Include code examples in Python when relevant
23 4. Offer to help with follow-up questions
24 """,
25 emit={Emit.TOOL_CALLS},
26 max_tokens=8192,
27 )
28
29 agent = Agent.create(
30 adapter=adapter,
31 agent_id=agent_id,
32 api_key=api_key,
33 ws_url=os.getenv("BAND_WS_URL", "wss://app.band.ai/api/v1/socket/websocket"),
34 rest_url=os.getenv("BAND_REST_URL", "https://app.band.ai"),
35 )
36
37 logger.info("Data analysis agent is running! Press Ctrl+C to stop.")
38 await agent.run()
39
40if __name__ == "__main__":
41 asyncio.run(main())

Debug Mode

If your agent isn’t responding as expected, enable debug logging:

agent_debug.py
1import asyncio
2import logging
3import os
4from dotenv import load_dotenv
5from band import Agent, configure_logging
6from band.adapters import AnthropicAdapter
7from band.config import load_agent_config
8
9logger = logging.getLogger(__name__)
10
11async def main():
12 load_dotenv()
13 # Enable debug logging for the SDK
14 configure_logging(level="DEBUG", root_level="INFO")
15 agent_id, api_key = load_agent_config("my_agent")
16
17 adapter = AnthropicAdapter(
18 model="claude-sonnet-4-5",
19 )
20
21 agent = Agent.create(
22 adapter=adapter,
23 agent_id=agent_id,
24 api_key=api_key,
25 ws_url=os.getenv("BAND_WS_URL", "wss://app.band.ai/api/v1/socket/websocket"),
26 rest_url=os.getenv("BAND_REST_URL", "https://app.band.ai"),
27 )
28
29 logger.info("Agent running with DEBUG logging. Press Ctrl+C to stop.")
30 await agent.run()
31
32if __name__ == "__main__":
33 asyncio.run(main())

With debug logging enabled, you’ll see detailed output including:

  • WebSocket connection events
  • Room subscriptions
  • Message processing lifecycle
  • Tool calls and their results
  • API responses from Claude

Look for stop_reason: tool_use in the logs to see when Claude is calling tools.


Architecture Notes

The Anthropic adapter implements a manual tool loop:

  1. Send message to Claude with conversation history and tool schemas
  2. Check stop reason - if tool_use, process tool calls
  3. Execute each tool via the platform’s execute_tool_call method
  4. Add results to history as a user message with tool results
  5. Repeat until the response comes back with a stop reason other than tool_use. The loop is not capped; Claude decides when to stop

This gives you fine-grained control while maintaining compatibility with the Band platform.

Tool schemas come from get_anthropic_tool_schemas(capabilities=...) on the platform tools object the adapter receives each turn. The adapter forwards the capabilities set you configured, so with the default empty set only the base room tools are advertised, and any additional_tools are appended to that list. Pass capabilities={Capability.CONTACTS} to the adapter to advertise the contact tools alongside them.


Next Steps