How mahavishnu-k/ore-kernel works
Purpose and Entry Points
ORE is a Rust workspace implementing a local LLM kernel: it mediates application access to inference, agent memory, collaboration, and tool execution. The persistent HTTP daemon starts at ore-server/src/main.rs; its Axum routes are implemented under ore-server/src/handlers/. The user-facing client and interactive workflows start at ore-cli/src/main.rs. Workspace composition is defined by Cargo.toml.
Server Bootstrap and Shared Kernel State
At startup, the server resolves configuration/base directories, loads manifests, selects an inference driver, creates shared kernel state, generates a session token, installs authentication middleware, and starts background cleanup. Shared state and configuration live in ore-server/src/state.rs; request authorization is in ore-server/src/middleware.rs; route payload contracts are in ore-server/src/payloads.rs. The daemon binds locally and is the principal boundary between clients and kernel subsystems.
Manifest-Centered Policy Boundary
Every agent/application is identified by a TOML manifest loaded into the in-memory registry. The registry supplies O(1) application policy lookup to inference, IPC, and execution paths, covering model access, quotas, paging, filesystem/network permissions, execution permissions, and IPC targets/pipes. Core implementation: ore-core/src/registry.rs; installed policy inputs: manifests/openclaw.toml, manifests/terminal_user.toml; system defaults: ore.toml.
Secured Inference Pipeline
Inference handlers accept authenticated requests, resolve the caller manifest, apply quota/security controls, restore state when enabled, acquire scheduling capacity, invoke the configured driver, and stream or return output. The prompt firewall detects injection patterns and redacts PII before model access in ore-core/src/firewall.rs. Per-agent token budgets and IPC facilities share ore-core/src/ipc.rs. Inference request orchestration is in ore-server/src/handlers/inference.rs.
Scheduling and Persistent Agent State
The GPU scheduler uses Tokio semaphore-based RAII leases to serialize/arbitrate active inference and optimize reuse: same model/agent, agent context swap, or model replacement. It is implemented in ore-core/src/scheduler.rs. Memory management pages chat histories and physical KV caches between RAM/VRAM and SSD, restores them on later requests, and compacts stale state; implementation is ore-core/src/memory.rs with native KV ownership in ore-core/src/native/kv_manager.rs. This is the key scaling boundary for concurrent, stateful agents.
Driver HAL and Native/External Engines
Application logic depends on the InferenceDriver abstraction in ore-core/src/driver.rs, allowing backend selection without handler changes. ore-core/src/external/ollama.rs proxies a running Ollama daemon over HTTP. The native backend in ore-core/src/native/mod.rs uses Candle to load GGUF models, detect CPU/CUDA/Metal hardware, stream generation, and provide local embeddings; runtime model routing resides in ore-core/src/native/engine.rs. Native model implementations include Llama/Qwen and BERT/Nomic embedding architectures under ore-core/src/native/models/.
Agent Collaboration and Tool Execution
IPC provides direct per-agent message queues plus semantic-memory pipes backed by embeddings, shared caches, similarity search, TTL cleanup, and manifest-enforced pipe permissions. The server boundary is ore-server/src/handlers/ipc.rs; kernel implementation is ore-core/src/ipc.rs. Tool execution is separately routed through ore-core/src/sandbox.rs: precompiled WASM tools execute with Wasmtime fuel limits, capability-scoped filesystem mounts, trapped I/O, and manifest checks. Shell execution is an explicit unsafe bypass; network/tool policies remain manifest-controlled.
Client and External Infrastructure
The CLI communicates with the authenticated local daemon and handles initialization, model lifecycle, manifests, interactive chat, and WASM tool compilation. Its command surface is organized in ore-cli/src/cli.rs and interactive UI in ore-cli/src/interactive.rs. Material dependencies are Tokio/Axum for async server/streaming, Candle for local inference, Wasmtime/cap-std for sandboxing, Hugging Face Hub for native model downloads, and optional Ollama as an external local inference service.
Main entry points: inference.rs Inference API · registry.rs Policy Registry · src/main.rs ORE CLI · src/main.rs HTTP Daemon
Components 19
Client Access
- ORE CLI · Commands and interactive local workflows.
ore-cli/src/main.rs - Interactive UI
ore-cli/src/interactive.rs
Local Daemon
- HTTP Daemon · Authenticated local boundary for kernel access.
ore-server/src/main.rs - Auth Middleware
ore-server/src/middleware.rs - Inference API
ore-server/src/handlers/inference.rs - IPC API
ore-server/src/handlers/ipc.rs - Shared Kernel State · Configuration, selected driver, registry, and session state.
ore-server/src/state.rs
Kernel Core
- App Manifests · Per-application permissions, quotas, model, IPC, and tool policy.
manifests/openclaw.toml - Policy Registry · In-memory O(1) policy lookup.
ore-core/src/registry.rs - Prompt Firewall · Detects injection patterns and redacts PII before inference.
ore-core/src/firewall.rs - GPU Scheduler · RAII leases arbitrate active inference and model/context reuse.
ore-core/src/scheduler.rs - Agent Memory · Pages histories and KV state across RAM, VRAM, and SSD.
ore-core/src/memory.rs - Agent IPC · Queues, embedding-backed pipes, caches, and TTL cleanup.
ore-core/src/ipc.rs - Tool Sandbox · Wasmtime fuel and capability-scoped tool execution.
ore-core/src/sandbox.rs
Inference Backends
- Inference Driver HAL · Backend-independent inference interface.
ore-core/src/driver.rs - Native Candle Engine · Routes GGUF models across CPU, CUDA, or Metal.
ore-core/src/native/engine.rs - Ollama Proxy · HTTP proxy to an optional local Ollama daemon.
ore-core/src/external/ollama.rs - Ollama Daemon
Other components
- Rust Workspace
Cargo.toml
Connections 24
- Rust Workspace → ORE CLI: builds
- Rust Workspace → HTTP Daemon: builds
- ORE CLI → Interactive UI: hosts
- ORE CLI → HTTP Daemon: authenticated local HTTP
- HTTP Daemon → Auth Middleware: protects routes with
- Auth Middleware → Inference API: authorizes
- Auth Middleware → IPC API: authorizes
- HTTP Daemon → Shared Kernel State: initializes and shares
- App Manifests → Policy Registry: loaded into
- Shared Kernel State → Policy Registry: holds
- Inference API → Policy Registry: resolves caller policy
- Inference API → Prompt Firewall: filters prompts
- Inference API → Agent Memory: restores and persists state
- Inference API → GPU Scheduler: acquires lease
- GPU Scheduler → Inference Driver HAL: invokes
- Shared Kernel State → Inference Driver HAL: selects
- Inference Driver HAL → Native Candle Engine: native implementation
- Inference Driver HAL → Ollama Proxy: external implementation
- Ollama Proxy → Ollama Daemon: HTTP
- Agent Memory → GPU Scheduler: supplies restored context
- IPC API → Agent IPC: serves
- Agent IPC → Policy Registry: enforces pipe permissions
- Tool Sandbox → Policy Registry: enforces tool permissions
- ORE CLI → Tool Sandbox: compiles WASM tools