A horde: one [task] agent per document, a bounded pool, a hard token budget, each verdict stored exactly once, a summary at the end
Demonstrates: horde(), on_result / on_error / on_done, budget_tokens, horde_status, an [immutable] result slot (a second write would raise). Serve: SOMA_LLM_MOCK=echo SOMA_LLM_MOCK_LATENCY_MS=1000 soma serve horde_audit.cell POST /audit {"n": 2000} then GET /progress (and /__soma/ for the dashboard) Test: SOMA_LLM_MOCK=echo soma test horde_audit.cell
A Soma program from the agents part of the verified corpus: 58 lines, cells Audit, Reviewer, AuditTest. It passes soma check with soma 3.2.4.
How it is built
The cell Audit declares 3 signals in its face: audit(n: Int) -> String, progress() -> Map and summary() -> Map; keeps 3 memory slots: verdicts (Map<String, Map>, persistent and immutable), failures (Map<String, String>, persistent) and batch (Map<String, String>, persistent). Handlers: audit (line 21), progress (line 32) and summary (line 33). Private helpers: _store, _failed and _finish.
The cell Reviewer has no face and no memory. Handlers: review (line 40).
The file also holds 1 test cell (AuditTest) with 5 assertions, run by soma test.
The source
soma.toml
[package]
name = "agents-corpus"
version = "0.1.0"
description = "Verified AI-agent example cells (training corpus)"
# Agent LLM config. `mock = "echo"` keeps every example in this directory
# hermetic: `soma test` / `soma run` need no network and no API key, and
# results are deterministic. For a live run, delete the `mock` line (or
# override with SOMA_LLM_MOCK) and provide the key via env.
[agent]
provider = "anthropic"
model = "claude-opus-4-6"
key = "${ANTHROPIC_API_KEY}"
mock = "echo"
# Termination proof for verified_termination.cell's `workflow` machine:
# every path eventually reaches a terminal, no deadlocks.
# `cells` scopes these properties to Solver — the other agents in this
# directory have their own state names and must not inherit them.
[verify]
cells = ["Solver"]
deadlock_free = true
eventually = ["done", "failed"]
[verify.after.understanding]
eventually = ["solving", "failed"]
[verify.after.solving]
eventually = ["verifying", "failed"]
[verify.after.verifying]
eventually = ["done", "failed"]horde_audit.cell
// A horde: one [task] agent per document, a bounded pool, a hard token
// budget, each verdict stored exactly once, a summary at the end.
// Demonstrates: horde(), on_result / on_error / on_done, budget_tokens,
// horde_status, an [immutable] result slot (a second write would raise).
//
// Serve: SOMA_LLM_MOCK=echo SOMA_LLM_MOCK_LATENCY_MS=1000 soma serve horde_audit.cell
// POST /audit {"n": 2000} then GET /progress (and /__soma/ for the dashboard)
// Test: SOMA_LLM_MOCK=echo soma test horde_audit.cell
cell Audit {
face {
signal audit(n: Int) -> String
signal progress() -> Map
signal summary() -> Map
}
memory {
verdicts: Map<String, Map> [persistent, immutable]
failures: Map<String, String> [persistent]
batch: Map<String, String> [persistent]
}
on audit(n: Int) {
let docs = range(0, n) |> map(i => map("id", "doc-{i}", "text", "contract {i}: the supplier may terminate at will"))
let h = horde(Reviewer.review, docs, map(
"concurrency", 200, "budget_tokens", 2000000, "max_attempts", 2,
"on_result", "_store", "on_error", "_failed", "on_done", "_finish"))
batch.set("current", h)
return h
}
on _store(v: Map) { verdicts.set(v.id, v) }
on _failed(d: Map, e: Map) { failures.set(d.id, e.kind) }
on _finish(h: String) { batch.set("finished", h) }
on progress() { return horde_status(batch.get("current") ?? "") }
on summary() {
let high = verdicts.values() |> filter(v => v.risk == "high")
return map("reviewed", len(verdicts), "high", len(high), "failed", len(failures))
}
}
cell agent Reviewer {
on review(d: Map) [task] {
require len(d.text) > 0 else EmptyDocument
let note = think("Risk of: {d.text}", map("max_tokens", 60))
let risk = if contains(d.text, "terminate at will") { "high" } else { "low" }
return map("id", d.id, "risk", risk, "note", note)
}
}
cell test AuditTest {
rules {
let h = Audit.audit(20)
assert Audit.progress().state == "done"
assert Audit.progress().done == 20
assert Audit.summary().reviewed == 20
assert Audit.summary().high == 20
assert Audit.summary().failed == 0
}
}What the toolchain says
$ soma check horde_audit.cell
note: 'immutable' on 'verdicts' implies 'consistent' (added automatically)
--> horde_audit.cell:17:9
|
17 | verdicts: Map<String, Map> [persistent, immutable]
| ^
warning: agent cell 'Reviewer' has no state machine — add a state section for verified behavior
✓ 1 warning(s), no errors.$ soma test horde_audit.cell
test AuditTest ...
✓ assert Audit.progress().state == "done"
✓ assert Audit.progress().done == 20
✓ assert Audit.summary().reviewed == 20
✓ assert Audit.summary().high == 20
✓ assert Audit.summary().failed == 0
5 tests: 5 passed, 0 failed$ soma verify horde_audit.cell
Verifying horde_audit.cell...
No state machine in this program: nothing to prove beyond `soma check` (invariants and lifecycles are what verify proves).
✓ cost: horde(Reviewer.review, …) in `audit` ≤ 2000000 tokens — budget_tokens: every think() of its tasks and callbacks reserves its bound first (a hard ceiling while the provider honors max_tokens)
note: the soma.toml beside this file declares [verify] properties; none applies here (no state machine)
VERIFY OK (vacuous — no state machine)Builtins used
contains, filter, horde, horde_status, len, map, range, think