---
title: Conversation architecture and boundaries
summary: Workflow layers, session persistence tiers, governance controls, and domain boundaries for Chat API and MCP Tools.
version: 1.0.0
type: engineering
order: 1
badges:
  - content: Architecture
    backgroundColor: green
    textColor: green
---

## Purpose & Scope

This document defines the runtime workflow stages, three-tier session and memory model, governance controls, and cross-domain boundaries for [[service|chat-api]] and [[service|mcp-server]] in the [[domain|conversational]] subdomain. Use it to verify where Conversational responsibilities start and end relative to [[domain|catalog]], [[domain|shopping]], [[domain|ordering]], and [[domain|reviews]].

## Visual Reference

The visual below shows how storefront chat requests traverse the API Gateway and [[service|chat-api]] workflow layers to reach Microsoft Foundry, [[container|chat-session-blob]], [[service|presidio-api]], [[service|mcp-server]], and [[service|rating-api]].

<MermaidFileLoader file="mermaids/01-conversation-architecture-diagram-1.mmd" />

_Conversational Workflow, Governance, and Integration Boundaries_

## Core Invariants & Design Rules

- **No relational database, cache, or message broker:** [[service|chat-api]] uses **no** PostgreSQL, Redis, or Kafka. All state is split across durable AG-UI session blobs in [[container|chat-session-blob]], ephemeral container-local research scratchpads, and user-scoped Microsoft Foundry preference memory.
- **Strict read-only domain boundaries:** [[service|chat-api]] and [[service|mcp-server]] never mutate backend domain state. Catalog access is read-only via [[service|mcp-server]] over gRPC to [[service|catalog-api]]; review summarization is read-only via A2A gRPC to [[agent|rating-agent]] on [[service|rating-api]]; store-policy answers come strictly from static policy skills with zero live access to [[service|basket-api]] or [[service|order-api]].
- **Client-side basket isolation:** Any user-confirmed basket UI actions (`addToBasket`, `viewBasket`, `showBasketSummary`) execute strictly in the Storefront browser client, never as server-side mutations in [[service|chat-api]].
- **Layered safety & confidence gating:**
  - **Input validation:** Enforces non-empty prompts, truncates inputs over `2000` characters to `1900` characters, and rejects prompt-injection patterns before model routing (bypassing pure tool-result resume turns).
  - **Decision routing & HITL disambiguation:** Evaluates safety, English language, and in-scope confidence (`< 0.5` rejects) plus route confidence (`< 0.6` pauses for human-in-the-loop disambiguation across `book`, `qa`, and `rating`).
  - **Response formatting:** Strips leaked system-prompt markers, passes empty strings on tool-call-only turns, and falls back to a safe rephrase prompt if no assistant text remains.
- **Constrained specialist handoffs:** [[agent|book-agent]] may hand off to [[agent|rating-agent]] (only when a single book UUID is resolved; terminal—cannot hand back) or to [[agent|qa-agent]] (for store-policy questions); [[agent|qa-agent]] may hand off book-specific portions to [[agent|book-agent]]. Emotional book feedback is handled inline by [[agent|book-agent]] without persisting Reviews [[entity|feedback]].

:::warning
**Tool governance is default-deny.** Any new MCP tool, skill tool, Storefront UI tool, or handoff tool fails silently or returns a governance denial unless explicitly allowlisted for the calling agent identity, and `qa-agent` must remain explicitly denied access to Catalog tools.
:::

## Boundaries & Guarantees

