Assertions
Most bugs in an agent framework do not crash. A tool step that ran with no calls, a transaction left open in the store, a list of outputs one shorter than its inputs: each of these lets the program carry on with state that is quietly wrong, and you find out three steps later, or after a resume. Troupekit follows the TigerBeetle style here: state what must be true, and stop the moment it is not.
What it looks like
These are three of the checks in the code. The run state machine refuses a tool step with no calls, and checks that every call got exactly one output:
assert!(!calls.is_empty(), "a tool step has at least one call");inrun.rsassert_eq!(outputs.len(), calls.len());inrun.rs
The SQLite store checks that no call starts inside a transaction or leaves one open, which is what keeps a checkpoint either fully written or not written at all:
assert!(conn.is_autocommit(), "a store call left a transaction open");inlib.rs
What it guarantees
- They run in release builds. The crates use
assert!, notdebug_assert!; the library code has nodebug_assert!at all. A broken invariant panics in production too, where silent corruption would cost the most. - They check internal invariants, not your input. Bad input, such as a blank law, a missing model or an over-long tool name, comes back as a named error from
buildor the call. An assertion is for a state that the code itself should make impossible. - There are many of them. Counting
assert!,assert_eq!andassert_ne!in the library sources before their test modules, v0.4.0 at 1ba7709 has about 380.
What it does not guarantee
An assertion turns a silent bug into a loud one; it does not remove the bug. A panic stops the step it happens in. Whether it also ends the process depends on your program; either way the last checkpoint was written before that step, so with Storage::sqlite checkpoints the run can resume from it like after any other crash (Durable runs). The number above is a plain text count, not a measure of coverage.