From Context to Code : Constraint Memory as Executable Checks in Agent Organizations
Abstract
Agent organisations, made of planners, workers, checkers and human approvers, are increasingly assembled by pairing a workflow engine with an agent runtime. This paper studies one such pairing, a LangGraph state graph driving the OpenClaw agent runtime, on a real business task. Against a single-agent baseline on the same platform and model, the organisation spent 23.8 times the tokens and about eleven times the wall-clock time to produce one monthly management report. The cause was structural. The graph opened a new agent session at every step, so 49 sessions each rebuilt the job’s memory by re-reading files that a single agent reads once. We make three contributions. First, we measure the cost of what Ning et al. (2026) call implicit shared state. In the heaviest sessions, reconstructed memory made up 41% of what the agents read but 60% of the tool context they carried, because it was read early and re-sent with every later call. Second, we name the fault that produced it, the one-to-one mapping of workflow steps onto agent sessions, and express its cost in a simple model of agent memory. Third, we propose that one part of agent memory, its constraints, should not live in context at all. In a sample of the job’s instruction text, about three quarters of the rules the agents were asked to remember could be written as executable checks, and one rule was restated 31 times across seven files. We call this constraint memory as code. A foundry step compiles rules into checks, a check library accumulates them across jobs, and the checks run inside the worker and at the points where defects spread. Prior work already stores procedures as code and enforces safety policies as code. What is new here is treating an agent’s accumulated rules as a memory tier whose natural form is a check, chosen for cost and for resilience to compaction. Our data suggest that the direct context saving is modest, about a tenth of carried tool context, while the larger gains lie in replacing model-based verification and preventing rework. We state these claims as testable hypotheses and give a protocol for testing them. Keywords: agent memory, constraint memory, code as harness, multi-agent systems, OpenClaw, LangGraph, context engineering, token economics, runtime verification Author’s note: the problem, ideas and direction of the analysis are the author’s; Claude (Anthropic) assisted with analysis, drafting, figures and formatting. See the declaration on the use of AI before the references.
// Source
Authors: Satyarth Priyedarshi
Institutions: Nirma University