DEV Community

Rushank Savant
Rushank Savant

Posted on

Day 7: Introducing AI Agents & Tools β€” Giving Your AI "Hands" πŸ› οΈ

We’ve spent a week building, where we predefined every single step. But what if you don't know the steps in advance? What if the AI needs to decide whether to search Google, check a database, or use a calculator based on the user's question?

This is where we move from "Chains" to Agents. If a Chain is a fixed railroad track, an Agent is a self-driving car. It has a destination (your goal) and a set of tools, and it decides the best route to get there.


πŸ€” What exactly is an AI Agent?

An Agent is an LLM that uses a "Reasoning Loop" to complete a task. In the official documentation, this is often called the ReAct pattern (Reason + Act).
Instead of just answering, the Agent follows this cycle:

1. Thought: "The user wants the current price of Bitcoin. I don't know that, so I should use a search tool."

2. Action: Calls the Search tool.

3. Observation: Reads the search results.

4. Final Response: Combines the observation into a helpful answer.


πŸ”§ The Power of Tools

Tools are the "hands" of your AI. A tool is essentially a Python function that the LLM knows how to call. LangChain comes with dozens of built-in tools, but you can also create your own!

Common Tools:

  • Tavily/Google Search: For real-time information.
  • Wikipedia: For general knowledge.
  • Python REPL: For executing complex math or data analysis.
  • Custom APIs: To connect to your own company's data.

πŸ—οΈ Building Your First Agent (The 2026 Way)

In modern LangChain, we use a specialized "Agent Executor" to manage the loop. Here’s a sneak peek at the setup:

from langchain_openai import ChatOpenAI
from langchain_community.tools.tavily_search import TavilySearchResults
from langchain.agents import create_react_agent, AgentExecutor
from langchain import hub

# 1. Define the Tools
tools = [TavilySearchResults(max_results=1)]

# 2. Get a "Prompt Template" from the LangChain Hub
# This prompt tells the AI how to use the tools
prompt = hub.pull("hwchase17/react")

# 3. Initialize the Brain (The LLM)
llm = ChatOpenAI(model="gpt-4o")

# 4. Construct the Agent
agent = create_react_agent(llm, tools, prompt)

# 5. Create the Executor (The engine that runs the loop)
agent_executor = AgentExecutor(agent=agent, tools=tools, verbose=True)

# 6. Run it!
agent_executor.invoke({"input": "What is the current stock price of NVIDIA?"})
Enter fullscreen mode Exit fullscreen mode

🎯 Day 7 Summary

Today, you learned about:

Agents: AI that can reason and decide its own path.

Tools: How to give LLMs access to the outside world.

The ReAct Loop: How AI thinks before it acts.

Agent Executor: The runtime that manages the process.

Your Homework: Go to the LangChain Tool Repository and look at the list. Which two tools would you combine to make a "Personal Research Assistant"?

See you tomorrow! β˜•

Top comments (0)