→ 呼び出しループ → 結果を返す までを全て手で 書くことに。 import boto3, math client = boto3.client("bedrock-runtime") # 1. ツール本体(本質はここの 2 行だけ) def circle_area_tool(radius): return f"{math.pi * radius**2:.10f}" tool_list = {"circle_area_tool": circle_area_tool} # 2. ツール定義(JSON Schema を手書き・ネストが深い…省略) tool_spec = {"toolSpec": { """name / description / inputSchema を全部手書き...""" }} messages = [{"role": "user", "content": [{"text": "半径3と7の面積を教えて"}]}] response = client.converse(modelId="...", messages=messages, toolConfig={"tools": [tool_spec]}) # 3. ツール呼び出しループを手で回す while True: tool_request = [c for c in response["output"]["message"]["content"] if "toolUse" in c] if not tool_request: break messages.append(response["output"]["message"]) tool_result = [...] # 各 toolUse を実行 → toolResult に詰め直す(10 行ほど省略) messages.append({"role": "user", "content": tool_result}) response = client.converse(...) # ↻ 再送信 これ全部が 毎回必要なボイラープレート。 本質のロジック(円の面積を計算する関数)は たった2行。 手書きで必要な行数 ≈ 60 ツール1つの最小構成でも、ループ管理と結果フォーマットでこの ボリューム ツール定義JSONを手書き ・ whileループの設計 ・ tool_use_idの取り回し ・ 結果をmessagesに詰め直し ・ 例外・最大ターン数の考慮(未対応) ・