BEFORE_TOOL_DEFINITIONS hook fires right after the tool list is assembled for a request and before it reaches the LLM — letting you drop tools, rewrite descriptions, or constrain parameter schemas on the fly.
For the full hook lifecycle model, see the Hooks concept page.
Quick Start
Drop a Tool by Name
Remove a tool from the LLM’s view for every request — the tool stays registered on the agent but the model never sees it:
Async Hook
The hook fires on both sync and async agent paths. Use an async function when you need async lookups:
How It Works
Deep copy guarantee: The agent deep-copiestool_definitions before passing them to the hook. This means:
- Hook mutations cannot accidentally poison the agent’s internal tool cache.
- Each request starts from the clean, registered tool list.
- Only in-place mutations (
data.tool_definitions[:] = ...) are adopted.
BeforeToolDefinitionsInput Fields
| Field | Type | Description |
|---|---|---|
tool_definitions | List[Dict[str, Any]] | The assembled OpenAI-style tool definitions. Mutate in-place. |
model | str | The LLM model name for this request |
agent_name | str | Name of the agent firing the hook |
session_id | str | Session identifier (for per-session filtering) |
Mutation Pattern
Always mutatetool_definitions in-place with slice assignment. Reassigning the variable does nothing:
Best Practices
Use session_id to scope per-user tool access
Use session_id to scope per-user tool access
The
session_id field lets you load per-session permissions from a store and filter tools accordingly. This is the recommended pattern for multi-tenant bots where different users get different tool sets.Prefer description rewriting over tool removal
Prefer description rewriting over tool removal
Removing a tool stops the model from calling it but can break agent plans that depend on it. Rewriting the description (e.g. adding
"(disabled for this session)") lets the model know the tool exists but should not be called.Keep hooks fast — they run on every request
Keep hooks fast — they run on every request
The hook fires before every LLM call. Avoid slow I/O in sync hooks; use async hooks for database or network lookups.
Test with the deep-copy guarantee in mind
Test with the deep-copy guarantee in mind
Because the runtime deep-copies before calling your hook, changes to one request’s tool list never affect the next. You cannot cache mutations across requests via the hook input itself.
Related
Hooks (Concept)
Full hook lifecycle model
Hook Events
All available hook events
Bot Lifecycle Hooks
Hooks for bot startup and shutdown
Tool Availability
Control which tools agents can use

