Work with your agent

Model a feature with your agent

Use a model to improve the design, then carry its rules and counterexamples into implementation tests.

Prerequisites: an installed Snap Pea CLI, an application repository, and a feature involving shared state, concurrency, retries or recovery. For an introduction to P, start with your first model.

Give the agent the contract

Describe what must remain true, the storage primitives that are actually atomic, and the failures you expect. Ask the agent to record assumptions and model bounds alongside the design. A useful starting instruction is:

Use P to model this feature before implementing it. Snappea is installed.
Read snappea guide. State the contract, atomic primitives, failure assumptions
and model bounds. Check the model and investigate lints, coverage gaps and
undetected mutations. Turn counterexamples into regression tests, then check
real application events against the same specs. Report what remains unchecked.
snappea guide
snappea guide modeling
snappea guide testing
snappea guide examples

The guide ships with the binary, so the agent can read it without browsing documentation. For a complete model-to-application example, ask it to readsnappea guide example reservation: an atomic reservation versus a stale read/write, with Python tests.

Review the model before implementation

Check that separate operations can interleave where the real system allows them to. A model that treats a read and a later write as one atomic operation assumes away the lost-update bug. Review specs against the contract independently of the implementation algorithm.

snappea check
snappea check --json
snappea check lint
snappea check mutation

Use the reported replay command to inspect a failure. Fix the design when the trace exposes a real bug; fix the model when its assumptions are wrong. Keep the scenario that exposed it.

Coverage identifies behavior the workload did not exercise. Lints catch common weak models. Mutation testing asks whether checks reject changed behavior. Investigate findings rather than removing the checks to obtain a pass.

Connect the implementation to the spec

Ask the agent to implement the reviewed design and record actual operation arguments and results. Use the helpers for Python, Rust, Go or Java to check those events against the model's specs.

Force the important interleavings in implementation tests: for example, ensure two calls read the same value before either writes. Run the real application calls; do not replace them with invented event lists. Keep each model counterexample as a regression test where practical.

The inventory model and application examples share a stock-reservation spec across languages.

Start from a runnable example

Export a complete queue model, independent contract, Python implementation and saved pytest regressions:

snappea guide example cas-queue --out /tmp
cd /tmp/cas-queue
python -m pip install pysnappea pytest
snappea check Queue.pproj --timeout 30s --deny mutation --json
python -m pytest -q

The tests force load/CAS conflicts without matching private storage-key names, retry through new objects after state changes, distinguish an empty result from zero, and show the shared P monitor rejecting an actual implementation defect. Sequential observations have a known operation order; concurrent races use ordinary assertions because response order is not commit order.

For immutable staging, root-CAS publication and saved crash/retry tests, export snappea guide example blob-publication --out /tmp. Its in-memory storage simulates durability across recreated workers. Read each README for the finite request, record and crash bounds. Require complete model exploration and zero coverage or mutation gaps; exit status alone does not establish that. These application tests validate selected real histories, not every execution or full model equivalence.

Keep the loop running in CI

Add snappea check and your ordinary application tests to CI. Start with automatic scheduling, then choose a time budget appropriate to the model. See GitHub Actions and the CLI reference.

Review search completion, model bounds, quality findings and instrumentation alongside a passing status. The model and observed events can both omit requirements. Update the design, model and tests together as the feature changes.

For how we measure agent outcomes, see the minimal-prompt eval.