Skip to content

Architecture Overview

Mash is a self-hosted, durable runtime for building agentic applications where users and agents work together. You write your agents and workflows in Python, deploy them behind one API on your own Postgres, and connect them to the places your users already are: a Slack workspace, your product, a terminal.

Your application sends Mash events, one for each thing a user says or does. A session holds the context of one conversation, so every agent in it knows what came before. An app holds memory across its sessions, so a new conversation starts with what earlier ones learned. A policy controls what agents can access, such as a sandbox to run code in and a browser to work on websites. Mash has no concept of a user. The application decides who takes part in a session, whether one person or a whole team, and everyone in it shares the same context.

A team bot in Slack

A team bot is a good fit. Each channel is an app, each thread is a session, and each message is an event.

Slack                                            Mash
───────────────────────────────────────────────  ─────────────────────────────────
#growth                                          app: growth
│                                                (memory for the channel)
│
├─ Thread                                        session
│  │                                             policy: growth
│  │
│  ├─ Alice: @bot pull last week's churn         event → agents
│  ├─ bot:   Run this query on the replica?      approval from an agent
│  │         [Approve] [Deny]
│  ├─ Alice: Approve                             answer to the approval
│  ├─ bot:   Churn was 2.1%, up from 1.8%        response
│  ├─ Bob:   @bot break it down by plan          event in the same session,
│  │                                             with Alice's context
│  └─ bot:   Pro 1.2%, Team 3.4%                 response
│
└─ Thread                                        new session, same app
   ├─ Carol: @bot what drove the Team churn?     event; knows what the
   └─ bot:   ...                                 channel has looked at

Alice asks for churn numbers and the bot hands the question to the right agents. One of them checks with her before it touches the database, and she approves from the thread. Bob picks up where she left off without repeating anything. A week later Carol opens a new thread, and the bot already knows what the channel has been working on.

The rest of this post follows Alice's message through the parts that handle it, in the order it reaches them. Each part has a post of its own in the Architecture series, and this one links to them.

What agents can do

Agents in Mash work for people, and they check in with them. An agent can ask for approval before it acts, ask a question when it needs an answer, and hand a browser to the user to sign in to a site. The request waits for the person, through restarts, for as long as the policy allows.

Each policy gives agents a computer to work on. In the sandbox, agents write and run code: they analyse a file, build a chart or a page, keep a database, and hand the user a link to what they made. In the browser, they work on the sites the user has signed in to, such as downloading a bill or checking an order. Mash never sees the password, and the sandbox holds no secrets.

A host puts several agents and workflows behind one conversation. A built-in companion reads each message and hands it to the agent or workflow that fits it, and every agent in the conversation reads what was said before, whichever agent said it. Workflows cover the work that should run the same way every time, as typed steps in code with agents where they are needed.

The pieces

Piece What it is In the team bot
App The application posting events, named by app_id. It scopes memory. The #growth channel, app growth
Event One input to a host: a message, posted to a session. Alice's message
Session One conversation. Its events run one at a time, in order. The Slack thread
Policy A named resource that owns a sandbox and a browser and sets what agents may use. Policy growth
Host The agents and workflows deployed together, which events are posted to. analyst, researcher, weekly-metrics
Companion The built-in agent every event to a host starts on. It routes the message. Picks analyst for the churn question
Board A conversation's entries, one per request, read by every agent routed in it. What Bob's request reads before it answers
Cortex Per-app memory, built from every session of the app. What Carol's new thread knows a week later

One message, end to end

sequenceDiagram
    participant Bot as Slack bot
    participant Host as Host<br/>(session queue)
    participant Co as Companion
    participant An as Analyst<br/>(agent process)
    participant Bd as Board
    participant Sb as Policy sandbox

    Bot->>Host: POST /sessions/{thread}/events
    Host-->>Bot: request_id
    Host->>Co: event reaches the front of its session
    Co->>Bd: read entries
    Co->>An: routed request (/h2a relay)
    An->>Bd: read at context load
    An->>Bot: approval prompt for run_query
    Bot->>Host: approve (same events endpoint)
    An->>Sb: run_code (host /sandbox relay)
    Sb-->>An: chart link
    An->>Bd: one entry at commit
    An-->>Bot: response

