Back to Case Studies
MobileAgentic AILLMOpsNext.jsWebBackendMistralPythonFastAPISwiftUI

AI Shopping Assistant

Full-stack e-commerce search platform built in 4 weeks: sandboxed LLM-to-Python code generation, hybrid pgvector + SQL filtering, PgBouncer transaction pooling, and a 60fps SwiftUI client.

Context: Built as a Pre-Seed Validation PoC for Alfee, backed by an established European retail group (20+ years in business), to validate conversational product discovery across iOS and web ahead of investor fundraising.

Traditional e-commerce search breaks down when shoppers describe outcomes rather than catalog attributes. Instead of forcing users to construct keyword filters like "bluetooth headphones noise cancelling under 100", the platform resolves natural-language queries such as "find me quiet headphones for my commute under €100" directly against structured inventory and semantic embeddings.

We delivered the multi-platform system (FastAPI backend, LangGraph agent runtime, Next.js web app, and native SwiftUI iOS client) from zero to deployed PoC in 4 weeks.

Native iOS app with real-time product recommendations


Web UI with Dark Mode and Voice Input

Web interface with dark mode and real-time multilingual voice transcription via OpenAI Whisper

The "Ready-for-Search" Decision Engine

A common UX failure in conversational commerce is the clarification loop: agents ask three or four follow-up questions ("What is your budget?", "Which brand do you prefer?") before displaying a single product.

To eliminate empty turns, we built a Feature Classification Engine that decomposes user input along two orthogonal axes:

  • Semantic Attributes: Subjective descriptors like "cozy", "minimalist", or "quiet typing feel" are encoded into dense vectors for pgvector cosine similarity search.
  • Deterministic Constraints: Hard catalog attributes like "under €200" or "Keychron" are extracted into parameterized SQL predicates.

Every query executes immediately using a Broad Match Fallback. If strict SQL predicates return zero rows, the engine progressively relaxes non-essential constraints while preserving the vector similarity ranking, ensuring the user always receives ranked inventory on the first turn.

Single-Turn Code Generation vs. Multi-Turn Tool Chaining

Standard tool-calling agents suffer from sequential roundtrip latency. A request like "Find a quiet mechanical keyboard under €100 for Mac" typically triggers four to five LLM inference turns: Search → (Wait) → Read Results → (Wait) → Filter Price → (Wait) → Filter OS → (Wait) → Final Answer.

We replaced multi-turn tool chaining with a Single-Turn Code Compiler that translates user intent into an executable Python retrieval script in one pass.

Execution Pipeline

  1. Compiler Node (Mistral Large): Parses the conversation state and emits a self-contained Python script targeting an internal, read-only catalog_tools SDK.
  2. Sandboxed Runtime: The generated script runs inside an isolated container with strict AST and namespace whitelisting—only json and the read-only catalog_tools module are permitted, while os, sys, filesystem writes, and outbound network sockets are blocked.
  3. Latency Impact: Collapsing five sequential LLM tool roundtrips into a single inference call plus ~1ms of native Python execution reduced end-to-end turn count by over 80%.

Anthropic later documented the same architectural pattern in Code Execution with MCP, showing how compiling intent into code avoids intermediate context bloat and sequential tool roundtrips.

Standard Multi-Turn Tool Loop:

