Swamp tutorial: make AI agent work repeatable
By Flavio
Updated
Tagged: AI
Learn how Swamp turns one-off AI agent work into typed, repeatable automation with models, workflows, assertions, and versioned data.
If you ask an AI agent to solve a tricky task today, it’ll probably figure it out. Ask it again tomorrow and it might take a completely different route, skip a check you cared about, reach for another tool, or miss a detail that only lived in yesterday’s chat.
That’s what Swamp is built for. You let the agent work out how to do the job once, and Swamp locks that work into typed models and workflows so every future run behaves the same way.
The example that made it click for me was a personal voice recorder setup. You record a quick note, and it might turn into a reminder, a research task, or a coding job. The agent figures out what the note is asking for, then hands off to Swamp to run the right automation and update the stored data.
You can picture the split between the agent and Swamp like this:
Agent decides what to build
↓
Swamp runs it repeatably
↓
Versioned data records what happened
Let’s walk through how Swamp fits together and build a small automation with it from scratch.
What Swamp is
Swamp is an open source automation runtime built specifically for AI agents. Rather than being another chat app or model provider, it sits underneath your agent as a CLI tool. Codex, Claude Code, Cursor, or whichever coding agent you use can call it to build and run automations.
It gives the agent six building blocks to work with:
- Models describe a single typed operation
- Workflows wire operations together into a dependency graph
- Data stores versioned outputs from every run
- Vaults keep credentials out of your files and logs
- Extensions package reusable models and integrations
- Skills teach your coding agent how to operate Swamp
If you’re already familiar with how MCP works, it helps to compare the two. MCP exposes tools an agent can call during a session, while Swamp gives the agent an execution layer for turning a working solution into a repeatable system. You can use both together because they cover different parts of the job.
The idea behind models
Every Swamp model splits into two pieces: a model type and a model definition.
The model type holds the reusable code, defining what inputs it accepts, what methods you can call on it, and what shape of data it saves. A model definition configures one concrete instance of that type.
Say we build an HTTP check model type that knows how to fetch a URL and measure how long the response takes. From that single type, we can spin up multiple definitions:
HTTP check type
├── check-primary → https://example.com
└── check-backup → https://example.org
All the logic lives in one place, and each definition just passes in its own URL and timeout. That beats having an agent write two separate check scripts from scratch, because once you build a model type you can reuse it anywhere in the repo.
Install Swamp
Swamp runs on macOS and Linux. You can install the CLI with the official install script:
curl -fsSL https://swamp-club.com/install.sh | sh
If you’d rather not pipe a remote script straight into your shell, open the URL in your browser and read through it first.
Once it finishes, restart your shell and check that the CLI is working:
swamp version
The installer drops the binary into ~/.local/bin, so if your shell says the command isn’t found, add that directory to your PATH.
Sign in to Swamp
Since October 2026, Swamp requires a swamp-club.com account before commands like swamp repo init will run. Sign in from your terminal with:
swamp auth login
If you don’t have an account yet, that flow creates one for you. You can verify which account is active anytime by running swamp auth whoami.
On a CI server you won’t have a browser to sign in through, so set the SWAMP_API_KEY environment variable instead. The Swamp account requirement page walks through generating the key and the sign-in token that goes with it.
Create a Swamp repository for Codex
Start by creating a fresh Git repository for this tutorial:
mkdir swamp-endpoint-check
cd swamp-endpoint-check
git init
Next, initialize Swamp in that folder and tell it you’re using Codex:
swamp repo init --tool codex
That generates a .swamp.yaml config file along with directories for models, workflows, vaults, and runtime data. It also writes Swamp instructions into AGENTS.md and installs its agent skills under .agents/skills/.
From there you can open Codex in this directory (if you haven’t used Codex yet, check out my complete guide to Codex) and ask it to walk you through getting started:
$swamp-getting-started
Because the installed skill gives Codex the current CLI commands and file formats, the agent can operate Swamp for you without guessing at syntax. For this tutorial, though, we’ll build each piece by hand so you can see what the agent generates under the hood.
Create a typed HTTP check
Create a new file at extensions/models/http_check.ts to define an HTTP check model type with a single check method:
import { z } from 'npm:zod@4'
const GlobalArguments = z.object({
url: z.string().url(),
timeout: z.number().positive().default(5000),
})
const Result = z.object({
status: z.number(),
latency: z.number(),
ok: z.boolean(),
})
export const model = {
type: '@local/http-check',
version: '2026.08.21.1',
globalArguments: GlobalArguments,
resources: {
result: {
description: 'HTTP endpoint check result',
schema: Result,
lifetime: 'infinite' as const,
garbageCollection: 100,
},
},
methods: {
check: {
description: 'Request the endpoint and record its status',
arguments: z.object({}),
async execute(
_args: Record<string, never>,
context: any,
) {
const { url, timeout } = context.globalArgs
const startedAt = Date.now()
let status = 0
let ok = false
try {
const response = await fetch(url, {
signal: AbortSignal.timeout(timeout),
})
status = response.status
ok = response.ok
} catch {
// A network error stays status 0 and ok false
}
const result = {
status,
latency: Date.now() - startedAt,
ok,
}
const handle = await context.writeResource(
'result',
'result',
result,
)
return { dataHandles: [handle] }
},
},
},
}
Swamp uses those Zod schemas both to document the model and to validate its inputs and saved outputs. Notice that the result resource has an infinite lifetime and retains its latest 100 versions, which we’ll query in a minute.
Make sure Swamp picks up your new model type by inspecting it from the CLI:
swamp model type describe @local/http-check
The output lists the url and timeout arguments, the result resource, and the check method.
Create two model definitions
Now let’s create two endpoint checks from that same model type. Start with the primary check:
swamp model create @local/http-check check-primary \
--global-arg 'url=https://example.com' \
--global-arg 'timeout=5000'
Then add the second definition for the backup endpoint:
swamp model create @local/http-check check-backup \
--global-arg 'url=https://example.org' \
--global-arg 'timeout=5000'
Both definitions share the same TypeScript code, while their individual settings live as YAML files under models/ so you can review and commit them to Git.
Try running the primary check directly:
swamp model method run check-primary check
Swamp prints the arguments it received along with the typed data from the run. You can also query the stored result data for check-primary anytime:
swamp data query 'model("check-primary") && name == "result"' --select content
That outputs a table with columns for status, latency, and ok. You’ll see a 200 status and ok set to true, while latency will vary depending on your connection. Pass --json if you want machine-readable output instead.
If you run into older Swamp tutorials using swamp data get check-primary result, it still works for now, though it’s deprecated and prints a warning pointing you to the matching swamp data query command.
Connect the checks in a workflow
A Swamp workflow is a directed acyclic graph (DAG): steps that don’t depend on each other run in parallel, and downstream jobs wait until their dependencies finish.
Create an empty workflow to start:
swamp workflow create endpoint-check
Swamp writes a new YAML file inside workflows/. Open it, keep the id it generated at the top, and replace the rest of the file with:
id: <keep the generated id>
name: endpoint-check
tags:
purpose: tutorial
jobs:
- name: collect
description: Check both endpoints in parallel
steps:
- name: primary
task:
type: model_method
modelIdOrName: check-primary
methodName: check
- name: backup
task:
type: model_method
modelIdOrName: check-backup
methodName: check
- name: verify
description: Verify the collected results
dependsOn:
- job: collect
condition:
type: completed
steps:
- name: primary-is-healthy
task:
type: assert
expr: data.latest("check-primary", "result").attributes.ok == true
message: The primary endpoint must be healthy
severity: high
- name: backup-is-healthy
task:
type: assert
expr: data.latest("check-backup", "result").attributes.ok == true
message: The backup endpoint must be healthy
severity: high
version: 1
Because neither step inside collect depends on the other, Swamp can run both checks at the same time. Once collect finishes, verify runs and evaluates its assertions against the latest typed results using CEL expressions.
Before running the workflow, validate its configuration:
swamp workflow validate endpoint-check
If you want to see how the jobs connect, you can print its graph too:
swamp workflow get endpoint-check --graph
Everything looks right, so go ahead and run it:
swamp workflow run endpoint-check
As long as both endpoints return a successful HTTP status, the workflow passes.
Make the workflow fail on purpose
Let’s break one of the checks on purpose to see how Swamp handles failures. Open the YAML file under models/ with name: check-backup and point its URL at a local port where nothing is listening:
globalArguments:
url: http://localhost:9
timeout: 2000
Now run the workflow again:
swamp workflow run endpoint-check
Even though the request failed, the HTTP model still writes a valid typed result:
{
"status": 0,
"latency": 2,
"ok": false
}
Then the verify job reads that output and fails the workflow on the assertion. Separating data collection from pass/fail rules keeps models clean: the model just records what happened, and the workflow decides whether that result is good enough.
Query the run history
Each time a check ran, Swamp saved a new version of its result resource. You can list the version history for the backup check with:
swamp data versions check-backup result
You can also query across all stored data to pull out every failed check:
swamp data query 'attributes.ok == false'
Because every run lands as structured data with a schema, version number, timestamp, and model identity, you don’t have to dig through raw logs or ask an agent to reconstruct what went wrong. Better yet, any later workflow or script can query those stored results directly and act on them.
Let the agent extend the system
Once you have a working pattern in the repo, you can hand changes off to Codex. Try giving it a prompt like this:
Add a third endpoint to the endpoint-check workflow.
Run all HTTP checks in parallel.
Add an assertion that fails when latency is over 1000ms.
Validate the models and workflow, then show me the graph.
Codex reads the Swamp skill, inspects your http_check model type, adds the new model definition, wires it into the workflow, and runs validation. You still get the agent’s flexibility while designing the change, and once those YAML and TypeScript files are saved, every future run executes them directly without relying on chat history.
Where vaults fit
Our two example endpoints are public, so we didn’t need any secrets here. Most real automations aren’t like that, and you definitely don’t want API keys sitting inside model definitions or workflow YAML.
Swamp vaults keep credentials in a separate store and let your definitions reference them through expressions like this:
vault.get('production', 'api-token')
Swamp can also redact secret values from command output and keep credential access isolated from the versioned data layer. That matters a lot when an agent is editing your repo: the agent can wire up a workflow that uses a credential without ever copying the secret into generated files or terminal logs.
How I would use Swamp
The first place I’d try Swamp is release verification for the open source projects in my software library. Every repo has its own quirks, yet the release checklist almost always follows the same steps:
- Run tests.
- Build the release artifact.
- Check the source package for private files and secrets.
- Verify the documentation and checksums.
- Run a smoke test.
- Record the result.
Setting that workflow up for a new repository is a great job for a coding agent, since it can inspect the codebase and figure out the exact commands and checks for that project. Once the workflow is written, though, every release should run the same typed steps, hit the same verification gates, and leave behind a queryable record instead of asking the agent to improvise a fresh checklist every time you ship an update.
You don’t need to move every existing script into Swamp, though. If a short shell script already handles a stable task reliably, leave it alone. Swamp pays off when a job spans several systems, an agent is helping you build out integrations, you need to inspect past run outputs later, or a team needs to share the same automation.
What to watch out for
Swamp is a fairly big runtime built for a specific kind of work. Reach for it when you want repeatable runs, typed outputs, managed secrets, versioned history, parallel execution, or reusable integrations. For a one-line cron job, it’s overkill.
Keep in mind that extensions are executable code, so review any third-party extension before installing it the same way you’d vet a package or an agent tool. Also check the license and pricing before adopting Swamp in a commercial team or hosted service: it’s licensed under AGPL-3.0 with an additional extension and definition exception.
Since Swamp faithfully repeats whatever model and workflow you give it, you still need solid tests, strict assertions, tightly scoped credentials, and a human approval step in front of any destructive action. I dug deeper into where to draw that line in how to let an AI agent perform irreversible actions safely.
The useful mental model
Use your coding agent for the exploratory part: figuring out the task, writing the TypeScript model type, wiring up the YAML, and adding new checks when requirements change. Once the workflow passes validation, let Swamp run it from the repo so every run validates its own inputs and outputs and leaves a queryable history behind.
Want me to talk about your product? You can sponsor this site.
Related posts about ai: