Agent archetypes

An archetype is a named agent setup: settings to create the agent with, and a NixOS module its container runs. The swarm UI's create form lists the archetypes the swarm knows. Picking one fills the form's permissions, resource caps, inference and AGENTS.md fields from it, and you can still change each field before you create the agent.

An agent created from an archetype has no agent-configs/<name> repo of its own. The swarm's internal/meta flake builds it from the archetype's module, so every agent of that archetype runs the same configuration. To change what it runs, change the archetype. Picking "none" creates a custom agent, with its own config repo. The swarm can also turn an archetype agent into a custom one later (below).

The built-in archetypes

The hyperhive flake ships these:

archetype what it sets
reviewer permissions messaging, inbox, execution: the default set without meta. With execution it can run hive-forge, git and other commands.
android-dev installs android-tools (adb, fastboot), Gradle, a JDK, the Android SDK (build-tools 36.1.0, platform 35) and nix-ld, and sets ANDROID_HOME, ANDROID_SDK_ROOT and JAVA_HOME, so the aapt2 Gradle downloads runs; default permissions.
reverse-engineer sets services.hyperhive.agent.rea.enable: installs REA, Ghidra 12.1 and procps, and allows all REA MCP tools; default permissions and the agent's normal memory cap.
ruth the manager agent. Inference model sonnet; permissions: the default set plus manage_root_agent, logs and metrics. Its module is empty. The swarm UI's setup assistant creates ruth from it.
triage labels and assigns every new issue and pull request, then routes it. Inference model haiku; default permissions. It has no forge subscription: its flows send it a todo for each new or reopened issue and each new pull request.

Run one triage agent per swarm. Its flows send to members, so every triage agent gets every new item, and two of them would both label and assign it.

An existing ruth, created before this archetype, keeps her own config repo and model. Set sonnet in the swarm UI's inference settings for her if wanted.

Each built-in archetype also sets services.hyperhive.agent.icon, so its agents show an icon in the swarm UI until their config sets another.

Where an archetype comes from

A flake declares archetypes in its hyperhiveArchetypes output:

hyperhiveArchetypes.reviewer = {
  module = { };
  meta = {
    description = "Reviews what it is sent.";
    permissions = [ "messaging" "inbox" "execution" ];
    limits = { memory_max = "4G"; };
    inference = { effort = "high"; };
    prompt = "You review pull requests and never push.";
  };
};

A long prompt can live in a file next to the flake. builtins.readFile gives a plain string at evaluation, so meta stays plain data:

hyperhiveArchetypes.reviewer.meta.prompt = builtins.readFile ./prompts/reviewer.md;

Today the swarm reads one flake: the hyperhive source the builder's host runs, so only the built-ins appear. The meta flake has one archetype source too, its own hyperhive input, and refuses an archetype from any other source name.

The prompt

An archetype's meta.prompt is starting text for the new agent's AGENTS.md: a reviewer that never pushes, a triage agent that keeps its notes in one place. Picking the archetype in the create form fills the form's AGENTS.md box with it, next to the permissions, caps and inference it fills. Edit the text freely; the agent starts with what the box holds when you create it. An archetype without prompt leaves the box alone.

Notification flows

An archetype's meta.flows lists notification router flows that run for every agent of the archetype, next to the built-in flows and the ones in the operator's document. A todo node in them sends to members: every agent created from the archetype.

hyperhiveArchetypes.triage.meta.flows = [
  {
    id = "new-issues";
    name = "new issues get a greeting";
    nodes = [
      { id = "src"; kind = "source"; events = [ "issues" ]; }
      { id = "opened"; kind = "match"; when = [ { field = "action"; equals = "opened"; } ]; }
      {
        id = "tell";
        kind = "todo";
        to = "members";
        op = "upsert";
        key = "forge:{{ repo }}#{{ number }}:greet";
        text = "greet {{ repo }}#{{ number }}: {{ title }}";
      }
    ];
    edges = [
      { from = "src"; to = "opened"; }
      { from = "opened"; to = "tell"; }
    ];
  }
];

On the board

The notification router card on /swarm lists each archetype flow under archetype flows, tagged with its archetype and with the agents it applies to now, drawn as a graph with hit counts like the other flows. The flow follows the archetype: an edit to the archetype reaches the card and every agent within about 10 seconds, and the card has no edit button.

How the list stays current

