Tool Use · Structured Output✓ Mathematical
◆ The PatternExtending LLMs with real-world capabilities via tool use
Function calling lets an LLM request the execution of external functions — APIs, databases, calculations — by outputting structured JSON matching a schema you define. The model decides when to call a function, which function, and with what arguments.
Input: tools=[{name, description, parameters}] + user message
You define available tools as JSON Schema. Model chooses to call one (or more) based on the query.
Output: tool_calls=[{function: {name, arguments}}]
Structured JSON that your code parses and executes. Return the result as a tool message for the next turn.
Parallel function calling: models can request multiple tool calls in one response. Structured output / JSON mode: forces the model to output valid JSON matching a schema — useful even without external tools for data extraction, classification, etc.
Function calling is the foundation of agents. Without it, LLMs can only output text. With it, they can search the web, query databases, send emails, write code — anything with an API.
Interactive — function call flow
Python — OpenAI function calling#
from openai import OpenAI
import json
client = OpenAI()
tools = [{
"type": "function",
"function": {
"name": "get_weather",
"description": "Get current weather for a location",
"parameters": {
"type": "object",
"properties": {
"location": {"type": "string"},
"unit": {"type": "string", "enum": ["celsius", "fahrenheit"]}
},
"required": ["location"]
}
}
}]
response = client.chat.completions.create(
model="gpt-4o",
messages=[{"role": "user", "content": "Weather in Oslo?"}],
tools=tools
)
# Parse tool call → execute → send result back
call = response.choices[0].message.tool_calls[0]
args = json.loads(call.function.arguments)Pattern bridge: The model outputting structured tool calls is classification over actions instead of tokens. In markets, Ichimoku’s multi-signal system calls different functions (trend, momentum, support) from one framework.