# leonadavinci/laya-system-one architecture

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

- Interactive diagram: https://gitdiagram.com/leonadavinci/laya-system-one
- Repository: https://github.com/leonadavinci/laya-system-one

## Overview

Laya is a multilingual, non-autoregressive typed-decision engine. The main workflow accepts a state and typed questions, routes the request to a suitable checkpoint, runs inference, and returns typed answers with routing information. Python is the sampled primary runtime; the README also documents batching, email cleaning, presets, HTTP/MCP and framework integrations, plus a TypeScript runtime. Some subsystem details are documented but unsampled, so the graph shows those capabilities without guessing internal call chains.

Main entry points: [`laya/agent.py`](https://github.com/leonadavinci/laya-system-one/blob/main/laya/agent.py) (Decision agent), [`laya/__init__.py`](https://github.com/leonadavinci/laya-system-one/blob/main/laya/__init__.py) (Python package API), [`laya/router.py`](https://github.com/leonadavinci/laya-system-one/blob/main/laya/router.py) (Checkpoint router), [`laya-ts/src/router.ts`](https://github.com/leonadavinci/laya-system-one/blob/main/laya-ts/src/router.ts) (TypeScript router)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Decision runtime"]
  node_api["Python package API<br/>[__init__.py]"]
  node_router["Checkpoint router<br/>[router.py]"]
  node_agent["Decision agent<br/>[agent.py]"]
  node_question_prep["Question preparation<br/>[common.py]"]
end

subgraph group_language["Language and tasks"]
  node_language_detect["Language detection<br/>[lang.py]"]
  node_preset_questions["Decision presets<br/>[presets.py]"]
  node_email_clean["Email cleaning<br/>[email.py]"]
end

subgraph group_interfaces["Product interfaces"]
  node_cli["Command-line interface<br/>[cli.py]"]
  node_http["HTTP inference server<br/>[serve.py]"]
  node_mcp_server["MCP server<br/>[server.py]"]
  node_mcp_tools["MCP decision tools<br/>[tools.py]"]
  node_framework["LangChain integration<br/>[langchain.py]"]
end

subgraph group_accelerators["Inference options"]
  node_onnx["ONNX inference<br/>[onnx_agent.py]"]
  node_fast["GPU fast path<br/>[fast.py]"]
end

subgraph group_typescript["TypeScript runtime"]
  node_ts_api["TypeScript package API<br/>[index.ts]"]
  node_ts_router["TypeScript router<br/>[router.ts]"]
  node_ts_language["TypeScript language detection<br/>[lang.ts]"]
  node_ts_agent["TypeScript decision agent<br/>[agent.ts]"]
  node_ts_provider["Model providers<br/>[providers.ts]"]
end

node_user(("Application caller"))
node_model_hub[("Checkpoint repository")]
node_http_client(("HTTP API client"))
node_mcp_client(("MCP client"))
node_framework_app(("LangChain application"))

node_user -->|"submits request"| node_api
node_api -->|"routes request"| node_router
node_router -->|"detects language"| node_language_detect
node_router -->|"loads and dispatches"| node_agent
node_agent -->|"downloads checkpoint"| node_model_hub
node_agent -->|"prepares questions"| node_question_prep
node_question_prep -->|"supplies encoded inputs"| node_agent
node_agent -->|"returns typed answers"| node_api
node_user -->|"runs local test"| node_cli
node_cli -->|"calls runtime"| node_api
node_http_client -->|"sends request"| node_http
node_http -->|"serves inference"| node_router
node_mcp_client -->|"calls tools"| node_mcp_server
node_mcp_server -->|"dispatches tools"| node_mcp_tools
node_mcp_tools -->|"routes or predicts"| node_router
node_mcp_tools -->|"uses presets"| node_preset_questions
node_framework_app -->|"evaluates state"| node_framework
node_framework -.->|"uses local runtime"| node_router
node_framework -.->|"uses remote runtime"| node_http
node_api -->|"exposes presets"| node_preset_questions
node_api -->|"exposes email cleaning"| node_email_clean
node_agent -.->|"optionally accelerates"| node_fast
node_onnx -->|"loads exported model"| node_model_hub
node_user -->|"uses package"| node_ts_api
node_ts_api -->|"routes request"| node_ts_router
node_ts_router -->|"analyses language"| node_ts_language
node_ts_router -->|"dispatches inference"| node_ts_agent
node_ts_agent -->|"loads model bundle"| node_ts_provider
node_ts_router -->|"returns routed result"| node_ts_agent

click node_api "https://github.com/leonadavinci/laya-system-one/blob/main/laya/__init__.py"
click node_router "https://github.com/leonadavinci/laya-system-one/blob/main/laya/router.py"
click node_language_detect "https://github.com/leonadavinci/laya-system-one/blob/main/laya/lang.py"
click node_agent "https://github.com/leonadavinci/laya-system-one/blob/main/laya/agent.py"
click node_question_prep "https://github.com/leonadavinci/laya-system-one/blob/main/laya/common.py"
click node_preset_questions "https://github.com/leonadavinci/laya-system-one/blob/main/laya/presets.py"
click node_email_clean "https://github.com/leonadavinci/laya-system-one/blob/main/laya/email.py"
click node_cli "https://github.com/leonadavinci/laya-system-one/blob/main/laya/cli.py"
click node_http "https://github.com/leonadavinci/laya-system-one/blob/main/laya/serve.py"
click node_mcp_server "https://github.com/leonadavinci/laya-system-one/blob/main/laya/mcp/server.py"
click node_mcp_tools "https://github.com/leonadavinci/laya-system-one/blob/main/laya/mcp/tools.py"
click node_framework "https://github.com/leonadavinci/laya-system-one/blob/main/laya/integrations/langchain.py"
click node_onnx "https://github.com/leonadavinci/laya-system-one/blob/main/laya/onnx_agent.py"
click node_fast "https://github.com/leonadavinci/laya-system-one/blob/main/laya/fast.py"
click node_ts_api "https://github.com/leonadavinci/laya-system-one/blob/main/laya-ts/src/index.ts"
click node_ts_router "https://github.com/leonadavinci/laya-system-one/blob/main/laya-ts/src/router.ts"
click node_ts_language "https://github.com/leonadavinci/laya-system-one/blob/main/laya-ts/src/lang.ts"
click node_ts_agent "https://github.com/leonadavinci/laya-system-one/blob/main/laya-ts/src/agent.ts"
click node_ts_provider "https://github.com/leonadavinci/laya-system-one/blob/main/laya-ts/src/providers.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_api,node_router,node_agent,node_question_prep,node_http_client,node_mcp_client toneBlue
class node_language_detect,node_preset_questions,node_email_clean,node_model_hub toneAmber
class node_cli,node_http,node_mcp_server,node_mcp_tools,node_framework toneMint
class node_onnx,node_fast toneRose
class node_ts_api,node_ts_router,node_ts_language,node_ts_agent,node_ts_provider,node_user,node_framework_app toneIndigo
```

## Components

### Decision runtime

- [Python package API](https://github.com/leonadavinci/laya-system-one/blob/main/laya/__init__.py): `laya/__init__.py`
- [Checkpoint router](https://github.com/leonadavinci/laya-system-one/blob/main/laya/router.py): `laya/router.py`
- [Decision agent](https://github.com/leonadavinci/laya-system-one/blob/main/laya/agent.py): `laya/agent.py`
- [Question preparation](https://github.com/leonadavinci/laya-system-one/blob/main/laya/common.py): `laya/common.py`

### Language and tasks

- [Language detection](https://github.com/leonadavinci/laya-system-one/blob/main/laya/lang.py): `laya/lang.py`
- [Decision presets](https://github.com/leonadavinci/laya-system-one/blob/main/laya/presets.py): `laya/presets.py`
- [Email cleaning](https://github.com/leonadavinci/laya-system-one/blob/main/laya/email.py): `laya/email.py`

### Product interfaces

- [Command-line interface](https://github.com/leonadavinci/laya-system-one/blob/main/laya/cli.py): `laya/cli.py`
- [HTTP inference server](https://github.com/leonadavinci/laya-system-one/blob/main/laya/serve.py): `laya/serve.py`
- [MCP server](https://github.com/leonadavinci/laya-system-one/blob/main/laya/mcp/server.py): `laya/mcp/server.py`
- [MCP decision tools](https://github.com/leonadavinci/laya-system-one/blob/main/laya/mcp/tools.py): `laya/mcp/tools.py`
- [LangChain integration](https://github.com/leonadavinci/laya-system-one/blob/main/laya/integrations/langchain.py): `laya/integrations/langchain.py`

### Inference options

- [ONNX inference](https://github.com/leonadavinci/laya-system-one/blob/main/laya/onnx_agent.py): `laya/onnx_agent.py`
- [GPU fast path](https://github.com/leonadavinci/laya-system-one/blob/main/laya/fast.py): `laya/fast.py`

### TypeScript runtime

- [TypeScript package API](https://github.com/leonadavinci/laya-system-one/blob/main/laya-ts/src/index.ts): `laya-ts/src/index.ts`
- [TypeScript router](https://github.com/leonadavinci/laya-system-one/blob/main/laya-ts/src/router.ts): `laya-ts/src/router.ts`
- [TypeScript language detection](https://github.com/leonadavinci/laya-system-one/blob/main/laya-ts/src/lang.ts): `laya-ts/src/lang.ts`
- [TypeScript decision agent](https://github.com/leonadavinci/laya-system-one/blob/main/laya-ts/src/agent.ts): `laya-ts/src/agent.ts`
- [Model providers](https://github.com/leonadavinci/laya-system-one/blob/main/laya-ts/src/providers.ts): `laya-ts/src/providers.ts`

### Other components

- **Application caller**
- **Checkpoint repository**
- **HTTP API client**
- **MCP client**
- **LangChain application**

## Connections

- Application caller → Python package API: submits request
- Python package API → Checkpoint router: routes request
- Checkpoint router → Language detection: detects language
- Checkpoint router → Decision agent: loads and dispatches
- Decision agent → Checkpoint repository: downloads checkpoint
- Decision agent → Question preparation: prepares questions
- Question preparation → Decision agent: supplies encoded inputs
- Decision agent → Python package API: returns typed answers
- Application caller → Command-line interface: runs local test
- Command-line interface → Python package API: calls runtime
- HTTP API client → HTTP inference server: sends request
- HTTP inference server → Checkpoint router: serves inference
- MCP client → MCP server: calls tools
- MCP server → MCP decision tools: dispatches tools
- MCP decision tools → Checkpoint router: routes or predicts
- MCP decision tools → Decision presets: uses presets
- LangChain application → LangChain integration: evaluates state
- LangChain integration → Checkpoint router: uses local runtime
- LangChain integration → HTTP inference server: uses remote runtime
- Python package API → Decision presets: exposes presets
- Python package API → Email cleaning: exposes email cleaning
- Decision agent → GPU fast path: optionally accelerates
- ONNX inference → Checkpoint repository: loads exported model
- Application caller → TypeScript package API: uses package
- TypeScript package API → TypeScript router: routes request
- TypeScript router → TypeScript language detection: analyses language
- TypeScript router → TypeScript decision agent: dispatches inference
- TypeScript decision agent → Model providers: loads model bundle
- TypeScript router → TypeScript decision agent: returns routed result
