Module commit

Module commit 

Source
Expand description

Commit governance for a tool that acts on the world: idempotency and compensation.

A voice agent that charges a card or books a table can call the same tool twice for one intent. The model retries after a timeout, the user repeats themselves, a resumed session replays. CommitGuard wraps such a tool:

  • Idempotency. An idempotency key is rendered from a template ("{user_id}:{amount}"). A call whose key already succeeded returns the first call’s result without running the tool again. The result is remembered in state under idempotency_key(tool, key). Calls with the same key run one at a time, so two concurrent retries (a duplicate background call, say) still charge once.
  • Compensation. When the tool fails, a compensating tool (a refund, a release) runs with the same arguments to undo any partial effect, and compensated:{tool} is set in state. The failure is still reported to the model.

Policy::commit(..) in the fluent crate lowers to this.

Structs§

CommitGuard
A tool wrapped with idempotency and compensation. See the module docs.

Functions§

compensated_key
The state key raised after a failed commit was compensated.
idempotency_key
The state key that remembers a committed call’s result.