---
id: chat-api
name: Chat API
version: 1.0.0
summary: |
  Internal HTTP host for BookWorm's interactive multi-agent chat workflow,
  agent discovery, and session persistence.
owners:
  - ai-capabilities-team
readsFrom:
  - id: chat-session-blob
    version: 1.0.0
writesTo:
  - id: chat-session-blob
    version: 1.0.0
styles:
  icon: /icons/languages/dotnet.svg
repository:
  language: C#
  url: "https://github.com/foxminchan/BookWorm"
badges:
  - content: Internal
    backgroundColor: gray
    textColor: gray
  - content: HTTP API
    backgroundColor: teal
    textColor: teal
---

## Service Responsibility & Boundary

Chat API is the interactive conversational host within the [[domain|conversational]] domain, orchestrating BookWorm's multi-agent chat workflow, prompt safety validation, and session persistence in [[container|chat-session-blob]]. It delegates catalog lookups to [[service|mcp-server]], review summarization to [[agent|rating-agent]] in [[service|rating-api]] over Agent-to-Agent (A2A) gRPC, and PII redaction to [[service|presidio-api]]. Chat API never places orders, modifies baskets, writes reviews, or publishes Kafka integration events.

## Service Profile

| Property                                  | Value                                                                                                                               |
| :---------------------------------------- | :---------------------------------------------------------------------------------------------------------------------------------- |
| **Bounded Context / Domain**              | [[domain\|conversational]]                                                                                                          |
| **Owner Team**                            | [[team\|ai-capabilities-team]]                                                                                                      |
| **Runtime Style**                         | REST / Streaming API (AG-UI & Agent Discovery)                                                                                      |
| **Public / Gateway Exposure**             | Yes via API Gateway                                                                                                                 |
| **Authentication & Authorization Policy** | Microsoft Entra ID JWT (`customer` or `admin` role + chat scopes) and Entra Agent Identities with On-Behalf-Of (OBO) token exchange |
| **Owned Data Store(s)**                   | [[container\|chat-session-blob]] (conversation transcripts and agent memory)                                                        |
| **Key Resilience / Idempotency Pattern**  | Fail-closed PII screening, per-user rate limiting, and prompt-injection/scope gating                                                |

## Contracts & Data Ownership

Chat API persists conversation session state and model memory in [[container|chat-session-blob]] and exposes the interactive streaming chat endpoint alongside agent discovery metadata.

:::warning
Chat API operates exclusively as an A2A **client** communicating with [[service|rating-api]]. All specialist agent inputs and outputs pass through fail-closed PII screening via [[service|presidio-api]]; streaming responses are buffered until privacy filtering succeeds, and any screening failure aborts the turn.
:::

<Accordion title="Multi-Agent Routing & Governance Notes">
	- **Validation & scope routing:** Empty or suspected prompt-injection inputs are rejected
	immediately, oversized inputs are truncated safely, and non-English or out-of-scope requests
	short-circuit before reaching specialist agents. - **Scoped specialists:** [[agent|qa-agent]]
	answers store-policy questions without catalog tools; [[agent|book-agent]] coordinates
	[[agent|book-catalog-researcher]] and [[agent|book-recommendation-researcher]] using read-only
	catalog tools on [[service|mcp-server]]; review insights delegate to [[agent|rating-agent]].
</Accordion>

## Architecture Visualizations & Specifications

### Conversational Workflow Context

<MermaidFileLoader file="mermaids/ChatAPI-diagram-1.mmd" />

### Service Interactions

<NodeGraph />

## Attached Resources & Related Docs

- [[doc|platform/006-api-and-contracts]] — Consolidated service and protocol index.
- [[agent|book-agent]] — Primary catalog and recommendation specialist.
- [[agent|qa-agent]] — Store-policy specialist.
- [[container|chat-session-blob]] — Conversation session storage.
- [[service|presidio-api]] — PII detection and anonymization sidecars.
- [[service|mcp-server]] — Read-only Catalog MCP server.
