# 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#