DEV Community

Indra Gunanda
Indra Gunanda

Posted on • Originally published at ciptadusa.com

How We Architect AI Chatbots That Actually Work in Production

How We Architect AI Chatbots That Actually Work in Production

Most AI chatbot demos look incredible. Most AI chatbots in production disappoint users within 48 hours.

The gap between demo and production is where engineering actually matters. At Cipta Dusa, we've shipped conversational AI systems for clients across e-commerce, education, healthcare admin, and B2B SaaS. Not as experiments — as tools that handle real customer conversations every day.

This is a technical walkthrough of how we design, build, and deploy chatbots that survive contact with real users.

Why Most Chatbot Projects Fail

Before the architecture, let's name the failure modes we've seen (and helped clients recover from):

  1. Hallucination without guardrails — the bot invents pricing, policies, or product details
  2. Latency kills UX — 8-second response times on WhatsApp feel broken
  3. No fallback path — when the AI doesn't know, the user gets stuck
  4. Context amnesia — every message feels like talking to a stranger
  5. One-size-fits-all prompts — the same system prompt for sales, support, and onboarding

Every architecture decision we make targets one or more of these failure modes.

The Stack: What We Actually Deploy

Here's the production architecture we use for most client chatbot projects at Cipta Dusa:

┌─────────────────────────────────────────────────────────┐
│                   Channel Adapters                        │
│   (WhatsApp, Telegram, Web Widget, Instagram DM)         │
└──────────────────────────┬──────────────────────────────┘
                           │
                           ▼
┌─────────────────────────────────────────────────────────┐
│                  Conversation Engine                      │
│                                                         │
│  ┌──────────┐  ┌───────────────┐  ┌──────────────────┐ │
│  │ Session  │  │  Intent       │  │  Response        │ │
│  │ Manager  │  │  Classifier   │  │  Generator       │ │
│  └──────────┘  └───────────────┘  └──────────────────┘ │
└──────────────────────────┬──────────────────────────────┘
                           │
              ┌────────────┼────────────┐
              ▼            ▼            ▼
       ┌───────────┐ ┌──────────┐ ┌──────────────┐
       │ RAG       │ │ Action   │ │ Human        │
       │ Pipeline  │ │ Engine   │ │ Handoff      │
       └───────────┘ └──────────┘ └──────────────┘
Enter fullscreen mode Exit fullscreen mode

Let's walk through each layer.

Layer 1: Channel Adapters

A chatbot that only works on your website isn't useful for most Indonesian businesses. Their customers live on WhatsApp. Their internal team uses Telegram. Their marketing runs on Instagram.

We built a channel adapter layer that normalizes messages from any platform into a unified format:

{
  "channel": "whatsapp",
  "sender_id": "+628123456789",
  "message_type": "text",
  "content": "Harga paket enterprise berapa ya?",
  "media_url": null,
  "timestamp": "2026-08-05T10:30:00Z",
  "context": {
    "is_group": false,
    "quoted_message_id": null
  }
}
Enter fullscreen mode Exit fullscreen mode

This abstraction means the conversation engine doesn't care which channel a message came from. We write business logic once. Channels are plugins.

For WhatsApp specifically, we handle the quirks that trip up most implementations:

  • Media messages (images, PDFs, voice notes) need to be downloaded and processed separately
  • Group messages need mention detection and quote-reply awareness
  • Phone number normalization across country codes
  • Rate limiting per WhatsApp's sending rules

Layer 2: Session Management

Context amnesia is the number one complaint users have about chatbots. The fix is proper session management.

Our session manager maintains:

  • Conversation history — last N messages with sliding window
  • Entity memory — extracted facts (name, order number, product interest)
  • State machine position — where in a flow the user currently is
  • Channel metadata — device type, language preference, timezone

We use Redis for active sessions (sub-millisecond reads) and PostgreSQL for long-term conversation history. Sessions expire after 24 hours of inactivity, but entity memory persists indefinitely per contact.

Session lifecycle:
  New message → Load session from Redis
                    ↓ (miss)
                Load from PostgreSQL
                    ↓ (miss)
                Create new session
                    ↓
  Process message → Update session → Write back to Redis
                                         ↓ (async)
                                    Persist to PostgreSQL
Enter fullscreen mode Exit fullscreen mode

The dual-store pattern gives us speed for active conversations and durability for history.

Layer 3: RAG Pipeline — Grounding Answers in Truth

This is where we kill hallucination.

RAG (Retrieval-Augmented Generation) means the LLM doesn't answer from its training data. It answers from documents the client has approved. Product catalogs, pricing sheets, FAQ docs, policy documents.

Our RAG pipeline:

  1. Ingest: Client uploads documents (PDF, Notion export, Google Docs, raw markdown)
  2. Chunk: Split into semantically meaningful segments (not arbitrary 500-token blocks)
  3. Embed: Generate vector embeddings using a multilingual model (critical for Bahasa Indonesia + English mixed content)
  4. Index: Store in a vector database with metadata filters
  5. Retrieve: On each query, fetch top-K relevant chunks
  6. Generate: LLM produces answer grounded in retrieved chunks only

