agent-kernel is a capability-based security kernel that sits above raw tool execution (MCP, HTTP APIs, internal services) and below the LLM context window.
graph TD
LLM["LLM / Agent"] -->|goal text| K["Kernel"]
K -->|search| REG["CapabilityRegistry"]
REG -->|CapabilityRequest| K
K -->|evaluate| POL["PolicyEngine"]
POL -->|PolicyDecision| K
K -->|issue| TOK["TokenProvider (HMAC)"]
TOK -->|CapabilityToken| K
K -->|route| ROU["Router"]
ROU -->|RoutePlan| K
K -->|execute| DRV["Driver (Memory / HTTP / MCP)"]
DRV -->|RawResult| K
K -->|transform| FW["Firewall"]
FW -->|Frame| K
K -->|store| HS["HandleStore"]
K -->|record| TS["TraceStore"]
K -->|Frame| LLM
The central orchestrator. Wires all components together and exposes five methods:
request_capabilities(goal)— discover relevant capabilitiesgrant_capability(request, principal, justification)— policy check + token issuanceinvoke(token, principal, args, response_mode)— execute + firewall + traceexpand(handle, query)— paginate/filter stored resultsexplain(action_id)— retrieve audit trace
A flat dict of Capability objects indexed by capability_id. Provides keyword-based search (no LLM, no vector DB — purely token overlap scoring).
The DefaultPolicyEngine implements role-based rules:
- READ — always allowed
- WRITE — requires
justification ≥ 15 chars+ rolewriter|admin - DESTRUCTIVE — requires role
admin - PII/PCI — requires
tenantattribute; enforcesallowed_fieldsunlesspii_reader - max_rows — 50 (user), 500 (service)
Issues HMAC-SHA256 signed tokens. Each token is bound to principal_id + capability_id + constraints. Verification checks: expiry → signature → principal → capability.
StaticRouter maps capability_id → [driver_id, ...]. First driver that succeeds wins; others are tried as fallbacks.
- InMemoryDriver — Python callables, used for tests and demos
- HTTPDriver —
httpx-based async HTTP client - (Future) MCPDriver — adapter for Model Context Protocol tool servers
Transforms RawResult → Frame. Never exposes raw output to the LLM.
- Four response modes:
summary,table,handle_only,raw - Enforces
Budgets(max_rows, max_fields, max_chars, max_depth) - Redacts sensitive fields and inline PII patterns
- Deterministic summarisation (no LLM)
Stores full results by opaque handle ID with TTL. expand() supports pagination, field selection, and basic equality filtering.
Records every ActionTrace. explain(action_id) returns the full audit record.