{"type": "session", "harness": "opencode", "id": "ai-0007", "name": "OpenAI Tool Calling Pattern"} {"type": "message", "message": {"role": "system", "content": "You are an expert software engineer."}} {"type": "message", "message": {"role": "user", "content": "How does OpenAI's tool/function calling work?"}} {"type": "message", "message": {"role": "assistant", "content": "Tool call flow:\n\n1. User defines tools: [{\"type\": \"function\", \"function\": {name, description, parameters (JSON Schema), strict}}]\n2. API returns message.tool_calls: [{id, function: {name, arguments (JSON string)}}]\n3. App executes local function using arguments\n4. App appends: assistant message (with tool_calls) + tool message (role: \"tool\", tool_call_id: id, content: result)\n5. Sends new request with updated messages\n\nAutomatic parsing with parse():\n- Validates tools are strict and function type\n- Returns ParsedChatCompletion with ParsedFunctionToolCall\n- function.parsed_arguments is a Pydantic model instance\n\nStreaming tool calls:\n- tool_calls.delta events with incremental arguments strings\n- tool_calls.done events provide complete parsed tool call\n- State accumulation concatenates JSON fragments until complete\n\nResponses API supports: function, web_search_preview, code_interpreter, computer_use_preview, image_generation, MCP tools."}}