Skip to main content
The 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.
The user prompts the agent; the hook trims tool definitions before the LLM sees them.

Quick Start

1

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:
2

Rewrite a Tool Description

Append usage guidance to a tool description before it reaches the model:
3

Async Hook

The hook fires on both sync and async agent paths. Use an async function when you need async lookups:
4

As a Plugin

Plugins implement before_tool_definitions() as a method:

How It Works

Deep copy guarantee: The agent deep-copies tool_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


Mutation Pattern

Always mutate tool_definitions in-place with slice assignment. Reassigning the variable does nothing:

Best Practices

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.
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.
The hook fires before every LLM call. Avoid slow I/O in sync hooks; use async hooks for database or network lookups.
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.

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