Back To Projects

Kapruka Multi-Agent Gift Concierge

The Kapruka Agent was designed as a complete AI system rather than a single chatbot prompt. It separates product knowledge from deterministic business data, decomposes compound requests into specialist routes, carries structured context through explicit graph state, and records every important step for inspection through Langfuse.

Kapruka Agent system architecture showing FastAPI, LangGraph orchestration, specialist agents, memory layers, Qdrant retrieval, Supabase, crawling pipelines, Tavily search, and Langfuse observability.

Project Overview

What I built, the problem, and the solution

Built an AI concierge platform for gift discovery and delivery planning across the Kapruka domain. The system crawls and indexes product data, routes compound requests across specialist agents, retrieves product knowledge through RAG, answers deterministic logistics questions through relational CRM tools, and preserves user context through short-term and distilled long-term memory.

Challenge Framing

Gift discovery requests often combine personal preferences, product questions, delivery locations, time-slot constraints, customer details, and follow-up references. A single retrieval prompt cannot reliably manage all of these concerns while preserving memory, grounding, and operational accuracy.

Solution Strategy

I designed a LangGraph supervisor architecture that recalls context, produces structured route decisions, fans requests out to specialist agents, retrieves products from Qdrant, queries CRM and logistics data from Supabase, merges agent outputs, and writes useful conversation details back into memory.

Project Highlights

Built a supervisor-led LangGraph workflow with structured routing and multi-route fan-out.Implemented short-term, long-term semantic, episodic, and procedural memory layers.Combined RAG, CAG, and confidence-triggered CRAG for grounded product retrieval.Separated deterministic CRM and logistics queries from fuzzy product knowledge retrieval.Created a Playwright crawling and parent-child chunking pipeline for the Kapruka product catalogue.Integrated Langfuse tracing, prompt versioning, token tracking, latency monitoring, and cost analysis.

Tech Stack

Built with tools chosen for reliability and iteration speed

Context engineering, memory distillation, multi-agent routing, LangGraph orchestration, retrieval engineering, state management, semantic caching, CRM tools, logistics reasoning, and AI observability.

Backend

  • FastAPI

AI / ML

  • Python
  • LangGraph
  • LangChain
  • OpenAI

Data

  • Qdrant
  • Supabase
  • PostgreSQL

DevOps

  • PGpgvector
  • LALangfuse
  • Playwright
  • Tavily

Key Features

Supervisor-led multi-agent routing

A structured router classifies requests, extracts parameters, supports up to three routes, repairs common logistics misroutes, and fans compound requests out to specialist agents.

Layered memory architecture

Recent turns, distilled user facts, conversation episodes, and reusable procedures are stored separately so each memory type can follow its own retrieval and retention policy.

Adaptive product retrieval

The product path combines Qdrant-based RAG, a semantic CAG cache, parent-child retrieval, and CRAG expansion when first-pass evidence is weak.

Structured logistics intelligence

Delivery coverage, courier capacity, slot availability, product constraints, and fulfilment history are resolved through relational data instead of generated from unverified text.

Observable AI execution

Langfuse captures graph traces, model calls, prompt versions, token usage, latency, cost, routing decisions, and memory operations.

Architecture

System architecture designed as a readable engineering story

Each layer stays explicit so reviewers can quickly understand where interface, orchestration, persistence, and service responsibilities live.

01

Client and API Layer

A web-based concierge interface communicates with a FastAPI service that exposes chat, streaming, health, graph, and memory endpoints.

FastAPIPydanticSSE
02

Orchestration Layer

LangGraph manages recall, supervisor routing, specialist execution, response merging, state transitions, and memory write-back.

LangGraphLangChainOpenAI
03

Retrieval Layer

Qdrant stores the Kapruka product knowledge base and semantic answer cache, with parent-child retrieval and confidence-based corrective expansion.

QdrantRAGCAGCRAG
04

Memory and Business Data Layer

Supabase PostgreSQL stores user profiles, CRM records, logistics tables, conversation turns, semantic facts, episodes, and procedures.

SupabasePostgreSQLpgvector
05

Ingestion and External Tools

A Playwright crawler converts Kapruka product pages into structured records, while Tavily provides live external information when required.

PlaywrightJSONLMarkdownTavily
06

Observability Layer

Langfuse monitors graph execution, model behaviour, costs, latency, prompts, user journeys, and errors.

LangfusePrompt ManagementTracing

System Flow

Key stages broken down as a readable execution path

The pipeline section keeps the most important engineering steps visible without collapsing them into generic bullet lists.

01

Crawl and structure

Render Kapruka product pages, extract structured metadata, and save catalogue records as JSONL and markdown documents.

PlaywrightMarkdownJSONL
02

Chunk and index

Split product records through parent-child chunking, generate embeddings, and persist retrieval units into Qdrant.

Parent-child chunkingOpenAI embeddingsQdrant
03

Recall and route

Load recent turns and long-term semantic facts before the supervisor produces validated route decisions for each request.

