The Smart Inventory Agent pulls together everything covered in this series, LangChain agents, structured data, tool use, email automation, and guardrails, into one autonomous system that monitors stock levels, detects low-inventory items, searches for suppliers, and sends professional email summaries without human oversight.
Purpose
Traditional inventory management often relies on manual audits or disconnected systems that require constant oversight. The Smart Inventory Agent replaces that with a fully automated workflow that reads inventory data from a SQLite database, identifies products below their threshold levels, searches the web for suppliers, generates professional HTML email reports, logs every action for auditability, and supports natural-language interaction through a chat interface.
System Architecture
LangChain Agent: a ReAct-style agent powered by GPT-4o-mini executes reasoning steps and calls tools for database access, web search, email sending, and logging, with a custom system prompt ensuring clean SQL generation, structured tool usage, and grounded final answers.
SQLite Database: stores products (barcode, name, threshold), inventory transactions (purchases, sales, returns, and damaged-goods entries), and a log table of timestamped agent actions, giving the agent everything it needs to calculate real-time stock levels.
Tools Layer: each tool performs one external action:
database_reader, executes SQL queries against the inventory databaseweb_searcher, retrieves supplier information via Tavily Searchemail_sender, sends formatted HTML reports over SMTPlog_tracker, records every action taken, for auditability
Building the Supplier Search Tool
The project starts with a single capability, letting the agent search the web for bulk suppliers, wired up with the Tavily search API:
from langchain_tavily import TavilySearch
from langchain.tools import tool
from config import TAVILY_API_KEY
search_tool = TavilySearch(api_key=TAVILY_API_KEY, max_results=5, include_answer=True)
@tool
def web_search_tool(query: str) -> str:
"""Perform a web search using Tavily and return formatted results."""
results = search_tool.invoke({"query": query})
output = f"Search results for **{query}**:\n"
for result in results["results"]:
title = result.get("title", "No title")
url = result.get("url", "")
snippet = result.get("content", "")
output += f"- [{title}]({url})\n {snippet}\n\n"
return output.strip()
That tool alone is enough to give an agent its first real capability:
from langchain.agents import create_agent
from langchain_openai import ChatOpenAI
from tools.web_search_tool import web_search_tool
llm = ChatOpenAI(model="gpt-4o-mini", temperature=0)
inventory_agent = create_agent(model=llm, tools=[web_search_tool], system_prompt="You are a helpful assistant.")
Reading the Database
The database sits behind a dedicated reader tool that safely executes SQL and formats the results as a table the LLM can read directly:
@tool
def read_database_tool(sql: str) -> str:
"""Execute a SQL query against the SQLite database and return formatted results."""
if not isinstance(sql, str) or not sql.strip():
return "Error executing SQL: empty query."
try:
cols, rows = _exec_sql(sql)
return _format_table(cols, rows)
except Exception as e:
return f"Error executing SQL: {e}"
Adding it to the agent's tool list turns a plain search assistant into something that can answer real questions about live inventory: "How many distinct products are there in inventory, and search online for bulk suppliers for those products."
Closing the Loop with Email and Logging
The final pieces give the agent a voice and a memory of its own actions: an SMTP-based send_email_tool for reporting, and a track_log_tool that writes every action to the logs table. Assembled together, the system prompt spells out exactly how the agent should behave:
inventory_agent = create_agent(
model=llm,
tools=[web_search_tool, read_database_tool, send_email_tool, track_log_tool],
system_prompt=f"""
You are a helpful assistant to manage inventory and find bulk suppliers online for products in the database.
When replying, use well-formatted markdown.
When sending email using the send_email_tool:
- ALWAYS pass the tool input in this exact format:
"subject text || body text"
- The body must be valid HTML.
- Include greetings and a signature. Your name is {AGENT_NAME}.
- Never change the delimiter. Always use "||" exactly once.
After completing the requested task, log your actions using the track_log_tool.
""",
)
From there, a Streamlit front end (app.py) turns the whole thing into a chat interface, and a scheduled task can run main.py daily so the agent checks inventory, searches for suppliers, and emails a summary without anyone opening a laptop. A later step swaps the hand-built tools for an MCP server, the same Model Context Protocol from Module 6, so the same inventory capabilities become available to any MCP-compatible client, not just this one agent.
Build It Yourself, or Clone It
The full project supports two paths: a step-by-step build that teaches LangChain orchestration, tool integration, database interactions, and autonomous agent design one piece at a time, or cloning a complete, working implementation straight from GitHub:
git clone https://github.com/solomontessema/smart-inventory-agent
git clone https://github.com/solomontessema/inventory-mcp-server
Where This Leaves You
The Smart Inventory Agent is a practical, deployable example of agentic AI applied to a real supply chain problem: it autonomously monitors inventory, researches suppliers, and communicates insights, turning inventory management into an intelligent, proactive workflow instead of a manual audit. It is also a foundation, not an endpoint, for extensions like demand forecasting, automated purchase orders, and multi-agent systems where specialized agents hand work off to each other.
Hands-On Labs, Step by Step
The Agentic AI Mastery course walks through this exact capstone one step at a time, each with its own notebook:
- Step 0: Project Scaffold:
- Step 1: Web Search Tool and Environment Setup:
- Step 2: SQLite Database and Tables:
- Step 3: Database Reader Tool:
- Step 4: Email and Logging Tools:
- Step 5: Chat Interface:
Step 6 swaps the hand-built tools for an MCP server, the repo for that is linked above in "Build It Yourself, or Clone It."
That closes the Agent Loop series. Start over from Module 1: Foundations of Agentic AI, or go build all nine of these modules hands-on, with live instruction, in the Agentic AI Mastery course at IONNOVA Academy.