The swarm controller asks the builder for the list when the queue connects and every 10 minutes after. A builder host redeploy can change it, and the next pass picks the change up. The controller leaves an archetype that fails its check off the list and logs it. When no builder answers, the controller keeps the stored list, and a swarm with no builder shows no archetype select.

The query, the stored record and the retry timing: archetypes.md.

Creating an agent from an archetype

The create form sends the picked archetype as archetype on POST /api/agents, { "source": "hyperhive", "name": "reviewer" }. The controller refuses with 400 an archetype the stored list doesn't hold, then:

  1. stores the choice in the agent-archetype KV bucket, keyed by agent name, next to the agent's permissions, caps and inference;
  2. queues the creation graph without CreateRepo, AddRepoMember and InitAgentConfigRepo. Identity, forge user, docs read, the mints and the wanted state stay, and the deploy waits on those alone.

Destroying the agent deletes its key. Every hive may read any key of the bucket ($JS.API.DIRECT.GET.KV_agent-archetype.>) and write none; only the controller writes it.

Deploy swarm-nats-auth before the hives: every provision reads the agent's key, and a hive whose queue connection predates the grant gets a refused read, so its Provision nodes fail until it reconnects.

swarm-controller renders internal/meta's flake.nix with the hive-meta-flake crate, and reads each agent's archetype from the agent-archetype bucket to do so. For an archetype agent the render:

The swarm builds from internal/meta alone and the hive deploys that closure. The hive reads the agent's key when it provisions the agent and on every rebuild, and keeps the last value read in /var/lib/hyperhive/swarm-agent-archetypes.json. When the read fails, a rebuild keeps the stored value. For an archetype agent the hive also:

The agent's system prompt says it has no config repo and names its archetype.

The module comes from the hyperhive input that internal/meta pins, not from the hive's own. When that pin predates the archetype, the agent's build fails with this hive's hyperhive input has no archetype <name>; update that input. Update the hyperhive pin in internal/meta to fix it.

Turn into custom

An archetype agent can become a custom agent with its own agent-configs/<name> repo, either from the agent's overview in the swarm UI (the "turn into custom" button asks first) or with POST /api/agents/{name}/custom. The agent keeps its state, permissions, caps, inference settings and accounts. Its configuration stays the same, except that it no longer has HIVE_ARCHETYPE in its environment. Keeping the config current is then up to the repo's owner. Nothing here undoes it.

The controller refuses with 409 an agent that no hive or more than one hive places, and one whose hive doesn't list the no-config-checkout capability (see below). Otherwise it queues a job graph:

  1. CreateRepo, CreateForgeUser and AddRepoMember: the repo and the agent's access to the repo, as for any custom agent. Each is a no-op for what exists.

  2. SeedArchetypeConfig commits two files to the repo. It copies nothing from the archetype:

    • flake.nix declares the archetype's source as an input, at the URL internal/meta holds for that source today (a pinned rev, which is the input's only pin: the repo has no lock, and a source meta doesn't pin to a commit fails the node), and imports inputs.<source>.hyperhiveArchetypes.<name>.module next to ./agent.nix;
    • agent.nix is an empty module for the owner's edits.

    The node leaves a repo whose flake.nix already is this file alone, whatever URL it pins. Any other flake.nix fails the node.

  3. DropArchetype deletes the agent's agent-archetype key, only after the seed and the member grant succeeded. A failure before it leaves the agent archetype-built and working, and you can send the same request again.

  4. UpdateMeta, then the build and the deploy, as for a merged config PR. If the build fails, the agent is custom and has no key. Sending the request again then queues only this step, as the earlier ones have run.

When the source is hyperhive, the meta flake sets agent-<name>.inputs.hyperhive.follows = "hyperhive" for an agent whose flake.nix or flake.lock declares a hyperhive input, so the lock holds one hyperhive, and the module comes from the pin internal/meta holds. Any other source keeps the pinned URL from its seeded flake.nix, and the meta lock records that rev. The follows applies to every custom agent whose flake.nix declares a hyperhive input, not only converted ones. A hyperhive node left in a lock doesn't count.

Which hives may convert

A hive that keeps a checkout of a custom agent's config would create one for the converted agent, under the container's running mount. A hive that lists no-config-checkout under capabilities in the status it publishes (the document GET /api/hives/status serves as snapshot) keeps none: it deploys a custom agent's closure from the swarm alone, and the agent clones its own repo from the forge. The controller reads the agent's hive's latest status and refuses unless it's fresh and lists the capability; an older hive lists none. Deploy the release to every hive that places archetype agents before converting theirs.