# 404sloth/piloth-ai architecture

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

- Interactive diagram: https://gitdiagram.com/404sloth/piloth-ai
- Repository: https://github.com/404sloth/piloth-ai

## Overview

1. **What this repo is**
PilotH is an enterprise multi-agent orchestration platform. The main runtime path is: user request enters FastAPI, is interpreted by an orchestrator, routed to a registered agent, executed as a LangGraph workflow, and resolved through tools that talk to the database, external services, or the LLM layer.

2. **Top-level request entrypoints**
The system exposes REST endpoints in `backend/api/` and a WebSocket channel in `backend/websocket/`. REST is used for health checks, agent execution, vendor APIs, knowledge base APIs, and human-loop decisions. WebSockets are used to push task progress, approvals, and escalation updates to clients in real time.

3. **Orchestration layer**
`orchestrator/` is the decision layer between incoming user text and the right agent/action. It handles intent parsing, task decomposition, fallback handling, routing, and workflow control. This is where plain-language requests become structured agent invocations.

4. **Agent registry and dispatch**
`backend/services/agent_registry.py` creates and registers agent instances at startup, while `agents/registry.py` tracks tools by name. The registry is the main composition boundary: the backend does not call agent internals directly; it asks for a named agent, and the agent owns its own execution graph and tool set.

5. **Agent execution model**
Each agent is a self-contained LangGraph-based workflow under `agents/<domain>/`. The important ones are:
- `agents/vendor_management/`: vendor search, scoring, SLA/risk/contract analysis
- `agents/communication/`: scheduling, summaries, briefings, sentiment, follow-ups
- `agents/compliance/`: regulatory checks, checklists, risk dashboards
- `agents/executive_support/`: prioritization, bottlenecks, strategy advice
- `agents/insights/`: KPI/forecasting/market analysis
- `agents/knowledge_base/`: semantic document and policy retrieval  
Each agent has its own `graph.py`, `nodes/`, `tools/`, and `schemas.py`, which keeps workflow logic isolated from I/O logic.

6. **Node-to-tool-to-data flow**
Agent nodes orchestrate state transitions, but they do not do raw I/O themselves. Nodes call tools; tools call the data layer or external integrations; results flow back into graph state and then into agent output schemas. This separation is central to the architecture and is what keeps the graphs testable and replaceable.

7. **Shared data access layer**
All SQL is concentrated in `integrations/data_warehouse/`, especially `sqlite_client.py`, `vendor_db.py`, and `meeting_db.py`. That layer owns schema creation, seeding, and query functions. Tools are supposed to call these helpers rather than embed SQL, making the database a replaceable persistence boundary.

8. **External service integrations**
The `integrations/` package contains adapters for Google Calendar, CRM systems, finance/ERP, and the data warehouse. These are the outbound boundaries for real-world side effects. In practice, meeting/scheduling tools use calendar integration; vendor and compliance tools use warehouse-backed data; CRM and finance modules are stubs or extension points.

9. **LLM abstraction and fallback**
`llm/` centralizes model selection and provider fallbacks through `model_factory.py`, with OpenAI, Groq, and Ollama clients available. Agents and tools do not choose providers directly; they ask for an LLM through this layer. That makes LLM behavior a shared infrastructure concern rather than agent-specific logic.

10. **Memory and context**
`memory/` provides short-lived session state, persistent global context, embeddings, and vector store abstractions. This is where cross-turn and cross-agent context lives. It acts as the shared memory boundary between otherwise isolated agent executions.

11. **Human-in-the-loop and safety**
`human_loop/` manages approval queues, escalation, feedback, and interrupts for high-risk actions. The architecture explicitly treats external communication, calendar creation, spending, and deletions as approval-gated operations. In the graph layer, this is surfaced as interrupt points and later resumed through the human-loop routes.

12. **Observability and security**
`observability/` provides structured logging, tracing, metrics, and PII sanitization. This is not just ancillary: the README makes clear that all logs and outputs are sanitized, and task execution is instrumented. That means operational visibility and privacy protection are built into the execution path, not bolted on.

