KelvinClaw is a Rust, interface-first agent runtime that mirrors KelvinClaw's core architecture patterns:
- run acceptance + async completion (
agent/agent.waitstyle) - per-session serialized execution lanes
- lifecycle + assistant + tool event streams
- pluggable memory backend with fallback behavior
- strict trait boundaries so implementations are swappable
The intent is to keep the "brains" (orchestration and contracts) stable while enabling plug-and-play implementations for memory, models, tools, sessions, and delivery surfaces.
- Contracts first: behavior is defined by traits in
kelvin-core. - Composition over inheritance: runtime behavior is assembled via dependency injection.
- Deterministic orchestration: session-lane serialization avoids race conditions.
- Failure containment: optional fallback managers prevent hard failures when a primary backend is unavailable.
- Small surface area: each crate has a focused responsibility and clear boundaries.
- Minimal core: provider/runtime specifics belong outside core contracts.
- docs/KELVIN_CORE_SDK.md
- docs/CORE_ADMISSION_POLICY.md
- docs/SDK_PRINCIPLES.md
- docs/trusted-executive-wasm.md
- docs/memory-control-data-plane.md
- docs/memory-rpc-contract.md
- docs/memory-module-sdk.md
- docs/memory-controller-deployment-profiles.md
Use these as merge criteria when deciding whether logic belongs in core or in extensions.
crates/kelvin-core: domain models and interfaces.crates/kelvin-memory-api: protobuf schema + generated gRPC contracts.crates/kelvin-memory-client: RPC adapter implementingMemorySearchManager.crates/kelvin-memory-controller: memory data plane gRPC service + WASM sandbox runtime.crates/kelvin-memory-module-sdk: module ABI constants and WIT contracts.crates/kelvin-memory: transitional in-process memory backends (deprecated for root composition).crates/kelvin-brain: agent loop orchestration implementation.crates/kelvin-wasm: trusted host runtime for loading untrusted WASM skills.apps/kelvin-host: thin SDK host executable.
Defined in kelvin-core:
Brain- single-run orchestration boundary
MemorySearchManagersearch,read_file,status,sync, probe methods
ModelProvider- model inference boundary
ToolandToolRegistry- tool invocation and discovery
PluginFactoryandPluginRegistry- plugin declaration, compatibility checks, and registration
SdkToolRegistry- validated projection from plugin metadata into runtime
ToolRegistry
- validated projection from plugin metadata into runtime
CoreRuntimeandRunRegistry- run lifecycle (
accepted -> running -> completed|failed) and wait semantics
- run lifecycle (
SessionStore- transcript/session persistence boundary
EventSink- stream/event emission boundary
These traits are the architecture's stable API.
KelvinBrain orchestrates one run end-to-end:
- Validate request.
- Emit lifecycle start.
- Ensure session record and persist user prompt.
- Assemble context (history + memory recall).
- Invoke model provider.
- Emit assistant event(s).
- Execute tool calls and emit tool events.
- Persist assistant/tool transcript entries.
- Emit lifecycle end or error.
CoreRuntime provides asynchronous run handling:
submitreturns immediate acceptance metadata.- run executes in a background task.
- run state is persisted in
RunRegistry. - caller can inspect state and
waitfor completion with timeout.
LaneScheduler ensures per-session serialization.
Control/Data split:
- Root (control plane) calls memory over gRPC through
RpcMemoryManager. - Memory Controller (data plane) re-validates JWT delegation claims and executes WASM memory modules.
- Module access is bounded by manifest capabilities, delegation claims, and enabled provider features.
Backends:
MarkdownMemoryManager- source-of-truth Markdown files (
MEMORY.md,memory/**/*.md) - scoped reads and graceful missing-file behavior
- source-of-truth Markdown files (
InMemoryVectorMemoryManager- in-memory token-overlap retrieval backend
FallbackMemoryManager- delegates to primary; on failure, flips to fallback backend
Selection:
MemoryFactorybuilds backend byMemoryBackendKindfor migration/fallback only.
WasmSkillHost executes untrusted WebAssembly modules with explicit capability boundaries:
- exports expected from skill modules:
run() -> i32 - host ABI imports exposed under
claw::*(for examplesend_message,move_servo) SandboxPolicycontrols which privileged imports are linked- denied capabilities fail module instantiation before skill execution
- module size and fuel budget limits are enforced for DoS resistance
kelvin-wasm-runner provides a minimal host CLI for executing skill binaries with policy presets.
installed_plugins provides a secure loader for prebuilt SDK plugin packages under ~/.kelvinclaw/plugins (or configured plugin home):
- runtime loader for installed
wasm_tool_v1plugins - execution bridge via SDK (
InMemoryPluginRegistry->SdkToolRegistry-> runtimeToolRegistry) - supply-chain trust verification (
plugin.sigEd25519 against trusted publisher keys) - trust policy revocation and plugin->publisher pinning enforcement
- scoped capability enforcement (
capability_scopes.fs_read_paths,capability_scopes.network_allow_hosts) - operational controls (
timeout_ms,max_retries, rate limit, circuit breaker)
This keeps plugin execution out of Kelvin root code compilation while preserving host-side policy enforcement.
First-party CLI plugin path:
- installable first-party plugin artifacts are hosted in
agentichighway/kelvinclaw-plugins. apps/kelvin-hostcallskelvin-sdk, which requires installed toolkelvin_clibefore each run.
apps/kelvin-hostparses input and callskelvin_sdk::run_with_sdk(...).- SDK loads installed plugins and requires tool
kelvin_cli. - SDK runs
kelvin_clipreflight, then constructsCoreRuntime. CoreRuntimesubmits run state and executesKelvinBrain.- Events stream through
EventSink. - Run completion/failure is stored in
RunRegistry. - Caller waits for final status/outcome.
AgentEventData stream types:
lifecycle(start | end | error)assistant(delta/final chunks)tool(start | end | error)
This aligns with KelvinClaw-style stream channels while remaining transport-agnostic.
Swap backend by changing one composition value (MemoryBackendKind) without touching orchestration logic.
Replace Arc<dyn ModelProvider> to support different provider implementations.
Register tools through ToolRegistry; SdkToolRegistry can compose this directly from SDK plugin registrations with fail-fast validation.
Kelvin also ships a first-party default SDK tool-pack plugin set (fs_safe_read, fs_safe_write, web_fetch_safe, schedule_cron, session_tools) with explicit sensitive-operation approvals.
Swap SessionStore for file/db/remote persistence.
Swap EventSink for stdout, in-memory capture, websocket bridge, etc.
- brain-level timeout can fail a run with
KelvinError::Timeout - runtime wait timeout returns
WaitStatus::Timeoutwithout forcing run cancellation - fallback memory manager degrades gracefully when primary backend fails
Current tests validate architecture behavior over implementation details:
- session-lane serialization for concurrent runs
- run wait timeout semantics
- result completion retrieval
- memory backend swap behavior
- memory fallback behavior
- graceful missing memory file reads
Implemented:
- trait-oriented architecture and crate boundaries
- KelvinClaw-style run/event/memory seams
- swappable backends and adapters
- remote test workflow
- dynamic installed plugin loading with trust/scoping/operational guardrails
- first-party SDK tool pack and tool execution receipts (
who/what/why/result_class) - websocket gateway control plane (
apps/kelvin-gateway) with connect/auth/idempotent run submission - SDK model failover chains with bounded retries and fail-closed non-retryable errors
- multi-channel gateway lane (
telegram,slack,discord) with channel-specific policy controls - deterministic channel routing rules by channel/account/workspace/session
- channel conformance tests (ordering/idempotency/auth mismatch/flood handling)
- optional WASM channel ingress policy ABI (
kelvin_channel_host_v1)
Not yet implemented:
- additional channel integrations beyond telegram/slack/discord and richer operator UI surfaces
- provider credential profile routing trees for non-channel model lanes
- full compaction/retry pipelines
- Local remote-test helper:
scripts/remote-test.sh - Remote host can be provided by
--hostorREMOTE_TEST_HOST(including.envconvenience loading) - Build/test can run natively on ARM64 EC2 or inside Docker mode