
Building a Tool-Using Agent with LangGraph and Vector Memory
January 26, 2025
Deploying LangGraph Agents to Production: From Localhost to Cloud
February 12, 2025(APIs, Browsers, File Systems)
Equipping your AI agents with tool access is what unlocks true autonomy. A goal-driven agent isn’t truly intelligent until it can interact with APIs, explore websites, or handle files. In this tutorial, we’ll show you how to connect your agents to the outside world using LangChain and CrewAI—and do it safely and effectively.
🧠 Why Tools Matter in Agentic AI
Large Language Models (LLMs) are great at reasoning and generating text, but they are limited to their training data and don’t have native access to real-time information, APIs, or environments.
Tools bridge that gap. They allow agents to:
- Query live data via APIs
- Scrape or interact with web pages
- Upload or download files
- Modify the file system
- Perform calculations, send emails, control workflows, and more
Frameworks like LangChain and CrewAI include built-in support for tools, enabling agents to decide when and how to use them autonomously.
🧰 Types of Tools You Can Add
| Tool Type | Example Use Case | Libraries & Tools |
|---|---|---|
| REST APIs | Weather, stock prices, search, CRM | requests, LangChain tools, Zapier API |
| Browser Access | Scraping or interacting with web UIs | Playwright, Puppeteer, Selenium |
| File System | Reading/writing files, logs, config updates | Python file I/O, OS commands |
| Search Engines | Context lookup, product info, news | Tavily API, Serper API, Google Search API |
🔧 Using Tool Access in LangChain
LangChain provides a convenient way to wrap Python functions into callable tools using the Tool class.
✅ Step 1: Define Your Tool
pythonCopyEditfrom langchain.tools import Tool
import requests
def get_weather(city):
response = requests.get(f"https://api.weatherapi.com/v1/current.json?q={city}&key=YOUR_KEY")
return response.json()["current"]["condition"]["text"]
weather_tool = Tool(
name="GetWeather",
func=get_weather,
description="Use this tool to get current weather for a given city"
)✅ Step 2: Plug Tool into an Agent
pythonCopyEditfrom langchain.agents import initialize_agent
from langchain.chat_models import ChatOpenAI
llm = ChatOpenAI(temperature=0)
tools = [weather_tool]
agent = initialize_agent(tools, llm, agent_type="zero-shot-react-description")
response = agent.run("What's the weather like in San Francisco?")
print(response)
☁️ This agent will now decide on its own to call the weather API tool when needed.
🤝 Tool Access with CrewAI
CrewAI takes tool access a step further by associating specific tools with specific agents—which is great for multi-agent teamwork.
✅ Example:
pythonCopyEditfrom crewai import Agent, Task, Crew
from langchain.tools import DuckDuckGoSearchRun
search = DuckDuckGoSearchRun()
researcher = Agent(
role="Researcher",
goal="Find recent articles on AI governance",
backstory="You're a brilliant analyst at a tech think tank.",
tools=[search]
)
task = Task(description="Summarize the top 3 findings", agent=researcher)
crew = Crew(agents=[researcher], tasks=[task])
crew.kickoff()🔍 Agents in CrewAI can each have their own toolset, making it easy to assign roles like:
- Searcher → Browser or API tool
- Editor → File writer tool
- Coordinator → Email or messaging tool
🌐 Browser-Based Tooling
pythonCopyEditfrom langchain.tools import Tool
import subprocess
def search_google(query):
subprocess.run(["playwright", "open", f"https://google.com/search?q={query}"])
return "Opened browser tab."
google_tool = Tool(name="BrowserSearch", func=search_google, description="Launches a browser search.")⚠️ Safety Tip: Always sandbox browser tools or run in isolated environments.
💾 File System Access (with Caution)
You can allow agents to read or write files, but always wrap actions with controlled access logic.
pythonCopyEditimport os
def read_file(file_path):
if os.path.exists(file_path):
with open(file_path, "r") as f:
return f.read()
return "File not found."
file_tool = Tool(name="ReadFile", func=read_file, description="Read contents of a file.")📁 Use cases: Code analysis agents, config updaters, file transformers.
🔐 Best Practices for Safe Tool Use
- ✅ Restrict scope – Only expose essential functions
- ✅ Validate inputs – Sanitize prompts to avoid injection attacks
- ✅ Log tool usage – Track which tools agents are calling
- ✅ Limit access – Use environment variables and scoped permissions


