Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Heuristic:1ay1 Agentty Effects As Values

From Leeroopedia
Knowledge Sources
Domains Architecture, Functional_Programming
Last Updated 2026-10-28 14:00 GMT

Overview

Represent side effects (file writes, API calls, state mutations) as data values that a pure reducer returns, so that the effect is described but not executed — the runtime interprets it, keeping the reducer pure and testable.

Description

The Effects_As_Values heuristic (the Elm architecture pattern) requires that the pure update/reducer function does not perform side effects directly. Instead, it returns effect descriptions as data values (a variant of "write this file," "call this API," "update this state"). The runtime interprets these effect values and executes them. This keeps the reducer pure — it is a pure function of (state, message) → (new_state, effects) — which makes it trivially testable (no mocks needed) and deterministic (same input always produces same output).

In agentty this appears in the persistence-as-effects implementation (`store_fx.hpp`) which represents persistence operations as effect values that the runtime interprets.

Usage

Apply this heuristic when using a reducer/update-loop architecture. The reducer must not perform IO directly — it returns effect descriptions as data. The runtime interprets and executes them. Test the reducer by checking the returned (state, effects) pair, not by mocking the filesystem.

The Insight (Rule of Thumb)

  • Action:*** Return side effects as data values from the reducer; let the runtime interpret them.
  • Value:*** Reducer is pure and testable without mocks; effects are inspectable and replayable.
  • Trade-off:*** Indirection (reducer describes, runtime executes); but the separation enables testing, replay, and auditing.
  • Compatibility:*** Pairs with Heuristic:1ay1_Agentty_Purity_Contract — the reducer is a pure function.

Reasoning

A reducer that performs IO directly (writes to disk, calls an API) is impossible to unit-test without mocking the filesystem and network. A reducer that returns effect descriptions is pure: `assertEqual(reducer(state, msg), (expectedState, [WriteFileEffect(...)]))`. No mocks, no filesystem, no network. The runtime interprets the effects, and the interpretation can be swapped (real filesystem, in-memory test filesystem, replay log) without changing the reducer. This also enables effect auditing: the sequence of effects is a log of what the system did, which can be replayed for debugging or tested for correctness.

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment