Skip to content
Core Concepts

Kova Core Concepts

From Agent, Workflow, and Swarm to WAL persistence — understand Kova’s core architecture components and design philosophy.

3μsscheduling latency
315Kops/s throughput
21workspace crates
<10MBsingle binary

Agent ​

An Agent is the basic unit of execution, composed of the following elements:

ElementDescription
System PromptSystem PromptA system prompt that defines the AI's role, capability boundaries, and behavioral rules. It goes first in the message array.Defines the Agent’s role, capability boundaries, and behavioral norms
ModelThe LLM model in use (switchable at runtime)
ToolsThe set of tools the Agent can invoke
MemoryThe Agent’s conversation history and persisted state

Agent Lifecycle ​

Agent State Machine
graph LR
  Created --> Idle
  Idle --> Running
  Running --> Completed
  Running --> Paused
  Running --> Failed
  Running --> Recovering
  Paused -.resume.-> Running
  Recovering -.replay WAL.-> Running
StateMeaning
IdleAgent created, awaiting a task
RunningExecuting a task
PausedManually paused, can be resumed
CompletedTask finished
FailedExecution failed (retry limit exceeded)
RecoveringDetected an incomplete WAL record, recovering automatically

Agent Decision Loop ​

Decision Loop
graph LR
  A[Receive task / previous result] --> B[LLM reasoning<br/>analyze + plan]
  B --> C{Tools needed?}
  C -->|Yes| D[Invoke tool] --> E[Tool result] --> B
  C -->|No| F[Generate final answer] --> G[Return result]

Every round is persisted to disk

Every decision round is written to the WAL, ensuring that after a crash execution can replay from the breakpoint without re-invoking the LLM.

Workflow ​

A Workflow orchestrates multiple Agents or steps into an ordered execution pipeline.

Step Types ​

TypeDescription
Agent stepDelegates execution to a specified Agent
Conditional branchChooses a different path based on the previous step’s result
Parallel stepMultiple steps execute simultaneously
Wait stepWaits for an external event or human approval
Loop stepRepeats execution until a condition is met

Data Passing ​

Steps pass data between one another via template variables:

{{input.topic}}              → 工作流输入参数
{{steps.research.output}}    → "research" 步骤的输出
{{steps.research.metadata}}  → "research" 步骤的元数据

Error Handling ​

Each step can be configured with its own error strategy:

StrategyBehavior
retryRetry N times (default 3, exponential backoff)
skipSkip the failed step and continue
abortTerminate the entire workflow
fallbackSwitch to a backup step

SwarmSwarmA swarm-intelligence pattern in which a coordinator assigns tasks to multiple agents that collaborate autonomously, with no predefined fixed workflow.Learn more → (Swarm Intelligence) ​

Swarm mode lets multiple Agents collaborate autonomously, without a predefined fixed process.

How It Works ​

Swarm Collaboration Flow
graph LR
  U[User task] --> C[Coordinator Agent]
  C --> S[Decompose subtasks]
  S --> R[Research Agent]
  S --> D[Coding Agent]
  S --> T[Testing Agent]
  R --> M[Collect results]
  D --> M
  T --> M
  M --> O[Synthesize output]

Agents communicate directly via the A2A (Agent-to-Agent)A2AThe Agent-to-Agent protocol, which lets multiple agents communicate directly, delegate tasks, and exchange information. protocol:

json
{
  "from": "coordinator",
  "to": "researcher",
  "type": "task_delegate",
  "payload": {
    "task": "调研 WebAssembly 在服务端的性能基准",
    "constraints": {
      "max_tokens": 2000,
      "deadline": "5min"
    }
  }
}

WALWALWrite-Ahead Log. Every state change is written to the log before it executes, ensuring recovery from the log after a crash.Learn more → (Write-Ahead Log) ​

The WAL is the core mechanism of Kova’s persistence, drawing on database system design.

Write Flow ​

WAL Write Flow
graph LR
  A[Agent state change] --> B[Serialize + CRC32<br/>compute checksum]
  B --> C[Write to WAL file<br/>log first]
  C --> D[Perform the actual operation]
  D --> E[Mark WAL complete<br/>confirm commit]

Recovery Flow ​

On startup, the WAL is scanned automatically to recover incomplete operations:

  1. Completed records — skip.
  2. CRC32 check failure — mark as corrupted and skip.
  3. Incomplete records — re-execute.

Ring BufferRing BufferA fixed-size circular storage structure. When the write pointer reaches the end it wraps around and overwrites old data; the WAL uses a power-of-2-sized ring buffer. ​

The WAL uses a power-of-2-sized ring buffer:

  • The write pointer wraps around automatically when it reaches the end
  • Confirmed old records are overwritten by new ones
  • Compaction is triggered when the buffer is full

Sync Modes ​

ModeDescriptionPerformanceDurability
normalThe operating system decides when to fsyncHighMay lose a few seconds of data
fullfsync on every writeLowZero data loss

Encryption Options ​

WAL encryption can be enabled for sensitive scenarios:

AlgorithmDescription
aes-256-gcmStandard AES-256 encryption
sm4Chinese national SM4 algorithm

HMAC integrity verification can also be enabled to prevent tampering with WAL files.


Lock Ordering ​

Kova internally uses a strict lock-acquisition order to fundamentally eliminate deadlocks:

Lock Acquisition Order
graph LR
  A[Buffer Lock] --> B[Queue Lock] --> C[Transaction Lock]

Compile-time deadlock prevention

All code paths must observe this order. Attempting to acquire locks in violation of the order triggers a compile-time check (guaranteed by Rust’s type system).

Tool System ​

Built-in Tools ​

ToolFunction
web_searchSearch the internet
file_readRead a file
file_writeWrite a file
http_requestSend an HTTP request
shell_execExecute a shell command (sandboxed environment)
db_queryQuery a database

MCP Tools ​

Connect to external tool services via the Model Context Protocol:

toml
# kova.toml
[[mcp.servers]]
name = "github"
command = "npx"
args = ["-y", "@modelcontextprotocol/server-github"]
env = { GITHUB_PERSONAL_ACCESS_TOKEN = "ghp_xxx" }

[[mcp.servers]]
name = "postgres"
command = "npx"
args = ["-y", "@modelcontextprotocol/server-postgres"]
env = { DATABASE_URL = "postgres://..." }

Agents can invoke MCP tools exactly as they would built-in tools.

A2A Protocol ​

The Agent-to-Agent communication protocol supports:

  • Task delegation: One Agent hands a subtask to another
  • Information query: Agents exchange information directly
  • Result notification: Notify the initiator once a task completes
  • Capability discovery: Query what other Agents can do

Feature Tiers ​

Kova uses Rust feature flags to control compilation scope. A minimal build needs only pure-rust, with layers added as needed: serde (serialization), workflow (workflow orchestration) → agent (Agent engine) → swarm (swarm intelligence), encrypt (encryption) → sm4 (Chinese national cryptography) / wal-hmac (integrity verification), and so on.


Next Steps ​

Next Steps

Powered by Lurus Technologies