eCommerce-Agent
Agentic e-commerce AI assistant powered by LangGraph, structured tool orchestration, context engineering, policy-aware RAG, multimodal AI, and a public MCP…
PocketMarket is an Agentic AI system built inside a realistic e-commerce environment. It demonstrates how an assistant can move beyond chat into a controlled system that plans, validates, uses tools, maintains context, retrieves policy-aware knowledge, handles multimodal input, exposes public capabilities through MCP, and executes real application actions while keeping sensitive authority outside the LLM.
Summary extracted from the README.
PocketMarket — Agentic E-Commerce AI Assistant
PocketMarket is an Agentic AI system built inside a realistic e-commerce environment. It demonstrates how an assistant can move beyond chat into a controlled system that plans, validates, uses tools, maintains context, retrieves policy-aware knowledge, handles multimodal input, exposes public capabilities through MCP, and executes real application actions while keeping sensitive authority outside the LLM.
The project is centered on an assistant that uses LangGraph to interpret user intent, construct structured plans, validate those plans, execute trusted application capabilities, and aggregate authoritative service results into a final response.
The React storefront, FastAPI API, PostgreSQL data model, product catalog, cart, order, return, and refund flows provide the application surface where the agent operates. They are the environment for testing safe AI action, not the main architectural focus.
PocketMarket also exposes selected public catalog and knowledge capabilities through a read-only Model Context Protocol (MCP) interface, allowing external AI clients to inspect public store data without crossing into authenticated customer or administrative actions.

