Skip to main content

Module turn_cache

Module turn_cache 

Source
Expand description

Per-turn memoization of turn-stable host capability reads.

Context assembly reads runtime.pipeline_input many times per agent-loop iteration — harn#5190 measured ~20 identical round-trips per turn, a cost that grows as hosts deliver more data through that channel. This module front-runs the thread-local HOST_CALL_BRIDGE with a per-turn memo so those reads collapse to one host round-trip per turn, leaving every call site unchanged. The allowlist ([is_turn_stable]) is deliberately narrow.

The memoized value is stable only within a turn: the host re-projects runtime.pipeline_input each turn (e.g. so a mid-session model switch is observed on the next prompt). The memo is therefore cleared at each agent-loop iteration boundary (iteration_start, wired in __host_agent_emit_event) and at run/embedder boundaries via [reset].

Functions§

lookup
Read a turn-stable host fact from the current turn’s memo.
lookup_by_name
Split a dotted capability.operation host-call name and lookup it. Convenience for embedder host_call implementations, which receive the dotted wire name rather than a split pair.
store
Memoize a turn-stable host fact for the remainder of the current turn. Non-allowlisted (capability, operation) pairs are ignored, so a caller cannot widen the allowlist by calling this directly. See lookup.
store_by_name
Dotted-name counterpart to store. See lookup_by_name.