Mash¶
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, a session holds the context of one conversation, an app holds memory across its sessions, and a policy controls what agents can access. The architecture overview walks through a Slack team bot built this way.
Agents get a sandbox to run code in, a browser for the sites users sign in to, web search, local and remote (MCP) tools, skills, and pauses for approvals and questions. Mash also ships synthetic evals, an API and CLI, and OpenTelemetry traces, and runs on both frontier and open-source models.
Try it now with Pilot:
Pilot is a ready-made Mash host
that ships in the mashpy repo. Its pilot agent answers questions about the Mash
codebase from the source and searches the docs site and GitHub in the policy's
browser, and its builder agent builds Mash apps in the policy's sandbox. It runs from a checkout with Docker Compose, which is a good way to get a
feel for the runtime before building your own.
# 1. Clone the repo; put GEMINI_API_KEY, OPENROUTER_API_KEY and MASH_HOST_SECRET in .env
git clone https://github.com/imsid/mashpy.git && cd mashpy
# 2. Start Postgres and the host
docker compose -f docker-compose.pilot.yml up -d --build
# 3. Install the CLI, create a policy, save the connection, and start asking
curl -fsSL https://raw.githubusercontent.com/imsid/mashpy/main/install.sh | sh
echo '{}' | mash policy put me --file - --api-base-url http://127.0.0.1:8000
mash connect --api-base-url http://127.0.0.1:8000 --app-id pilot --policy-id me
pilot repl
Once you're ready to build your own agent, keep reading.
Install:
The rest of this page builds the Slack team bot from the
architecture overview: a #growth channel whose bot
answers metrics questions, researches the market, and posts a weekly metrics
digest.
Define your agents:
Each agent is an AgentSpec subclass. It names itself, picks an LLM, and
declares a system prompt, tools, skills and agent config. The analyst's
run_query tool needs approval, so the bot asks in the thread before it
touches the database.
## team_bot/agents.py
from mash import AgentSpec
from mash.core.config import AgentConfig
from mash.core.llm import AnthropicProvider
from mash.skills import SkillRegistry
from mash.tools.base import FunctionTool, ToolResult
from mash.tools.registry import ToolRegistry
from .warehouse import query_replica # your own database code
async def run_query(args):
rows = await query_replica(args["sql"])
return ToolResult.success(rows)
class AnalystAgent(AgentSpec):
def get_agent_id(self):
return "analyst"
def build_tools(self):
tools = ToolRegistry()
tools.register(FunctionTool(
name="run_query",
description="Run a read-only SQL query on the analytics replica.",
parameters={
"type": "object",
"properties": {"sql": {"type": "string"}},
"required": ["sql"],
},
requires_approval=True,
_executor=run_query,
))
return tools
def build_skills(self):
return SkillRegistry()
def build_llm(self):
return AnthropicProvider(agent_id="analyst")
def build_agent_config(self):
return AgentConfig(
agent_id="analyst",
system_prompt="You answer product metrics questions from the analytics replica.",
)
class ResearchAgent(AgentSpec):
def get_agent_id(self):
return "researcher"
def build_tools(self):
return ToolRegistry()
def build_skills(self):
return SkillRegistry()
def build_llm(self):
return AnthropicProvider(agent_id="researcher")
def build_agent_config(self):
return AgentConfig(
agent_id="researcher",
system_prompt="You research competitors, pricing and market questions.",
)
Author the workflow:
The workflow is the automation that should run the same way every week: an
ordered pipeline of typed steps that code owns end to end. Use a CodeStep
for deterministic Python and an AgentStep when the work needs an agent.
## team_bot/workflows.py
from pydantic import BaseModel, Field
from mash import AgentStep, CodeStep, StepContext, WorkflowSpec
from .warehouse import weekly_metrics # your own database code
class WeeklyMetricsRequest(BaseModel):
week_start: str = Field(description="The Monday the week starts on, as YYYY-MM-DD")
class MetricsSnapshot(BaseModel):
week_start: str
signups: int
churn_rate: float
churn_by_plan: dict[str, float]
class MetricsDigest(BaseModel):
summary: str
highlights: list[str]
def pull_metrics(
request: WeeklyMetricsRequest,
_context: StepContext,
) -> MetricsSnapshot:
row = weekly_metrics(request.week_start)
return MetricsSnapshot(week_start=request.week_start, **row)
WEEKLY_METRICS = WorkflowSpec(
workflow_id="weekly-metrics",
input_model=WeeklyMetricsRequest,
metadata={
"display_name": "Weekly metrics digest",
"description": "Pulls one week's signups and churn and writes a digest.",
},
steps=[
CodeStep(
step_id="pull",
run=pull_metrics,
input=WeeklyMetricsRequest,
output=MetricsSnapshot,
),
AgentStep(
step_id="digest",
agent_id="analyst",
input=MetricsSnapshot,
output=MetricsDigest,
),
],
)
The CodeStep output becomes the AgentStep input. Mash validates both edges,
runs each step durably, and uses the last step's output as the workflow result.
Build the host:
The host is the unit of deploy: agents and workflows registered together. The companion routes every message to one of them, and the metadata is what it reads to choose.
## team_bot/host.py
from mash import AgentMetadata, HostBuilder
from .agents import AnalystAgent, ResearchAgent
from .workflows import WEEKLY_METRICS
def build_host():
return (
HostBuilder()
.agent(
AnalystAgent(),
metadata=AgentMetadata(
display_name="Analyst",
description="Answers product metrics questions from the analytics replica.",
capabilities=["signups", "churn", "revenue", "SQL"],
usage_guidance="Questions about the product's own numbers.",
),
)
.agent(
ResearchAgent(),
metadata=AgentMetadata(
display_name="Researcher",
description="Researches competitors, pricing and the market.",
capabilities=["web research", "competitor pricing"],
usage_guidance="Questions about anything outside the product's data.",
),
)
.workflow(WEEKLY_METRICS)
.build()
)
A host can also be workflows alone. A workflow of pure CodeSteps references
no agents, and the resulting host serves only workflow runs:
def build_host():
# EXPORT_METRICS is a WorkflowSpec of pure CodeSteps; no agents needed.
return HostBuilder().workflow(EXPORT_METRICS).build()
Configure the environment:
The host needs an LLM key, a Postgres URL for its durable runtime, and a
secret it derives agent and sandbox tokens from. Put them in a .env file the
host loads on start:
# .env
ANTHROPIC_API_KEY=sk-ant-...
MASH_DATABASE_URL=postgresql://user:pass@localhost:5432/mash
MASH_HOST_SECRET=... # openssl rand -hex 32
Start the host:
The host runs each agent as its own subprocess. For agents to get the sandbox
tools, it also needs a Docker daemon; it pulls Mash's sandbox image,
ghcr.io/imsid/mash-sandbox, on first start. Without Docker the host still
runs, and its agents get no sandbox tools. Agents whose specs list sites with
browser_sites() also get the browser tools, and the host pulls Mash's browser
image, ghcr.io/imsid/mash-browser, the first time one opens a page.
Create a policy, connect, and browse available agents. Every message is
an event that names the app posting it and the policy it runs under. For the
bot, the #growth channel is the app growth, and its policy is also
growth. The connection saves both:
echo '{"sandbox": true}' | mash policy put growth --file - \
--api-base-url http://127.0.0.1:8000
mash connect --api-base-url http://127.0.0.1:8000 --app-id growth --policy-id growth
mash browse
Talk to the host or execute / commands using the Mash REPL:
The Slack bot itself posts each message to
POST /api/v1/sessions/{session_id}/events, with the thread as the session.
Events and sessions covers that API.
Learn More¶
- General concepts: the building blocks behind every agentic platform
- Architecture overview: what Mash offers, the parts of a deployment, and how an event moves through them
Architecture¶
- Events and sessions: how an app posts work, and how a session orders it
- Companion: the classifier, and routing each message to one agent or workflow
- Shared board: the context every agent in a conversation reads, and its one summary
- Cortex: memory across sessions, scoped to the app
- Policies: sandbox and browser: what agents can use, and the computer they work on
- Durable agent loop: the event log as a request's only state, recovery, and cancel
- Human-in-the-loop: approvals, questions and browser sign-ins on one durable mechanism
- Workflows: typed step pipelines mixing code steps and agent steps
Agent Building Blocks¶
- One LLM contract: normalized requests, caching, streaming
- Open-source models: running Gemma, Qwen, and DeepSeek on the same harness, self-hosted or hosted
- Skills: Instructions on demand: markdown bundles loaded through one meta-tool
- Remote tools over MCP: connecting MCP servers and their tools
Observability & Evals¶
- Reading a trace: events to spans to latency answers
- Synthetic evals: generated datasets and rubrics, experiments over the live host, read-time comparison
Reference¶
- H2A Protocol RFC: the host-to-agent boundary
- Reference documentation: the module READMEs for specs, tools, providers, hosts, workflows and policies
Guides¶
- Exploring Mash with Pilot: ask the Pilot CLI questions about the Mash codebase
- Host API and CLI: the HTTP surface applications integrate with, and the REPL built on it
- Building an agent CLI: an app's own CLI, built on the Mash REPL
- Deploying a Mash Host: agent processes, per-policy sandboxes and browsers, on a laptop or a server
- Release process: how versioning, changelogs, and releases work
Learnings¶
- Prompt caching and the token meter: what an eval fan-out pays on a cold cache, read from real scoring runs