Tool use lets an LLM match a request to a named function and return structured arguments. The model suggests the call; application code executes the matching function. section 5.2.1
A basic tool-use workflow is:
- Define a function name, description, and object-shaped parameter schema. section 5.2.1
- Send the user request and tool specification to the LLM, which selects a function and extracts arguments. section 5.2.1
- Parse the returned name and arguments, invoke the corresponding function, and send its result back for a final response. section 5.2.1 section 7.5
Recommendation and weather tools
A request for a good time-travel movie produces a recommend call with topic and rating arguments. An agent can also expose get_current_weather; its action decorator generates an OpenAI-compatible tool specification, and both calls may execute in parallel. section 5.2.1 section 7.5
Listing 7.14 oai_agent.py (get_response_stream: execute tool calls)
if tool_calls: #1
available_functions = {
action["name"]: action["pointer"] for action in self.actions
} #2
self.messages.append(
response_message
)
for tool_call in tool_calls: #3
function_name = tool_call.function.name
function_to_call = available_functions[function_name]
function_args = json.loads(tool_call.function.arguments)
function_response = function_to_call(
**function_args, _caller_agent=self
)
self.messages.append(
{
"tool_call_id": tool_call.id,
"role": "tool",
"name": function_name,
"content": str(function_response),
}
)
second_response = self.client.chat.completions.create(
model=self.model,
messages=self.messages,
) #4
response_message = second_response.choices[0].message
Trace how returned tool calls are mapped to available functions, executed, recorded as tool messages, and followed by a second API response. section 7.5












