# openonion/email-agent architecture

> Architecture diagram of the GitHub repository openonion/email-agent, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-09). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/openonion/email-agent
- Repository: https://github.com/openonion/email-agent

## Overview

Email Agent supports interactive and direct CLI use, natural-language email work, calendar scheduling, CRM/contact workflows, persistent memory, and HTTP hosting. The main runtime path is user input through the CLI or hosted agent, then agent tools and results. The graph also shows the distinct CLI command layer and CRM initialization sub-agent. README statements support documented integrations not visible in sampled calls; unsampled contact-provider internals and storage behavior are left unspecified.

Main entry points: [`agent.py`](https://github.com/openonion/email-agent/blob/main/agent.py) (Email agent), [`cli/core.py`](https://github.com/openonion/email-agent/blob/main/cli/core.py) (CLI operations), [`cli/commands.py`](https://github.com/openonion/email-agent/blob/main/cli/commands.py) (CLI commands), [`cli/interactive.py`](https://github.com/openonion/email-agent/blob/main/cli/interactive.py) (Interactive chat)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["User interfaces"]
  node_cli_entry["CLI entry<br/>[cli.py]"]
  node_cli_commands["CLI commands<br/>[commands.py]"]
  node_interactive["Interactive chat<br/>[interactive.py]"]
  node_contacts_provider["Contact autocomplete"]
  node_cli_core["CLI operations<br/>[core.py]"]
  node_setup["Setup checks<br/>[setup.py]"]
  node_hosted_entry["HTTP host entry<br/>[main.py]"]
end

subgraph group_agent["Agent runtime"]
  node_agent["Email agent<br/>[agent.py]"]
  node_today_prompt["Daily briefing prompt<br/>[today.md]"]
  node_gmail_prompt["Gmail instructions<br/>[gmail_agent.md]"]
end

subgraph group_crm["CRM and memory"]
  node_crm_init["CRM initializer<br/>[agent.py]"]
  node_memory[("Agent memory<br/>[agent.py]")]
  node_web_fetch["Contact research<br/>[agent.py]"]
end

subgraph group_integrations["External services"]
  node_gmail["Gmail tools"]
  node_outlook["Outlook tools"]
  node_calendar["Calendar tools"]
  node_llm["LLM provider"]
  node_host_service["ConnectOnion host"]
end

node_user(("User"))

node_user -->|"runs"| node_cli_entry
node_cli_entry -->|"starts"| node_cli_commands
node_cli_commands -->|"checks setup"| node_setup
node_cli_commands -->|"starts chat"| node_interactive
node_cli_commands -->|"dispatches"| node_cli_core
node_interactive -->|"loads suggestions"| node_contacts_provider
node_interactive -->|"runs commands"| node_cli_core
node_interactive -->|"sends chat"| node_agent
node_cli_core -->|"asks agent"| node_agent
node_cli_core -->|"uses email tools"| node_gmail
node_agent -->|"uses"| node_gmail
node_agent -->|"uses alternatively"| node_outlook
node_agent -->|"uses"| node_calendar
node_agent -->|"reads and writes"| node_memory
node_crm_init -->|"saves CRM context"| node_memory
node_crm_init -->|"researches contacts"| node_web_fetch
node_agent -->|"invokes initializer"| node_crm_init
node_cli_core -->|"loads prompt"| node_today_prompt
node_agent -->|"uses instructions"| node_gmail_prompt
node_agent -->|"reasons with"| node_llm
node_user -.->|"sends request"| node_hosted_entry
node_hosted_entry -->|"registers agent"| node_host_service
node_hosted_entry -->|"hosts"| node_agent
node_cli_core -->|"starts server"| node_host_service

click node_cli_entry "https://github.com/openonion/email-agent/blob/main/cli.py"
click node_cli_commands "https://github.com/openonion/email-agent/blob/main/cli/commands.py"
click node_interactive "https://github.com/openonion/email-agent/blob/main/cli/interactive.py"
click node_contacts_provider "https://github.com/openonion/email-agent/blob/main/cli/contacts_provider.py"
click node_cli_core "https://github.com/openonion/email-agent/blob/main/cli/core.py"
click node_setup "https://github.com/openonion/email-agent/blob/main/cli/setup.py"
click node_agent "https://github.com/openonion/email-agent/blob/main/agent.py"
click node_crm_init "https://github.com/openonion/email-agent/blob/main/agent.py"
click node_memory "https://github.com/openonion/email-agent/blob/main/agent.py"
click node_web_fetch "https://github.com/openonion/email-agent/blob/main/agent.py"
click node_today_prompt "https://github.com/openonion/email-agent/blob/main/commands/today.md"
click node_gmail_prompt "https://github.com/openonion/email-agent/blob/main/prompts/gmail_agent.md"
click node_hosted_entry "https://github.com/openonion/email-agent/blob/main/main.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_cli_entry,node_cli_commands,node_interactive,node_contacts_provider,node_cli_core,node_setup,node_hosted_entry,node_user toneBlue
class node_agent,node_today_prompt,node_gmail_prompt toneAmber
class node_crm_init,node_memory,node_web_fetch toneMint
class node_gmail,node_outlook,node_calendar,node_llm,node_host_service toneRose
```

## Components

### User interfaces

- [CLI entry](https://github.com/openonion/email-agent/blob/main/cli.py): `cli.py`
- [CLI commands](https://github.com/openonion/email-agent/blob/main/cli/commands.py): `cli/commands.py`
- [Interactive chat](https://github.com/openonion/email-agent/blob/main/cli/interactive.py): `cli/interactive.py`
- [Contact autocomplete](https://github.com/openonion/email-agent/blob/main/cli/contacts_provider.py): `cli/contacts_provider.py`
- [CLI operations](https://github.com/openonion/email-agent/blob/main/cli/core.py): `cli/core.py`
- [Setup checks](https://github.com/openonion/email-agent/blob/main/cli/setup.py): `cli/setup.py`
- [HTTP host entry](https://github.com/openonion/email-agent/blob/main/main.py): `main.py`

### Agent runtime

- [Email agent](https://github.com/openonion/email-agent/blob/main/agent.py): `agent.py`
- [Daily briefing prompt](https://github.com/openonion/email-agent/blob/main/commands/today.md): `commands/today.md`
- [Gmail instructions](https://github.com/openonion/email-agent/blob/main/prompts/gmail_agent.md): `prompts/gmail_agent.md`

### CRM and memory

- [CRM initializer](https://github.com/openonion/email-agent/blob/main/agent.py): `agent.py`
- [Agent memory](https://github.com/openonion/email-agent/blob/main/agent.py): `agent.py`
- [Contact research](https://github.com/openonion/email-agent/blob/main/agent.py): `agent.py`

### External services

- **Gmail tools**
- **Outlook tools**
- **Calendar tools**
- **LLM provider**
- **ConnectOnion host**

### Other components

- **User**

## Connections

- User → CLI entry: runs (evidence: `README.md`)
- CLI entry → CLI commands: starts (evidence: `cli.py`)
- CLI commands → Setup checks: checks setup (evidence: `cli/commands.py`)
- CLI commands → Interactive chat: starts chat (evidence: `cli/commands.py`)
- CLI commands → CLI operations: dispatches (evidence: `cli/commands.py`)
- Interactive chat → Contact autocomplete: loads suggestions (evidence: `cli/interactive.py`)
- Interactive chat → CLI operations: runs commands (evidence: `cli/interactive.py`)
- Interactive chat → Email agent: sends chat (evidence: `cli/interactive.py`)
- CLI operations → Email agent: asks agent (evidence: `cli/core.py`)
- CLI operations → Gmail tools: uses email tools (evidence: `cli/core.py`)
- Email agent → Gmail tools: uses (evidence: `agent.py`)
- Email agent → Outlook tools: uses alternatively (evidence: `agent.py`)
- Email agent → Calendar tools: uses (evidence: `README.md`)
- Email agent → Agent memory: reads and writes (evidence: `agent.py`)
- CRM initializer → Agent memory: saves CRM context (evidence: `agent.py`)
- CRM initializer → Contact research: researches contacts (evidence: `agent.py`)
- Email agent → CRM initializer: invokes initializer (evidence: `agent.py`)
- CLI operations → Daily briefing prompt: loads prompt (evidence: `cli/core.py`)
- Email agent → Gmail instructions: uses instructions (evidence: `agent.py`)
- Email agent → LLM provider: reasons with (evidence: `README.md`)
- User → HTTP host entry: sends request
- HTTP host entry → ConnectOnion host: registers agent (evidence: `main.py`)
- HTTP host entry → Email agent: hosts (evidence: `main.py`)
- CLI operations → ConnectOnion host: starts server (evidence: `cli/core.py`)
