How 404sloth/piloth-ai works
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: registry.py Tool registry · agent_registry.py Agent registry · main.py API main · controller.py Controller
Components 25
Client
User-facing presentation layer
- Frontend · React client for task state, approvals, and results
frontend/src/App.tsx
API & Realtime
FastAPI routes and websocket delivery
- API main · Application wiring and route registration
backend/api/main.py - Agent routes · REST entrypoint for agent execution
backend/api/routes/agent_routes.py - KB routes · Knowledge base and retrieval endpoints
backend/api/routes/knowledge_base_routes.py - HITL routes · Approval and escalation endpoints
backend/api/routes/human_loop_routes.py - WebSocket · Pushes progress and decision updates
backend/websocket/manager.py
Orchestration
Intent parsing, routing, and workflow control
- Controller · Coordinates request handling and execution flow
orchestrator/controller.py - Intent parse · Converts user text into structured intent
orchestrator/intent_parser.py - Decomposer · Breaks tasks into executable steps
orchestrator/task_decomposer.py - Agent router · Selects the target agent and fallback path
orchestrator/agent_router.py - Workflow engine · Runs orchestration state and transitions
orchestrator/workflow_engine.py
Agents
LangGraph-based domain workflows
- Agent registry · Registers and resolves agent instances
backend/services/agent_registry.py - Vendor graph · Vendor search, scoring, and risk analysis workflow
agents/vendor_management/graph.py - Comm graph · Scheduling, summaries, and follow-up workflow
agents/communication/graph.py - Compliance graph · Regulatory checks and risk workflow
agents/compliance/graph.py - Exec graph · Prioritization and strategy workflow
agents/executive_support/graph.py - Insights graph · KPI, forecasting, and market analysis workflow
agents/insights/graph.py - KB agent · Semantic document and policy retrieval agent
agents/knowledge_base/agent.py
Shared Infra
Cross-cutting runtime services
- Tool registry · Shared tool naming and dispatch boundary
tools/registry.py - LLM factory · Model selection and provider fallback
llm/model_factory.py - Session memory · Short-lived and persistent context store
memory/session_store.py - HITL manager · Approval queues, escalation, and resume flow
human_loop/manager.py - Logging · Structured logging and sanitization
observability/logger.py
Integrations
Outbound service and persistence adapters
- SQLite client · Warehouse-backed local persistence boundary
integrations/data_warehouse/sqlite_client.py - Calendar client · Outbound scheduling integration
integrations/google_calendar/client.py
Connections 32
- 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