Building Agentic AI with Python, Langchain, and Ollama for eCommerce & Factory Automation
Artificial Intelligence has moved beyond passive Q\&A bots. Agentic AI is a new frontier — where AI systems don't just respond, they reason, plan, and act autonomously. In this post, we’ll build a hands-on Agentic AI system using:
- 🧠 Langchain — to structure our agent’s logic, memory, and tools
- 🔓 Ollama — to run powerful open-source LLMs locally (like LLaMA3 or Mistral)
- 🏭 Custom tools — for eCommerce and Factory Automation use cases
🚀 What Is Agentic AI?
Agentic AI refers to systems that operate with goals, autonomy, and tool-using capabilities. Unlike basic chatbots, an agentic AI can:
- Retain memory of past actions and conversations
- Use external tools (e.g., databases, APIs, scripts)
- Reason and plan steps to solve complex tasks
- Take multiple actions toward achieving a goal
🧰 Tech Stack Overview
Component | Description |
---|---|
Python | Main language |
Langchain | Agent framework (tool use, planning, memory) |
Ollama | Local LLM runtime for open-source models |
Custom Tools | Functions for eCommerce & factory scenarios |
🧠 Agent Architecture
Here’s a high-level view of how our agent works:
graph TD
A["User Query"] --> B["Langchain Agent"]
B --> C["LLM via Ollama (e.g., LLaMA3)"]
B --> D["Memory (ConversationBuffer)"]
B --> E["Tool Selector"]
E --> F["search_products()"]
E --> G["track_order()"]
E --> H["check_production_status()"]
E --> I["log_factory_issue()"]
F --> J["eCommerce Inventory"]
G --> K["Order System"]
H --> L["Factory Machine DB"]
I --> M["Maintenance Logging System"]
C -->|Plan & Reason| B
D -->|Context| B
📦 Step 1: Define Tools
Each tool simulates a real-world function such as looking up products or checking a machine’s status.
# tools.py
from langchain.tools import tool
@tool
def search_products(keyword: str) -> str:
return f"Found 3 products matching '{keyword}': A, B, C."
@tool
def track_order(order_id: str) -> str:
return f"Order {order_id} is currently in transit."
@tool
def check_production_status(machine_id: str) -> str:
return f"Machine {machine_id} is 87% complete with batch #42."
@tool
def log_factory_issue(issue: str) -> str:
return f"Issue '{issue}' has been logged and assigned to a technician."
🤖 Step 2: Initialize the Agent with Langchain + Ollama
# agent.py
from langchain_community.chat_models import ChatOllama
from langchain.agents import initialize_agent, AgentType
from langchain.memory import ConversationBufferMemory
from tools import search_products, track_order, check_production_status, log_factory_issue
llm = ChatOllama(model="llama3") # Run with: `ollama run llama3`
memory = ConversationBufferMemory(memory_key="chat_history", return_messages=True)
agent = initialize_agent(
tools=[search_products, track_order, check_production_status, log_factory_issue],
llm=llm,
agent=AgentType.CONVERSATIONAL_REACT_DESCRIPTION,
memory=memory,
verbose=True
)
💬 Step 3: Run the Agent
# main.py
from agent import agent
print("=== Agentic AI for eCommerce + Factory ===")
while True:
query = input("You: ")
if query.lower() in ['exit', 'quit']:
break
result = agent.run(query)
print("Agent:", result)
🧪 Sample Interaction
You: Search for bluetooth speakers
Agent: Found 3 products matching 'bluetooth speakers': A, B, C.
You: Track order #99123
Agent: Order 99123 is currently in transit.
You: What's the status of machine A7?
Agent: Machine A7 is 87% complete with batch #42.
You: Log issue: Machine A7 overheating
Agent: Issue 'Machine A7 overheating' has been logged and assigned to a technician.
✅ Why It Matters
Agentic AI enables next-generation automation and digital assistants. With this approach:
- Businesses can create smart back-office tools that act, not just chat.
- Factories can monitor equipment, log issues, and respond faster.
- eCommerce platforms can offer smarter support without human intervention.
And because it’s powered by open-source LLMs, you have:
- Full control over data and model behavior
- No vendor lock-in
- Cost-effective deployment
📦 Next Steps
Want to go further?
- Add FastAPI or Streamlit for a frontend
- Integrate real APIs instead of mock functions
- Use vector memory for long-term knowledge retention
- Add multi-agent collaboration using CrewAI or LangGraph
Related Posts
- How AI Supercharges Accounting and Inventory in Odoo (with Dev Insights)
- Building a Fullstack E-commerce System with JavaScript
- Diagnosing the Root Cause of P0420 with Python, OBD-II, and Live Sensor Data
- How to Apply The Mom Test to Validate Your Startup Idea the Right Way
- When to Choose Rasa vs Langchain for Building Chatbots
- Introducing OCR Document Manager: Extract Text from Documents with Ease
- Testing an AI Tool That Finds Winning Products Before They Trend — Interested?
- Your Website Is Losing Leads After Hours — Here’s the Fix
- How Agentic AI is Revolutionizing Smart Farming — And Why Your Farm Needs It Now
- How to Apply RAG Chatbot with LangChain + Ollama
- Automating EXFO Instruments with SCPI: A Practical Guide
- Design Patterns That Help Tame Legacy Code (With Python Examples)
- How to Safely Add New Features to Legacy Code — A Developer’s Guide
- Modernizing Legacy Software — Without Breaking Everything
- How OpenSearch Works — Architecture, Internals & Real-Time Search Explained
- Choosing the Right Strategy for Basic vs Premium Features in Django
- Transform Your Custom Furniture Business with a Modern eCommerce Platform
- Introducing simpliPOS: The Smart POS Built on ERPNext
- 🌾 Smart Farming Made Simple: A Tool to Help Farmers Track and Plan Inputs Efficiently
- Simulate Electromagnetic Waves with MEEP: A Hands-On Introduction
Our Products
Related Posts
- How AI Supercharges Accounting and Inventory in Odoo (with Dev Insights)
- Building a Fullstack E-commerce System with JavaScript
- Diagnosing the Root Cause of P0420 with Python, OBD-II, and Live Sensor Data
- How to Apply The Mom Test to Validate Your Startup Idea the Right Way
- When to Choose Rasa vs Langchain for Building Chatbots
- Introducing OCR Document Manager: Extract Text from Documents with Ease
- Testing an AI Tool That Finds Winning Products Before They Trend — Interested?
- Your Website Is Losing Leads After Hours — Here’s the Fix
- How Agentic AI is Revolutionizing Smart Farming — And Why Your Farm Needs It Now
- How to Apply RAG Chatbot with LangChain + Ollama
- Automating EXFO Instruments with SCPI: A Practical Guide
- Design Patterns That Help Tame Legacy Code (With Python Examples)
- How to Safely Add New Features to Legacy Code — A Developer’s Guide
- Modernizing Legacy Software — Without Breaking Everything
- How OpenSearch Works — Architecture, Internals & Real-Time Search Explained
- Choosing the Right Strategy for Basic vs Premium Features in Django
- Transform Your Custom Furniture Business with a Modern eCommerce Platform
- Introducing simpliPOS: The Smart POS Built on ERPNext
- 🌾 Smart Farming Made Simple: A Tool to Help Farmers Track and Plan Inputs Efficiently
- Simulate Electromagnetic Waves with MEEP: A Hands-On Introduction