Toolkits#
A Toolkit groups related tools into a single, reusable unit. Instead of passing individual tools one by one, you can bundle them into a toolkit and pass the whole collection to an agent. This is useful for organizing domain-specific capabilities (e.g., all database tools, all file-system tools) and sharing them across multiple agents.
A toolkit accepts both plain functions and @tool-decorated functions in its tools list. Plain functions are automatically converted, just like when passing them directly to an agent.
Registering Tools via a Decorator#
You can also add tools to a toolkit using the @toolkit.tool decorator, following the same pattern as @agent.tool:
The toolkit can then be passed to any number of agents:
Combining Toolkits with Standalone Tools#
You can freely mix toolkits and individual tools in an agent's tools list:
Toolkit middleware#
Pass middleware=[...] to the Toolkit constructor to apply hooks to every tool in the set — both tools passed to the constructor and tools added later via @toolkit.tool:
Toolkit middleware is the outermost layer: it runs before any per-tool middleware defined with @tool(middleware=[...]).
Per-tool middleware#
@toolkit.tool also accepts the same middleware=[...] option as @tool and @agent.tool. These per-tool hooks run inside the toolkit-level middleware. See Tool middleware.