#!/usr/bin/env python3 """Interactions API tools: `tools: [{"type":"function", …}]` + `generation_config.tool_choice` → status "requires_action" with a function_call step → answer with a `function_result` input chained via previous_interaction_id. STATUS: LIVE_VERIFIED 2026-09-18 (gemini-3.5-flash-lite, tmp-live/gemini-tools/h6*.json). Observed: top-level `tool_choice` → 400 "Unknown parameter 'tool_choice'" (it lives in generation_config); function_call step = {id:"call_…", type, name, arguments}; function_result must be {type, name, call_id, result:[{type:"text", text}]}; the follow-up returned steps [thought, model_output]. `{"type":"google_search"}` returned 429 RESOURCE_EXHAUSTED on this key (h7) — same restriction as generateContent googleSearch. Run: .venv/bin/python examples/gemini/interactions/interactions_tools.py """ import json, sys from pathlib import Path sys.path.insert(0, str(Path(__file__).resolve().parents[3])) from scripts.live import gemini_request MODEL = "gemini-3.5-flash-lite" TOOLS = [{"type": "function", "name": "get_weather", "description": "Get the weather for a city.", "parameters": {"type": "object", "properties": {"city": {"type": "string"}}, "required": ["city"]}}] st, r, _ = gemini_request("POST", "/v1beta/interactions", {"model": MODEL, "input": "Weather in Paris?", "tools": TOOLS, "generation_config": {"tool_choice": {"allowed_tools": {"mode": "any", "tools": ["get_weather"]}}, "max_output_tokens": 64}}, note="interactions_tools.py function tool") fc = next(s for s in r["steps"] if s["type"] == "function_call") print("turn 1:", st, r["status"], json.dumps(fc)) st, r2, _ = gemini_request("POST", "/v1beta/interactions", {"model": MODEL, "previous_interaction_id": r["id"], "tools": TOOLS, "input": [{"type": "function_result", "name": fc["name"], "call_id": fc["id"], "result": [{"type": "text", "text": json.dumps({"temperature_c": 18})}]}], "generation_config": {"max_output_tokens": 32}}, note="interactions_tools.py function_result") print("turn 2:", st, r2["status"], " ".join(c["text"] for s in r2["steps"] if s["type"] == "model_output" for c in s["content"] if c["type"] == "text")) for i in (r["id"], r2["id"]): gemini_request("DELETE", f"/v1beta/interactions/{i}", note="interactions_tools.py cleanup")