A tool result is the information returned after an agent runs a tool, such as an API response, computed value, or command output. It differs from a tool call, which is the model’s structured request. Results usually enter the working context and can inform the model’s next response; only relevant outputs are later persisted as memory. section 1.5.3
Weather lookup
A function-calling loop executes a requested weather function and adds its returned weather value to the model’s context before it generates the final answer. section 4.6.1
Listing 4.1 Python script using an OpenAI model and a mock weather tool
from openai import OpenAI
import json
client = OpenAI()
TOOLS = [{ #1
"type": "function",
"name": "get_weather", #2
"description": "Get the current weather in a location",
"parameters": {
"type": "object",
"properties": {
"location": {
"type": "string",
"description": "City or place name"
}
},
"required": ["location"]
}
}]
def query_model(prompt, model="gpt-4o-mini"):
response = client.responses.create( #3
model=model,
input=prompt,
tools=TOOLS,
tool_choice="required",
)
input_items = list(response.output)
for item in response.output: #4
if item.type != "function_call":
continue
function_name = item.name
function_args = json.loads(item.arguments)
result = route_function_call(function_name, function_args) #5
input_items.append({
"type": "function_call_output",
"call_id": item.call_id,
"output": json.dumps(result),
})
final_response = client.responses.create( #6
model=model,
input=input_items,
tools=TOOLS,
)
return final_response.output_text
Trace the function-calling loop that returns a mock weather result to the model. section 4.6.1