Table of Contents
- What Makes PocketMarket Agentic
- Core AI Capabilities
- Example Requests
- Agentic Architecture
- Design Principles
- Policy-Aware RAG
- Context Engineering
- Model Routing and Observability
- Model Context Protocol (MCP)
- Technology Stack
- Quick Start
- Documentation
- Repository Map
What Makes PocketMarket Agentic
PocketMarket is designed around controlled planning and execution rather than unconstrained tool calling:
- The orchestrator produces a structured
OrchestrationPlaninstead of directly invoking arbitrary tools. - Deterministic validation checks missing fields, unsupported task shapes, conflicting actions, duplicated writes, and unsafe assumptions before execution.
- A single user request can become multiple ordered capability calls across catalog, reviews, cart, order, policy, and support services.
- Missing action-critical information triggers a clarification question instead of guessed values.
- Backend services remain authoritative for authentication, authorization, refund eligibility, order ownership, policy enforcement, and database writes.
- The final response is generated from trusted service results, with deterministic responses for sensitive return/refund outcomes.
In short: the model reasons about what should happen; application services decide what is allowed to happen.
Core AI Capabilities
- Structured LangGraph orchestration: planner, validator, clarification, capability execution, and aggregation stages.
- Context engineering and bounded memory: recent messages, prose summaries, structured memory, identifiers, goals, pending actions, and completed actions.
- Policy-aware RAG: structured policy rules are preferred for deterministic decisions, with retrieval used for manuals, explanations, comparisons, and source-grounded questions.
- Model routing and fallback: lightweight and complex model chains across Groq and Gemini, with schema validation for structured outputs.
- Multimodal interaction: image attachments are analyzed as contextual visual evidence while protected business facts remain authoritative in backend state.
- MCP interoperability and observability: read-only public MCP tools/resources plus optional LangSmith traces for orchestration, tools, summarization, model attempts, and aggregation.
Example Requests
Find me in-stock laptops under PKR 400,000.
Compare the reviews for the Dell XPS 15 and MacBook Air M4, then recommend the one customers prefer.
Add two units of the cheaper one to my cart and show my cart total.
Place an order using my cart for delivery to DHA Lahore with cash on delivery.
I want a refund for my latest order because the item arrived damaged.
What does the return policy say about damaged electronics?
A request such as "show my latest order and get reviews for the laptop I bought" can produce multiple planned tasks. If required values such as an order ID, shipping address, payment method, rating, or refund reason are missing, the assistant asks for clarification instead of inventing them.
Agentic Architecture
flowchart LR
U[User] --> C[Conversation Context]
C --> O[LangGraph Orchestrator]
O --> V[Plan Validator]
V -->|Missing action-critical information| Q[Clarification]
V -->|Valid tasks| X[Capability Execution]
V -->|No tasks required| A[Aggregator]
X --> S[Trusted Application Services]
S --> P[Policy Engine / RAG / Database]
P --> A
A --> R[Final Response]
Q --> R
| Stage | Responsibility |
|---|---|
| Orchestrator | Builds a structured execution plan from the latest user turn, recent context, and structured memory. |
| Validator | Checks task shapes, required fields, conflicts, duplicated writes, and explicit response-format requests. |
| Capability Layer | Delegates approved actions to application services for catalog, cart, orders, reviews, returns, knowledge, and escalation. |
| Trusted Services | Enforce business rules, authorization, policy decisions, and database changes outside the LLM. |
| Aggregator | Produces the final answer from trusted results and deterministic sensitive-action outcomes. |
For detailed workflow behavior, schemas, validator rules, and capability execution, see Architecture and Capabilities.
Design Principles
- Plan before execution: the model first proposes a constrained plan.
- Validate model output: Pydantic schemas and deterministic checks gate execution.
- Keep business authority outside the LLM: services own authentication, authorization, policy eligibility, refunds, returns, and writes.
- Treat retrieved content as reference data: documents and user-provided text cannot become higher-priority instructions.
- Preserve context intentionally: summaries and structured memory keep useful state without unbounded prompts.
- Separate public MCP access from private actions: MCP exposes read-only public data, not customer or administrative operations.
Policy-Aware RAG
PocketMarket avoids treating every policy question as a vector search problem. It uses a registry-first strategy:
Structured Policy Registry
|
+--> high-confidence structured rule
|
+--> compiled policy summary
|
+--> RAG fallback for detailed, uncertain, or source-heavy queries
This design lets deterministic policy rules support reliable action decisions, while retrieval remains available for manuals, policy explanations, product comparisons, and source-grounded questions.
The knowledge stack includes ChromaDB, BAAI/bge-base-en-v1.5 embeddings, semantic PDF chunking, cosine similarity retrieval when dense RAG is enabled, and a lexical fallback over the Chroma collection.
For implementation details, compilation workflow, retrieval routing, and generated artifacts, see Policy-Aware RAG.
Context Engineering
PocketMarket maintains recent conversation context, prose summaries, validated structured memory, referenced product/order/return/refund IDs, user goals/preferences, pending actions, completed actions, unresolved questions, and explicit corrections. Automatic summarization keeps context bounded while preserving action-critical identifiers and removing sensitive credentials or payment details.
For the memory schema, summarization trigger behavior, context-budget settings, and sensitive-data handling, see Context Engineering.
Model Routing and Observability
Model calls go through a centralized gateway with lightweight and complex routing. Each route has ordered provider/model fallback chains, structured outputs are validated against schemas, and failed attempts can fall through to alternate configured models. Optional LangSmith tracing can capture orchestration, validation, capability calls, summarization, model attempts, and aggregation without becoming a hard runtime dependency.
For fallback chains, structured-output modes, tracing configuration, and failure behavior, see Model Routing & Observability.
Model Context Protocol (MCP)
PocketMarket exposes a separate public, read-only MCP interface built with FastMCP.
Tools:
search_productsget_product_detailsget_product_reviewssearch_knowledge_base
Resources:
pmarket://catalog/categoriespmarket://mcp/capabilities
The public MCP interface does not expose authentication, private order access, cart modification, order placement, refunds, returns, document modification, or administrative actions.
For transports, server commands, endpoint details, resources, tool contracts, and examples, see MCP Integration.
Technology Stack
| Area | Technologies |
|---|---|
| Agentic AI | LangGraph, Pydantic structured outputs, Groq, Gemini, LangSmith |
| Retrieval & Knowledge | ChromaDB, Sentence Transformers, BAAI/bge-base-en-v1.5, policy compiler, unstructured PDF processing |
| MCP | FastMCP, Model Context Protocol |
| Backend | FastAPI, PostgreSQL, SQLAlchemy |
| Frontend | React, TypeScript, Vite |
Quick Start
git clone https://github.com/mahadamir19/eCommerce-Agent.git
cd eCommerce-Agent/backend
docker compose up -d
python -m venv venv
Activate the environment, install backend dependencies, and configure backend/.env from backend/.env.example. If you use the included Docker Compose file, set POSTGRES_PASSWORD=postgres123 so it matches the Postgres container.
pip install -r requirements.txt
python database/seed.py
cd rag
python ingest.py
cd ..
python -m app.policy_compiler.cli compile
uvicorn app.main:app --reload
In another terminal:
cd frontend
npm install
npm run dev
For full setup, environment variables, model provider configuration, knowledge ingestion, troubleshooting, and MCP startup commands, see Local Setup.
Documentation
- Architecture: LangGraph workflow, planning, validation, execution, aggregation, and trusted service boundaries.
- Capabilities: supported agent capabilities and the application services they delegate to.
- Context Engineering: bounded memory, summaries, structured memory, and sensitive-data handling.
- Policy-Aware RAG: policy compiler, generated artifacts, registry-first routing, Chroma retrieval, and RAG fallback behavior.
- MCP Integration: public MCP tools/resources, security boundary, transports, and server commands.
- Model Routing & Observability: model chains, structured output handling, fallback, and LangSmith tracing.
- Local Setup: complete local development setup and operational notes.
Repository Map
backend/
app/agentic/ LangGraph workflow, model gateway, tracing, vision gateway
app/mcp/ public read-only MCP server
app/policy_compiler/ policy extraction, validation, and artifact generation
app/services/ trusted application services used by capabilities
rag/ Chroma ingestion and retrieval pipeline
frontend/ React/TypeScript storefront and chat UI
docs/ deeper technical documentation