The event. The bot posts Alice's message to POST /api/v1/sessions/slack:C42:1731864100.0001/events with its event_id (the Slack message timestamp), app_id: growth, policy_id: growth and the text. The host stores it as a row in the events table and returns a request_id derived from the session and event ids. A redelivered webhook with the same event_id returns the same row. The first event binds the thread to the policy. Events and sessions covers the queue, the event statuses and the stream.

The companion. When the event reaches the front of its session, the host starts it as a request on the companion. The companion runs no agent loop. It makes one structured output call whose only field is an enum of the host's agent ids, workflow ids, about and unclear, with the agents' metadata, the board and the message as input. It picks analyst, starts the analyst's request in the same session through the host's /h2a relay, and ends. The event follows the analyst's request from then on. The companion covers routing, workflow routes and recovery.

The agent process. Each agent on the host runs as its own subprocess of the host (mash agent serve) on a localhost port. The analyst's request runs the think, act, observe loop there: a model call, tool calls, a commit, and again until the model answers. Every step appends its output to runtime_event_log with a dedupe key. If the process dies, the host restarts it and the request continues from its events. The durable agent loop covers that.

The approval. The model calls run_query, which has requires_approval. The loop opens an approval interaction and waits. The event's status becomes waiting, the bot renders the prompt from the request.interaction.create frame, and Alice's click comes back as a post to the same events endpoint with the interaction_id and approve. The wait survives restarts for as long as the policy allows. Human-in-the-loop covers approvals, questions and browser sign-ins.

The sandbox. To build a chart, the analyst calls run_code. The call goes to the host's /sandbox relay with the agent's token and the request id, and the host runs it in the growth policy's sandbox, in the analyst's own folder. The model hands Alice a link to the chart the code wrote. Policies: sandbox and browser covers what a policy controls.

The board. When the analyst's request commits, it writes one entry to the conversation's board: Alice's message, the reply, and analyst as the author. Tool calls and results stay in the request's event log. Bob's message is the next event in the thread. The companion reads the board, routes Bob's follow-up to the agent that wrote the churn entry, and that request reads the board at context load, so it knows what Alice asked. The shared board covers entries, the summary the companion writes when the board grows, and the board tools.

Cortex. A week later Carol opens a new thread. Her session has an empty board, but the app growth has a Cortex if the host enabled it: a profile in every request's system prompt and a search_cortex tool over entries built from the channel's earlier sessions. Cortex covers how a build runs and how the app edits the result.

Workflows. On Monday the bot posts @bot run the weekly metrics digest. The companion picks the weekly-metrics workflow, fills its input from the message with a second structured output call, asks for any required field it could not fill, and runs it. A scheduler can also start the same workflow directly with POST /api/v1/workflow/weekly-metrics/run, under an app and a policy and with no session. Workflows covers the step pipeline.

The core agent loop

Every agent request runs the same durable request, whether the companion routed it or a workflow step started it. Inside it, the agent loop thinks, acts and observes with the request's context, memory, tools and skills, and ends with a response and optional structured output. It can pause for a person, and it is resumable, replayable and traced. Code the model writes runs in the policy's sandbox, the browser tools drive the policy's browser, and remote tools call the MCP servers the agent connects to.

                               api · cli · REPL
                                       ▲
                                       │
                                       ▼
