Questions
9 of 24
1What is a Tool in LangChain and how does it differ from a plain function or API call?
2What is the difference between the tool() helper, DynamicTool, and StructuredTool class?
3How does an LLM decide which tool to call — what role does the tool description play?
4What is the role of Zod schema in tool definitions and how does it map to OpenAI's function calling spec?
5What is a ToolNode in LangGraph and how does it differ from calling a tool manually inside a graph node?
6How do you wrap a REST API call with auth headers inside a Tool in TypeScript?
7How do you handle async errors and retries inside a Tool without crashing the agent loop?
8How do you pass runtime context (userId, authToken, DB connection) into a Tool using RunnableConfig?
9How do you build a Toolkit (grouped set of related tools) using BaseToolkit?
10How do you validate and sanitize tool output before it is passed back to the LLM?
11How do you stream tool call results back to the client in real time?
12How do you implement tool-level authorization — allowing certain tools only for certain users?
13How do you build stateful tools that read/write to a database across multiple agent turns?
14How do you prevent tool abuse or infinite loops where an agent keeps calling the same tool repeatedly?
15How do you implement parallel tool calling — when the LLM decides to call multiple tools simultaneously?
16How do you create a human-in-the-loop tool that pauses the agent and waits for user approval before executing?
17How do you unit test and mock tools in isolation without invoking the LLM?
18How do you implement tool call caching to avoid redundant API calls for identical inputs?
19How do you design a multi-agent system where one agent's tool is actually another agent (agent-as-tool pattern)?
20How does LangGraph's ToolNode handle tool call errors and surface them back into the message state?
21What is the difference between tool_choice: "auto", "required", and "none" when binding tools to an LLM?
22How do you implement dynamic tool loading — where the set of available tools changes based on user role or session state?
23How do you trace and observe tool call latency in production using LangSmith?
24What are the token cost implications of registering too many tools and how do you mitigate it?
09 / 24

How do you build a Toolkit (grouped set of related tools) using BaseToolkit?

Build a custom Toolkit in LangChain by subclassing BaseToolkit and implementing the abstract get_tools method to return a list of related BaseTool instances, providing a cohesive interface for grouping tools by functionality.

In LangChain, a Toolkit is a powerful abstraction for grouping a cohesive set of related tools under a single interface. This is particularly useful when you have multiple tools that operate on the same domain (e.g., a database, a CRM, or a file system) and you want to present them as a unified package to an agent. The BaseToolkit class provides the blueprint for this pattern, and building one involves creating your own subclass that implements the required get_tools method.

  1. 1

    Subclass BaseToolkit: Create a new class that inherits from langchain_community.agent_toolkits.base.BaseToolkit. This gives your toolkit the foundational structure and integrates with LangChain's tooling ecosystem. BaseToolkit itself is an abstract base class (ABC), so you are required to implement its abstract methods.

  2. 2

    Implement get_tools: Override the abstract get_tools method. This method is the core of your toolkit and must return a list of BaseTool objects. These are the individual tools that your toolkit groups together (e.g., ReadFileTool, WriteFileTool, ListDirectoryTool).

  3. 3

    Initialize Tools: Inside get_tools, instantiate and configure your specific tools. This is where you can pass runtime dependencies like API keys, database connections, or configuration objects to the tools, keeping them decoupled from the toolkit's creation logic.

Example: Building a Database Toolkit
  1. 1

    Creating the Agent: Once you have your toolkit, you create an instance and call its get_tools() method to retrieve the list of tools. This list can be passed directly to agent constructors like create_react_agent or create_agent.

  2. 2

    Modular Architecture: The toolkit pattern promotes clean code organization. It allows you to encapsulate the logic for creating a set of related tools, making it easy to manage, test, and reuse across different agents or projects. It also provides a single import path for consumers of your toolkit.

  3. 3

    Configuration and Dependencies: The __init__ method of your toolkit is the ideal place to accept configuration (like API keys, endpoints, or client objects). This config can then be passed down to individual tools during the get_tools() call, ensuring all tools are correctly set up without each consumer having to configure them individually.