Real World Example
Similar Assistants in Production
- E-commerce shopping assistants (Flipkart, Amazon, Myntra style): product Q&A from listings and reviews, recommendations, order help.
- Food delivery support (Swiggy, Zomato style): order status tools, refund rules, escalation to agents.
- Help-desk platforms (Freshworks, Zoho style): RAG over help articles with tool actions, sold to thousands of businesses.
Under different brand names, these assistants share the architecture you have built in this level: a router or classifier at the front, retrieval over the company's own content, a small set of narrow tools for account actions, guardrails on both sides, and heavy investment in evaluation and monitoring. The model is often the part that changes most easily; the surrounding system is what each company spends years improving.
Reading the Endpoint
The endpoint below is the whole capstone in about twenty lines, and each line maps to a module. Depends(current_user) authenticates the customer, so tools can scope data to user.id rather than trusting IDs from the chat. mask_pii and injection_score are the Safety module's first layers. The semantic cache is keyed by language. route_intent uses a small model. The policy branch is the Advanced RAG pipeline: standalone query rewrite, hybrid search for 30 candidates, re-rank to 4. The whole request runs inside a tracing span, and guarded(...) wraps the stream so the output filter and PII unmasking run on every chunk before it reaches the browser as SSE.
The Main Endpoint
@app.post("/assistant/stream")
async def assistant_stream(body: ChatIn, user: User = Depends(current_user)):
msg, pii_map = mask_pii(body.message)
if injection_score(msg) >= 3:
return sse_once("I can only help with ShopEase orders and products.")
if (cached := await semantic_cache.get(msg, lang=user.lang)) is not None:
return sse_once(cached)
intent = await route_intent(msg) # Haiku, effort low
with tracer.start_as_current_span("assistant") as span:
span.set_attribute("intent", intent)
if intent == "order":
stream = order_agent_stream(msg, body.history, customer_id=user.id) # tool runner + MCP tools
elif intent == "product":
stream = product_search_stream(msg, filters=user.preferences)
else:
docs = await hybrid_search(await standalone_query(body.history, msg), k=30)
docs = await rerank(msg, docs, top_k=4)
stream = rag_answer_stream(msg, docs, body.history)
return StreamingResponse(guarded(stream, pii_map), media_type="text/event-stream")Call it
curl -N -X POST https://assistant.shopease.in/assistant/stream \
-H "Authorization: Bearer $TOKEN" -H "Content-Type: application/json" \
-d '{"message": "Can I return my Airdopes from order SE1042?"}'Example output
data: {"text": "Yes - your Boat Airdopes 141 (SE1042) "}
data: {"text": "are eligible for a 7-day replacement "}
data: {"text": "until 19 Oct. Shall I book a pickup?"}
event: done
data: {"output_tokens": 31, "intent": "order"}Next Steps
Practise by building a smaller version for your own portfolio: pick one domain (college notices, a local shop catalogue), build RAG + one tool + an eval set of 30 questions, deploy it, and write down your metrics. Then go to the interview questions.
- Summary: production assistants share one shape: route, retrieve, act with narrow tools, guard, evaluate, monitor.
- Every line of the endpoint maps to a module in this level.
- A small, measured portfolio project shows these skills better than a large untested one.