┌─ Host ──────────────────────────────────────────────────────────────────────┐
│                                      │                                      │
│            ┌─────────────────────────┼─────────────────────────┐            │
│            ▼                         ▼                         ▼            │
│      ┌───────────┐            ┌─────────────┐            ┌───────────┐      │
│      │   agent   │            │  companion  │            │ workflow  │      │
│      │           │            │  (events)   │            │           │      │
│      └───────────┘            └─────────────┘            └───────────┘      │
│            │                         ▲                         │            │
│            │   approvals, questions  │ classifier: routes to   │            │
│            │   and answers go back   │ one agent per message   │            │
│            │           ┌─────────────┼─────────────┐           │            │
│            │           ▼             ▼             ▼           │            │
│            │      ┌─────────┐   ┌─────────┐   ┌─────────┐      │            │
│            │      │  agent  │   │  agent  │   │  agent  │      │ agent step │
│            │      └─────────┘   └─────────┘   └─────────┘      │            │
│            │           │             │             │           │            │
│            └───────────┴─────────────┼─────────────┴───────────┘            │
│                                      │ every agent request                  │
│                                      ▼                                      │
│                 ┌─────────────────────────────────────────┐                 │
│                 │          Durable Request                │                 │
│                 │                                         │                 │
│                 │   ┌─ context ─── memory ──┐             │                 │
│                 │   │                       │             │                 │
│                 │   │     Agent Loop        │ ─► response │                 │
│                 │   │ think → act → observe │       ┊     │                 │
│                 │   │                       │       ▼     │                 │
│                 │   └─ tools ───── skills ──┘  structured │                 │
│                 │      │                        output    │                 │
│                 │      │ ▲ user interaction               │                 │
│                 │      │ │ (approval / ask-user /         │                 │
│                 │      │ ▼  browser sign-in)              │                 │
│                 │      │                                  │                 │
│                 │      │  resumable · replayable · traced │                 │
│                 └──────┼──────────────────────────────────┘                 │
└────────────────────────┼────────────────────────────────────────────────────┘
            ┌────────────┴─────────────┬──────────────────────────┐
            │ run_code                 │ browser                  │ MCP tools
            ▼                          ▼                          ▼
┌───────────────────────┐  ┌───────────────────────┐  ┌───────────────────────┐
│ Sandbox: per policy   │  │ Browser: per policy   │  │ MCP servers: your own │
│ workspaces/<agent_id> │  │ Chromium, own profile │  │ remote tools          │
│ files persist         │  │ listed sites only     │  │ web search            │
│ no secrets · no db    │  │ sign-in via live view │  │ listed at startup     │
└───────────────────────┘  └───────────────────────┘  └───────────────────────┘

Processes and trust

The host is one process that serves the API, runs the session queues, and supervises the agent processes. It holds the API key and MASH_HOST_SECRET. Each agent process holds its own model keys and database connections, and gets an agent token derived from the secret. Sandboxes and browsers are Docker containers, one of each per policy, started on first use and stopped when idle.

The host is the trust boundary. The app authenticates with the API key and asserts its app_id and policy_id, and the host stores them on every request and never shows them to the model. Agents reach the sandbox, the browser and other agents only through the host's relays, which read the app and policy from the request as stored. A model cannot pick another policy's sandbox, and a request the companion routes always carries the companion request's app and policy. The H2A RFC specifies the host-to-agent calls.

Storage

Everything durable is in one Postgres database:

Tables What they hold
sessions, events Each session's host and policy, and every event with its status and outcome
policies Policy documents
runtime_request, runtime_event_log Each request's identity and status, and its ordered events, the only record of a request in flight
memory_turns, memory_signals Board entries, one per request, and per-turn signals
cortex_app, cortex_entry Each app's profile and entries
workflow_runs, workflow_steps, workflow_step_events Runs, per-step input and output snapshots, and the step audit trail

Traces are computed from runtime_event_log, which names each event after the OpenTelemetry span it opens or closes, and can be exported over OTLP. Reading a trace covers that.

Running Mash

Mash runs on your infrastructure: one host process, your Postgres, and Docker for the sandboxes and browsers. Every request is durable, so a restart picks up mid-conversation. Each agent picks its own model, from Anthropic, OpenAI and Gemini to open-source models like Gemma, Qwen and DeepSeek on your own hardware.

You work with it over an HTTP API from any stack, or from the mash CLI and REPL, which you can ship as your own branded client. Every request is traced with OpenTelemetry and can go to Grafana, Datadog or any OTLP backend. Before launch, synthetic evals generate test scenarios from your host's agents and score how well it handles them, so you can compare changes on quality and cost. Getting started covers installing it and sending your first event, and the deployment guide covers a server.

The next post starts where the message enters: the event and its session.

Next: Events and Sessions.