{ "nodes": [ { "id": "query", "label": "Query", "x": 0, "y": 0, "type": "input" }, { "id": "llm1", "label": "LLM", "x": 0, "y": 100 }, { "id": "tool1", "label": "Tool", "x": 0, "y": 200, "type": "decision" }, { "id": "llm2", "label": "LLM", "x": 0, "y": 300 }, { "id": "tool2", "label": "Tool", "x": 0, "y": 400, "type": "decision" }, { "id": "llm3", "label": "LLM", "x": 0, "y": 500 }, { "id": "tool3", "label": "Tool", "x": 0, "y": 600, "type": "decision" }, { "id": "llm4", "label": "LLM", "x": 0, "y": 700 }, { "id": "result", "label": "Result", "x": 0, "y": 800, "type": "output" } ], "edges": [ { "source": "query", "target": "llm1" }, { "source": "llm1", "target": "tool1" }, { "source": "tool1", "target": "llm2", "label": "roundtrip 1" }, { "source": "llm2", "target": "tool2" }, { "source": "tool2", "target": "llm3", "label": "roundtrip 2" }, { "source": "llm3", "target": "tool3" }, { "source": "tool3", "target": "llm4", "label": "roundtrip 3" }, { "source": "llm4", "target": "result" } ] }

Compiled Single-Turn Execution:

{ "nodes": [ { "id": "query", "label": "Query", "x": 0, "y": 0, "type": "input" }, { "id": "llm", "label": "Generate Script", "x": 0, "y": 130 }, { "id": "sandbox", "label": "Execute Logic", "x": 0, "y": 260, "type": "decision" }, { "id": "result", "label": "Result", "x": 0, "y": 390, "type": "output" } ], "edges": [ { "source": "query", "target": "llm", "animated": true }, { "source": "llm", "target": "sandbox", "label": "1 LLM call", "animated": true }, { "source": "sandbox", "target": "result", "label": "deterministic", "animated": true } ] }

Single-Transaction Hybrid Search

The compiled script executes relational filtering and vector similarity inside a single PostgreSQL query:

  • Relational Predicates (SQL): Enforces exact catalog constraints (price < 100 AND brand = 'Keychron').
  • Vector Similarity (pgvector): Ranks matching candidates by cosine distance (embedding <=> query_vector).

Executing both inside PostgreSQL avoids pulling hundreds of unranked product rows into the LLM context window for post-filtering.

Session-Scoped Language Persistence

To support French, English, and Portuguese seamlessly, we implemented sticky language state in the LangGraph checkpointer:

  • Failure Mode: Brand-only or short queries (such as "Nike Air Max") frequently cause stateless per-turn language detectors to revert to English mid-conversation.
  • Fix: Once a session's locale is established, it is persisted in the graph state and injected into downstream synthesis prompts until an explicit language switch occurs.

Connection Multiplexing with PgBouncer

Agent workflows can trigger parallel database reads per turn. Because each PostgreSQL backend process allocates ~10MB of RAM, direct connections saturate a small database instance at ~100 concurrent clients.

By deploying PgBouncer in Transaction Mode (pool_mode = transaction) and disabling driver-level prepared statement caches in asyncpg, we multiplexed 2,000+ concurrent client connections onto a pool of 20 physical database connections on a single €20/month PostgreSQL instance.

Automated Evaluation & Streaming UX

CI Quality Gates with DeepEval

To prevent prompt edits from breaking catalog constraints, we integrated DeepEval into the GitHub Actions CI pipeline. Pull requests are evaluated against a suite of 50+ golden shopping scenarios:

  • Answer Relevancy (> 0.7): Verifies that returned recommendations address the user's stated use case and ecosystem constraints (e.g., excluding Android-only wearables when the user specifies an iPhone).
  • Faithfulness (> 0.9): Verifies that stated prices, specifications, and availability match the retrieved database records without fabrication.

Read our full technical breakdown on LLMOps CI/CD testing here.

Native iOS Streaming Client (SwiftUI)

For the mobile client, we built a native SwiftUI application connected to the FastAPI backend via Server-Sent Events (SSE):

  • 60fps Incremental Rendering: Streaming state events bind directly to SwiftUI @Observable view models, displaying active search filters and progressive product cards as soon as the sandbox execution completes, before the conversational summary finishes streaming.
  • Tactile Feedback: CoreHaptics triggers align with stream completion events when product cards lock into the viewport.

Product Card Design


Questions about this architecture or looking to validate an AI product? Get in touch.

— Pedro

Founder & Principal Engineer