Security
~9 min readUpdated: December 2026

FormalClaw: Verification-Grounded Contracts for Reliable Multi-Agent Communication

FormalClaw 4-Tier Verification-Grounded Multi-Agent Contract and Evidence Protocol

FormalClaw (arXiv:2612.00411, Peking University) replaces unstructured natural-language agent hand-offs with verifier-checkable contracts K=(Γ, R) and evidence-carrying messages M=(y, E, τ′). By routing individual obligations across four verification tiers—Trace Evidence, Structured Checks, SMT Solvers, and Kernel Proofs—without demanding full-environment formalization, FormalClaw lifts Qwen3.5-4B safety on SCAM from 26.30% to 89.20% and ClawArena Qwen3.5-9B performance from 44.02% to 82.08%.

Technical Review: Smoke Monkey Core Architecture Team
Tested on Node.js 18+ & BunTypeScript 5.x
Quick Answer & Executive Definition

FormalClaw: Verification-Grounded Contracts for Reliable Multi-Agent Communication: FormalClaw (arXiv:2612.00411, Peking University) replaces unstructured natural-language agent hand-offs with verifier-checkable contracts K=(Γ, R) and evidence-carrying messages M=(y, E, τ′). By routing individual obligations across four verification tiers—Trace Evidence, Structured Checks, SMT Solvers, and Kernel Proofs—without demanding full-environment formalization, FormalClaw lifts Qwen3.5-4B safety on SCAM from 26.30% to 89.20% and ClawArena Qwen3.5-9B performance from 44.02% to 82.08%. Designed as a zero-dependency, open-source TypeScript architecture under the MIT License with native Model Context Protocol (MCP) support and deterministic phase state machines.

Key Architectural Takeaways
Quick Implementation Exampleformalclaw-contract-agent.ts
formalclaw-contract-agent.tstypescript
import { createAgent } from '@smoke-monkey/harness';
// Enforce FormalClaw precommit & post-output contract obligations in Smoke Monkey Harness
const contractedAgent = createAgent({
agentId: 'formalclaw-verified-executor',
provider: 'openai-compatible',
model: 'Qwen/Qwen3.5-9B',
baseUrl: 'http://127.0.0.1:8000/v1',
workspacePath: process.cwd(),
permissions: {
read_file: 'allow',
write_file: 'ask', // Gate mutations through FormalClaw precommit verifier
run_command: 'ask',
},
mcpServers: {
filesystem: {
command: 'npx',
args: ['-y', '@modelcontextprotocol/server-filesystem', process.cwd()],
},
},
});
async function executeVerifiedContract() {
const result = await contractedAgent.run(
'Execute migration under FormalClaw contract: Tier 1 assert AccessedData not in /secrets, Tier 2 assert runtime <= 60s, Tier 3 verify Z3 role-permission invariant, and attach clause evidence bundle.'
);
console.log('Verified contract hand-off:', result.summary);
}
executeVerifiedContract().catch(console.error);
Video Guides

Watch: Related Video Guides

A2A vs MCP: AI Agent Communication Explained

A2A Protocol (Agent2Agent) Explained: How AI Agents Collaborate

How FormalClaw’s 4-Tier Verification Protocol Replaces Unstructured Prompts

Unstructured multi-agent instructions suffer from specification drift across tool hops, while full formal verification (like FormalJudge) fails when open-ended environments cannot be completely formalized. FormalClaw turns every hand-off into a contract-and-evidence handshake C -> K / M -> A, decomposing obligations r_i = (predicate, scope_selector, tier) across four practical tiers:

TierVerification MechanismWhen SelectedConcrete Contract Check Example
Tier 1Trace EvidenceEnvironment logs raw access without structured assertionsAccessedData ∉ τ_private (no private file reads)
Tier 2Structured CheckDeterministic Python/TypeScript runtime assertionsCompleteTime(τ) <= 60s and schema validation
Tier 3SMT VerificationDecidable symbolic constraints over state variables∃u ∈ Users(db2), Perm3(u) ≠ Perm2(u) is unsat
Tier 4Kernel ProofFully formalizable mathematical/code theoremsLean 4 theorem migrate_correct : ... := by ...

Benchmark Results: SCAM Safety, ClawArena, Multi-Agent Swarms & DPO

