> Visual Mermaid diagrams of core platform workflows and data flows

# Architecture Diagrams

This section contains canonical visual architecture diagrams illustrating Dewee’s internal workflows, progressive memory loops, and multi-tenant isolation boundaries.

## 8-Stage Agent Pipeline

The core execution loop inside `internal/pipeline/` processes each incoming message through eight deterministic stages: Context resolution, History retrieval, Prompt compilation, Model reasoning, Tool execution, Observation capture, Memory consolidation, and Session compaction.

```mermaid
flowchart LR
  In[Inbound Message] --> Ctx[Context Resolution]
  Ctx --> His[History Buffer]
  His --> Pr[Prompt Compiler]
  Pr --> Th[Model Reasoning]
  Th --> Act[Tool Execution]
  Act --> Obs[Observation Capture]
  Obs --> Mem[Memory Consolidation]
  Mem --> Sum[Session Compaction]
  Sum --> Out[Response Delivery]
```

## 3-Tier Progressive Memory Model

The progressive memory hierarchy spans three persistent tiers:

* **L0 Working Memory:** Ephemeral conversation buffer maintained in turn context.
* **L1 Episodic Memory:** Vectorized session summaries stored in PostgreSQL with pgvector embeddings.
* **L2 Semantic Memory:** Knowledge Graph entities and semantic relations extracted across conversations.

```mermaid
flowchart TB
  Turn[Conversation Turn] --> L0[Working Memory L0: Active Context Buffer]
  L0 --> Compaction[Session Summarization]
  Compaction --> L1[Episodic Memory L1: PostgreSQL pgvector Embeddings]
  L1 --> KGExtraction[Knowledge Graph Extraction]
  KGExtraction --> L2[Semantic Memory L2: Entities & Relations Graph]
```

## Multi-Tenant Gateway Architecture

The multi-tenant gateway guarantees strict tenant isolation across database queries, workspace context directories, and encrypted provider credentials.

```mermaid
flowchart TB
  Client[Client / Webapp / CLI] --> Gateway[Dewee Go 1.26 Gateway Core]
  Gateway --> Auth[Auth & Tenant Resolver]
  Auth --> TenantDB[(Tenant PostgreSQL DB)]
  Auth --> WorkspaceFS[Workspace Isolated Context Files]
  Gateway --> ProviderAdapter[Provider Adapter: 20+ LLMs]
```
