# Useful but Little-Known Features of OpenAI Agent SDK
๐ Want to dynamically toggle which tools are available based on user permissions or plan tier?
The `is_enabled` parameter lets you conditionally control tool availability, providing context-appropriate toolsets.
๐ Title: Conditional Tool Enabling
๐ URL:
๐งฉ Overview
By passing a boolean `True`/`False` or a callback function `(ctx, agent) -> bool` to the `is_enabled` parameter on `as_tool()`, you can dynamically control whether a tool is enabled or disabled. Disabled tools don't appear in the model's tool list and consume no tokens. This is ideal for feature gating and permission-based access control.
๐ How to use it
```python
from agents import Agent, function_tool, RunContextWrapper
@function_tool
def admin_tool(command: str) -> str:
return execute_admin(command)
@function_tool
def basic_tool(query: str) -> str:
return basic_search(query)
# Dynamic check via callback
def is_admin(ctx: RunContextWrapper, agent: Agent) -> bool:
return ctx.context.user_role == "admin"
agent = Agent(
name="assistant",
tools=[
admin_tool.as_tool(is_enabled=is_admin),
basic_tool,
],
)
```
๐ Building it into production
ใปGate premium feature tools based on SaaS plan tiers
ใปControl tool access by user role (admin/member/viewer)
ใปIntegrate with feature flags for A/B testing or canary releases of new capabilities
ใปOptimize toolsets based on context (region, time of day, etc.)
๐ก Use cases
๐ Restricting operational tools to administrators only
๐ Offering advanced tools exclusively to paid-plan users
๐ Feature flag-driven gradual rollouts
๐ Switching available services by region
โ ๏ธ Watch out
When `is_enabled` is `False`, the tool is not presented to the model at all, so the model has no awareness it exists. While effective for security, if you want to inform users that a feature is unavailable, you'll need a separate messaging mechanism.
โจ Deliver the optimal agent experience for each user with conditional tool enabling.
#
OpenAIAgentSDK# #
AIAgent#