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%
2.0 KB · 19 lines shellscript
Raw Blame History
1#!/usr/bin/env bash2set -euo pipefail3cd "$(dirname "$0")/../../../.."4source scripts/lib.sh5MODEL="${MODEL:-claude-haiku-4-5-20251001}"6# Programmatic tool calling: query_database is callable only from code (allowed_callers), code_execution_20260120 runs the cell.7# Step 1 pauses with stop_reason tool_use + tool_use.caller {type: code_execution_20260120, tool_id}. Step 2 returns ONLY tool_result blocks + container id.8# STATUS: LIVE_VERIFIED 2026-09-18 (g1/g2 on claude-sonnet-4-6, ~$0.02). Haiku 4.5 -> 400 (g3). Needs MODEL=claude-sonnet-4-6 (or newer).9MODEL="${MODEL:-claude-sonnet-4-6}"10TOOLS='[{"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"]}]'11Q="Use code to call query_database with sql 'SELECT 1 AS one' and tell me the value of one. One sentence."12R1=$(ant POST /v1/messages -d "$(jq -n --argjson t "$TOOLS" --arg m "$MODEL" --arg q "$Q" '{model:$m,max_tokens:500,tools:$t,messages:[{role:"user",content:$q}]}')")13log_request anthropic POST /v1/messages "$ANT_STATUS" 0.011 "ptc/basic.sh step1"14echo "$R1" | jq -c '.stop_reason, .container, (.content[]|select(.type=="tool_use")|{name,input,caller})'15CID=$(echo "$R1" | jq -r '.container.id'); RESULTS=$(echo "$R1" | jq '[.content[]|select(.type=="tool_use" and .caller.type!="direct")|{type:"tool_result",tool_use_id:.id,content:"[{\"one\": 1}]"}]')16R2=$(ant POST /v1/messages -d "$(jq -n --argjson t "$TOOLS" --arg m "$MODEL" --arg q "$Q" --arg c "$CID" --argjson a "$(echo "$R1"|jq .content)" --argjson r "$RESULTS" '{model:$m,max_tokens:400,container:$c,tools:$t,messages:[{role:"user",content:$q},{role:"assistant",content:$a},{role:"user",content:$r}]}')")17log_request anthropic POST /v1/messages "$ANT_STATUS" 0.010 "ptc/basic.sh step2"18echo "$R2" | jq -c '.stop_reason, (.content[]|{type,content,text})'19