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
Get in Touch with us
Related Posts
- 实用型 GovTech 架构:ERP、GIS、政务服务平台与数据中台
- A Practical GovTech Architecture: ERP, GIS, Citizen Portal, and Data Platform
- 为什么应急响应系统必须采用 Offline First 设计(来自 ATAK 的启示)
- Why Emergency Systems Must Work Offline First (Lessons from ATAK)
- 为什么地方政府的软件项目会失败 —— 如何在编写代码之前避免失败
- Why Government Software Projects Fail — And How to Prevent It Before Writing Code
- AI 热潮之后:接下来会发生什么(以及这对中国企业意味着什么)
- After the AI Hype: What Always Comes Next (And Why It Matters for Business)
- 为什么没有系统集成,回收行业的 AI 项目往往会失败
- Why AI in Recycling Fails Without System Integration
- ISA-95 vs RAMI 4.0:中国制造业应该如何选择(以及为什么两者缺一不可)
- ISA-95 vs RAMI 4.0: Which One Should You Use (And Why Both Matter)
- 为什么低代码正在退潮(以及它正在被什么取代)
- Why Low‑Code Is Falling Out of Trend (and What Replaced It)
- 2025 年失败的产品 —— 真正的原因是什么?
- The Biggest Product Failures of 2025 — And the Real Reason They Failed
- Agentic AI Explained: Manus vs OpenAI vs Google —— 中国企业的实践选择
- Agentic AI Explained: Manus vs OpenAI vs Google — What Enterprises Really Need
- AI驱动的医院信息系统纵向整合(Vertical Integration)
- How AI Enables Vertical Integration of Hospital Systems













