agentleFS
dgeniodgenio/agent-kernel/AGENTS.md

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.

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
  1. Distinctive:

    I-01: Every tool output must pass through a context boundary before reaching the LLM.

    line 29
  2. Distinctive:

    I-02: Every execution must be authorized and auditable (preceded by a policy decision, followed by a trace event).

    line 30
  3. Distinctive:

    Use these terms consistently.

    line 40
  4. Distinctive:

    All public interfaces need type hints and docstrings.

    line 52
  5. Very specific:

    Never raise bare ValueError or KeyError to callers.

    line 53
  6. Very specific:

    Keep modules ≤ 300 lines. Split if needed.

    line 55
  7. Distinctive:

    No randomness in matching, routing, or summarization.

    line 63
  8. Very specific:

    No new dependencies without justification.

    line 64
  9. Common:

    Never log or print secret key material.

    line 87
  10. Distinctive:

    Never bypass token verification before capability invocation.

    line 91
  11. Distinctive:

    No duplicate capability IDs in the registry.

    line 94
  12. Very specific:

    Use FirewallError for exceptions.

    line 111
  13. Very specific:

    Every module has a corresponding test file (kernel.py → test_kernel.py).

    line 114
  14. Distinctive:

    Prefer offline. Network examples OK only with a clear fallback.

    line 118
  15. Very specific:

    Update CHANGELOG.md in the same PR when adding features or fixes.

    line 124
  16. Very specific:

    Add integration tests in tests/test_drivers.py.

    line 133
  17. Very specific:

    If adding a new SensitivityTag, you must also add a corresponding policy rule — otherwise the tag is silently ignored.

    line 142
  18. Distinctive:

    Before submitting a PR, verify:

    line 147

≈ “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.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
AGENTS.md

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:

TermMeansNot
capabilitya registered, auditable actiontool, function, API
principalthe identity invoking a capabilityagent, user, caller
granta policy-approved token issuancepermission, access
Framethe bounded, redacted result returned to the LLMresponse, output

Quality bar

  • make ci must pass before every push. It runs: fmt-check → lint → type → test → example. Use make fmt to auto-fix formatting before re-running make ci.
  • All public interfaces need type hints and docstrings.
  • Never raise bare ValueError or KeyError to callers. Use custom exceptions from errors.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 by tests/test_docstrings.py.
  • Branch coverage must stay at or above the fail_under floor in pyproject.toml (make test fails 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).

LayerMay import (within the package)
firewall/models, errors, enums only — never execution/policy/registry
drivers/models, errors, enums only
routermodels only (stateless dispatch)
modelsenums, errors only
enums, errorsnothing else in the package (leaves)
kernel/ and everything elseunconstrained (the kernel is the orchestrator)

Security rules

  • Never log or print secret key material.
  • HMAC secrets come from WEAVER_KERNEL_SECRET env 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 raw response mode. The Firewall downgrades to summary.
  • 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 ci is the single authoritative pre-push command.
  • Update CHANGELOG.md in 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

  1. Implement the Driver protocol in src/weaver_kernel/drivers/.
  2. Register it with StaticRouter or implement a custom Router.
  3. Add integration tests in tests/test_drivers.py.

See docs/integrations.md for MCP and HTTP examples.

Adding a policy rule

  1. Implement the condition in the appropriate default_policy_*_rules.py helper.
  2. Register it exactly once in the ordered _DEFAULT_RULES tuple in default_policy_rules.py; both evaluate() and explain() consume that chain.
  3. Placement matters: rules are evaluated in order. A new rule placed before sensitivity checks can change which denial short-circuits first.
  4. If adding a new SensitivityTag, you must also add a corresponding policy rule — otherwise the tag is silently ignored.
  5. Cover decision/explanation agreement in tests/test_policy_rule_chain.py and behavior in tests/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

TopicCanonical source
Architecture & design intentdocs/agent-context/architecture.md
Components & API referencedocs/architecture.md
Security model & threatsdocs/security.md
Hard invariants & forbidden shortcutsdocs/agent-context/invariants.md
Workflow rules & commandsdocs/agent-context/workflows.md
Recurring mistakesdocs/agent-context/lessons-learned.md
Review & self-checkdocs/agent-context/review-checklist.md
Driver integration patternsdocs/integrations.md
Capability design conventionsdocs/capabilities.md
Context firewall detailsdocs/context_firewall.md
Action trace export contractdocs/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.

Download now (ZIP)

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
What did you use it for? e.g. Reviewing pull requests in a Rails app

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.