tl  tr
  Home | Tutorials | Articles | Videos | Products | Tools | Search
Interviews | Open Source | Tag Cloud | Follow Us | Bookmark | Contact   
 Generative AI > LangChain > LangChain Custom Tools and Tool Kits

LangChain Custom Tools and Tool Kits

Author: Venkata Sudhakar

LangChain tools give agents the ability to take actions beyond generating text - searching databases, calling APIs, running calculations, or querying internal systems. Custom tools let you expose your own business logic to an agent, enabling it to fetch live ShopMax product prices, check inventory levels, or look up order status in real time during a conversation.

There are two ways to define custom tools in LangChain: using the @tool decorator for simple functions and using the BaseTool class for tools that need custom validation, async support, or complex configuration. Tool kits group related tools together and can be registered with an agent in a single step, making it easy to build domain-specific agents like a ShopMax order management agent.

The below example defines three ShopMax India custom tools - price lookup, inventory check, and order status - and combines them into a tool kit for a LangChain agent.


It gives the following output,

The MacBook Air M3 is currently out of stock in Delhi.
The price is Rs 114900. You can check availability in other
ShopMax stores in Mumbai or Bangalore, or place an order
for home delivery.

The agent called both get_product_price and check_inventory automatically, then combined the results. The @tool decorator uses the function docstring as the tool description - write clear, specific descriptions so the agent knows exactly when to call each tool. For production ShopMax systems, replace the hardcoded dictionaries with real database calls or API requests to fetch live inventory and pricing data.


 
  


  
bl  br