The governance layer for multi-agent swarms. Stop your AI agents from deleting your files, escaping their workspace, and gaslighting each other.
You run 3+ AI coding agents โ Claude Code, Cursor, OpenCode, Codex, Kimiโฆ They talk to you. They don't talk to each other. And they have no rules about what they can touch.
CrewAI / LangGraph / Ruflo answer "how do agents execute tasks together." KAF answers "how do you stop agents from wrecking your machine."
It's not an orchestrator. It's the constitution + runtime guardrail that sits under any orchestrator.
- An agent
rm -rf'd a folder it shouldn't have. Gone. No backup. - An agent dropped 47 temp files across your
C:\drive. - An agent overwrote
constitution.json. Your rules vanished. - Two agents read each other's private memory. Context contaminated.
- Something broke at 2 AM. No script, no log. Nobody knows what happened.
KAF was forged inside a real 6-agent cluster (WorkBuddy + OpenCode + Claude + Kimi + Cursor) running daily for 3 months. We lost 2000+ map assets to one irreversible delete before we built the guardrails.
KAF is the scar tissue. MIT-licensed, so you don't have to bleed for it.
Every action an agent takes must be:
| Principle | What it means in code | |
|---|---|---|
| 5 | Traceable | Every op has a script + log entry (kaf_operations.log) |
| 2 | Recoverable | Deletes go to recycle bin; configs are backed up first |
| 0 | Fixable | On failure, on_failure() hands you rollback options |
| + | Evolvable | Good workflows auto-crystallize into reusable Skills |
Three Iron Laws โ violations are blocked at runtime, not just warned:
- ๐ Law 8 โ Destructive ops (
rm/mv/copy) MUST come from a script, then be verified. - ๐ Law 9 โ Any number written to memory MUST be verified against the filesystem.
- ๐ Law 10 โ Before deleting, the agent MUST show the full file list and get your confirmation.
$ python kaf.py guard
pre:delete โ ้ๅพ10๏ผๅ ้คๅๅฑ็คบๆธ
ๅ+็จๆท็กฎ่ฎค
pre:destructive_op โ ้ๅพ8๏ผ็ ดๅๆงๆไฝๅฟ
้กปๆ่ๆฌ
post:write_memory โ ้ๅพ9๏ผ่ฎฐๅฟๆฐๅญๅฎๅฐๆ ธๆฅ
startup โ ่ฎฐๅฟๅฎๆดๆง๏ผๆ็บนๆ ก้ชfrom guard520 import Guard520
guard = Guard520("constitution.json")
guard.pre_execute({"type": "rm", "target": "D:/x"})
# โ block: ้ๅพ8่ฟ่ง๏ผrm ๆไฝๆ ่ๆฌ
guard.pre_delete({"type": "rm", "target": "constitution.json"})
# โ block: ้ๅพ10่ฟ่ง๏ผๆชๅฑ็คบๆธ
ๅ/ๆช่ท็กฎ่ฎคใๅพ
ๅ 1้กน
guard.pre_execute({"type": "rm", "target": "D:/x", "script": "clean.py", "verified": True})
# โ okNo config, no --force, no "are you sure?" bypass. The guard returns BLOCK and writes it to the log.
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Platform Adapters (WorkBuddy/Claude/...) โ 5 lines of code to plug in
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ Coordinator Protocol (Prime Minister rotate)โ who's in charge, right now
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ 520 Runtime Guard (4 checkpoints) โ blocks Law 8/9/10 violations
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ Constitution-as-Code (JSON, machine-readable)โ rules you can diff & CI-test
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ Memory Integrity (SHA-256 fingerprint) โ detect unauthorized drift
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Why JSON, not a markdown doc? So your constitution can be parsed, diffed, and CI-tested โ not just read.
git clone https://github.com/lsjpp2/king-agent-swarm.git
cd king-agent-swarm/kaf
python kaf.py init # generate constitution.json + register memory fingerprints
python kaf.py check # 520 self-check โ โ
PASS
python kaf.py verify # memory integrity (fingerprint + drift detect)
python kaf.py status # who's the current Prime MinisterReal kaf check output on a fresh cluster:
==================================================
KAF 520 ่ชๆฃ
==================================================
โ
traceable: ๆฅๅฟ่ฎฐๅฝ่ฝๅ: ๅฐฑ็ปช | ๆฅๅฟๆไปถ: ๅพ
็ๆ๏ผ้ฆๆฌก่ฟ่กๆญฃๅธธ๏ผ
โ
recoverable: ๅ ้คๆไฝ่ตฐๅๆถ็ซ(FOF_ALLOWUNDO)
โ
fixable: on_failureๆไพๅๆปๆนๆก
โ
evolvable: skill็ฎๅฝ: .../.workbuddy/skills (25ไธชskill)
ๆปไฝ: PASS
Your governance is a JSON file, not a vibe:
{
"rule_520": {
"enabled": true,
"immutable": true,
"note": "ๅฐฑ็ฎไธ็็ญไบก๏ผ่ฟไธชๆ ๅไธ่ฝไธข",
"iron_laws": {
"law_8": "script_then_execute_then_verify",
"law_9": "verify_any_number_in_memory",
"law_10": "show_list_before_delete"
}
},
"rules": [
{ "id": "delete_auth", "trigger": "pre:delete",
"require": "user_confirm", "irreversible_action": "warn_and_block" },
{ "id": "path_discipline", "trigger": "pre:write",
"allow_only": "{{workspace}}/**",
"blocked_zones": ["Desktop", "Documents", "Downloads", "system_root"] }
]
}Path discipline alone stops ~90% of "why is my Desktop full of agent junk" incidents.
| KAF | CrewAI / LangGraph | RuFlo | AutoGen | |
|---|---|---|---|---|
| Layer | Governance (how to rule agents) | Orchestration (how to run tasks) | Homogeneous swarm | Conversation orchestration |
| Dangerous-op guard | โ runtime BLOCK | โ | โ | โ |
| Path discipline | โ built-in | โ | โ | โ |
| Memory isolation walls | โ | โ | โ | |
| Constitution-as-Code | โ JSON, CI-testable | โ | โ | โ |
| Heterogeneous agents | โ Claude+Cursor+โฆ+ | โ (Claude-only) | ||
| Platform-agnostic | โ adapter SDK | varies | โ |
KAF doesn't replace them. It governs them. Drop it under any orchestrator.
from adapters.base import PlatformAdapter
class MyAdapter(PlatformAdapter):
platform_name = "my_platform"
def read_constitution(self): ...
def read_memory(self, key=None): ...
def write_memory(self, key, value, protect_check=True): ...
def register_hook(self, event, callback): ...
def execute(self, action): ...
def get_agent_id(self): ...
def get_workspace(self): ...The WorkBuddy adapter ships in-box. Claude / Cursor / OpenCode adapters are doc-based (adapters/*.md). Full SDK in kaf/adapters/.
king-agent-swarm/
โโโ kaf/ # โ
KAF v5.0 core (this is the framework)
โ โโโ constitution.json # declarative constitution (machine-readable)
โ โโโ guard520.py # 520 runtime guard โ 4 checkpoints
โ โโโ memory_integrity.py # SHA-256 fingerprint + drift detection
โ โโโ coordinator.json # Prime Minister registry (rotate / vote)
โ โโโ kaf.py # CLI: init / check / verify / guard / rotate / status
โ โโโ adapters/ # platform SDK (base / workbuddy / template)
โ โโโ README.md # deep dive (ไธญๆ + English)
โโโ templates/ # coordination-protocol layer (v1, config-only)
โโโ docs/ # architecture / quick-start / principles / faq
โโโ adapters/ # per-platform injection guides (.md)
โโโ diagrams/ # SVG architecture diagrams
โโโ examples/ # minimal 3-agent & 6-agent clusters
KAF is the engine; templates/ + docs/ + diagrams/ form the coordination-protocol layer โ the v1 "King / Prime Minister / Swarm" metaphor that KAF grew out of.
PRs, issues, and war stories welcome. See CONTRIBUTING.md.
Even the governance is governed: user_feedback โ coordinator_evaluate โ king_confirm โ merge.
MIT โ see LICENSE.