Sub topic 1
Built-in Tools Versus Function Tools
Prerequisites
Assume you can call an LLM API with Python, read JSON responses, and understand basic tool calling. A tool is a capability the model can request while generating an answer.
Built-in Tools Versus Function Tools
A built-in tool is hosted and executed by the model provider. Examples include web search, code execution, and file search. You declare the tool in the request, and the provider runs it during generation.
A function tool is declared by you, but your application runs it. The model returns a function name and arguments. Your code validates those arguments, performs the operation, and sends the result back to the model.
| Tool type | Who runs it? | Typical use |
|---|---|---|
| Built-in tool | Model provider | Search, computation, document retrieval |
| Function tool | Your application | Business APIs, databases, internal services |
How the Provider Runs the Tool Loop for You
With a built-in tool, the provider usually performs this sequence:
- The model decides that a tool is useful.
- The provider executes the tool.
- The tool result is added to the model's context.
- The model writes the final response.
Your application receives one API response instead of implementing this loop itself.
flowchart TD
A[Your request] --> B[Model selects built-in tool]
B --> C[Provider executes tool]
C --> D[Tool result enters context]
D --> E[Model produces response]Declaring Built-in Tools in a Request
The request lists a built-in tool by its provider-defined type. This example enables web search:
from openai import OpenAI
client = OpenAI()
response = client.responses.create(
model="gpt-4.1",
tools=[{"type": "web_search"}],
input="What are the latest stable Python releases?",
)
print(response.output_text)The exact tool name and options depend on the provider. Do not treat built-in tool types as portable function schemas.
Reading Tool-Call Items in the Response
A response can contain both tool-call items and a final message. Inspecting the items helps you audit what happened:
for item in response.output:
if item.type == "web_search_call":
print("search status:", item.status)
elif item.type == "message":
for part in item.content:
for annotation in getattr(part, "annotations", []) or []:
if annotation.type == "url_citation":
print(annotation.title, annotation.url)Web-search citations identify the sources attached to generated text. Store or display them when users need to verify current claims.
Web Search: Grounding Answers in Current Information
Web search is useful for facts that change, such as software releases, regulations, prices, or current events. Tell the model when freshness matters, and apply provider controls such as allowed domains, geographic location, or a maximum number of searches.
Search results are untrusted input. They can contain incorrect claims or instructions aimed at the model. Treat them as evidence to evaluate, not as commands to execute.
Exercise
Who executes a built-in web-search tool, and what should you inspect to audit its use?
Show answer
The provider executes it. Inspect response output items, search-call status, and URL-citation annotations.