---
id: chat-system
name: Chat System
version: 1.0.0
summary: |
  Internal system that hosts BookWorm's conversational workflow and specialist
  AI agents for customer support and catalog-backed book discovery.
scope: internal
owners:
  - ai-capabilities-team
services:
  - id: chat-api
    version: 1.0.0
containers:
  - id: chat-session-blob
    version: 1.0.0
flows:
  - id: agent-orchestration
    version: 1.0.0
relationships:
  - id: mcp-tools
    version: 1.0.0
    label: retrieves catalog data and reusable AI prompts through MCP
  - id: rating-system
    version: 1.0.0
    label: discovers and calls Rating agents through A2A
  - id: data-privacy
    version: 1.0.0
    label: analyzes and anonymizes agent input and output through Presidio
  - id: identity-provider
    version: 1.0.0
    label: validates tokens for protected agent-to-agent endpoints
actors:
  - id: customer
    name: Customer
    label: submits a bookstore or book-discovery request
    direction: inbound
repository:
  language: C#
  url: https://github.com/foxminchan/BookWorm
badges:
  - content: Internal
    backgroundColor: gray
    textColor: gray
    icon: LockClosedIcon
---

## System Purpose & Boundary

The Chat System delivers BookWorm's interactive conversational assistant and multi-agent orchestration within the [[domain|conversational]] domain. It serves **Customers** seeking store-policy answers, catalog-backed book discovery, personalized recommendations, and review insights. Modifying shopping baskets ([[domain|shopping]]), placing or mutating orders ([[domain|ordering]]), and persisting customer reviews ([[domain|reviews]]) are explicitly out of scope—the system operates strictly as a read-only advisor.

:::warning
All conversational inputs and outputs pass through fail-closed PII detection and anonymization in [[system|data-privacy]]. Streaming replies are buffered until privacy screening succeeds; if privacy screening is unavailable, the turn fails rather than bypassing redaction.
:::

## Contained Capabilities

| Service / Agent                           | Role in System                                                                                       | Primary Data Store               | Interaction Style (Sync / Async) |
| :---------------------------------------- | :--------------------------------------------------------------------------------------------------- | :------------------------------- | :------------------------------- |
| [[service\|chat-api]]                     | Hosts the interactive AG-UI conversational workflow, routing, safety validation, and agent discovery | [[container\|chat-session-blob]] | Sync (HTTP / Streaming)          |
| [[agent\|qa-agent]]                       | Answers store policy and general service questions from approved policy context                      | [[container\|chat-session-blob]] | Sync (In-process)                |
| [[agent\|book-agent]]                     | Coordinates book search, catalog details, recommendations, and feedback discussions                  | [[container\|chat-session-blob]] | Sync (In-process + MCP / A2A)    |
| [[agent\|book-catalog-researcher]]        | Investigates catalog-backed book, author, and category facts                                         | None (Stateless)                 | Sync (In-process + MCP)          |
| [[agent\|book-recommendation-researcher]] | Builds catalog-backed book shortlists tailored to stated reader preferences                          | None (Stateless)                 | Sync (In-process + MCP)          |

## External Interactions & Trust Boundaries

- **Customer entry point:** Customers interact over the authenticated AG-UI streaming surface via the API Gateway, backed by [[system|identity-provider]] token validation and per-user rate limiting.
- **Catalog tooling:** Book specialists connect to [[system|mcp-tools]] using delegated On-Behalf-Of (OBO) tokens to invoke read-only catalog lookup tools; [[agent|qa-agent]] has no catalog tool access.
- **Review insights:** [[agent|book-agent]] or the conversational router delegates book-specific review analysis to [[agent|rating-agent]] in [[system|rating-system]] over Agent-to-Agent (A2A) gRPC.
- **Privacy boundary:** [[system|data-privacy]] screens and redacts personal information on every turn before model invocation and before responses reach the customer.

<Accordion title="Governance & Session Persistence Notes">
	- **Prompt safety & scope routing:** Empty inputs and prompt-injection attempts are rejected
	upfront; non-English or out-of-scope requests receive a boundary response without invoking
	specialist agents. - **Session memory:** Conversation transcripts and agent memory are persisted
	in [[container|chat-session-blob]] across turns.
</Accordion>

## System Visualizations

### System Context

<ContextDiagram />

### Component Topology

<NodeGraph />

### Architecture Decisions

<ADRTable />

## Related Documentation

- [[flow|agent-orchestration]] — End-to-end conversational routing and specialist handoff flow.
- [[doc|domains/bookworm/subdomains/conversational/engineering/01-conversation-architecture]] — Conversational workflow architecture and governance boundaries.
- [[doc|domains/bookworm/subdomains/conversational/guides/01-route-customer-requests]] — Request routing and scope enforcement guide.
- [[doc|domains/bookworm/subdomains/conversational/guides/02-handle-book-discovery]] — Catalog-backed book discovery guide.
