Capability-based security kernel for AI agents operating in large tool ecosystems
Project description
agent-kernel
A capability-based security kernel for AI agents operating in large tool ecosystems (MCP, A2A, 1000+ tools).
30-second pitch
Modern AI agents face three hard problems when given access to hundreds or thousands of tools:
- Context blowup — raw tool output floods the LLM context window.
- Tool-space interference — agents accidentally invoke the wrong tool or escalate privileges.
- No audit trail — there's no record of what ran, when, and why.
agent-kernel solves all three with a thin, composable layer that sits above your tool execution layer:
- Capability Tokens — HMAC-signed, time-bounded, principal-scoped. No token → no execution.
- Policy Engine — READ/WRITE/DESTRUCTIVE safety classes + PII/PCI sensitivity handling.
- Context Firewall — raw driver output is never returned to the LLM; always a bounded
Frame. - Audit Trail — every invocation creates an
ActionTraceretrievable viakernel.explain().
Architecture
graph LR
LLM["LLM / Agent"] -->|goal| K["Kernel"]
K -->|search| REG["Registry"]
K -->|evaluate| POL["Policy Engine"]
K -->|sign| TOK["HMAC Token"]
K -->|route| DRV["Driver (MCP/HTTP/Memory)"]
DRV -->|RawResult| FW["Context Firewall"]
FW -->|Frame| LLM
K -->|record| AUD["Audit Trace"]
Quickstart
pip install weaver-kernel
Note: The PyPI package is
weaver-kernel(Weaver ecosystem), but the Python import remainsagent_kernel.
import asyncio, os
os.environ["AGENT_KERNEL_SECRET"] = "my-secret"
from agent_kernel import (
Capability, CapabilityRegistry, HMACTokenProvider,
InMemoryDriver, Kernel, Principal, SafetyClass, StaticRouter,
)
from agent_kernel.drivers.base import ExecutionContext
from agent_kernel.models import CapabilityRequest
# 1. Register a capability
registry = CapabilityRegistry()
registry.register(Capability(
capability_id="tasks.list",
name="List Tasks",
description="List all tasks",
safety_class=SafetyClass.READ,
tags=["tasks", "list"],
))
# 2. Wire up a driver
driver = InMemoryDriver()
driver.register_handler("tasks.list", lambda ctx: [{"id": 1, "title": "Buy milk"}])
# 3. Build the kernel
kernel = Kernel(registry=registry, router=StaticRouter(routes={"tasks.list": ["memory"]}))
kernel.register_driver(driver)
async def main():
principal = Principal(principal_id="alice", roles=["reader"])
# 4. Discover → grant → invoke → expand → explain
token = kernel.get_token(
CapabilityRequest(capability_id="tasks.list", goal="list tasks"),
principal, justification="",
)
frame = await kernel.invoke(token, principal=principal, args={})
print(frame.facts) # ['Total rows: 1', 'Top keys: id, title', ...]
print(frame.handle) # Handle(handle_id='...', ...)
expanded = kernel.expand(frame.handle, query={"limit": 1, "fields": ["title"]})
print(expanded.table_preview) # [{'title': 'Buy milk'}]
trace = kernel.explain(frame.action_id)
print(trace.driver_id) # 'memory'
asyncio.run(main())
Where it fits
┌─────────────────────────────────────────────┐
│ LLM / Agent loop │
├─────────────────────────────────────────────┤
│ agent-kernel ← you are here │
│ (registry · policy · tokens · firewall) │
├────────────────┬────────────────────────────┤
│ contextweaver │ tool execution layer │
│ (context │ (MCP · HTTP · A2A · │
│ compilation) │ internal APIs) │
└────────────────┴────────────────────────────┘
agent-kernel sits above contextweaver (context compilation) and above raw tool execution. It provides the authorization, execution, and audit layer.
Weaver Spec Compatibility: v0.1.0
agent-kernel is a compliant implementation of weaver-spec v0.1.0. The following invariants are satisfied:
| Invariant | Description | How agent-kernel satisfies it |
|---|---|---|
| I-01 | LLM never sees raw tool output by default | Context Firewall always transforms RawResult → Frame; raw driver output is not returned by default, and non-admin principals cannot obtain raw response mode |
| I-02 | Every execution is authorized and auditable | PolicyEngine authorizes at grant time; a valid CapabilityToken (HMAC-verified on every invoke()) carries the authorization decision; TraceStore records every ActionTrace |
| I-06 | CapabilityTokens are scoped | Tokens bind principal_id + capability_id + constraints with an explicit TTL; revoke(token_id) / revoke_all(principal_id) are supported |
See docs/agent-context/invariants.md for the full internal invariant list and weaver-spec INVARIANTS.md for the specification.
Security disclaimers
v0.1 is not production-hardened for real authentication.
- HMAC tokens are tamper-evident (SHA-256) but not encrypted. Do not put sensitive data in token fields.
- Set
AGENT_KERNEL_SECRETto a strong random value in production. If unset, a random dev secret is generated per-process with a warning. - PII redaction is heuristic (regex). It is not a substitute for proper data governance.
- See docs/security.md for the full threat model.
Documentation
Development
git clone https://github.com/dgenio/agent-kernel
cd agent-kernel
pip install -e ".[dev]"
make ci # fmt + lint + type + test + examples
License
Apache-2.0 — see LICENSE.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file weaver_kernel-0.5.0.tar.gz.
File metadata
- Download URL: weaver_kernel-0.5.0.tar.gz
- Upload date:
- Size: 77.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c3a2efb4c0ad63b0aab54c04b8e66659e13fc6676f5b823a8c961b58615c6d58
|
|
| MD5 |
b94d043fc3e74097638a27faa3a55074
|
|
| BLAKE2b-256 |
00f8747d9084e9357d33469eac627259428489c6d7f83a7172baee4b6a276cc5
|
Provenance
The following attestation bundles were made for weaver_kernel-0.5.0.tar.gz:
Publisher:
publish.yml on dgenio/agent-kernel
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
weaver_kernel-0.5.0.tar.gz -
Subject digest:
c3a2efb4c0ad63b0aab54c04b8e66659e13fc6676f5b823a8c961b58615c6d58 - Sigstore transparency entry: 1280750002
- Sigstore integration time:
-
Permalink:
dgenio/agent-kernel@bc677b4044f41577c4600c2e99cf077a1f018c45 -
Branch / Tag:
refs/tags/v0.5.0 - Owner: https://github.com/dgenio
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@bc677b4044f41577c4600c2e99cf077a1f018c45 -
Trigger Event:
push
-
Statement type:
File details
Details for the file weaver_kernel-0.5.0-py3-none-any.whl.
File metadata
- Download URL: weaver_kernel-0.5.0-py3-none-any.whl
- Upload date:
- Size: 48.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
27d91747b917685bd88e26d0905899bdc252d391d111d0782df2b3c033450318
|
|
| MD5 |
30707d2d0f0ddfe9cd80107ac7675f04
|
|
| BLAKE2b-256 |
77e2007520ff35bb82c92f297e1f8bf2c010064e84d86b41625539d54af4e309
|
Provenance
The following attestation bundles were made for weaver_kernel-0.5.0-py3-none-any.whl:
Publisher:
publish.yml on dgenio/agent-kernel
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
weaver_kernel-0.5.0-py3-none-any.whl -
Subject digest:
27d91747b917685bd88e26d0905899bdc252d391d111d0782df2b3c033450318 - Sigstore transparency entry: 1280750004
- Sigstore integration time:
-
Permalink:
dgenio/agent-kernel@bc677b4044f41577c4600c2e99cf077a1f018c45 -
Branch / Tag:
refs/tags/v0.5.0 - Owner: https://github.com/dgenio
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@bc677b4044f41577c4600c2e99cf077a1f018c45 -
Trigger Event:
push
-
Statement type: