# davidondrej/pi-agent architecture

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

- Interactive diagram: https://gitdiagram.com/davidondrej/pi-agent
- Repository: https://github.com/davidondrej/pi-agent

## Overview

Pi Monorepo is a toolkit for building AI agents and managing LLM deployments. Its principal workflow is the coding-agent CLI: users start a run, which resolves configuration and session state before entering the agent runtime. The repository also provides a multi-provider AI API, agent and terminal-UI libraries, a browser chat UI, GPU-pod management, and a Slack bot that delegates work to the coding agent. The graph emphasizes documented package roles and indexed source references; several runtime connections are omitted where sampled code does not establish them.

Main entry points: [`packages/coding-agent/src/main.ts`](https://github.com/davidondrej/pi-agent/blob/main/packages/coding-agent/src/main.ts) (Coding CLI), [`packages/coding-agent/src/core/agent-session-services.ts`](https://github.com/davidondrej/pi-agent/blob/main/packages/coding-agent/src/core/agent-session-services.ts) (Session Services), [`packages/coding-agent/src/core/agent-session.ts`](https://github.com/davidondrej/pi-agent/blob/main/packages/coding-agent/src/core/agent-session.ts) (Coding Agent), [`packages/tui/src/tui.ts`](https://github.com/davidondrej/pi-agent/blob/main/packages/tui/src/tui.ts) (Terminal UI)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_coding["Coding Agent"]
  node_cli["Coding CLI<br/>[main.ts]"]
  node_configuration["Configuration<br/>[config.ts]"]
  node_session[("Session Manager<br/>[session-manager.ts]")]
  node_runtime["Agent Session Runtime"]
  node_services["Session Services"]
  node_tools["Coding Tools"]
  node_codingagent["Coding Agent<br/>[agent-session.ts]"]
end

subgraph group_ai["Agent Platform"]
  node_aiapi["Multi-provider AI API<br/>[types.ts]"]
  node_agentcore["Agent Runtime<br/>[agent-loop.ts]"]
end

subgraph group_interfaces["User Interfaces"]
  node_tui["Terminal UI<br/>[tui.ts]"]
  node_editor["Terminal Editor<br/>[editor.ts]"]
  node_webchat["Web Chat UI<br/>[ChatPanel.ts]"]
  node_webstorage[("Browser Storage<br/>[app-storage.ts]")]
end

subgraph group_deploy["Deployment"]
  node_pods["Pod Management CLI<br/>[cli.ts]"]
  node_podssh["Pod SSH<br/>[ssh.ts]"]
end

subgraph group_slack["Slack Bot"]
  node_slackbot["Slack Bot<br/>[slack.ts]"]
  node_momagent["Delegated Agent<br/>[agent.ts]"]
end

node_user(("User"))

node_user -->|"starts run"| node_cli
node_cli -->|"resolves settings"| node_configuration
node_cli -->|"opens session"| node_session
node_cli -->|"creates runtime"| node_runtime
node_cli -->|"loads services"| node_services
node_services -->|"reads config"| node_configuration
node_services -->|"uses sessions"| node_session
node_services -->|"loads tools"| node_tools
node_user -->|"uses terminal UI"| node_tui
node_tui -->|"hosts editor"| node_editor
node_user -->|"uses web chat"| node_webchat
node_webstorage -.->|"stores chat state"| node_webchat
node_user -->|"manages deployments"| node_pods
node_pods -->|"dispatches SSH"| node_podssh
node_user -->|"messages bot"| node_slackbot
node_slackbot -->|"routes requests"| node_momagent
node_momagent -->|"delegates work"| node_codingagent
node_codingagent -.->|"uses agent runtime"| node_agentcore
node_codingagent -.->|"uses model API"| node_aiapi

click node_cli "https://github.com/davidondrej/pi-agent/blob/main/packages/coding-agent/src/main.ts"
click node_configuration "https://github.com/davidondrej/pi-agent/blob/main/packages/coding-agent/src/config.ts"
click node_session "https://github.com/davidondrej/pi-agent/blob/main/packages/coding-agent/src/core/session-manager.ts"
click node_runtime "https://github.com/davidondrej/pi-agent/blob/main/packages/coding-agent/src/core/agent-session-runtime.ts"
click node_services "https://github.com/davidondrej/pi-agent/blob/main/packages/coding-agent/src/core/agent-session-services.ts"
click node_tools "https://github.com/davidondrej/pi-agent/tree/main/packages/coding-agent/src/core/tools"
click node_aiapi "https://github.com/davidondrej/pi-agent/blob/main/packages/ai/src/types.ts"
click node_agentcore "https://github.com/davidondrej/pi-agent/blob/main/packages/agent/src/agent-loop.ts"
click node_tui "https://github.com/davidondrej/pi-agent/blob/main/packages/tui/src/tui.ts"
click node_editor "https://github.com/davidondrej/pi-agent/blob/main/packages/tui/src/components/editor.ts"
click node_webchat "https://github.com/davidondrej/pi-agent/blob/main/packages/web-ui/src/ChatPanel.ts"
click node_webstorage "https://github.com/davidondrej/pi-agent/blob/main/packages/web-ui/src/storage/app-storage.ts"
click node_pods "https://github.com/davidondrej/pi-agent/blob/main/packages/pods/src/cli.ts"
click node_podssh "https://github.com/davidondrej/pi-agent/blob/main/packages/pods/src/ssh.ts"
click node_slackbot "https://github.com/davidondrej/pi-agent/blob/main/packages/mom/src/slack.ts"
click node_momagent "https://github.com/davidondrej/pi-agent/blob/main/packages/mom/src/agent.ts"
click node_codingagent "https://github.com/davidondrej/pi-agent/blob/main/packages/coding-agent/src/core/agent-session.ts"

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,node_configuration,node_session,node_runtime,node_services,node_tools,node_codingagent,node_user toneBlue
class node_aiapi,node_agentcore toneAmber
class node_tui,node_editor,node_webchat,node_webstorage toneMint
class node_pods,node_podssh toneRose
class node_slackbot,node_momagent toneIndigo
```

## Components

### Coding Agent

- [Coding CLI](https://github.com/davidondrej/pi-agent/blob/main/packages/coding-agent/src/main.ts): `packages/coding-agent/src/main.ts`
- [Configuration](https://github.com/davidondrej/pi-agent/blob/main/packages/coding-agent/src/config.ts): `packages/coding-agent/src/config.ts`
- [Session Manager](https://github.com/davidondrej/pi-agent/blob/main/packages/coding-agent/src/core/session-manager.ts): `packages/coding-agent/src/core/session-manager.ts`
- [Agent Session Runtime](https://github.com/davidondrej/pi-agent/blob/main/packages/coding-agent/src/core/agent-session-runtime.ts): `packages/coding-agent/src/core/agent-session-runtime.ts`
- [Session Services](https://github.com/davidondrej/pi-agent/blob/main/packages/coding-agent/src/core/agent-session-services.ts): `packages/coding-agent/src/core/agent-session-services.ts`
- [Coding Tools](https://github.com/davidondrej/pi-agent/tree/main/packages/coding-agent/src/core/tools): `packages/coding-agent/src/core/tools`
- [Coding Agent](https://github.com/davidondrej/pi-agent/blob/main/packages/coding-agent/src/core/agent-session.ts): `packages/coding-agent/src/core/agent-session.ts`

### Agent Platform

- [Multi-provider AI API](https://github.com/davidondrej/pi-agent/blob/main/packages/ai/src/types.ts): `packages/ai/src/types.ts`
- [Agent Runtime](https://github.com/davidondrej/pi-agent/blob/main/packages/agent/src/agent-loop.ts): `packages/agent/src/agent-loop.ts`

### User Interfaces

- [Terminal UI](https://github.com/davidondrej/pi-agent/blob/main/packages/tui/src/tui.ts): `packages/tui/src/tui.ts`
- [Terminal Editor](https://github.com/davidondrej/pi-agent/blob/main/packages/tui/src/components/editor.ts): `packages/tui/src/components/editor.ts`
- [Web Chat UI](https://github.com/davidondrej/pi-agent/blob/main/packages/web-ui/src/ChatPanel.ts): `packages/web-ui/src/ChatPanel.ts`
- [Browser Storage](https://github.com/davidondrej/pi-agent/blob/main/packages/web-ui/src/storage/app-storage.ts): `packages/web-ui/src/storage/app-storage.ts`

### Deployment

- [Pod Management CLI](https://github.com/davidondrej/pi-agent/blob/main/packages/pods/src/cli.ts): `packages/pods/src/cli.ts`
- [Pod SSH](https://github.com/davidondrej/pi-agent/blob/main/packages/pods/src/ssh.ts): `packages/pods/src/ssh.ts`

### Slack Bot

- [Slack Bot](https://github.com/davidondrej/pi-agent/blob/main/packages/mom/src/slack.ts): `packages/mom/src/slack.ts`
- [Delegated Agent](https://github.com/davidondrej/pi-agent/blob/main/packages/mom/src/agent.ts): `packages/mom/src/agent.ts`

### Other components

- **User**

## Connections

- User → Coding CLI: starts run (evidence: `README.md`)
- Coding CLI → Configuration: resolves settings (evidence: `packages/coding-agent/src/main.ts`)
- Coding CLI → Session Manager: opens session (evidence: `packages/coding-agent/src/main.ts`)
- Coding CLI → Agent Session Runtime: creates runtime (evidence: `packages/coding-agent/src/main.ts`)
- Coding CLI → Session Services: loads services (evidence: `packages/coding-agent/src/main.ts`)
- Session Services → Configuration: reads config (evidence: `packages/coding-agent/src/core/agent-session-services.ts`)
- Session Services → Session Manager: uses sessions (evidence: `packages/coding-agent/src/core/agent-session-services.ts`)
- Session Services → Coding Tools: loads tools (evidence: `packages/coding-agent/src/core/agent-session-services.ts`)
- User → Terminal UI: uses terminal UI (evidence: `README.md`)
- Terminal UI → Terminal Editor: hosts editor (evidence: `packages/tui/src/components/editor.ts`)
- User → Web Chat UI: uses web chat (evidence: `README.md`)
- Browser Storage → Web Chat UI: stores chat state
- User → Pod Management CLI: manages deployments (evidence: `README.md`)
- Pod Management CLI → Pod SSH: dispatches SSH (evidence: `packages/pods/src/cli.ts`)
- User → Slack Bot: messages bot (evidence: `README.md`)
- Slack Bot → Delegated Agent: routes requests (evidence: `packages/mom/src/agent.ts`)
- Delegated Agent → Coding Agent: delegates work (evidence: `README.md`)
- Coding Agent → Agent Runtime: uses agent runtime
- Coding Agent → Multi-provider AI API: uses model API
