SPB Git forge

spb/doc-api

Public
2commits 1branches 0releases
15.7 MBsize
maindefault branch
14 days agolast push
Python 88.3% TypeScript 7.6% Shell 4.1%
1.4 KB · 15 lines python
Raw Blame History
1#!/usr/bin/env python32"""Programmatic tool calling step 1 (pauses with tool_use.caller {type: code_execution_20260120, tool_id}). Step 2 = tool_result-only user message + container id, see basic.sh. STATUS: LIVE_VERIFIED 2026-09-18 (g1 on claude-sonnet-4-6; haiku -> 400).3Run: .venv/bin/python examples/anthropic/tools/programmatic-tool-calling/basic.py4"""5import json, sys6from pathlib import Path7sys.path.insert(0, str(Path(__file__).resolve().parents[3]))8from scripts.live import anthropic_request9MODEL = "claude-sonnet-4-6"10st, r, _ = anthropic_request("POST", "/v1/messages", {"model": MODEL, "max_tokens": 500, "tools": [{"type": "code_execution_20260120", "name": "code_execution"}, {"name": "query_database", "description": "Execute a SQL query. Returns a JSON array of row objects.", "input_schema": {"type": "object", "properties": {"sql": {"type": "string"}}, "required": ["sql"]}, "allowed_callers": ["code_execution_20260120"]}], "messages": [{"role": "user", "content": "Use code to call query_database with sql 'SELECT 1 AS one' and tell me the value of one."}]}, beta=None, note="basic.py")11print("HTTP", st, "stop_reason:", r.get("stop_reason"))12for b in r.get("content", []):13    print(json.dumps({k: v for k, v in b.items() if k in ("type", "name", "toolset_name", "input", "caller", "text", "content", "tool_use_id", "server_name", "is_error")}, ensure_ascii=False)[:600])14print("usage:", json.dumps(r.get("usage")), "container:", r.get("container"))15