AEGIS gate — a pre-execution verification gate for Hermes agents
No agent should execute what it hasn't verified.
AI agents are now told to execute instructions written by third
parties: mint pages that embed step-by-step playbooks for the
agent, skill packages served from mutable "latest" URLs, payloads
generated at runtime by a counterparty's server. A compliant agent is
one pasted paragraph away from draining its owner's wallet.
AEGIS gate verifies before the agent executes. It is a Hermes
plugin that registers a single fail-closed pre_tool_call hook.
Before every tool call, the hook inspects the call's arguments, runs
whichever of the four AEGIS gates apply, and returns a verdict —
ALLOW, WARN, or BLOCK — with reasons. The gates are a
Python port of the AEGIS kit
built for the NEAR Hackathon (Nov 2026), whose verdicts were anchored
on NEAR testnet; AEGIS gate is that same verification discipline,
living inside the agent runtime instead of beside it. The port is
calibrated against the kit's own test battery and case files (see
Testing below).
Demo: a <90 s video of the plugin blocking real attacks inside a
live Hermes session is pinned at
@aegisonnear.
Install
hermes plugins install Rainyy99/aegis-hermes
Requires Hermes >=0.21.5. Python dependencies: none — stdlib
only.
How a verdict becomes a directive
| Merged verdict | Hermes directive | Effect |
|---|---|---|
| BLOCK | {"action": "block", "message": …} | The tool call is vetoed; the message (gate reasons) is returned to the model as the tool error. |
| WARN | {"action": "approve", "message": …} | The call escalates to Hermes's human-approval gate. Denial, timeout, or gate error fails closed. |
| NO_VERDICT (a gate could not complete) | {"action": "approve", "message": …} | An incomplete assessment escalates; it is never silently allowed and never fabricated into a pass. |
| ALLOW | (no directive) | The call proceeds untouched. |
The merge rule is the AEGIS runner's: the worst verdict among gates
that produced one wins (BLOCK > WARN > ALLOW); any applicable gate
with NO_VERDICT caps the outcome at WARN/escalation; gates that were
not applicable do not affect the merge.
How it decides — the dispatcher
The hook classifies a call by its argument content, not by tool
name, so it works for built-in and plugin tools alike:
- Fast path. Args with no risk markers — no EVM address, no
EIP-712-shaped payload, no execution pattern, no substantial text —
return no directive immediately. No network, no delay: anls, a
file read, a git status are never gated. - Gate 3 — signature (pure local). Any EIP-712-shaped payload
in the args — a nested object, a JSON string, or JSON embedded in a
command line — is structurally decoded before anything signs it:
domain name/chainId/verifyingContract present; primaryType never a
Permit shape; nospender/value/amountfield anywhere in the
message or the declared types; verifyingContract never Permit2
(built in). One failed hard check = BLOCK, with the payload's
failures named. - Gate 2 — contract (network, cached). When a call shows
execution intent (acontract-call execute/preview, a raw
transaction send, a value-moving call shape, calldata flags) and
names contract addresses, each target is checked on Sourcify:
exact match preferred, partial match forced to WARN, unverified =
BLOCK, and the verified source is scanned for risk patterns
(delegatecall,selfdestruct,permitin project source force
WARN; approval/fund-flow/admin counts are evidence). Verdicts are
cached per (chainId, address) for 5 minutes. - Gate 1 — provenance (network). When the args also carry a
URL presented as the address's source, the claim is checked the
AEGIS way: the official page must actually carry the address, and
the address's Sourcify record (an independent host) must confirm
it. Official-only confirmation = WARN; a contradicting record =
BLOCK. - Gate 4 — instruction channel (pure local). Free text in the
args (a brief being written to a file, a page being followed, a
command carrying instructions) is scored across six weighted
signal groups: server-sign-submit (5), external-server-connect
(4), agent-install-script (4), agent-addressed-instruction (2),
false-authority (2), manufactured-urgency (1). Score ≥ 8 = BLOCK,
≥ 3 = WARN — and two hard rules BLOCK at any score: a
challenge→sign→submit sequence, or sign-submit instructions
combined with a direction to connect to an external server (the
Nonce Protocol shape: a foreign server that both instructs the
agent and feeds it payloads to sign — the case this gate was
distilled from).
The time budget
Hermes runs pre_tool_call callbacks under a fail-closed timeout
(default 30 s): a slow gate blocks the call. So the hook works to an
internal budget of ~20 s per call: every fetch's timeout shrinks
to the time remaining, retries stop when the budget is spent, and a
network gate that cannot finish abstains (NO_VERDICT →
escalation) rather than guessing. Gates 3 and 4 are local and
effectively instant, so the headline blocks never touch the network.
Settings (optional)
Four caller-context settings, declared in plugin.yaml's
config_schema and read once at registration via ctx.get_config
from plugins.entries.<plugin id>.settings in config.yaml. All
default to the Node kit's defaults (nothing pinned, nothing listed):
| Setting | Gate | Meaning |
|---|---|---|
official_domains | 1 | Official hosts for the project being checked. A claimed official source on any other host fails provenance (BLOCK). |
held_contracts | 3 | Addresses of contracts/tokens you hold; an EIP-712 payload naming one as its verifyingContract is BLOCKED. |
routers | 3 | Known router addresses; same BLOCK treatment as verifyingContract. |
denied_contracts | 3 | Your own denylist; same BLOCK treatment. |
plugins:
entries:
aegis-gate:
settings:
official_domains: ["project.example"]
denied_contracts: ["0x0000000000000000000000000000000000000000"]
Disclosure (catalog rule 13)
- Network: read-only HTTPS GETs to
sourcify.devand to source
URLs referenced by a tool call's own arguments (Gates 1/2 evidence
fetches only), inside the budget above. No telemetry, no other
endpoints. Fetches are https-only and destination-guarded
(since 0.1.1): before connecting — and again on every redirect
hop — the host is resolved and the fetch is refused when any
resolved address is private, loopback, link-local (including
cloud-metadata addresses), CGNAT, reserved, multicast or
unspecified. A refused URL is never fetched and produces no
verdict — the gate abstains and the call escalates to a human. - Reads: the arguments of tool calls in the agent's own session
(that is the hook's purpose). Nothing else on disk is read. - State: an in-process, TTL-bound Gate 2 verdict cache and a
one-line stderr journal per gated call (tool name, merged verdict,
report hash). No files are written; no credentials are held,
requested, or read; no subprocesses are spawned; nothing is signed
or executed by the plugin itself — AEGIS only ever checks. - Prior work: the four gates are adapted from the author's own
open-source AEGIS kit (NEAR Hackathon, Nov 2026), ported from
Node.js to Python for Hermes; verdict semantics and thresholds are
unchanged (deviations forced by the hook context are listed in the
plugin's build log, available on request and summarized in the
catalog PR).
Testing
The ported battery runs fully offline (the HTTP layer is stubbed):
python3 tests/run_tests.py # 105 checks, stdlib unittest
It covers the Node kit's calibration cases — the Nonce brief must
score 15 and BLOCK, the ERC-2612 Permit and Permit2 fixtures must
BLOCK, the benign SignIn fixture must ALLOW, partial-match must
force WARN, persistent Sourcify failure must produce no verdict —
plus the hook's dispatcher, cache, budget-abstain, never-raises, and
settings-wiring behavior through a mock-ctx harness. Gate 3 and
Gate 4 outputs were additionally diffed field-by-field against the
original Node implementation on the kit's fixtures and case files:
identical.
Development install (sideload):
cp -r aegis-hermes ~/.hermes/plugins/aegis-gate # this repo's root
hermes plugins enable aegis-gate
hermes plugins doctor ~/.hermes/plugins/aegis-gate
hermes plugins validate ~/.hermes/plugins/aegis-gate --install-deps
Scope & known limitations
Disclosed openly, in the AEGIS house style — nothing below is hidden
from reviewers or judges. Numbers follow the kit's AUDIT.md where
they carry over.
New in the plugin context:
- A WARN is only as strong as the surface's approval policy.
WARN escalates to Hermes's human-approval gate — that gate is
real on interactive surfaces and wherever the surface denies by
default when nobody can answer (e.g. single-query mode). But on
unattended one-shot surfaces (hermes -z, cron with
cron_mode: approve,--yolo), Hermes by its own documented
contract auto-approves approval-gate escalations, so a WARN
proceeds there without a human ever seeing it. This is a Hermes
surface property, not a plugin defect — and it is exactly why
AEGIS reserves BLOCK for the verdicts that must hold
everywhere: ablockveto never enters the approval gate and is
absolute on every surface we tested (interactive, single-query,
one-shot). Installers who run Hermes unattended should treat WARN
as advisory and BLOCK as the enforcement line. (Verified live in
end-to-end sessions against Hermes 0.23.0, 6 Nov 2026.) - Live-fetch abstain under the time budget. Gates 1/2 fetch
live evidence inside Hermes's 30 s fail-closed callback budget
(internal budget ~20 s). Under a slow network a gate may abstain
(NO_VERDICT → human escalation) where the standalone kit would
have waited longer. Abstention is always disclosed in the
directive message; it never becomes a silent allow, and never a
fabricated verdict. The kit's per-request retry policy is
unchanged, but backoff sleeps and attempt counts shrink to the
budget. - The dispatcher is a content heuristic. It classifies by
argument content, not tool identity: a Permit-shaped payload
anywhere in the args is treated as a signing candidate (even if
the call is "only" writing it to a file as documentation), and a
novel tool shape can evade classification. Execution intent is
recognized from common CLI/calldata shapes (contract-call,
transaction sends, value-moving function calls, calldata flags);
Gate 2/1 run only when intent and an address are both present —
an address merely mentioned in a read is not gated. - Gate 1's domain registry is only as good as its setting.
The kit's--registry(caller-pinned official domains) is wired
to theofficial_domainssetting; when it is not configured,
in-hook Gate 1 rests on the content tests (official page carries
the claim + independent record confirms) and every report states
when no registry was supplied — the kit's own limitation 9
applies at full strength then. - Gate 3's caller context comes from settings. The held-
contract / router / denylist checks read theheld_contracts,
routers, anddenied_contractssettings; unconfigured lists
are reported as not checked. Beyond those, Gate 3 enforces the
built-in rules (Permit shapes, forbidden fields, Permit2,
structure) plus a chain check when the call itself states its
chain (e.g.--binanceChainId). The kit's limitation 10 applies:
classification is only as complete as the context supplied. - Cache scope is one process. Gate 2 verdicts are cached
in-process with a 5-minute TTL; nothing persists across restarts
(the sanctioned plugin data directory is the planned home for a
persistent cache and the verdict journal). - The hook never raises — by design, errors escalate. Any
unexpected internal error returns an "approve" directive with the
error named, so a defective gate degrades to human-in-the-loop,
never to a silent pass. (Hermes itself blocks on callback
timeout; the internal budget exists to stay well clear of it.)
Carried over from the kit (AUDIT.md):
- Gate 2 pattern counts are raw text occurrences (code + comments
- strings), never attributions; the project/library split is
path-based (node_modules/= library); setter detection lists
onlyfunction setX(…)declarations; the verdict escalates only
on unverifiable code and project-sourcedelegatecall/
selfdestruct/permit(pluspartial_match) — dangerous
combinations still ALLOW with the evidence attached, for a
human/agent audit to decide. (Kit limitations 1–4.)
- strings), never attributions; the project/library split is
- Sourcify is Gate 2's single trust anchor: the port trusts its
match and sources at query time and does not independently
compare runtime bytecode; an outage fails loudly with no verdict.
(Kit limitation 6.) - Gate 1's "claim found" is a content heuristic (substring, or
record-existence for record-style URLs), not semantic proof that
a page endorses the claim in the asserted role; Gate 1 does not
discover official channels — whoever supplies the URL frames the
check. (Kit limitations 8–9.) - Gate 3 is structural only: it verifies no signature, recovers no
signer, and cannot prove a verifyingContract really belongs to
the project; types/message mismatch is WARN, not BLOCK, by
design; an ALLOW never replaces building and simulating the
final transaction separately. (Kit limitations 10–11.) - Gate 4 is regex/heuristic screening: paraphrased, obfuscated,
image-carried, or non-English instructions can evade it;
thresholds are calibrated on the kit's cases, not a broad
labelled corpus; text discussing these patterns scores like
text using them. (Kit limitation 12.) - Python
revs JavaScriptRegExpdialect differences may exist
in edge cases beyond the calibration corpus; the port was
verified identical to the Node implementation on all kit
fixtures and case files (Gate 3 verdicts/reasons/decoded/checks;
Gate 4 scores/counts/reasons on 8 texts including both case
files). - The destination guard resolves, then the fetcher resolves
again. The guard checks every address a host resolves to
before the request and on each redirect hop, but stdlib urllib
cannot pin the connection to the checked addresses without
breaking TLS verification, so a DNS-rebinding race between the
check and the connect is not fully closed. The same guard also
refuses synthetic answers from "fake-IP" DNS proxies (which map
public names into 198.18.0.0/15): in such an environment Gates
1/2 abstain and escalate rather than fetch — fail-closed, but
live evidence is unavailable there.
License
MIT — same as the AEGIS kit.
README from the reviewed commit 54b2602; it updates when the author re-pins.

Rainyy99