The key engineering decision: we use a multilingual embedding model. Indonesian businesses mix Bahasa and English constantly. A customer might ask "berapa harga enterprise plan?" and the answer lives in an English pricing document. The embedding model needs to bridge that gap.

We also enforce source attribution. Every generated answer internally tracks which document chunks it drew from. If the retrieval confidence is below threshold, the bot says "I don't have that information" instead of guessing.

Layer 4: The Fallback Chain

No AI system should be a dead end. When the bot can't help, the user needs a path forward.

Our fallback chain, in order:

  1. RAG answer — if confident, respond directly
  2. Clarification — if ambiguous, ask one focused follow-up question
  3. Suggested actions — offer 2-3 buttons ("Talk to sales", "Browse FAQ", "Leave a message")
  4. Human handoff — route to available team member with full context attached

The handoff is seamless. The human agent sees the entire conversation history, the bot's confidence scores, and the retrieved documents. They pick up exactly where the AI left off.

This is the same pattern we implemented in Hallo Zetta for WhatsApp-native support, and it works across all our client deployments.

Latency Budget: The 2-Second Rule

On WhatsApp, users expect replies in seconds. A chatbot that takes 8 seconds to respond feels broken. Our latency budget:

Step Budget Technique
Channel adapter <50ms Edge processing
Session load <10ms Redis
RAG retrieval <200ms Optimized vector search
LLM generation <1500ms Streaming + model selection
Response delivery <100ms Direct API call
Total <2000ms

To hit that 1.5s LLM budget, we make pragmatic model choices:

  • Simple FAQ-style questions → smaller, faster model
  • Complex multi-turn reasoning → larger model with streaming
  • Structured actions (booking, order lookup) → no LLM needed, direct function call

This tiered approach means 70% of messages get sub-second AI responses.

Deployment: Not Just "Deploy to Cloud"

Shipping the bot is half the work. Keeping it reliable is the other half.

Our deployment stack for client chatbots:

  • Infrastructure: Docker containers on cloud VMs (we prefer Hetzner or DigitalOcean for Southeast Asian latency)
  • Monitoring: Response time percentiles, fallback rates, handoff rates, user satisfaction signals
  • Knowledge updates: Clients can update their knowledge base without redeploying — hot-reload via webhook
  • A/B testing: Different system prompts for different user segments, measured by resolution rate

We also run a weekly accuracy audit. Sample 50 conversations, check if the bot's answers were correct and helpful. This catches drift before users complain.

Real Numbers From Client Deployments

Across our Cipta Dusa chatbot projects in the last quarter:

  • Average first-response time: 1.4 seconds
  • Accuracy rate (answer matches source material): 94%
  • Deflection rate (resolved without human): 78%
  • Human handoff rate: 22% (these are the conversations that SHOULD go to humans)
  • Average deployment time: 5 working days from kickoff to live

The 5-day deployment is possible because of our reusable architecture. The channel adapters, session management, RAG pipeline, and handoff system are battle-tested modules. Client-specific work is mainly: ingesting their knowledge base, tuning the system prompt, and configuring their channel connections.

When NOT to Use AI

Honesty moment: not every client needs an AI chatbot.

We actively recommend against it when:

  • The business gets <20 messages per day (just reply manually)
  • Every conversation requires complex human judgment (legal, medical diagnosis)
  • The knowledge base changes hourly (the RAG pipeline can't keep up)
  • The team wants to replace humans entirely (AI-first ≠ AI-only)

For those cases, we often recommend a simpler solution: a shared inbox tool like Zetta CRM where the team collaborates on replies without AI complexity.

The Builder's Perspective

If you're building chatbots (or evaluating vendors), here's what to look for:

  1. Ask about hallucination prevention. If they can't explain their RAG pipeline, walk away.
  2. Test the fallback path. Ask the bot something it shouldn't know. Does it gracefully hand off or confidently lie?
  3. Measure latency under load. Demo performance means nothing. Ask for p95 response times in production.
  4. Check the update workflow. Can business teams update knowledge without a developer? If not, the bot will rot within weeks.
  5. Verify channel support. WhatsApp is not the same as web chat. Media handling, group behavior, and rate limits are entirely different engineering challenges.

What's Next

We're currently working on:

  • Voice note understanding — transcribe and respond to voice messages natively
  • Proactive outreach — AI that initiates follow-ups based on conversation patterns
  • Multi-agent orchestration — specialized bots that route between each other (sales bot → support bot → billing bot)

All built on the same modular architecture, all deployable within a week.

Work With Us

If your business needs a chatbot that works in production — not just in demos — we'd like to talk. Cipta Dusa builds custom AI systems, web applications, and mobile apps for teams that need to move fast without breaking things.

We don't do 6-month projects. We ship working systems in days, not quarters.


Built by Cipta Dusa — software development for teams that move fast.

Top comments (0)