I Built 2 AI Agents with LangChain — Here’s How They Work
I Built 2 AI Agents with LangChain — Here’s How They Work
Posted by Nabira | @tech.with.nabira
From smart research to file analysis — here’s how I built my first real RAG and tool-calling AI agents.
In the last few months, I’ve been diving deep into GenAI and LangChain — not just watching tutorials but actually building working agents that can search, analyze, and respond using real data.
I wanted to build tools that do more than just chat — so I built two AI agents from scratch:
🧠 A Gemini-powered research assistant that uses real-time search and Wikipedia
📂 A Llama3 file analyzer bot that answers questions based on actual review data
Here’s how I built both, the tech I used, and how you can do the same 👇
🧠 Agent #1: Research Assistant (LangChain + Gemini)
This AI agent helps you research any topic by combining real-time search with encyclopedic knowledge — and then saves the findings in a structured format.
🔧 What it uses:
-
search_tool(DuckDuckGo) -
wiki_tool(Wikipedia) -
save_tool(writes to.txt) -
LangChain's agent executor with tool calling
-
Google Gemini 2.0 Flash
📂 How it works:
-
You enter a query (e.g., “What are gravitational waves?”)
-
The agent uses DuckDuckGo + Wikipedia tools to gather info
-
Gemini summarizes it using a custom prompt with a
PydanticOutputParser -
The results are saved to a
.txtfile with a timestamp
📊 The output includes:
-
Topic
-
Summary
-
Sources used
-
Tools called during research
This isn’t just LLM output — it’s structured, saved, and traceable.
📂 Agent #2: File Analyzer Bot (LangChain + Llama3)
This agent analyzes real data files using RAG (Retrieval-Augmented Generation) and responds based on what it finds.
💡 For this project, I used a dataset of pizza restaurant reviews, but you can plug in any data.
🔧 What it uses:
-
mxbai-embed-largefrom Ollama for embeddings -
ChromaDB to store vectorized review data
-
Llama3 (run locally with Ollama)
-
LangChain’s retriever + prompt chaining
📂 How it works:
-
CSV file of restaurant reviews is converted into documents
-
Each review is embedded with Ollama embeddings and stored in a Chroma vector store
-
When a user asks a question, LangChain retrieves the top 5 most relevant chunks
-
Llama3 answers the question only using the review data — no hallucinations allowed
🧪 Example question:
“Are there vegan options?”
If the reviews mention vegan items, the model will include that. If not, it says so — thanks to a restricted prompt that prevents it from making things up.
📊 The Full Tech Stack
-
Python + LangChain
-
Gemini 2.0 Flash (Google Generative AI)
-
Llama3.2 via Ollama
-
mxbai-embed-large (Ollama embeddings)
-
ChromaDB (Vector Search)
-
DuckDuckGo + Wikipedia API wrappers
-
Pydantic + dotenv + pandas
-
VS Code for development
🧠 Why I’m Sharing This
Most AI content right now is just frontend “chatbots.” But with LangChain, you can build agents that think, call tools, save files, and search your own data.
These two projects gave me:
-
Experience with embedding real data
-
Confidence to use local LLMs
-
A clear way to combine retrieval + generation + action
💬 Final Thoughts
If you’re just getting started with LangChain or AI agents:
-
Start with a single tool (like Wikipedia search)
-
Add on saving or summarization
-
Then level up with RAG and vector databases
You don’t need a giant team or enterprise stack — just Python, persistence, and a little creativity.
📩 Want to try this with your own data? The GitHub repository can be found here: https://github.com/nabirarashid/ai-agents
Feel free to DM me on Instagram for more help: @tech.with.nabira!
Comments
Post a Comment