# Useful but Little-Known Features of OpenAI Agent SDK
๐ Too many tools eating up your token budget? There's a way to load tools only when needed.
Combining `defer_loading` with `ToolSearchTool`, the model can search for and dynamically load only the tools it needs, dramatically reducing token consumption.
๐ Title: Hosted Tool Search / tool_namespace / defer_loading
๐ URL:
๐งฉ Overview
Tools decorated with `
@function_tool(defer_loading=True)` are excluded from the tool list on the initial model call. By adding `ToolSearchTool()` to the agent, the model first searches for relevant tools and loads only the ones it needs. You can also group tools using `tool_namespace`. This is a powerful feature for optimizing token usage in agents with many tools. Note that this feature is only available with `OpenAIResponsesModel`.
๐ How to use it
```python
from agents import Agent, function_tool
from agents.tool import ToolSearchTool
@function_tool(defer_loading=True, tool_namespace="analytics")
def run_report(report_type: str) -> str:
return generate_report(report_type)
@function_tool(defer_loading=True, tool_namespace="analytics")
def export_csv(dataset: str) -> str:
return create_csv(dataset)
@function_tool(defer_loading=True, tool_namespace="admin")
def manage_users(action: str) -> str:
return user_management(action)
agent = Agent(
name="assistant",
tools=[
ToolSearchTool(), # Enable tool search
run_report, export_csv, manage_users,
],
)
```
๐ Building it into production
ใปReduce token costs for agents with dozens to hundreds of tools
ใปUse `tool_namespace` to logically group tools and improve search accuracy
ใปKeep frequently used tools at `defer_loading=False` (default) and defer only rarely used ones
ใปScale tool count without worrying about prompt size
๐ก Use cases
๐งฐ Tool management for feature-rich SaaS agents
๐ On-demand loading of analytics and reporting tools
๐ง Showing admin tools only when needed
๐ Ensuring tool count scalability
โ ๏ธ Watch out
This feature works only with `OpenAIResponsesModel` and is not available with other model providers. Deferred tools are unavailable on the first turn, so they're not suitable for tools that must respond immediately to the user's initial request.
โจ Load "only the right tools at the right time" with tool search for smarter agents.
#
OpenAIAgentSDK# #
AIAgent#