| Concern                      | Strategy & Guarantee                                                                                                                                                                                                                                                                                                                                | Failure / Edge-Case Behavior                                                                                                                              | Related Resources                                                                                                                                                                                                                                                                                                                    |
| :--------------------------- | :-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :-------------------------------------------------------------------------------------------------------------------------------------------------------- | :----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **Persistence**              | AG-UI transcripts persist durably in <ResourceLink id="chat-session-blob" type="container">chat-session-blob</ResourceLink> (`ag-ui/` prefix) with claims-based per-user isolation; Foundry memory stores cross-session reading preferences by Entra ID subject; working file memory is container-local.                                            | Container restarts preserve AG-UI transcripts and Foundry preferences but discard ephemeral working file scratchpads unless backed by persistent storage. | <ResourceLink id="chat-session-blob" type="container">chat-session-blob</ResourceLink>, <ResourceLink id="adr-006-user-scoped-episodic-and-semantic-memory" type="adr">adr-006-user-scoped-episodic-and-semantic-memory</ResourceLink>                                                                                               |
| **Caching & Transport**      | <ResourceLink id="mcp-server" type="service">mcp-server</ResourceLink> operates as a stateless Streamable HTTP (`/mcp`) adapter backed by <ResourceLink id="catalog-api" type="service">catalog-api</ResourceLink> gRPC; <ResourceLink id="chat-api" type="service">chat-api</ResourceLink> exposes `/ag-ui` and `/agents` with `PerUserRateLimit`. | Rate-limit exhaustion returns `429 Too Many Requests` with `Retry-After`; missing Catalog attributes are reported as unavailable rather than guessed.     | <ResourceLink id="mcp-server" type="service">mcp-server</ResourceLink>, <ResourceLink id="adr-001-mcp-read-only-domain-adapter" type="adr">adr-001-mcp-read-only-domain-adapter</ResourceLink>, <ResourceLink id="adr-002-stateless-streamable-http-transport" type="adr">adr-002-stateless-streamable-http-transport</ResourceLink> |
| **Messaging & Protocols**    | No Kafka messaging; <ResourceLink id="chat-api" type="service">chat-api</ResourceLink> uses HTTP (`/ag-ui`), MCP Streamable HTTP (`/mcp`), and A2A gRPC (`2m` timeout with Entra Agent Identity token exchange to <ResourceLink id="rating-api" type="service">rating-api</ResourceLink>).                                                          | Unavailable downstream MCP or A2A gRPC calls surface partial-evidence or fallback responses without fabricating catalog or review data.                   | <ResourceLink id="chat-api" type="service">chat-api</ResourceLink>, <ResourceLink id="rating-agent" type="agent">rating-agent</ResourceLink>, <ResourceLink id="adr-003-separate-interactive-and-agent-protocols" type="adr">adr-003-separate-interactive-and-agent-protocols</ResourceLink>                                         |
| **Concurrency & Governance** | Per-user token-bucket rate limiting (`30` token limit, `20` per `10s`, queue `5`) plus global concurrency limits; Presidio PII middleware redacts sensitive entities on specialist turns; conversation guardian bounds turns (`30`) and retry cycles (`3`).                                                                                         | Guardrail, injection, or threshold violations short-circuit the turn with a structured rejection message before invoking specialist tools.                | <ResourceLink id="presidio-api" type="service">presidio-api</ResourceLink>, <ResourceLink id="adr-002-fail-closed-pii-middleware" type="adr">adr-002-fail-closed-pii-middleware</ResourceLink>, <ResourceLink id="adr-005-govern-agent-tools-per-agent" type="adr">adr-005-govern-agent-tools-per-agent</ResourceLink>               |

<AccordionGroup>
	<Accordion title="Specialist delegation & research fan-out">
		[[agent|book-agent]] can delegate multi-step catalog and recommendation lookups concurrently to
		[[agent|book-catalog-researcher]] and [[agent|book-recommendation-researcher]], synthesizing and
		deduplicating results while surfacing partial-evidence gaps transparently.
	</Accordion>
	<Accordion title="HITL disambiguation resume normalization">
		When route confidence is below `0.6`, execution pauses at the disambiguation interrupt with
		three choices (`book`, `qa`, `rating`). Both structured tool-result responses and plain-text
		customer replies (such as `1`/`book`, `2`/`qa`, `3`/`rating`) are normalized to resume the
		selected specialist at `1.0` confidence.
	</Accordion>
</AccordionGroup>

## Safe Change & Verification Checklist

- Preserve read-only boundaries across [[service|chat-api]] and [[service|mcp-server]]; never introduce PostgreSQL, Redis, Kafka, or direct backend write clients.
- Update per-agent governance allowlists whenever adding MCP, skill, harness, or Storefront UI tools, keeping `qa-agent` denied from Catalog tools.
- Keep Presidio PII middleware, Entra ID `customer` authorization (`chatting_read` / `chatting_write`), claims-based session isolation, and Entra Agent Identity token exchange intact.
- Verify prompt validation, routing thresholds (`0.5` / `0.6`), HITL disambiguation resume, specialist handoff preconditions, and session persistence in Chat unit tests via `mise run test`.

## Related Resources

- [[service|chat-api]] — Conversational workflow host and AG-UI endpoint
- [[service|mcp-server]] — Stateless read-only Catalog MCP adapter
- [[agent|book-agent]], [[agent|book-catalog-researcher]], [[agent|book-recommendation-researcher]], [[agent|qa-agent]], [[agent|rating-agent]] — Conversational specialists
- [[flow|agent-orchestration]] — End-to-end conversational orchestration flow
- [[adr|adr-001-chat-agent-orchestration-boundary]], [[adr|adr-002-fail-closed-pii-middleware]], [[adr|adr-005-govern-agent-tools-per-agent]], [[adr|adr-007-system-one-decision-model-routing-and-tool-selection]]
- [[doc|misc/001-ms-decisions-model-use-case-and-lessons-learned]] — Routing decision model design and lessons learned
