> ## Documentation Index
> Fetch the complete documentation index at: https://notes.kodekloud.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Understanding and Using tools

> Describes LangChain tools, their difference from RAG, and how to use external APIs and runtimes for live data, computation, and agent workflows.

Having implemented retrieval-augmented generation (RAG) and built chains for summarization and retrieval, it's time to focus on tools — what they are, why they matter, and how they differ from RAG.

[LangChain](https://python.langchain.com/en/latest/) provides a set of tools to integrate large language models (LLMs) with external systems. In production, LLMs rarely operate alone; they often need access to up-to-date information, computation, or services outside of pre-indexed content.

<Frame>
  <img src="https://mintcdn.com/kodekloud-c4ac6d9a/Xqjckn2TzkOV2Gz2/images/LangChain/Using-Tools/Understanding-and-Using-tools/introduction-toolbox-llm-data-source.jpg?fit=max&auto=format&n=Xqjckn2TzkOV2Gz2&q=85&s=e8686e5269126283c733d5d4653c50c3" alt="The image features an &#x22;Introduction&#x22; title, an icon of a toolbox with tools and a question mark, and three labeled elements: &#x22;LLM,&#x22; &#x22;Data Source,&#x22; and a question mark." width="1920" height="1080" data-path="images/LangChain/Using-Tools/Understanding-and-Using-tools/introduction-toolbox-llm-data-source.jpg" />
</Frame>

We always need an LLM, and we frequently use a data source (for example, documents stored in a vector database). But many real-world tasks need integration points to external systems — tooling that either supplies live data or performs on-demand computation.

Example: an airline chatbot

* Customer asks, “What is the baggage policy?” — this typically triggers RAG: retrieve relevant policy text from an indexed document (vector DB), inject it into the prompt, and generate an answer.
* Customer asks, “When is my flight expected to arrive?” — that requires current status from a flight-tracking API; the answer depends on live data, not the stored PDF.

<Frame>
  <img src="https://mintcdn.com/kodekloud-c4ac6d9a/Xqjckn2TzkOV2Gz2/images/LangChain/Using-Tools/Understanding-and-Using-tools/airline-baggage-policy-user-vector-icons.jpg?fit=max&auto=format&n=Xqjckn2TzkOV2Gz2&q=85&s=2db895caddb95cbc41de8e75b1111fbd" alt="The image depicts an airline use case with a user asking, &#x22;What is the baggage policy?&#x22; accompanied by icons representing a vector database and a user." width="1920" height="1080" data-path="images/LangChain/Using-Tools/Understanding-and-Using-tools/airline-baggage-policy-user-vector-icons.jpg" />
</Frame>

For live queries like the flight status, you must call an external API. This is the job of tools: they let your LangChain application interact with real-time services, streaming data sources, or specialized compute environments.

<Frame>
  <img src="https://mintcdn.com/kodekloud-c4ac6d9a/Xqjckn2TzkOV2Gz2/images/LangChain/Using-Tools/Understanding-and-Using-tools/airline-use-case-flight-tracking-api.jpg?fit=max&auto=format&n=Xqjckn2TzkOV2Gz2&q=85&s=4b2eece04f11e4651d72fbb4403dcaf0" alt="The image illustrates an airline use case involving a user asking about flight arrival using a flight tracking API, with a crossed-out PDF icon suggesting non-use of PDFs." width="1920" height="1080" data-path="images/LangChain/Using-Tools/Understanding-and-Using-tools/airline-use-case-flight-tracking-api.jpg" />
</Frame>

What is a tool?

* In LangChain, a tool is a configurable module that exposes some external capability to your chain.
* Tools can fetch live data, call APIs, run custom logic, or execute code in a runtime (for example, Python).
* Agents — autonomous components that plan and pick actions — depend on tools to perform operations that the LLM cannot do by generation alone.

<Frame>
  <img src="https://mintcdn.com/kodekloud-c4ac6d9a/Xqjckn2TzkOV2Gz2/images/LangChain/Using-Tools/Understanding-and-Using-tools/toolbox-tools-configurable-module-illustration.jpg?fit=max&auto=format&n=Xqjckn2TzkOV2Gz2&q=85&s=a2e3cfd1e2893ace3bddbf798fbfb755" alt="The image displays a simple illustration of a toolbox with tools inside, labeled &#x22;Tools&#x22; and &#x22;Configurable Module,&#x22; under the question &#x22;What is a Tool?&#x22;" width="1920" height="1080" data-path="images/LangChain/Using-Tools/Understanding-and-Using-tools/toolbox-tools-configurable-module-illustration.jpg" />
</Frame>

Common tool examples

* Wikipedia — fetch and summarize articles ([Wikipedia](https://en.wikipedia.org/))
* Web search — perform live internet queries
* YouTube — retrieve transcripts or summarizations ([YouTube](https://www.youtube.com/))
* Python runtime — run code for numerical computation or data processing ([Python](https://www.python.org/))
* Custom tools — wrappers for internal APIs or business logic

<Frame>
  <img src="https://mintcdn.com/kodekloud-c4ac6d9a/Xqjckn2TzkOV2Gz2/images/LangChain/Using-Tools/Understanding-and-Using-tools/wikipedia-tools-examples-icons.jpg?fit=max&auto=format&n=Xqjckn2TzkOV2Gz2&q=85&s=ce2ec62de91f15883805c2cae40e379d" alt="The image shows icons representing &#x22;Wikipedia&#x22; and &#x22;Tools&#x22; under the heading &#x22;Tools – Examples.&#x22;" width="1920" height="1080" data-path="images/LangChain/Using-Tools/Understanding-and-Using-tools/wikipedia-tools-examples-icons.jpg" />
</Frame>

YouTube is a common case: fetch a transcript, summarize salient points, or answer questions about the video in real time.

<Frame>
  <img src="https://mintcdn.com/kodekloud-c4ac6d9a/Xqjckn2TzkOV2Gz2/images/LangChain/Using-Tools/Understanding-and-Using-tools/youtube-logo-search-bar-tools-examples.jpg?fit=max&auto=format&n=Xqjckn2TzkOV2Gz2&q=85&s=484eb1a5c967dc149f7e96e6022e2d98" alt="The image shows the YouTube logo with a search bar beneath it. The words &#x22;Tools – Examples&#x22; are at the top left corner." width="1920" height="1080" data-path="images/LangChain/Using-Tools/Understanding-and-Using-tools/youtube-logo-search-bar-tools-examples.jpg" />
</Frame>

A Python runtime as a tool is especially powerful:

* Run complex simulations, perform statistical analyses, or generate structured outputs.
* Return results to the LLM for further reasoning or response composition.
* Wrap domain-specific functions as callable tools to preserve business logic and ensure repeatability.

When to use RAG vs Tools

* RAG: augment prompts with context retrieved from preprocessed, indexed data (vector databases, document stores). Best for static or slowly changing content (policies, manuals, archived logs).
* Tools: interact with live systems or perform computation that must occur at query time (APIs, streaming data, heavy algorithms).

<Frame>
  <img src="https://mintcdn.com/kodekloud-c4ac6d9a/Xqjckn2TzkOV2Gz2/images/LangChain/Using-Tools/Understanding-and-Using-tools/rag-tools-comparison-interconnected-systems.jpg?fit=max&auto=format&n=Xqjckn2TzkOV2Gz2&q=85&s=05d9821c6b7048ac51175d250da3dbdf" alt="The image illustrates a comparison between RAG (Retrieval-Augmented Generation) and tools, showing interconnected external systems and applications. It includes icons representing tools and technology within a dotted framework." width="1920" height="1080" data-path="images/LangChain/Using-Tools/Understanding-and-Using-tools/rag-tools-comparison-interconnected-systems.jpg" />
</Frame>

Key distinctions

* RAG is usually asynchronous and batch-driven: documents get vectorized over time, and retrieval happens during queries.
* Tools provide synchronous access to external capabilities and real-time data.
* For heavy computation or real-time decision-making, delegate to tools (e.g., a Python tool). For retrieving policy text or archived content, use RAG.

Example recap

* Baggage policy → RAG (static documentation)
* Flight tracking → Tool (flight-tracking API / real-time data)

<Frame>
  <img src="https://mintcdn.com/kodekloud-c4ac6d9a/Xqjckn2TzkOV2Gz2/images/LangChain/Using-Tools/Understanding-and-Using-tools/airlines-chatbot-use-cases-features.jpg?fit=max&auto=format&n=Xqjckn2TzkOV2Gz2&q=85&s=118c61f3a85827c31cd02a00de72329d" alt="The image illustrates use cases for an airlines chatbot, highlighting features like RAG, baggage policy, tools, and flight tracking." width="1920" height="1080" data-path="images/LangChain/Using-Tools/Understanding-and-Using-tools/airlines-chatbot-use-cases-features.jpg" />
</Frame>

Quick reference: RAG vs Tools

|                           Capability | Best For                                      | Typical Example                                               |
| -----------------------------------: | --------------------------------------------- | ------------------------------------------------------------- |
| Retrieval-Augmented Generation (RAG) | Static or pre-indexed content                 | `Search a company's archived policy PDFs`                     |
|                                Tools | Real-time data, external APIs, or computation | `Call a flight-tracking API` or `Execute a Python simulation` |

<Callout icon="lightbulb" color="#1CB2FE">
  RAG is ideal for retrieving pre-indexed, relatively static content. Use tools when you need real-time data, live API calls, or external computation.
</Callout>

Next steps

* We will demonstrate concrete tool implementations and how to wire them into LangChain chains.
* After the demos, we’ll dive into agents: how they plan, decide which tools to call, and orchestrate multi-step workflows.

Links and references

* [LangChain Documentation](https://python.langchain.com/en/latest/)
* [Wikipedia](https://en.wikipedia.org/)
* [YouTube](https://www.youtube.com/)
* [Python](https://www.python.org/)

<CardGroup>
  <Card title="Watch Video" icon="video" cta="Learn more" href="https://learn.kodekloud.com/user/courses/langchain/module/06905b96-585d-4c9e-835a-d8fcaca76e2a/lesson/aa3a1783-f92e-417b-9352-d18c1784a501" />
</CardGroup>