Evaluated across SCAM, ClawEval, ClawArena, TAMAS, and CuisineWorld (budget=5), FormalClaw outperforms natural-language refinement (LLM+NL), Python feedback (LLM+Structured), AgentSpec, Progent, and FormalJudge:

Benchmark & ModelDirect ExecutionLLM + NLAgentSpec / FormalJudgeFormalClaw
SCAM Safety (Qwen3.5-4B)26.30%52.94%67.60% / 58.80%`89.20% (+62.90)`
SCAM Safety (Qwen3.5-27B)54.80%67.13%87.40% / 72.90%`94.90% (+40.10)`
ClawArena (Qwen3.5-9B)44.02%63.89%42.02% / 47.91%`82.08% (+38.06)`
ClawArena (Qwen3.5-2B)12.37%17.50%16.91% / 21.81%`35.86% (2.05x NL)`

In heterogeneous orchestrator-executor swarms, FormalClaw drove TAMAS attack success rates near zero and raised CuisineWorld schema-valid message rates by 17–29 points over structured JSON and 27–48 points over natural language. Sequential DPO training on FormalClaw’s verified refinement trajectories reached 81.25% on Qwen3.5-9B, whereas NL and Python feedback traces degraded under multi-stage preference tuning.

Precommit Gating Stops Irreversible Side Effects

FormalClaw evaluates precommit clauses on a copy of environment state before dispatching any tool call—preventing destructive SQL writes or unauthorized network requests from executing even during failed intermediate attempts.

Reproducible FormalClaw Installation & Contract Verification Loop

Clone the official FormalClaw repository released by Peking University (github.com/htlou/formalclaw) and wire tiered SMT/structured checks into your Smoke Monkey Harness verification stage.

bash
# 1. Clone the open-source FormalClaw protocol reference implementation
git clone https://github.com/htlou/formalclaw.git
cd formalclaw && pip install -e . z3-solver

# 2. Run a Tier 3 SMT permission-invariance check before committing a DB migration
python -c "
from z3 import Solver, Int, unsat
s = Solver()
perm_before, perm_after = Int('perm_before'), Int('perm_after')
s.add(perm_before == 1, perm_after == 1, perm_before != perm_after)
assert s.check() == unsat, 'Permission invariant violated'
print('Tier 3 SMT Contract PASS: unsat')
"
Google Search Questions & Answers

Frequently Asked Questions

Q:How does FormalClaw differ from end-to-end formal verification tools like FormalJudge?

FormalJudge tries to formalize the entire environment, which bottlenecks on ambiguous real-world tasks and hurts frontier models (dropping GPT-5 on SCAM from 79.40% to 58.40%). FormalClaw decomposes tasks into local obligations and routes each to the lightest sufficient tier (Trace, Structured, SMT, or Kernel Proof).

Q:What is a FormalClaw contract and evidence-carrying message?

A contract K=(Γ, R) bundles task context with finite obligations specifying predicates, artifact/trace scope selectors, and verification tiers. The executor replies with M=(y, E, τ′) containing the artifact, obligation evidence, and observable execution trace.

Q:How does FormalClaw prevent vulnerability propagation in multi-agent systems?

On the TAMAS multi-agent benchmark, enforcing contract verification at every caller-to-executor hand-off plus precommit tool gating reduced attack success rates near zero across weak-to-strong and strong-to-weak model pairs.

Q:Can FormalClaw refinement traces be used to fine-tune smaller models?

Yes. Converting successful FormalClaw refinement transitions into DPO preference pairs lifted Qwen3.5-9B on ClawArena to 81.25% across three sequential stages, outperforming DPO pairs derived from natural-language or Python feedback.

Q:Where can I integrate FormalClaw concepts inside Smoke Monkey Harness?

Map FormalClaw’s precommit checks to Smoke Monkey Harness’s Edit/Verify state-machine transitions and permission gates, rejecting non-compliant MCP tool calls before filesystem or shell mutation.

Related Alternatives & Comparisons

Related Architecture Guides

View all guides

Build with Smoke Monkey Harness

Zero dependencies. 24 built-in tools. Human-in-the-loop safety. 100% open source under the MIT License.

npm install smoke-monkey-harness