tinycodinglm / ai /ai-0007.jsonl
winapiadmin's picture
Upload folder using huggingface_hub
1f3a244 verified
|
Raw History Blame Contribute Delete
1.36 kB
opencode trace
System You are an expert software engineer.

You are an expert software engineer.

User

How does OpenAI's tool/function calling work?

Assistant

Tool call flow:

  1. User defines tools: [{"type": "function", "function": {name, description, parameters (JSON Schema), strict}}]
  2. API returns message.tool_calls: [{id, function: {name, arguments (JSON string)}}]
  3. App executes local function using arguments
  4. App appends: assistant message (with tool_calls) + tool message (role: "tool", tool_call_id: id, content: result)
  5. Sends new request with updated messages

Automatic parsing with parse():

  • Validates tools are strict and function type
  • Returns ParsedChatCompletion with ParsedFunctionToolCall
  • function.parsed_arguments is a Pydantic model instance

Streaming tool calls:

  • tool_calls.delta events with incremental arguments strings
  • tool_calls.done events provide complete parsed tool call
  • State accumulation concatenates JSON fragments until complete

Responses API supports: function, web_search_preview, code_interpreter, computer_use_preview, image_generation, MCP tools.