This repository demonstrates how to use LangChain Tools β both built-in and custom β to extend the functionality of language models. Tools allow LLMs to interact with external systems such as search engines, APIs, databases, or even the local shell, making them more practical and powerful.
LangChain comes with a variety of prebuilt tools that can be used out of the box:
- DuckDuckGo Search Tool β enables LLMs to fetch real-time search results from the web.
- Shell Tool β executes shell commands directly from within an agent.
You can also create your own tools to suit specific needs:
- @tool decorator (
langchain_community.tools import tool) β simple way to wrap Python functions as LangChain tools. - StructuredTool (with
pydanticmodels) β allows defining structured input and validation usingBaseModelandField. - BaseTool (
langchain.tools import BaseTool) β the most flexible way to build custom tools by subclassing and implementing specific logic.
- Toolkit β a collection of tools bundled together that an agent can use.
- Tool Binding β the process of associating a specific function or API with a tool definition.
- Tool Calling β the LLM decides when to invoke a tool during reasoning.
- Tool Execution β the actual running of the tool, returning results back to the LLM.
- AgentExecutor β orchestrates the interaction loop between the LLM, the tools, and the user prompt.
This project demonstrates how to build and use custom tools with LangChain by implementing a Currency Conversion Agent.
- User Input β The user provides two currencies and an amount.
- Tool 1: Fetch Conversion Rate β A tool queries an API (Exchange Rate API) to get the exchange rate between the two currencies.
- Tool 2: Multiply Conversion β A simple tool multiplies the rate with the userβs input amount to calculate the converted value.
- AgentExecutor β manages the reasoning flow, ensuring the right tools are called in the right sequence.
This setup showcases how multiple tools can be combined to solve a practical task.