# Multi-Agent Architecture
> Source: https://useagentos.dev/docs/core/architecture

How several agents share one gateway: which agent an inbound message reaches,
how a team of agents hands work around, what happens to the subagents a turn
spawns, and which sessions an agent's tools may reach. This page is the
overview; each section links to the page that documents the commands and
settings.

![Channels on the left feed a central hub, which routes to three agent cards, each with subagent cards beneath it](https://raw.githubusercontent.com/use-agent-os/agent-os/main/docs/assets/architecture/architecture-hero.png)

*Illustration generated with an image model; the diagrams below are the reference.*

Use this page when you run more than the built-in `main` agent: a second agent
bound to a channel, the team preset, or agents that spawn subagents. With one
agent and no bindings, every message goes to `main` and none of the policies
here restrict anything.

| Part | What it decides | Detailed page |
| --- | --- | --- |
| [Routing](#routing) | Which agent answers an inbound message | [`agents.md#routing`](https://useagentos.dev/docs/core/agents#routing) |
| [Agent team](#agent-team) | Which agent may delegate to which | [`agents.md#agent-team-preset`](https://useagentos.dev/docs/core/agents#agent-team-preset) |
| [Subagent lifecycle](#subagent-lifecycle-and-the-session-panel) | How child sessions run, end and report back, and where you see them | [Sessions and History](https://useagentos.dev/docs/core/sessions#abort-a-running-turn), [`web-ui.md#session-tab`](https://useagentos.dev/docs/core/web-ui#session-tab) |
| [Session access](#session-access-decision) | Which sessions an agent's session tools reach | [`sessions.md#session-access`](https://useagentos.dev/docs/core/sessions#session-access) |

Each picture is followed by the same content as a Mermaid diagram, which is
the searchable text of the picture.

## Routing

![Multi-agent routing: channel entries feed the bindings resolution with its six tiers, which routes to the agents ops, support and main; each agent has sessions, one with two subagent child sessions; the session access policy sits under them inside the gateway](https://raw.githubusercontent.com/use-agent-os/agent-os/main/docs/assets/architecture/architecture-routing-dark.png)

```mermaid
flowchart LR
  subgraph GW[Gateway]
    direction LR
    subgraph CH[Channel entries]
      T["telegram, account personal"]
      S["slack, account work"]
      D["discord, account community"]
    end
    subgraph RT["[[bindings]] resolution: most specific tier wins, config order breaks ties"]
      direction TB
      B1["1 exact peer: peer_kind + peer_id"] --> B2["2 peer kind: peer_kind"]
      B2 --> B3["3 guild: guild_id"] --> B4["4 team: team_id"]
      B4 --> B5["5 account: account"] --> B6["6 channel: channel"]
    end
    FB["Fallback: the channel entry's agent_id (default main)"]
    subgraph AG["Agents: workspace, model, tools, skills allowlist"]
      OPS[ops]
      SUP[support]
      MAIN[main]
    end
    subgraph SE[Sessions]
      SO["session agent:ops:…"]
      K1[subagent child session]
      K2[subagent child session]
      SS["session agent:support:…"]
      SM["session agent:main:…"]
    end
    POL{{"Session access policy [session_access]"}}
    T --> RT
    S --> RT
    D --> RT
    RT -->|match| OPS
    RT -->|match| SUP
    RT -.->|"no rule matches, or the rule names an unknown or disabled agent"| FB
    FB -.-> MAIN
    OPS --> SO
    SUP --> SS
    MAIN --> SM
    SO --> K1
    SO --> K2
    SO -.->|"session tools reaching another agent's session"| POL
    POL -.-> SS
  end
```

- A channel entry (`telegram`, `slack`, `discord`, ...) has an `agent_id`,
  `main` unless you set it. `[[bindings]]` send the messages they match to
  another agent.
- When several bindings match, the most specific tier wins: exact peer
  (`peer_kind` + `peer_id`), then `peer_kind` alone, `guild_id`, `team_id`,
  `account`, and `channel` alone. Inside a tier the rule listed first in the
  config wins.
- No match falls back to the channel entry's `agent_id`. So does a binding
  that names an unknown or disabled agent.
- Each agent has its own workspace, model, tool policy and, optionally, a
  `skills` allowlist ([`agents.md#per-agent-skills`](https://useagentos.dev/docs/core/agents#per-agent-skills)).
- The agent is part of the session key (`agent:ops:…`), so a chat bound to
  another agent starts a new session. A subagent is a child session of the
  session that spawned it.
- The CLI, the web console and the desktop app name the agent themselves
  (`agentos agent --agent ops ...`); bindings only route channel traffic.
- Bindings are read when the gateway starts: run `agentos gateway restart`
  after changing them.

Commands and the full match table: [`agents.md#routing`](https://useagentos.dev/docs/core/agents#routing).
Config keys: [`configuration.md#agent-routing-bindings`](https://useagentos.dev/docs/core/configuration#agent-routing-bindings).
Channel setup: [Channels](https://useagentos.dev/docs/core/channels).

## Agent Team

![Agent team: you talk to the coordinator, which spawns the researcher, the writer and the reviewer; artifacts and evidence return to the coordinator; specialists do not delegate to other agents; human approval comes before external actions](https://raw.githubusercontent.com/use-agent-os/agent-os/main/docs/assets/architecture/architecture-team-dark.png)

```mermaid
flowchart LR
  H([You])
  G{{"Human approval first: external send, publication, purchase, deletion, production change"}}
  C["coordinator: allow_agents = [researcher, writer, reviewer], delegation_mode = prefer"]
  R["researcher: allow_agents = []"]
  W["writer: allow_agents = []"]
  V["reviewer: allow_agents = []"]
  RH[helper of its own kind]
  WH[helper of its own kind]
  VH[helper of its own kind]
  H -->|request| C
  C -->|one result| H
  C -.->|before acting externally| G
  G -.->|asks you| H
  C -->|sessions_spawn| R
  C -->|sessions_spawn| W
  C -->|sessions_spawn| V
  R -.->|artifacts and evidence| C
  W -.->|artifacts and evidence| C
  V -.->|artifacts and evidence| C
  R -.-> RH
  W -.-> WH
  V -.-> VH
```

- `agentos agents team create` writes four agents: a **coordinator** you talk
  to and a **researcher**, **writer** and **reviewer** it delegates to.
- The only delegation edges are the coordinator's:
  `allow_agents = ["researcher", "writer", "reviewer"]`. Each specialist has
  `allow_agents = []`: it can still spawn helpers of its own kind, but no
  other agent. There is no edge between specialists and none back to the
  coordinator; results come back as the spawn's completion.
- Specialists return artifacts and evidence to the coordinator, never act
  externally and do not contact you directly.
- All four role contracts start with the same rule: get human approval before
  any external send, publication, purchase, deletion or change to a
  production system.
- `delegation_mode = "prefer"` is prompt guidance only. `allow_agents` is
  what `sessions_spawn` enforces.

The preset, role contracts and delegation modes:
[`agents.md#agent-team-preset`](https://useagentos.dev/docs/core/agents#agent-team-preset).

## Subagent Lifecycle and the Session Panel

![Subagent lifecycle: a parent turn calls sessions_spawn, child sessions go from queued to running to done, failed or cancelled, and the completion wake returns to the parent; beside it the Session panel with Changes and five subagents, the gateway methods it reads, and the sidebar tree](https://raw.githubusercontent.com/use-agent-os/agent-os/main/docs/assets/architecture/architecture-subagent-lifecycle-dark.png)

```mermaid
flowchart TB
  P["Parent session: a turn is running"]
  subgraph KIDS["Child sessions (subagents)"]
    direction LR
    Q[queued] --> RUN[running]
    RUN --> DONE[done]
    RUN --> FAIL["failed (also a timeout or an abandoned run)"]
    RUN --> CAN[cancelled]
  end
  WAKE["Completion wake: runs under the authority ceiling of the turn that spawned the child"]
  P -->|sessions_spawn| KIDS
  KIDS -->|every child of the group has ended| WAKE
  WAKE -->|wakes the parent| P

  subgraph UI["Session panel (web and desktop)"]
    ENV["Environment: Changes +83 −6"]
    SUBS["Subagents: avatar, status, label, duration"]
  end
  TREE["Sidebar tree (web and desktop): child sessions under their parent"]
  M1[checkpoints.summary] -.-> ENV
  M2[checkpoints.diff] -.-> ENV
  M3[sessions.children] -.-> SUBS
  M4["sessions.changed with parent_session_key"] -.-> SUBS
  KIDS -.-> M3
  KIDS -.-> M4
  KIDS -.-> TREE
```

- A turn calls `sessions_spawn` once per child; the call returns at once.
  Each child is a session of its own.
- A child is `queued`, `running`, then `done`, `failed` (also a timeout or an
  abandoned run) or `cancelled`. At most `subagents.max_concurrent_children`
  children of one parent run at a time (default 2); the rest stay `queued` in
  spawn order.
- When the children of a spawn group have ended, the parent session is woken
  once with their results. The wake turn runs under the authority ceiling of
  the turn that spawned the child, never more: a child a channel turn
  spawned does not wake its parent with your reach.
- A scheduled run is the exception: it is one-shot, so nothing under it is
  ever woken. Its `sessions_yield` waits for the children and returns their
  results in the same turn, and every subagent under the run does the same
  for its own children (a job needs `--delegation` to spawn at all); see
  [Scheduling](https://useagentos.dev/docs/core/scheduling#delegate-to-subagents).
- The **Session** panel of the web console and the desktop app reads
  `checkpoints.summary` (lines added and removed since the session's first
  checkpoint), `checkpoints.diff` (the changed files' diff) and
  `sessions.children` (the runs the session spawned, in spawn order). It
  stays live through `sessions.changed`: a child's event carries
  `parent_session_key`, so the panel showing that parent refreshes.
- Both sidebars list child sessions under the session that spawned them,
  with the same avatar as the panel. An avatar is drawn from the child's
  session key alone, so it is the same in every client.

Concurrency, restarts and wake delivery:
[`sessions.md#abort-a-running-turn`](https://useagentos.dev/docs/core/sessions#abort-a-running-turn).
The panel: [`web-ui.md#session-tab`](https://useagentos.dev/docs/core/web-ui#session-tab) and
[`desktop-app.md#session`](https://useagentos.dev/docs/core/desktop-app#session). The sidebar tree:
[`web-ui.md#layout-and-routes`](https://useagentos.dev/docs/core/web-ui#layout-and-routes) and
[`desktop-app.md#subagents-under-their-session`](https://useagentos.dev/docs/core/desktop-app#subagents-under-their-session).
The methods:
[`http-api.md#session-children-and-workspace-changes`](https://useagentos.dev/docs/core/http-api#session-children-and-workspace-changes).

## Session Access Decision

![Session access decision as six checks in order: a caller that is you (the gateway owner), policy at its defaults, the caller's own session, visibility (self, spawned by the caller, tree, agent, all), the pair policy, and allow_agents for spawn and send](https://raw.githubusercontent.com/use-agent-os/agent-os/main/docs/assets/architecture/architecture-session-access-dark.png)

```mermaid
flowchart TB
  S(["A session tool reaches for a target session"])
  C1{"1 Is the caller you, the owner? Your CLI or web console, judged by the original requester, not the envelope a queued turn runs in"}
  C2{"2 Policy at its defaults? visibility = all, agent_to_agent = true, allow_pairs = []"}
  C3{"3 The caller's own session?"}
  V1{"4 visibility = self?"}
  V2{"The caller spawned the target, at any depth?"}
  V3{"visibility = tree?"}
  V4{"visibility = agent?"}
  V5{"Same agent?"}
  P1{"5 Pair policy: same agent?"}
  P2{"agent_to_agent = false?"}
  P3{"allow_pairs empty, or lists [caller, target] (* matches any agent)?"}
  A1{"6 sessions_spawn or sessions_send to another agent?"}
  A2{"The caller's subagents.allow_agents is set?"}
  A3{"It lists the target, or *?"}
  A4{"A tool policy narrowed the caller?"}
  OK([Allowed])
  NO([Refused, or hidden like a missing session])
  SP(["sessions_spawn of another agent (no target session yet)"])
  S --> C1
  SP -->|agent caller| P1
  SP -->|"you, the owner: skips the pair policy"| A2
  C1 -->|yes| OK
  C1 -->|no| C2
  C2 -->|yes| OK
  C2 -->|no| C3
  C3 -->|yes| OK
  C3 -->|no| V1
  V1 -->|"yes (only a page of a spawned child's final answer stays readable)"| NO
  V1 -->|no| V2
  V2 -->|yes| A1
  V2 -->|no| V3
  V3 -->|yes| NO
  V3 -->|no| V4
  V4 -->|yes| V5
  V5 -->|yes| OK
  V5 -->|no| NO
  V4 -->|"no: visibility = all"| P1
  P1 -->|yes| OK
  P1 -->|no| P2
  P2 -->|yes| NO
  P2 -->|no| P3
  P3 -->|no| NO
  P3 -->|yes| A1
  A1 -->|"no: a read, list, yield or pin, or the same agent"| OK
  A1 -->|yes| A2
  A2 -->|yes| A3
  A3 -->|yes| OK
  A3 -->|no| NO
  A2 -->|no| A4
  A4 -->|no| OK
  A4 -->|yes| NO
```

One check covers `sessions_send`, `sessions_list`, `sessions_history`,
`sessions_yield`, `session_pin`, `session_search`, the `acp` tool and
session-bound `cron` jobs. In order:

1. **Your own caller.** A turn from your CLI or web console is not
   limited by `[session_access]`. The caller is judged by the original
   requester, not by the envelope a queued turn runs in: a turn a channel or
   another agent queued on a console session is not yours.
2. **Default policy.** With `visibility = "all"`, `agent_to_agent = true` and
   no `allow_pairs`, nothing is restricted.
3. **Own session.** The session the tool is called from is always reachable.
4. **`visibility`.** `self` hides every other session (only a page of a
   spawned child's final answer stays readable). Otherwise a session the
   caller spawned, at any depth, is reachable, even on another agent. `tree`
   stops there. `agent` adds the caller agent's other sessions. `all` goes on
   to the pair policy.
5. **Pair policy.** Sessions of the same agent pass. `agent_to_agent = false`
   refuses every other pair; otherwise an empty `allow_pairs` allows all
   pairs, and a non-empty one must list `[caller, target]` (`*` matches any
   agent, and pairs are directional).
6. **`allow_agents`.** A cross-agent `sessions_spawn` or `sessions_send` must
   also pass the caller agent's `subagents.allow_agents`, whatever let it
   through above. A spawn has no target session yet, so it starts at the pair
   policy; a spawn you start yourself skips the pair policy but still obeys
   `allow_agents` when it is set. When it is not set, the call is allowed
   unless a tool policy narrowed the caller.

A hidden session answers exactly like a missing one (`Session not found`),
and a refusal names the setting that refused it.

Every mode and its exceptions: [`sessions.md#session-access`](https://useagentos.dev/docs/core/sessions#session-access).
Config keys:
[`configuration.md#session-access-and-per-agent-skills`](https://useagentos.dev/docs/core/configuration#session-access-and-per-agent-skills).

## About the Pictures

The four diagrams are drawn in the console's dark theme colours and typefaces,
and the agent and subagent avatars come from the product's own generator
(`frontend/src/lib/subagent-avatar.ts`). They have their own dark background
and a thin frame, so they read the same on a light and on a dark page. When a
picture and its Mermaid diagram disagree with the code, the code is right:
please [report it](https://github.com/use-agent-os/agent-os/issues/new?template=docs_report.yml).

Read next:

- [Durable Agents](https://useagentos.dev/docs/core/agents)
- [Sessions and History](https://useagentos.dev/docs/core/sessions)
- [Web UI](https://useagentos.dev/docs/core/web-ui)
- [Desktop App (macOS)](https://useagentos.dev/docs/core/desktop-app)