SupabasepgvectorLangGraph
04

Execute specialists

Run product retrieval, CRM and logistics actions, direct concierge generation, or live web search based on the selected routes.

RAGToolCRMToolTavilyOpenAI
05

Merge and persist

Combine parallel specialist responses, return one coherent answer, store the turn, and distil durable facts when the memory policy is triggered.

LangGraph reducersMemoryDistillerSupabase
06

Trace and evaluate

Record graph nodes, prompts, tokens, costs, latency, tool actions, and memory behaviour for debugging and optimisation.

LangfuseTracingPrompt Management

Timeline

A case-study flow that explains how the system took shape

This timeline keeps the implementation story concise: what was framed first, what was hardened next, and what ultimately made the project production-ready.

01
Phase 01

Product knowledge acquisition

Built the Kapruka crawler, structured product documents, evaluated chunking approaches, and created the Qdrant product collection.

02
Phase 02

Context and memory design

Introduced session-scoped short-term turns, semantic user facts, token-budgeted recall, memory distillation, and additional episodic and procedural stores.

03
Phase 03

Multi-agent orchestration

Implemented the supervisor, specialist routes, reducer-backed branch outputs, compound-request fan-out, and merged response synthesis.

04
Phase 04

CRM and logistics integration

Modelled users, delivery zones, slots, couriers, product rules, and delivery history as structured relational data and exposed them through agent tools.

05
Phase 05

Retrieval optimisation

Added semantic caching, corrective retrieval, parent-child context expansion, FAQ cache warming, and evidence-aware answer generation.

06
Phase 06

Observability and interface

Connected Langfuse tracing and prompt management, then built the gift concierge UI for end-to-end product and delivery demonstrations.

Challenges

Technical constraints, decisions, and the reasoning behind them

Each challenge is tied to a concrete design choice and a specific outcome.

Solution

Designed a structured router that can emit multiple validated routes and fan them out to separate specialist nodes.

Outcome

The system can answer product and logistics concerns together without forcing one agent to handle unrelated data sources.

Solution

Separated recent-turn memory from distilled semantic facts and applied a strict token budget with short-term and long-term allocation.

Outcome

Follow-up requests retain useful personal context while keeping recall controlled and inspectable.

Solution

Added a Qdrant-backed semantic CAG cache with similarity matching, TTL expiry, and duplicate cleanup.

Outcome

Repeated and paraphrased questions can bypass full retrieval and generation.

Solution

Introduced a heuristic confidence score and expanded retrieval from four to eight results when evidence quality fell below the threshold.

Outcome

The product agent can recover from weak first-pass retrieval without requiring a separate reranking service.

Solution

Stored coverage, slots, courier availability, delivery rules, and historical signals in relational tables queried through a dedicated CRM tool.

Outcome

Operational responses are grounded in deterministic business data rather than model assumptions.

Solution

Instrumented router calls, graph nodes, retrieval operations, memory generation, latency, token usage, costs, and prompts through Langfuse.

Outcome

Agent behaviour can be inspected at node level, making failures and performance bottlenecks easier to identify.

Results

Metrics and outcomes presented for quick technical review

The emphasis here is signal, not decoration: key numbers, verifiable outcomes, and the context needed to interpret them responsibly.

96

Product Records

Structured JSONL and markdown product documents prepared for vector ingestion.

11K+

Logistics Records

Delivery zones, slots, couriers, product rules, and historical delivery records.

4

Agent Routes

CRM, product RAG, web search, and direct concierge execution paths.

4

Memory Layers

Short-term, semantic fact, episodic, and procedural memory stores.

Key Results

  • Built an end-to-end multi-agent concierge from product crawling and vector ingestion to personalised recommendations and delivery reasoning.
  • Implemented explicit LangGraph state for messages, identities, memory context, semantic facts, route decisions, specialist outputs, and memory write signals.
  • Combined short-term recall with distilled long-term semantic facts under a controlled token budget.
  • Separated product retrieval in Qdrant from deterministic CRM and logistics queries in PostgreSQL.
  • Added CAG semantic caching and confidence-triggered CRAG retrieval expansion.
  • Supported compound requests through parallel specialist routes and reducer-backed response merging.
  • Instrumented agent behaviour with Langfuse tracing, cost analysis, prompt management, token usage, and latency monitoring.

Business Impact

Context engineering

Context is assembled from recent turns, semantic facts, product evidence, CRM records, route state, and specialist outputs instead of being stored as one unstructured prompt string.

Retrieval quality

Parent-child retrieval, semantic caching, corrective expansion, and source-specific tools improve grounding while keeping product and operational knowledge separate.

Operational accuracy

Delivery feasibility, capacity, product restrictions, and customer information are resolved through relational queries rather than generated assumptions.

AI observability

Node-level traces, prompt versions, costs, tokens, latency, and routing decisions make the agent easier to debug and optimise.

Extension path

The architecture leaves clear room for transactional ordering, payment integration, richer evaluation datasets, automated reranking, and additional specialist agents.

Continue