aien-architecture-mv
Canonical architecture for the AIEN ecosystem: flows, boundaries, ADRs, and the map from design to implementation repositories.
Brought by drakestapleton
aien-architecture-mv / docs / research / hermes-agent-prior-art.md
| 1 | # Research Note: Hermes Agent and AIEN |
| 2 | |
| 3 | Written 2026-10-18 for Drake's question: *does the open-source Hermes Agent hold |
| 4 | principles or mechanics that are unique and worth rewriting in our own language?* |
| 5 | Source of truth for every claim: the Hermes tree pinned below, read on disk (not |
| 6 | run). Claims are tagged [OBSERVED path] (read in the code), [DOCUMENTED path] |
| 7 | (read in Hermes's own developer guide) or [INFERRED]. Nothing here was executed. |
| 8 | |
| 9 | ## Source |
| 10 | |
| 11 | | Item | Value | |
| 12 | |---|---| |
| 13 | | Repository | https://github.com/NousResearch/hermes-agent | |
| 14 | | Commit read | `548091836760a67e331b8f5643be8e5c08fae1e6` (2026-10-18) | |
| 15 | | Licence | MIT, Copyright (c) 2025 Nous Research. Rewrites are allowed; keep the credit line. | |
| 16 | | Language | Python (9,836 files, about 2.4 M lines, 1.47 M of them tests) | |
| 17 | | My copy | `~/workspace/investigations/2026-10-18-hermes-agent/upstream` on the Spark, with `PINS` and scout notes in `notes/` beside it | |
| 18 | | Prior mentions on my side | none outside the archived Odysseus fork (org-check receipt `org:8d23a45c210a`) | |
| 19 | |
| 20 | Hermes is a general chat and messaging agent harness: a loop around a hosted or |
| 21 | local language model with tools, skills, memory files, a messaging gateway for |
| 22 | about 27 platforms, a cron scheduler and a session database. It is the kind of |
| 23 | thing AIEN's host runtime (sovereign core `aien` chat loop, aegis-runtime, |
| 24 | Aien) is also becoming, which is why the comparison is worth making. |
| 25 | |
| 26 | ## Method |
| 27 | |
| 28 | Architecture and agent-loop guides read first-hand; the four large subsystems |
| 29 | (agent core; memory, skills, learning; tools, approvals, delegation; gateway, |
| 30 | cron, state) were each read by one scout against written questions, with |
| 31 | file:line citations, and the judgment below is the orchestrator's. My own side |
| 32 | was checked with `org-check` before any "I lack this" claim. |
| 33 | |
| 34 | ## 1. Context compression: the clearest lesson |
| 35 | |
| 36 | Hermes keeps a conversation inside the model's window with two mechanisms |
| 37 | [DOCUMENTED website/docs/developer-guide/context-compression-and-caching.md, |
| 38 | micro-compaction.md; OBSERVED agent/context_compressor.py, |
| 39 | agent/conversation_compression.py]. |
| 40 | |
| 41 | **Batch compression** fires at 50 % of the window before a call (85 % between |
| 42 | gateway turns). It flushes memory to disk first, keeps the last 20 messages |
| 43 | verbatim, never splits a tool call from its result, and writes a structured |
| 44 | summary (goal, constraints, progress, decisions, files, next steps). Each |
| 45 | compression starts a child session lineage. |
| 46 | |
| 47 | **Micro-compaction** is the part I do not have. It is opt-in in Hermes (off by |
| 48 | default, because each pass breaks the prompt-cache prefix). When on, after every normal turn it |
| 49 | absorbs exactly one *exchange* (one assistant turn with its tool results) into |
| 50 | a single rolling summary. Properties the code enforces: |
| 51 | |
| 52 | - The user's own messages are never summarized. Only the agent's derived |
| 53 | material (what it read, ran, saw) is compacted, because intent cannot be |
| 54 | rebuilt from the work that followed it. |
| 55 | - Cost per turn is bounded: one exchange, one small summarizer call. |
| 56 | - The transcript is the source of truth for the cursor: a resumed process |
| 57 | finds the last summary marker and continues after it, so nothing is |
| 58 | summarized twice. |
| 59 | - Only the newest summary marker is kept; when the summary grows past 2,000 |
| 60 | tokens the next pass re-summarizes the summary itself ("defrag") without |
| 61 | touching messages. |
| 62 | - The database step is an atomic archive-and-insert, so a resumed session never |
| 63 | loads both the summary and the rows it replaced. |
| 64 | - A failing exchange is retried on later turns and skipped after three |
| 65 | failures, so one bad exchange cannot stall every turn. |
| 66 | |
| 67 | **Token accounting** is anchored on evidence, not estimates [DOCUMENTED |
| 68 | context-compression-and-caching.md "Token accounting"; OBSERVED |
| 69 | agent/usage_anchor.py]: the provider's last reported prompt and completion |
| 70 | counts, keyed by a content fingerprint and persisted on the session row, are the |
| 71 | truth; local estimates cover only the messages appended since. An estimate over |
| 72 | threshold, even one above the whole window, is not treated as proof that a |
| 73 | request will fail; the gate waits one request for provider evidence. Image |
| 74 | token cost is learned per model from the provider's reported usage, not from a |
| 75 | vendor formula. |
| 76 | |
| 77 | **Failure handling** is a persisted cooldown ladder (60 s, 300 s, 900 s) per |
| 78 | session, with a deterministic fallback summary route when the summarizer stalls |
| 79 | twice, and commits through a lease, fence and watermark so two compactions |
| 80 | cannot interleave. |
| 81 | |
| 82 | **What I have today.** The sovereign core already has a conversation compactor |
| 83 | (`crates/aien-cli/src/compaction.rs`, issue 397 there): tool-aware groups, |
| 84 | unsafe-boundary refusal, and durable originals with digests written before the |
| 85 | list changes, with replay. Hermes does not have that last property. I lack: |
| 86 | the one-exchange-per-turn bounded pass, the never-summarize-the-user rule, the |
| 87 | transcript-recovered cursor, the rolling summary with defrag, the atomic store |
| 88 | swap, and evidence-anchored token accounting. (org-check receipt |
| 89 | `org:461d52d75b01`.) |
| 90 | |
| 91 | ## 2. Memory and skills: small, plain, and written by the agent itself |
| 92 | |
| 93 | Findings from the scout note `notes/scout-B-memory-skills-learning.md`. |
| 94 | |
| 95 | **Memory** is two plain-text files with hard character caps, MEMORY.md at |
| 96 | 2,200 and USER.md at 1,375 characters [OBSERVED tools/memory_tool_store.py, |
| 97 | agent/memory_manager.py]. A full store makes the write fail with a listing of |
| 98 | current entries, so the model must free space in the same batch. The prompt |
| 99 | snapshot of memory is frozen at session start; writes persist at once but are |
| 100 | visible only after the next rebuild. There is no vector store in the core. |
| 101 | External memory providers plug in behind one interface [OBSERVED |
| 102 | agent/memory_provider.py]; two adapters are in-tree. External recall is not put |
| 103 | in the system prompt: it is appended to the current user message as a fenced |
| 104 | "reference data" block, and the harness prints a deterministic "recalled N |
| 105 | memories" line so the model cannot silently ignore it. |
| 106 | |
| 107 | **Skills** are folders with a `SKILL.md` plus optional references, templates |
| 108 | and scripts. The system prompt carries only an index: name and a 60-character |
| 109 | description, enforced by tests; the model loads a skill by calling a view tool |
| 110 | and is told to load anything even partly relevant. There is no matcher and no |
| 111 | embedding [OBSERVED tools/skills_tool.py, agent/prompt_builder.py]. |
| 112 | |
| 113 | **The agent writes its own skills** ("the agent that grows with you") |
| 114 | [OBSERVED agent/background_review.py, agent/learn_prompt.py, |
| 115 | tools/skill_manager_tool.py, tools/skill_ledger.py]: |
| 116 | |
| 117 | - After a turn, and on two independent counters (every 10 user turns for memory, |
| 118 | every 10 tool iterations for skills), a forked copy of the agent reviews the |
| 119 | conversation. The fork runs on the same prompt cache with a dispatch-side |
| 120 | tool whitelist, so the tool schema bytes stay identical. |
| 121 | - The review prompt carries editorial policy: lessons, not logs; class-level |
| 122 | skills over one-off recipes; never record an unresolved failure or a negative |
| 123 | claim about a tool. |
| 124 | - Read-before-write is enforced in code: the fork must view the exact file |
| 125 | within the same review before patching it. |
| 126 | - Unattended forks may only add to memory; patch and remove are staged for a |
| 127 | person's approval. |
| 128 | - Every skill mutation by any actor goes to a JSONL ledger with |
| 129 | content-addressed before and after blobs and single-edit rollback that fails |
| 130 | closed. |
| 131 | - Skill telemetry (views, uses, patches) lives in a sidecar file and drives an |
| 132 | inactivity state machine: active, stale after 14 days, archived after 30, |
| 133 | with exemptions for pinned and cron-referenced skills. |
| 134 | |
| 135 | **What I have today.** Cortex (omega) is an append-only lessons and sources |
| 136 | memory with recall; the Skill Router and Capability Graph are host-side omega |
| 137 | modules; skills on the Spark are Claude Code skills. I have no mechanism by |
| 138 | which the agent itself distils a run into a skill under an editorial policy, |
| 139 | no skill ledger with rollback, and no use-driven skill ageing. |
| 140 | |
| 141 | ## 3. The turn loop: persist before acting, plan the tool batch |
| 142 | |
| 143 | Findings from `notes/scout-A-agent-core.md` [OBSERVED agent/conversation_loop.py, |
| 144 | agent/turn_tool_round.py, agent/turn_context.py, agent/tool_executor.py, |
| 145 | tools/tool_dispatch_helpers.py, agent/turn_retry_state.py, |
| 146 | agent/turn_truncation.py, tools/budget_config.py]. |
| 147 | |
| 148 | - **Persist before acting.** The assistant message that requests tools is |
| 149 | written durably to the session database before any tool runs; if that write |
| 150 | fails the turn ends. The exact wire bytes of an injected user message are |
| 151 | kept as a sidecar so later turns replay byte-identical prompts. |
| 152 | - **Tool batch planning.** A batch of tool calls is planned into ordered |
| 153 | parallel and sequential segments using path-overlap reservations between |
| 154 | readers and writers, with a start-order gate and timeout. Results spill to |
| 155 | disk under three budgets (per result, per turn, window-scaled), largest |
| 156 | first. |
| 157 | - **Recovery that cannot loop.** About 28 failure reasons are classified; each |
| 158 | recovery is a one-shot flag per attempt. A tool call truncated by the output |
| 159 | cap is retried with an exponentially raised cap and is never executed with |
| 160 | incomplete arguments. The credential pool is tried before the fallback model |
| 161 | chain. |
| 162 | - **Cache-stable extras.** Mixture-of-agents guidance and mid-session "skills |
| 163 | changed" notes travel as trailing user messages, never as prompt rebuilds; |
| 164 | many comments name prompt-cache stability as the reason. |
| 165 | - **Trajectories** are written as ShareGPT-style JSONL with tool-call tags and |
| 166 | a think block per assistant turn; an offline tool replaces the middle of a |
| 167 | trajectory with one summary turn. Whether any released model was trained on |
| 168 | this data is UNKNOWN from the tree. |
| 169 | |
| 170 | **What I have today.** The sovereign core chat loop has hooks and the |
| 171 | compactor; it has no persist-before-act rule, no batch planner with path |
| 172 | reservations, and no one-shot recovery ledger (not checked by org-check; |
| 173 | stated from the sc#397 inventory, which lists the loop's entry points). |
| 174 | |
| 175 | ## 4. Gateway, cron and state: guarantees chosen per path and written down |
| 176 | |
| 177 | Findings from `notes/scout-D-gateway-cron-state.md` [OBSERVED |
| 178 | gateway/delivery_ledger.py, gateway/session.py, cron/scheduler_tick.py, |
| 179 | cron/occurrences.py, cron/scheduler_authority.py, cron/scheduler_liveness.py, |
| 180 | cron/quota_hold.py, hermes_state.py, hermes_state_repair.py, pm/environments.py, |
| 181 | hermes_platform/]. |
| 182 | |
| 183 | - **Delivery guarantees are chosen per path and stated in code.** Gateway |
| 184 | replies are at-least-once: the reply row is written to a ledger before the |
| 185 | send, and a crash-recovered send carries a visible "Recovered reply" marker. |
| 186 | Cron sends are at-most-once: any uncertainty is recorded as `unknown` and |
| 187 | never replayed. The obligation id is a content hash of session key, message |
| 188 | reference and reply text, so an identical re-record collapses to one row. |
| 189 | Owner stamps are pid plus process start time, compare-and-set, to survive |
| 190 | pid reuse. |
| 191 | - **Cron fires at most once.** The schedule is advanced before the job runs; |
| 192 | if the advance cannot be persisted the due jobs are skipped on purpose. Each |
| 193 | fire is identified by its exact scheduled instant. Jobs run as gateway |
| 194 | sessions through an on-disk admission journal; an unclear admission pauses |
| 195 | the job, and only the matching verified receipt lifts that pause. Liveness |
| 196 | is silence since the last progress stamp, not run length. A provider quota |
| 197 | hold parks the next run at the usage-window end and coalesces missed |
| 198 | occurrences. |
| 199 | - **Session admission** is a durable per-session queue (32 rows) with a |
| 200 | runtime epoch and generation fences; rows started by an older epoch become |
| 201 | `unknown` and need an operator's word before the queue resumes. |
| 202 | - **State store.** One SQLite file per profile; writes retry the whole |
| 203 | transaction with jitter; full-text search with no embeddings; index |
| 204 | corruption degrades to plain scans rather than blocking writes; offline |
| 205 | repair works on a scratch copy with a persistent ledger of strategies tried. |
| 206 | - **Environments as immutable generations.** The package manager builds a new |
| 207 | environment beside the old one; a selection record written last, after a |
| 208 | filesystem sync, is the completion marker; leases block deletion of a |
| 209 | generation in use. Binaries are pinned by URL and sha256 only. |
| 210 | - **Machine facts take no environment-variable input**; hardware recognisers |
| 211 | are table-driven from OS-reported identity (the GB10 is in that table). |
| 212 | |
| 213 | **What I have today.** aegis-runtime has a WebSocket gateway and a heartbeat |
| 214 | scheduler but no delivery ledger and no at-most-once cron discipline (its |
| 215 | README and source list neither). The hive's forge queue and lanes ledger are |
| 216 | shell-level. Synapse has revisions and recovery for changesets, not for |
| 217 | message delivery. The Aienux continuity commit path already does |
| 218 | advance-before-act for its own store (ADR 0016). |
| 219 | |
| 220 | ## 5. Tools, approvals, delegation, checkpoints |
| 221 | |
| 222 | Findings from `notes/scout-C-tools-approvals-delegation.md` [OBSERVED |
| 223 | tools/approval_floors.py, tools/approval.py, tools/approval_smart.py, |
| 224 | tools/delegate_tool_registry.py, tools/checkpoint_manager.py, |
| 225 | tools/code_kernel.py, tools/budget_config.py, agent/tool_executor.py]. |
| 226 | |
| 227 | - **Approval floors above every mode.** Four floors are checked first and |
| 228 | cannot be bypassed by "yolo" or "off": a hardline command list, deletion of |
| 229 | the runtime itself, `sudo` with a piped password, and the operator's own |
| 230 | deny patterns, which outrank even the container shortcut. Only after the |
| 231 | floors do mode, permanent allowlist, presence of a person, about 102 |
| 232 | dangerous-command patterns, and the human decision run. "Smart" mode asks a |
| 233 | guardian model for approve, deny or escalate behind a circuit breaker; |
| 234 | unattended modes default to deny. |
| 235 | - **Delegation** runs children as in-process threads on a daemon pool, with |
| 236 | background children recorded in a durable ledger and recovered after a |
| 237 | restart. The docs and code disagree on defaults (docs: depth 2, concurrency |
| 238 | 3, 250 iterations; code: depth 1, 10, 50). |
| 239 | - **Checkpoints** use one shared bare git store with one snapshot per |
| 240 | directory per turn, plus a ledger of the agent's own writes, so a rollback |
| 241 | restores what the agent changed and leaves the operator's own edits alone. |
| 242 | - **Code execution** is a persistent per-conversation kernel behind a |
| 243 | token-checked socket; each cell receives its own revocable tool authority; |
| 244 | a timeout kills the kernel and discards its state on purpose. |
| 245 | - **Budgets** are iterations (consume, refund, one grace call) and result |
| 246 | sizes (100k per result, 200k per turn, 50k for MCP, spilled to files, head |
| 247 | 40 % and tail 60 % kept). No hard cost or token budget was found. |
| 248 | |
| 249 | **What I have today.** Capability-bounded, receipt-producing effects are |
| 250 | Omega doctrine (SMART is not TRUSTED), ARGUS is the defensive plane, and |
| 251 | INTERPLANE holds an action for a person when untrusted content is in view. |
| 252 | What I lack is the ordering rule as code (floors first, then modes, with the |
| 253 | operator's deny list outranking everything) and a file rollback that keeps |
| 254 | the agent's writes apart from the operator's. |
| 255 | |
| 256 | ## 6. Judgment: what is worth rewriting, in which language, and where |
| 257 | |
| 258 | The principles below are the ones that are both unusual in Hermes and absent |
| 259 | on my side. Each becomes one issue; the issue carries the credit line. |
| 260 | |
| 261 | | # | Principle (Hermes mechanic) | Why it is worth making mine | Lands in | |
| 262 | |---|---|---|---| |
| 263 | | 1 | Bounded micro-compaction: never summarize the operator; one exchange per turn; transcript-recovered cursor; rolling summary with defrag; atomic store swap; evidence-anchored token accounting | Direct fit with "no guessing": provider usage is a receipt, an estimate is not. Extends sc#397 instead of replacing it | aien-sovereign-core (`aien` chat loop) | |
| 264 | | 2 | Persist-before-act turn discipline; byte-identical replay sidecar; one-shot recovery flags; never run a truncated tool call | Same idea as Aienux continuity commits (advance the record, then act), applied to the chat loop | aien-sovereign-core | |
| 265 | | 3 | Tool batch planning with reader/writer path reservations; result spill under three budgets | My loop runs tools one at a time; this is the safe form of parallelism | aien-sovereign-core | |
| 266 | | 4 | Agent-written skills under an editorial policy: forked reviewer, lessons not logs, read-before-write enforced, unattended is add-only, content-addressed skill ledger with rollback, use-driven ageing | My Cortex records lessons but nothing distils runs into skills; the ledger is content-addressed, which is Omega's own idea | omega (Cortex, Skill Router) | |
| 267 | | 5 | Delivery and scheduling guarantees stated per path: at-least-once reply ledger with content-hash obligation ids and a visible duplicate marker; at-most-once cron (advance before run, pause on uncertainty, liveness by silence since progress, pid plus start-time owner stamps, epoch fences) | Aien's heartbeat and the hive's queue have no stated guarantee today; this is how "it ran once" becomes provable | aegis-runtime (gateway, heartbeat) | |
| 268 | | 6 | Approval floors ordered above every mode; agent-write ledger so rollback spares the operator's edits | Turns ARGUS and capability doctrine into one ordering rule the loop cannot skip | aien-sovereign-core (with aienos ARGUS as reviewer) | |
| 269 | |
| 270 | **Language.** Rust now, Omega as the destination (ADR 0024). Omega has no |
| 271 | general compiler today (omega README, 2026-10-03), so "an Omega" is not an |
| 272 | option for working code this month. The rule for each rewrite: the pure part |
| 273 | (summary folding, token accounting, the delivery state machine, the skill |
| 274 | ledger) is written as a content-addressed, effect-free module with a stated |
| 275 | interface, so it can be carried into Omega as a semantic identity later; only |
| 276 | the edges (SQLite, sockets, files) stay host Rust. |
| 277 | |
| 278 | **Not worth rewriting** (ordinary, or already mine): the three API modes and |
| 279 | provider adapters, the 27 messaging platforms, the Python package manager, |
| 280 | the browser and computer-use stacks, the TUI, and the mixture-of-agents |
| 281 | provider. The environment-generation idea in the package manager and the |
| 282 | table-driven machine facts are good habits, noted here, not issues. |
| 283 | |
| 284 | **Licence and credit.** MIT allows rewriting. No Hermes code is to be copied; |
| 285 | mechanisms are re-implemented from the description above and from reading. |
| 286 | Each issue and each resulting module header names Hermes Agent, Nous Research, |
| 287 | the MIT licence and the commit read. If any text is carried over verbatim |
| 288 | (for example a prompt rule), the MIT notice goes into that repository's |
| 289 | NOTICE file. |
| 290 | |
| 291 | ## 7. If I move onto Hermes as the day-to-day harness |
| 292 | |
| 293 | Drake raised a transfer to Hermes on 2026-10-18. What the tree says a transfer |
| 294 | needs [DOCUMENTED README.md, website/docs/user-guide/which-file-does-what.md; |
| 295 | OBSERVED agent/prompt_builder.py, tools/memory_tool_store.py]: |
| 296 | |
| 297 | | My asset today | Hermes equivalent | Caveat | |
| 298 | |---|---|---| |
| 299 | | `~/.claude/CLAUDE.md`, `AGENTS.md` | `AGENTS.md` and project files in the context tier; `SOUL.md` for identity | project files are capped per file; order is SOUL, guidance, pinned skills, then project files | |
| 300 | | Memory directory (over 100 files) | `MEMORY.md` (2,200 characters) and `USER.md` (1,375) | will not fit; needs an external memory provider, which is where my Cortex could plug in | |
| 301 | | Claude Code skills | `skills/<name>/SKILL.md` with a 60-character description | the model, not a matcher, chooses skills from the index | |
| 302 | | Hooks (manual-guard, docs-guard, chat-size) | gateway hooks and observer hooks, middleware | hooks are gateway-side; CLI-side enforcement is thinner | |
| 303 | | Subagents | the delegate tool (in-process threads) | defaults differ between docs and code | |
| 304 | | MCP servers | `optional-mcps` and the MCP tool | OAuth sessions handled in the TUI gateway | |
| 305 | | Cron jobs on the Spark | Hermes cron (at-most-once, see section 4) | jobs run as gateway sessions | |
| 306 | | Python rule | Hermes is Python end to end | it would be an outside tool I use, not part of the trusted base | |
| 307 | |
| 308 | ## 8. Limits of this note |
| 309 | |
| 310 | One commit read on one day. Scouts did not read: the micro-compaction body |
| 311 | itself (documentation plus gating code only), the conversation-turn undo code, |
| 312 | the docker egress and ownership modules, 26 of 27 platform adapters, the full |
| 313 | scheduler, and the package-manager update path. No Hermes code was executed, |
| 314 | so timings, cache savings and the vendor's cost claims are unverified. Whether |
| 315 | Hermes's self-review improves outcomes is UNKNOWN from the tree: its evals do |
| 316 | not test memory or skill quality. |