13. **Frontend and user interaction**
`frontend/` is a lightweight Vite/React client that consumes the backend API and listens for WebSocket updates. It is not the system of record; it is a presentation layer for task state, approvals, and results.

14. **Operational/runtime artifacts**
`pilot_db.sqlite`, `data/conversations/`, `Scripts/`, `docker-compose.yml`, `Dockerfile`, and `Makefile` support local startup, seeding, deployment, and repeatable testing. The repository is designed to run as a containerized FastAPI service backed by SQLite for local/dev use, with clear hooks for swapping in real external systems.

15. **Architectural boundary summary**
The cleanest diagram is: client → FastAPI/API + WebSocket → orchestrator → agent registry → LangGraph agent subgraph → tools → shared infrastructure (LLM, memory, HITL, observability) → integrations/data warehouse/external services. The main architectural idea is strict layering: API routes do transport, orchestrator does routing, agents do workflow, tools do I/O, and the data/integration layers own persistence and external calls.

Main entry points: [`tools/registry.py`](https://github.com/404sloth/piloth-ai/blob/main/tools/registry.py) (Tool registry), [`backend/services/agent_registry.py`](https://github.com/404sloth/piloth-ai/blob/main/backend/services/agent_registry.py) (Agent registry), [`backend/api/main.py`](https://github.com/404sloth/piloth-ai/blob/main/backend/api/main.py) (API main), [`orchestrator/controller.py`](https://github.com/404sloth/piloth-ai/blob/main/orchestrator/controller.py) (Controller)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Client"]
  node_frontend_app["Frontend<br/>[App.tsx]"]
end

subgraph group_api["API & Realtime"]
  node_api_main["API main<br/>fastapi<br/>[main.py]"]
  node_agent_routes["Agent routes<br/>api-route<br/>[agent_routes.py]"]
  node_kb_routes["KB routes<br/>api-route"]
  node_human_routes["HITL routes<br/>api-route"]
  node_ws_manager["WebSocket<br/>realtime<br/>[manager.py]"]
end

subgraph group_orchestration["Orchestration"]
  node_controller["Controller<br/>orchestrator<br/>[controller.py]"]
  node_intent_parser["Intent parse<br/>nlp<br/>[intent_parser.py]"]
  node_task_decomposer["Decomposer<br/>planner<br/>[task_decomposer.py]"]
  node_agent_router["Agent router<br/>[agent_router.py]"]
  node_workflow_engine["Workflow engine<br/>executor<br/>[workflow_engine.py]"]
end

subgraph group_agents["Agents"]
  node_agent_registry["Agent registry<br/>[agent_registry.py]"]
  node_vendor_graph["Vendor graph<br/>agent-graph<br/>[graph.py]"]
  node_comm_graph["Comm graph<br/>agent-graph<br/>[graph.py]"]
  node_compliance_graph["Compliance graph<br/>agent-graph<br/>[graph.py]"]
  node_exec_graph["Exec graph<br/>agent-graph<br/>[graph.py]"]
  node_insights_graph["Insights graph<br/>agent-graph<br/>[graph.py]"]
  node_kb_agent["KB agent<br/>[agent.py]"]
end

subgraph group_infra["Shared Infra"]
  node_tool_registry["Tool registry<br/>[registry.py]"]
  node_llm_factory["LLM factory<br/>[model_factory.py]"]
  node_memory_store["Session memory<br/>[session_store.py]"]
  node_hitl_manager["HITL manager<br/>approval<br/>[manager.py]"]
  node_logger["Logging<br/>observability<br/>[logger.py]"]
end

subgraph group_integrations["Integrations"]
  node_sqlite_client[("SQLite client<br/>persistence<br/>[sqlite_client.py]")]
  node_calendar_client["Calendar client<br/>integration<br/>[client.py]"]
end

node_frontend_app -->|"uses"| node_api_main
node_frontend_app -->|"subscribes"| node_ws_manager
node_api_main -->|"mounts"| node_agent_routes
node_api_main -->|"mounts"| node_kb_routes
node_api_main -->|"mounts"| node_human_routes
node_api_main -->|"binds"| node_ws_manager
node_agent_routes -->|"dispatches"| node_controller
node_kb_routes -->|"invokes"| node_kb_agent
node_human_routes -->|"resumes"| node_hitl_manager
node_ws_manager -->|"publishes"| node_hitl_manager
node_controller -->|"parses"| node_intent_parser
node_controller -->|"plans"| node_task_decomposer
node_controller -->|"routes"| node_agent_router
node_controller -->|"executes"| node_workflow_engine
node_agent_router -->|"resolves"| node_agent_registry
node_agent_registry -->|"starts"| node_vendor_graph
node_agent_registry -->|"starts"| node_comm_graph
node_agent_registry -->|"starts"| node_compliance_graph
node_agent_registry -->|"starts"| node_exec_graph
node_agent_registry -->|"starts"| node_insights_graph
node_agent_registry -->|"starts"| node_kb_agent
node_vendor_graph -->|"uses"| node_tool_registry
node_comm_graph -->|"uses"| node_tool_registry
node_compliance_graph -->|"uses"| node_tool_registry
node_exec_graph -->|"uses"| node_tool_registry
node_insights_graph -->|"uses"| node_tool_registry
node_kb_agent -->|"uses"| node_tool_registry
node_tool_registry -->|"requests"| node_llm_factory
node_tool_registry -->|"reads/writes"| node_memory_store
node_tool_registry -->|"queries"| node_sqlite_client
node_comm_graph -->|"calls"| node_calendar_client
node_workflow_engine -->|"emits"| node_logger

click node_frontend_app "https://github.com/404sloth/piloth-ai/blob/main/frontend/src/App.tsx"
click node_api_main "https://github.com/404sloth/piloth-ai/blob/main/backend/api/main.py"
click node_agent_routes "https://github.com/404sloth/piloth-ai/blob/main/backend/api/routes/agent_routes.py"
click node_kb_routes "https://github.com/404sloth/piloth-ai/blob/main/backend/api/routes/knowledge_base_routes.py"
click node_human_routes "https://github.com/404sloth/piloth-ai/blob/main/backend/api/routes/human_loop_routes.py"
click node_ws_manager "https://github.com/404sloth/piloth-ai/blob/main/backend/websocket/manager.py"
click node_controller "https://github.com/404sloth/piloth-ai/blob/main/orchestrator/controller.py"
click node_intent_parser "https://github.com/404sloth/piloth-ai/blob/main/orchestrator/intent_parser.py"
click node_task_decomposer "https://github.com/404sloth/piloth-ai/blob/main/orchestrator/task_decomposer.py"
click node_agent_router "https://github.com/404sloth/piloth-ai/blob/main/orchestrator/agent_router.py"
click node_workflow_engine "https://github.com/404sloth/piloth-ai/blob/main/orchestrator/workflow_engine.py"
click node_agent_registry "https://github.com/404sloth/piloth-ai/blob/main/backend/services/agent_registry.py"
click node_vendor_graph "https://github.com/404sloth/piloth-ai/blob/main/agents/vendor_management/graph.py"
click node_comm_graph "https://github.com/404sloth/piloth-ai/blob/main/agents/communication/graph.py"
click node_compliance_graph "https://github.com/404sloth/piloth-ai/blob/main/agents/compliance/graph.py"
click node_exec_graph "https://github.com/404sloth/piloth-ai/blob/main/agents/executive_support/graph.py"
click node_insights_graph "https://github.com/404sloth/piloth-ai/blob/main/agents/insights/graph.py"
click node_kb_agent "https://github.com/404sloth/piloth-ai/blob/main/agents/knowledge_base/agent.py"
click node_tool_registry "https://github.com/404sloth/piloth-ai/blob/main/tools/registry.py"
click node_llm_factory "https://github.com/404sloth/piloth-ai/blob/main/llm/model_factory.py"
click node_memory_store "https://github.com/404sloth/piloth-ai/blob/main/memory/session_store.py"
click node_hitl_manager "https://github.com/404sloth/piloth-ai/blob/main/human_loop/manager.py"
click node_logger "https://github.com/404sloth/piloth-ai/blob/main/observability/logger.py"
click node_sqlite_client "https://github.com/404sloth/piloth-ai/blob/main/integrations/data_warehouse/sqlite_client.py"
click node_calendar_client "https://github.com/404sloth/piloth-ai/blob/main/integrations/google_calendar/client.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_frontend_app toneBlue
class node_api_main,node_agent_routes,node_kb_routes,node_human_routes,node_ws_manager toneAmber
class node_controller,node_intent_parser,node_task_decomposer,node_agent_router,node_workflow_engine toneMint
class node_agent_registry,node_vendor_graph,node_comm_graph,node_compliance_graph,node_exec_graph,node_insights_graph,node_kb_agent toneRose
class node_tool_registry,node_llm_factory,node_memory_store,node_hitl_manager,node_logger toneIndigo
class node_sqlite_client,node_calendar_client toneTeal
```

## Components

### Client

User-facing presentation layer

- [Frontend](https://github.com/404sloth/piloth-ai/blob/main/frontend/src/App.tsx): frontend · React client for task state, approvals, and results · `frontend/src/App.tsx`

### API & Realtime

FastAPI routes and websocket delivery

- [API main](https://github.com/404sloth/piloth-ai/blob/main/backend/api/main.py): fastapi · Application wiring and route registration · `backend/api/main.py`
- [Agent routes](https://github.com/404sloth/piloth-ai/blob/main/backend/api/routes/agent_routes.py): api-route · REST entrypoint for agent execution · `backend/api/routes/agent_routes.py`
- [KB routes](https://github.com/404sloth/piloth-ai/blob/main/backend/api/routes/knowledge_base_routes.py): api-route · Knowledge base and retrieval endpoints · `backend/api/routes/knowledge_base_routes.py`
- [HITL routes](https://github.com/404sloth/piloth-ai/blob/main/backend/api/routes/human_loop_routes.py): api-route · Approval and escalation endpoints · `backend/api/routes/human_loop_routes.py`
- [WebSocket](https://github.com/404sloth/piloth-ai/blob/main/backend/websocket/manager.py): realtime · Pushes progress and decision updates · `backend/websocket/manager.py`

### Orchestration

Intent parsing, routing, and workflow control

- [Controller](https://github.com/404sloth/piloth-ai/blob/main/orchestrator/controller.py): orchestrator · Coordinates request handling and execution flow · `orchestrator/controller.py`
- [Intent parse](https://github.com/404sloth/piloth-ai/blob/main/orchestrator/intent_parser.py): nlp · Converts user text into structured intent · `orchestrator/intent_parser.py`
- [Decomposer](https://github.com/404sloth/piloth-ai/blob/main/orchestrator/task_decomposer.py): planner · Breaks tasks into executable steps · `orchestrator/task_decomposer.py`
- [Agent router](https://github.com/404sloth/piloth-ai/blob/main/orchestrator/agent_router.py): router · Selects the target agent and fallback path · `orchestrator/agent_router.py`
- [Workflow engine](https://github.com/404sloth/piloth-ai/blob/main/orchestrator/workflow_engine.py): executor · Runs orchestration state and transitions · `orchestrator/workflow_engine.py`

### Agents

LangGraph-based domain workflows

- [Agent registry](https://github.com/404sloth/piloth-ai/blob/main/backend/services/agent_registry.py): registry · Registers and resolves agent instances · `backend/services/agent_registry.py`
- [Vendor graph](https://github.com/404sloth/piloth-ai/blob/main/agents/vendor_management/graph.py): agent-graph · Vendor search, scoring, and risk analysis workflow · `agents/vendor_management/graph.py`
- [Comm graph](https://github.com/404sloth/piloth-ai/blob/main/agents/communication/graph.py): agent-graph · Scheduling, summaries, and follow-up workflow · `agents/communication/graph.py`
- [Compliance graph](https://github.com/404sloth/piloth-ai/blob/main/agents/compliance/graph.py): agent-graph · Regulatory checks and risk workflow · `agents/compliance/graph.py`
- [Exec graph](https://github.com/404sloth/piloth-ai/blob/main/agents/executive_support/graph.py): agent-graph · Prioritization and strategy workflow · `agents/executive_support/graph.py`
- [Insights graph](https://github.com/404sloth/piloth-ai/blob/main/agents/insights/graph.py): agent-graph · KPI, forecasting, and market analysis workflow · `agents/insights/graph.py`
- [KB agent](https://github.com/404sloth/piloth-ai/blob/main/agents/knowledge_base/agent.py): agent · Semantic document and policy retrieval agent · `agents/knowledge_base/agent.py`

### Shared Infra

Cross-cutting runtime services

- [Tool registry](https://github.com/404sloth/piloth-ai/blob/main/tools/registry.py): registry · Shared tool naming and dispatch boundary · `tools/registry.py`
- [LLM factory](https://github.com/404sloth/piloth-ai/blob/main/llm/model_factory.py): llm · Model selection and provider fallback · `llm/model_factory.py`
- [Session memory](https://github.com/404sloth/piloth-ai/blob/main/memory/session_store.py): memory · Short-lived and persistent context store · `memory/session_store.py`
- [HITL manager](https://github.com/404sloth/piloth-ai/blob/main/human_loop/manager.py): approval · Approval queues, escalation, and resume flow · `human_loop/manager.py`
- [Logging](https://github.com/404sloth/piloth-ai/blob/main/observability/logger.py): observability · Structured logging and sanitization · `observability/logger.py`

### Integrations

Outbound service and persistence adapters

- [SQLite client](https://github.com/404sloth/piloth-ai/blob/main/integrations/data_warehouse/sqlite_client.py): persistence · Warehouse-backed local persistence boundary · `integrations/data_warehouse/sqlite_client.py`
- [Calendar client](https://github.com/404sloth/piloth-ai/blob/main/integrations/google_calendar/client.py): integration · Outbound scheduling integration · `integrations/google_calendar/client.py`

## Connections

- Frontend → API main: uses · UI calls backend endpoints and listens for updates
- Frontend → WebSocket: subscribes · Receives live task and approval events
- API main → Agent routes: mounts · Registers agent execution routes
- API main → KB routes: mounts · Registers knowledge base routes
- API main → HITL routes: mounts · Registers human-loop routes
- API main → WebSocket: binds · Initializes websocket channel handling
- Agent routes → Controller: dispatches · Sends requests into orchestration
- KB routes → KB agent: invokes · Direct retrieval-oriented agent path
- HITL routes → HITL manager: resumes · Routes approvals and escalations back into execution
- WebSocket → HITL manager: publishes · Streams approval and escalation state
- Controller → Intent parse: parses · Interprets user request intent
- Controller → Decomposer: plans · Breaks work into smaller steps
- Controller → Agent router: routes · Chooses the named agent or fallback path
- Controller → Workflow engine: executes · Drives the orchestration lifecycle
- Agent router → Agent registry: resolves · Looks up the target agent instance
- Agent registry → Vendor graph: starts · Vendor domain workflow
- Agent registry → Comm graph: starts · Communication workflow
- Agent registry → Compliance graph: starts · Compliance workflow
- Agent registry → Exec graph: starts · Executive support workflow
- Agent registry → Insights graph: starts · Insights workflow
- Agent registry → KB agent: starts · Knowledge retrieval agent
- Vendor graph → Tool registry: uses · Invokes registered tools by name
- Comm graph → Tool registry: uses · Invokes scheduling and communication tools
- Compliance graph → Tool registry: uses · Invokes compliance tools
- Exec graph → Tool registry: uses · Invokes strategy and prioritization tools
- Insights graph → Tool registry: uses · Invokes analytics tools
- KB agent → Tool registry: uses · Invokes retrieval and search tools
- Tool registry → LLM factory: requests · Tool-backed agent steps can ask for LLM access
- Tool registry → Session memory: reads/writes · Shared context and session state
- Tool registry → SQLite client: queries · Warehouse-backed persistence access
- Comm graph → Calendar client: calls · Scheduling and calendar side effects
- Workflow engine → Logging: emits · Instrumentation and sanitized execution logs
