A tool-calling support agent for an e-commerce store, built to explore what "agentic AI" actually requires under the hood: tool orchestration, guarded state transitions, retrieval-grounded answers, and human escalation — first hand-rolled from scratch, then rebuilt in LangGraph for production patterns.
- Why two implementations
- What it does
- Architecture
- Tech stack
- Tools implemented
- Setup
- Evaluation
- What's intentionally out of scope
- Screenshots
Most tutorials teach agent frameworks without explaining what they're abstracting. This project deliberately builds the agent loop by hand first (agent.py) — a raw while loop calling the Gemini API, executing tools, and feeding results back — before rebuilding the same agent in LangGraph (agent_lg.py) with explicit state, nodes, and checkpointing.
This surfaces real problems the hand-rolled version has (state lost on crash, fragile string-matched confirmation gating, no visualized flow) that LangGraph is specifically designed to solve — rather than adopting a framework on faith.
- Looks up order status, checks return eligibility, processes refunds and cancellations
- Answers general policy questions (shipping, returns, payments) via RAG over policy documents
- Requires explicit customer confirmation before any destructive action (refund, cancellation)
- Enforces a $100 refund threshold in code — refunds at or above that amount are escalated to a human, never auto-processed
- Detects customer frustration and agent uncertainty locally (no LLM call needed) and escalates proactively
- Persists conversation state to Postgres so sessions survive a restart
- Traces every tool call and LLM turn to Langfuse for observability
- Ships with a Streamlit UI showing a live tool-call trace panel alongside the chat
User message
|
v
Frustration check (local, no LLM call)
|
v
Call model (Gemini) --tool call--> Execute tool --> back to model
| |
|<--------------------------------------------------|
v
Confidence check (local, no LLM call)
|
v
Reply + trace logged (Langfuse) + session saved (Postgres)
The LangGraph version (agent_lg.py) makes this flow explicit as a graph — frustration_check -> call_model -> run_tools -> post_check — with automatic state checkpointing after every node, instead of the implicit control flow of the hand-rolled while loop.
| Layer | Choice |
|---|---|
| LLM | Google Gemini 2.5 Flash (free tier) |
| Orchestration | Hand-rolled loop -> LangGraph |
| Database | PostgreSQL (Docker) |
| Vector store | ChromaDB (local embeddings, all-MiniLM-L6-v2) |
| Observability | Langfuse |
| UI | Streamlit |
| Tool | Type | Guardrail |
|---|---|---|
get_order_status |
Read | — |
check_return_eligibility |
Read | — |
initiate_refund |
Write | Requires confirmation; blocked at >=$100, escalates instead |
cancel_order |
Write | Requires confirmation; only allowed if not yet shipped |
escalate_to_human |
Write | Triggered by $100+ refunds, customer frustration, or agent uncertainty |
search_policy |
Read | RAG over policy docs (returns, shipping, general FAQ) |
git clone https://github.com/Bajrang007/ShopHelp.git
cd ShopHelp
python -m venv venv
venv\Scripts\Activate.ps1 # Windows
pip install -r requirements.txt
# Start Postgres
docker compose up -d
# Seed the database and build the RAG index
python data/seed_db.py
python backend/build_index.py
python backend/add_memory_table.py
# Copy .env.example to .env and fill in your own keys
copy .env.example .envRun the hand-rolled agent (terminal):
python backend/agent.pyRun the LangGraph version:
python backend/agent_lg.pyRun the UI:
streamlit run frontend/app.pyRun the automated eval suite (no LLM calls -- tests tools, guardrails, and escalation logic directly):
python backend/eval_suite.pybackend/eval_suite.py runs 8 deterministic tests covering tool correctness, confirmation guardrails, the $100 refund threshold, and escalation trigger detection -- all without spending LLM calls, so it runs as a fast regression check any time the underlying logic changes.
PASS get_order_status returns correct item
PASS get_order_status handles missing order
PASS eligibility rejects non-delivered order
PASS cancel_order blocked without confirmation
PASS refund >= $100 is blocked
PASS frustration triggers escalation
PASS normal question does not trigger escalation
PASS agent uncertainty triggers escalation
Results: 8/8 passed
Product recommendations and real payment gateway integration were deliberately excluded -- they exercise different skills (recommender systems, payments infrastructure) than agent design, and would have diluted the project's focus.
Full production deployment (Docker orchestration for the app itself, CI/CD, multi-tenant auth/RBAC) was also scoped out as infra work rather than agentic AI work. In a real deployment, the tool-call trace panel shown in this demo would move behind role-based access to an internal/admin view -- customers would see only the clean chat.
Chat interface with a live tool-call trace panel showing exactly which tool was called, with what input, and what it returned from the database.
