Practice · From Demo to Product

Where This Chapter Comes From: Building Alice

This chapter is not a literature review or a repackaged tutorial — it is a first-hand summary of my experience building Alice, an AI Agent desktop app. Behind every lesson that follows is a real pitfall I actually hit.

AI Assistant
Alice
An AI assistant who knows the ropes — and knows you

She remembers your preferences and handles tasks across work and life. When needed, she assembles specialist Agents from different domains and drives the task through to completion.

macOS · Windows · Free

Alice — your AI assistant
The other side of the product. "Remembers your preferences," "assembles specialist Agents" — every line of marketing copy on the official site is backed by a real engineering system: long-term memory, multi-Agent collaboration, loop control, context compression, permission approvals, and a two-way MCP ecosystem. This chapter takes those systems apart, one by one.
Alice in Numbers
~500,000
lines of code
Electron + React + TypeScript
132
built-in tools
injected on demand, never all at once
10+
LLM providers integrated
3 protocol adapters + unified routing
8
engineering modules
mapping one-to-one to this chapter
This Chapter's 8 Sections = Alice's 8 Real Modules
🎨AI Image Generation
Alice's visual identity depends on consistent image generation — multi-model fallback chain + reference-image anchoring; when a model goes down, it switches automatically and users never notice
🔄Agent Loop
The main loop ships with anti-stall machinery: four-level stream-failure recovery (rate-limit backoff → model switch → resume from breakpoint → distinguishable errors), tool-failure circuit breakers, and session guards against duplicate dispatch
🗜️Context Management
A five-layer compression pipeline: truncate → snip stale results → micro-compact → collapse → full auto-compact; the user's own words are the last thing touched
🧠Long-Term Memory
Behind "she remembers you after one meeting": a gatekeeper that filters what's worth remembering, vector retrieval + LLM adjudication of new / merge / conflict, and injection only on retrieval hits
🧩Prompt Harness
The System Prompt is assembled in layers: identity, environment, and tool guidance kept independent; stable layers go first to maximize cache hits; Skills are file-as-config
👥Multi-Agent
Parallel subagents + multi-role brainstorming + scheduled tasks — Alice's "friends" are literally an Agent collaboration network
🔐Permissions & Security
Five permission modes + risk-tiered approval prompts, backed by an event-stream log and per-message Token / cost tracking
🔌MCP in Practice
Two-way MCP: consumes others' tools (lazy connections — don't connect until needed), exposes itself as an MCP server, and can even configure new connections on its own
What You'll Learn in This Chapter
What's the gap between "the API works" and "users can use it"?
Walk the full productization checklist using image generation as the example: fallback, graceful degradation, consistency, UX — none of it visible in a demo.
Why do Agents stall, run away, and burn money?
The typical failure modes of runaway loops, plus three families of safeguards — caps, detection, degradation — and where a PM should draw the line.
Conversations get pricier and dumber as they grow — now what?
A decision framework for context compression: what can be deleted, what can't, what costs money to compress; and how long-term memory filters, resolves conflicts, and injects.
How does a Prompt go from a blob of text to an operable architecture?
Layered management, on-demand loading, Skill modularity — and the subtle ledger between prompt edits and KV Cache.
When do you need multiple Agents, and at what cost?
Three real scenarios — parallelism, brainstorming, scheduled tasks — plus how to judge concurrency safety and avoid cost traps.
How do you rein in an Agent and plug into the ecosystem?
Finding the balance in permission tiers and human-in-the-loop, observability, and strategies for joining the two-way MCP ecosystem.
Every concept in this chapter is running in Alice for real. What you'll learn is not "how it should work in theory" but "how it actually plays out" — including the pitfalls no tutorial mentions, the kind you only meet in production. You'll get the most out of it by reading with one question in mind: "If this were my product, what would I decide?"