In Chapter 1: AI Agents & Personas, we learned how to create an AI Agent by giving a raw model a specific "Job Description."
However, even the best Market Analyst agent has a major flaw: It is frozen in time. If you ask it, "What is the price of Apple (AAPL) right now?", it will either:
This chapter introduces the solution: External Tools.
Imagine the AI model is a genius locked in a room with no windows and no internet. They have memorized every book ever written up to 2023.
Tool Integration is like giving that genius a Laptop with internet access. Now, when you ask about the weather, they don't guessβthey look it up.
In Python terms, a tool is simply a function that the AI is allowed to call.
It works like this:
get_stock_price. I will use it."$150.00.The Agent acts as the brain that decides which tool to use, and the Tool acts as the hands that actually do the work.
Let's look at how this is implemented in our project using the YFinanceStockTool (from the file multi_agent_financial_analyst/tools/financial_tools.py).
We wrap a standard Python library (yfinance) inside a class structure that the Agent can understand.
# Simplified from tools/financial_tools.py
import yfinance as yf
from crewai.tools import BaseTool
class YFinanceStockTool(BaseTool):
name: str = "stock_data_tool"
description: str = "Get real-time stock prices and company info."
def _run(self, symbol: str) -> str:
# The actual work happens here
stock = yf.Ticker(symbol)
price = stock.history(period="1d")['Close'].iloc[-1]
return f"The price of {symbol} is ${price}"
name: How the Agent identifies the tool.description: The Agent reads this to know when to use the tool._run: The logic that fetches the data.When we create an Agent (using a framework like Agno or CrewAI), we pass these tools in a list.
# Conceptual example of equipping an agent
finance_agent = Agent(
role="Financial Analyst",
instructions="Use your tools to find live data.",
tools=[YFinanceStockTool()] # <--- We hand over the tools here
)
Now, if you ask this agent "Tell me a joke," it won't use the tool.
If you ask "How is Apple doing today?", it will automatically trigger YFinanceStockTool.
How does a text-generating AI know how to run a Python function? It uses a concept called Function Calling (or Tool Calling).
The AI doesn't actually run the code itself. It outputs a structured request (usually JSON), and our code framework runs the function for it.
stock_data_tool with input AAPL."
In our project file agentic_rag_with_qwen_and_firecrawl/app.py, we see another powerful use case: Web Search.
Here, we give an agent the ability to search the internet using FirecrawlTools.
# From agentic_rag_with_qwen_and_firecrawl/app.py
agent = Agent(
model=model,
instructions=[...],
# Give the agent the ability to crawl the web
tools=[FirecrawlTools(api_key=key, scrape=False, crawl=True)],
show_tool_calls=True
)
Why is this amazing?
If you are analyzing a PDF about a company from 2021 (using the concepts we will learn in the next chapter), the data is old. By adding FirecrawlTools, the Agent can:
In this chapter, we learned:
Now our Agent is smart and connected to the internet. But what if we want it to read a specific, massive 500-page manual that isn't on the public internet?
For that, we need a way to "retrieve" specific knowledge.
π Next Step: Retrieval-Augmented Generation (RAG)
Generated by Code IQ