agent-kernel
AGENTS.md2 starsChanged 3 months agoApache-2.0View on GitHub
This is the canonical source of truth for AI coding agents working in this repository. Tool-specific instruction files (.github/copilot-instructions.md, .claude/CLAUDE.md) reference this file and add only tool-specific guidance. agent-kernel is part of the Weaver ecosystem: - weaver-spec — formal specification with invariants - contextweaver — context compilation library - ChainWeaver — orchestration layer This repo must conform to weaver-spec invariants. Key invariants (all equally critical): - I-01: Every tool output must pass through a context boundary before reaching the LLM.…
Where files are headingNew AGENTS.md files have more rules about keeping secrets out of the code, and fewer about checking a change actually works.
Of the AGENTS.md files we read, the 11,773 first seen in the last six months, against the older ones: the kind of rule that gained most share, and the kind that lost most. About files like this in general, not this one, and an estimate, since a kind is a pattern in the words.
In this repository2 other files it gives its agents.
- .claude/CLAUDE.mdCLAUDE.md
- .github/copilot-instructions.mdCopilot instructions
The file
Show its rules and text
We split this AGENTS.md into the rules it gives an agent
18 rules. About 1 is common, 9 are distinctive, and 8 are very specific to this project.
≈1
Common · estimate
Many files like this have a rule of this kind.
≈9
Distinctive · estimate
This author's own choices. Worth a look.
8
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 29
I-01: Every tool output must pass through a context boundary before reaching the LLM.
- Distinctive: line 30
I-02: Every execution must be authorized and auditable (preceded by a policy decision, followed by a trace event).
- Distinctive: line 40
Use these terms consistently.
- Distinctive: line 52
All public interfaces need type hints and docstrings.
- Very specific: line 53
Never raise bare ValueError or KeyError to callers.
- Very specific: line 55
Keep modules ≤ 300 lines. Split if needed.
- Distinctive: line 63
No randomness in matching, routing, or summarization.
- Very specific: line 64
No new dependencies without justification.
- Common: line 87
Never log or print secret key material.
- Distinctive: line 91
Never bypass token verification before capability invocation.
- Distinctive: line 94
No duplicate capability IDs in the registry.
- Very specific: line 111
Use FirewallError for exceptions.
- Very specific: line 114
Every module has a corresponding test file (kernel.py → test_kernel.py).
- Distinctive: line 118
Prefer offline. Network examples OK only with a clear fallback.
- Very specific: line 124
Update CHANGELOG.md in the same PR when adding features or fixes.
- Very specific: line 133
Add integration tests in tests/test_drivers.py.
- Very specific: line 142
If adding a new SensitivityTag, you must also add a corresponding policy rule — otherwise the tag is silently ignored.
- Distinctive: line 147
Before submitting a PR, verify:
≈ “Common” is an estimate: at least 1 in 5 of the 16,595 AGENTS.md files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
AGENTS.md — AI Agent Instructions
This is the canonical source of truth for AI coding agents working in this repository.
Tool-specific instruction files (.github/copilot-instructions.md, .claude/CLAUDE.md)
reference this file and add only tool-specific guidance.
Repo layout
src/weaver_kernel/ — library source (one module per concern, ≤300 lines each)
drivers/ — capability drivers (one file per driver)
firewall/ — context firewall (redaction, summarization, budgets)
stores/ — pluggable persistence (SQLite/JSONL) + verifiable audit chain
cli/ — `weaver-kernel` console entry point (audit, doctor)
tests/ — pytest suite (one test file per module)
examples/ — runnable demos (prefer offline; network OK with fallback)
docs/ — reference documentation
docs/agent-context/ — deeper agent guidance (architecture, workflows, invariants)Weaver ecosystem
agent-kernel is part of the Weaver ecosystem:
- weaver-spec — formal specification with invariants
- contextweaver — context compilation library
- ChainWeaver — orchestration layer
This repo must conform to weaver-spec invariants. Key invariants (all equally critical):
- I-01: Every tool output must pass through a context boundary before reaching the LLM.
- I-02: Every execution must be authorized and auditable (preceded by a policy decision, followed by a trace event).
- I-06: Tokens must bind principal + capability + constraints; no reuse across principals.
Note: Budget enforcement (size, depth, field count) is an agent-kernel implementation constraint that satisfies I-01 — it is not a separate weaver-spec invariant number.
Full spec: dgenio/weaver-spec
Domain vocabulary
Use these terms consistently. Never substitute synonyms:
| Term | Means | Not |
| capability | a registered, auditable action | tool, function, API |
| principal | the identity invoking a capability | agent, user, caller |
| grant | a policy-approved token issuance | permission, access |
| Frame | the bounded, redacted result returned to the LLM | response, output |
Quality bar
make cimust pass before every push. It runs:fmt-check → lint → type → test → example. Usemake fmtto auto-fix formatting before re-runningmake ci.- All public interfaces need type hints and docstrings.
- Never raise bare
ValueErrororKeyErrorto callers. Use custom exceptions fromerrors.py. Catching stdlib exceptions internally to remap them is fine. - Error messages are part of the contract — tests must assert both exception type and message.
- Keep modules ≤ 300 lines. Split if needed. Enforced by
tests/test_architecture.py(over-budget files are pinned with a shrink-only ceiling; new files must be ≤ 300). - All
__all__exports need a Google-style docstring (Args:for functions with parameters). Enforced bytests/test_docstrings.py. - Branch coverage must stay at or above the
fail_underfloor inpyproject.toml(make testfails otherwise). The floor is a ratchet — only raise it. - No randomness in matching, routing, or summarization. Deterministic outputs always.
- No new dependencies without justification. The runtime dep list is
intentionally minimal (
httpx,pydantic); a CI job installs with no extras to prove it. Optional features live behind extras (mcp,otel,policy,tiktoken,conformance).
Architectural conformance
tests/test_architecture.py mechanically enforces the layering below (stdlib
ast only — no architecture tool). Module-scope imports are checked; lazy
imports inside functions and TYPE_CHECKING blocks are exempt (that is the
optional-extra seam).
| Layer | May import (within the package) |
firewall/ | models, errors, enums only — never execution/policy/registry |
drivers/ | models, errors, enums only |
router | models only (stateless dispatch) |
models | enums, errors only |
enums, errors | nothing else in the package (leaves) |
kernel/ and everything else | unconstrained (the kernel is the orchestrator) |
Security rules
- Never log or print secret key material.
- HMAC secrets come from
WEAVER_KERNEL_SECRETenv var; fallback to a random dev secret with a logged warning. - Tokens are HMAC-signed but not encrypted. Never store secrets in token payloads.
- Confused-deputy prevention: tokens bind
principal_id + capability_id + constraints. - Never bypass token verification before capability invocation.
- Firewall always transforms
RawResult → Frame. Raw driver output never reaches the LLM. - Non-admin principals never get
rawresponse mode. The Firewall downgrades tosummary. - No duplicate capability IDs in the registry.
See docs/agent-context/invariants.md for the full "never do" list and security traps.
Code conventions
All modules (src/weaver_kernel/):
Relative imports. Dataclasses with slots=True. Protocols for interfaces.
__all__ in every __init__.py. Google-style docstrings.
CamelCase for classes, snake_case for functions. Error classes end with Error.
Drivers (drivers/):
One file per driver. Driver Protocol in base.py. Async execute() method.
Driver classes end with Driver. Use DriverError for exceptions.
Firewall (firewall/):
Pure functions for redaction and summarization. Firewall class in transform.py orchestrates.
Use FirewallError for exceptions.
Tests (tests/):
Every module has a corresponding test file (kernel.py → test_kernel.py).
Conftest fixtures only for cross-test reuse (≥2 test files). Local helpers otherwise.
Examples (examples/):
Prefer offline. Network examples OK only with a clear fallback.
Workflow
- One logical change per PR. Squash-merge. Conventional commit titles (
feat:,fix:,test:,docs:). make ciis the single authoritative pre-push command.- Update
CHANGELOG.mdin the same PR when adding features or fixes. - Code is authoritative over docs. Fix stale docs when you spot discrepancies.
See docs/agent-context/workflows.md for full details.
Adding a capability driver
- Implement the
Driverprotocol insrc/weaver_kernel/drivers/. - Register it with
StaticRouteror implement a customRouter. - Add integration tests in
tests/test_drivers.py.
See docs/integrations.md for MCP and HTTP examples.
Adding a policy rule
- Implement the condition in the appropriate
default_policy_*_rules.pyhelper. - Register it exactly once in the ordered
_DEFAULT_RULEStuple indefault_policy_rules.py; bothevaluate()andexplain()consume that chain. - Placement matters: rules are evaluated in order. A new rule placed before sensitivity checks can change which denial short-circuits first.
- If adding a new
SensitivityTag, you must also add a corresponding policy rule — otherwise the tag is silently ignored. - Cover decision/explanation agreement in
tests/test_policy_rule_chain.pyand behavior intests/test_policy.py.
Review checklist (beyond make ci)
Before submitting a PR, verify:
- Docstrings and descriptions match the actual implementation.
- Security edge cases handled (whitespace-only justification, truncated JSON, bare
int()on untrusted input). - No dead or unused code (parameters, fixtures, helpers).
- No backward compatibility breaks (e.g., adding required methods to a Protocol).
- Naming consistent across docs and code (use capability, principal, grant, Frame — never synonyms).
See docs/agent-context/review-checklist.md for the full checklist.
Documentation map
| Topic | Canonical source |
| Architecture & design intent | docs/agent-context/architecture.md |
| Components & API reference | docs/architecture.md |
| Security model & threats | docs/security.md |
| Hard invariants & forbidden shortcuts | docs/agent-context/invariants.md |
| Workflow rules & commands | docs/agent-context/workflows.md |
| Recurring mistakes | docs/agent-context/lessons-learned.md |
| Review & self-check | docs/agent-context/review-checklist.md |
| Driver integration patterns | docs/integrations.md |
| Capability design conventions | docs/capabilities.md |
| Context firewall details | docs/context_firewall.md |
| Action trace export contract | docs/trace_export.md |
Command-line interface (weaver-kernel) | docs/cli.md |
Update policy
Code is authoritative. When docs contradict code, fix the docs. Each topic has one canonical source (see table above). Update the canonical source; do not create parallel guidance elsewhere.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

