Anthropic Agent SDK Integration
Build Claude-powered agents with native payment tools using Anthropic's Agent SDK. 6 tools as tool_use JSON schemas with automatic execution.
Installation
pip install sardis-agent-sdkThe Agent SDK integration provides Sardis tools as tool_use JSON definitions compatible with Claude's tool use pattern.
Quick Start
SardisToolkit
Initialize the toolkit and get tool definitions for Claude.
import anthropic
from sardis_agent_sdk import SardisToolkit
# Initialize the toolkit
toolkit = SardisToolkit(
api_key="sk_live_...",
agent_id="agent_abc123"
)
# Get tool definitions for Claude
tools = toolkit.get_tools()
# Create Claude client
client = anthropic.Anthropic(api_key="your_anthropic_key")
# Send message with tools
response = client.messages.create(
model="claude-sonnet-4-20250514",
max_tokens=1024,
tools=tools,
messages=[{
"role": "user",
"content": "Pay $20 to OpenAI for API credits"
}]
)
print(response.content)Available Tools
The toolkit provides 6 tools as tool_use JSON schemas:
sardis_pay
Execute a payment to a merchant with policy validation.
{
"name": "sardis_pay",
"description": "Execute a payment to a merchant",
"input_schema": {
"type": "object",
"properties": {
"merchant": {"type": "string"},
"amount": {"type": "string"},
"token": {"type": "string"},
"chain": {"type": "string"},
"purpose": {"type": "string"}
},
"required": ["merchant", "amount", "token", "chain"]
}
}sardis_check_balance
Get current wallet balances.
{
"name": "sardis_check_balance",
"description": "Check wallet balance across chains",
"input_schema": {
"type": "object",
"properties": {
"chain": {"type": "string"},
"token": {"type": "string"}
}
}
}sardis_check_policy
Validate if a payment would be allowed.
sardis_set_policy
Update spending policies with natural language.
sardis_list_transactions
Query transaction history with filtering.
sardis_create_hold
Create a payment hold that requires explicit release.
// Tool input
{
"merchant": "api.openai.com",
"amount": "100.00",
"token": "USDC",
"chain": "base",
"duration_hours": 24
}
// Tool output
{
"hold_id": "hold_xyz789",
"status": "active",
"expires_at": "2026-01-16T10:30:00Z"
}Tool Execution
handle_tool_call()
Process tool_use blocks and execute Sardis operations.
import anthropic
from sardis_agent_sdk import SardisToolkit
toolkit = SardisToolkit(api_key="sk_live_...", agent_id="agent_abc123")
client = anthropic.Anthropic(api_key="your_anthropic_key")
# Initial request
response = client.messages.create(
model="claude-sonnet-4-20250514",
max_tokens=1024,
tools=toolkit.get_tools(),
messages=[{
"role": "user",
"content": "Pay $20 to OpenAI"
}]
)
# Check for tool use
for block in response.content:
if block.type == "tool_use":
# Execute the tool
result = toolkit.handle_tool_call(
tool_name=block.name,
tool_input=block.input
)
print(f"Tool: {block.name}")
print(f"Result: {result}")Agent Loop
run_agent_loop()
Automated conversation loop with tool execution.
from sardis_agent_sdk import SardisToolkit
toolkit = SardisToolkit(api_key="sk_live_...", agent_id="agent_abc123")
# Run automated agent loop
final_response = toolkit.run_agent_loop(
anthropic_api_key="your_anthropic_key",
user_message="Check my balance, then pay $25 to Anthropic for Claude API",
model="claude-sonnet-4-20250514",
max_turns=10 # Prevent infinite loops
)
print(final_response)Example: Full Agent Loop
Complete implementation of an agent with manual tool handling.
import anthropic
from sardis_agent_sdk import SardisToolkit
# Initialize
toolkit = SardisToolkit(
api_key="sk_live_...",
agent_id="agent_abc123"
)
client = anthropic.Anthropic(api_key="your_anthropic_key")
# Conversation state
messages = [{
"role": "user",
"content": "Check my balance, then pay $30 to OpenAI if I have enough"
}]
# Agent loop
while True:
response = client.messages.create(
model="claude-sonnet-4-20250514",
max_tokens=2048,
tools=toolkit.get_tools(),
messages=messages
)
# Check stop reason
if response.stop_reason == "end_turn":
final_text = next(
(block.text for block in response.content if hasattr(block, "text")),
None
)
print(f"\nFinal Answer: {final_text}")
break
# Process tool uses
if response.stop_reason == "tool_use":
messages.append({
"role": "assistant",
"content": response.content
})
tool_results = []
for block in response.content:
if block.type == "tool_use":
print(f"\nExecuting: {block.name}")
result = toolkit.handle_tool_call(
tool_name=block.name,
tool_input=block.input
)
tool_results.append({
"type": "tool_result",
"tool_use_id": block.id,
"content": str(result)
})
messages.append({
"role": "user",
"content": tool_results
})
else:
print(f"Stopped: {response.stop_reason}")
breakRead-Only Mode
Create observer agents that can query but not execute payments.
from sardis_agent_sdk import SardisToolkit
# Read-only toolkit for auditing/monitoring
toolkit = SardisToolkit(
api_key="sk_live_...",
agent_id="agent_abc123",
read_only=True # Disable payment execution
)
# Only includes:
# - sardis_check_balance
# - sardis_list_transactions
# - sardis_check_policy (validation only)
#
# Excludes:
# - sardis_pay
# - sardis_set_policy
# - sardis_create_hold
tools = toolkit.get_tools()
print(f"Available tools: {[t['name'] for t in tools]}")
# Output: ['sardis_check_balance', 'sardis_list_transactions', 'sardis_check_policy']Error Handling
Handle tool execution errors gracefully in your agent loop.
from sardis_agent_sdk import SardisToolkit, SardisError
toolkit = SardisToolkit(api_key="sk_live_...", agent_id="agent_abc123")
try:
result = toolkit.handle_tool_call(
tool_name="sardis_pay",
tool_input={
"merchant": "api.openai.com",
"amount": "999999.00", # Exceeds balance
"token": "USDC",
"chain": "base"
}
)
except SardisError as e:
# Return error to Claude for reasoning
error_result = {
"type": "tool_result",
"tool_use_id": block.id,
"content": f"Error: {str(e)}",
"is_error": True
}
# Claude will see the error and can retry or adjustBest Practices
- Use
run_agent_loop()for simple use cases, manual loops for custom behavior - Set
max_turnsto prevent infinite loops in automated agent execution - Use
read_only=Truefor monitoring/auditing agents that should not execute payments - Always pass tool execution errors back to Claude as
tool_resultblocks - Use
claude-sonnet-4-20250514for best tool use accuracy - Include conversation context in messages to help Claude reason about multi-step tasks
- Use
sardis_create_holdfor payments that require human approval workflows