The sardis-agent-sdk package provides a high-level toolkit for integrating Sardis payments into Anthropic Claude agents. It handles tool definitions, result parsing, and the full agent loop automatically.
from sardis_agent_sdk import SardisToolkittoolkit = SardisToolkit( client=sardis_client, wallet_id="wallet_abc123", read_only=False, # Set True for observer agents)# Get tool definitionstools = toolkit.get_tools()# Handle tool callsfor block in response.content: if block.type == "tool_use": result = toolkit.handle_tool_call(block) # result is a dict with {"type": "tool_result", "tool_use_id": "...", "content": "..."}
Use run_agent_loop for fully managed conversations:
result = toolkit.run_agent_loop( client=anthropic.Anthropic(), model="claude-sonnet-4-5-20250929", system_prompt="You are a procurement agent...", user_message="Purchase $30 of OpenAI API credits", max_turns=10, max_tokens=4096,)# Returns:# {# "response": "Final text response",# "messages": [...], # Full message history# "tool_calls": [...], # All tool calls made# "turns": 3 # Number of turns taken# }
toolkit = SardisToolkit( client=sardis, wallet_id=wallet.wallet_id, read_only=True, # Only balance, policy checks, and transaction history)result = toolkit.run_agent_loop( client=claude, model="claude-sonnet-4-5-20250929", system_prompt=( "You are a financial auditor. You can check balances and " "review transaction history, but you cannot make payments. " "Analyze the wallet's spending patterns and report any concerns." ), user_message="Review this wallet's balance and recent transactions. Flag anything unusual.", max_turns=3,)
import osimport anthropicfrom sardis import SardisClientfrom sardis_agent_sdk import SardisToolkit# Initializesardis = SardisClient(api_key=os.environ["SARDIS_API_KEY"])# Create agent and walletagent = sardis.agents.create( name="claude-procurement-agent", description="Claude-powered procurement agent with Sardis wallet",)wallet = sardis.wallets.create( agent_id=agent.agent_id, chain="base_sepolia", currency="USDC",)# Create toolkittoolkit = SardisToolkit( client=sardis, wallet_id=wallet.wallet_id,)# Run automated agent loopclaude = anthropic.Anthropic()result = toolkit.run_agent_loop( client=claude, model="claude-sonnet-4-5-20250929", system_prompt=( "You are a procurement agent with a Sardis wallet. " "You help purchase software tools and API credits. " "Always check the balance before making payments, and " "explain your reasoning clearly." ), user_message=( "I need to purchase $30 of OpenAI API credits. " "Check my balance and policy first, then make the payment." ), max_turns=5,)print(f"Agent response: {result['response']}")print(f"Tool calls made: {len(result['tool_calls'])}")print(f"Turns taken: {result['turns']}")for i, call in enumerate(result["tool_calls"], 1): print(f"\nTool call {i}: {call['tool_name']}") print(f" Input: {call['tool_input']}") print(f" Result: {call['result']}")
messages = [{ "role": "user", "content": "Check my balance, then pay $50 to AWS if I have enough"}]response = claude.messages.create( model="claude-sonnet-4-5-20250929", max_tokens=2048, tools=tools, messages=messages,)# Claude will:# 1. Call sardis_check_balance# 2. Receive result# 3. Call sardis_pay if balance is sufficient
messages = [{ "role": "user", "content": ( "Check the policy for a $200 payment to aws.amazon.com. " "If allowed, execute the payment. If not, explain why." )}]# Claude will:# 1. Call sardis_check_policy# 2. If allowed: call sardis_pay# 3. If blocked: explain the policy violation
with claude.messages.stream( model="claude-sonnet-4-5-20250929", max_tokens=2048, tools=tools, messages=messages,) as stream: for text in stream.text_stream: print(text, end="", flush=True) # Get final message message = stream.get_final_message() # Handle tool calls for block in message.content: if block.type == "tool_use": result = toolkit.handle_tool_call(block) print(f"\nTool result: {result['content']}")
system = ( "You are a procurement agent with a Sardis wallet. " "Before making any payment:" "1. Check wallet balance using sardis_check_balance" "2. Validate against policy using sardis_check_policy" "3. Execute payment with sardis_pay" "4. Confirm with transaction ID")
for block in response.content: if block.type == "tool_use": result = toolkit.handle_tool_call(block) messages.append({"role": "user", "content": [result]})