Learning Experts' Unwritten Rules as Bounded-Memory Monitors

Experts follow rules they rarely write down. "Never restart the service unless you looked at its logs in the last few commands." "Confirm with the customer before any irreversible change." "Put the plate down before the cutlery." Most of these rules share one shape: an action is allowed only if something happened, or did not happen, in the recent past. This note proposes to extract such rules from logs of expert behavior by searching only over that shape. The hypothesis space is guard rules written in past-time temporal logic, which is logic that talks only about what has already happened, with a bounded look-back depth or time window. The payoff of this restriction is that every candidate rule is a small monitor with a fixed-size state. That lets the learner score thousands of candidate rules while reading an unbounded stream of behavior in constant memory. It also means the rules it outputs can be installed directly as runtime guards on an agent.

The two literatures this joins have each solved half of the problem. Work on bounded history encoding shows how to evaluate a given temporal query over an infinite stream while keeping only a fixed amount of past state. Work on tacit knowledge externalization recovers rules from demonstrations, but it does so either in offline batch over stored complete traces or as informal text. The core claim is that restricting hypotheses to bounded-past guards has two consequences. First, the likelihood used by the best existing specification learner becomes a running sum over monitor states, so batch inference becomes streaming inference. Second, the same monitor states say precisely when the learner is uncertain enough about the current step to be worth asking the expert a question.

Core Claim

The closest existing work is Bayesian Inference of Temporal Task Specifications from Demonstrations. It infers Linear Temporal Logic (LTL) specifications from positive-only demonstrations using Markov chain Monte Carlo over stored traces. Its search uses three templates: things that always hold, things eventually completed, and orderings. Its key ingredient is a "size principle" likelihood that favors the most restrictive specification consistent with the data. It reaches over 90% Jaccard similarity to ground truth on a 71-demonstration table-setting task, with runtimes of roughly 10 to 90 minutes. It is post-hoc, needs whole traces, and has no metric windows ("within 5 seconds").

We keep its size-principle idea and change two things. We change the hypothesis form to guards of the shape $G(a \rightarrow \varphi)$, read as "always, action $a$ only when $\varphi$." Here $\varphi$ is a pure-past formula of past depth at most $d$ or metric window at most $w$. We also change the inference to a single online pass. Let $A_R(h_t)$ be the set of actions that rule set $R$ permits after history $h_t$. Assume the expert chooses uniformly among permitted actions and slips with small probability $\epsilon$. Under those assumptions the log-likelihood of a demonstration stream is

$$\log P(a_{1:T}\mid R)=\sum_{t=1}^{T}\Big[\mathbb{1}[a_t\in A_R(h_t)]\,\log\tfrac{1-\epsilon}{|A_R(h_t)|}+\mathbb{1}[a_t\notin A_R(h_t)]\log\epsilon\Big].$$

Because every guard's truth value at time $t$ is a function of that guard's finite monitor state, $A_R(h_t)$ is computable from those states alone. The sum can therefore be accumulated incrementally. Memory is proportional to the number of live hypotheses times the monitor state size, and it does not grow with $T$.

Restricting to past-time guards loses little in principle for safety-style rules. Temporal Query Answering in DL-Lite uses Gabbay's separation theorem to rewrite mixed past/future queries into past-only ones for bounded-buffer monitoring. It notes the non-elementary blow-up of that rewriting. We avoid the blow-up by never writing future formulas in the first place: hypotheses are born in past-only form.

Research Program

The system has three parts.

Hypothesis proposal. A generator enumerates bounded-past guards over a fixed vocabulary of logged events. The vocabulary covers tool calls, shell commands, object placements, and simple arguments. The formulas use previous, since, once-within-$w$, and negation. This is where a skeptic's simplest alternative gets absorbed rather than argued against. A language model reading a sample of traces is a cheap, strong proposer of plausible rules. We use it as one proposal source alongside enumeration. We never let it score rules; scoring comes only from the likelihood above.

Monitoring and pruning. Each candidate is compiled to a deterministic monitor. The pure-past fragment gives constant-memory monitors directly, in the manner of the fixed-horizon discarding in Online Quantitative Timed Pattern Matching with Semiring-Valued Weighted Automata. It also follows the fixed-size intermediate tables in On Implementing Temporal Query Answering in DL-Lite (extended abstract). Scoring is exact for single guards. For conjunctions, where guards interact through $|A_R(h_t)|$, we score a beam of top-scoring rule sets and rescore it periodically. Hypotheses whose posterior falls below a threshold are dropped together with their state.

This pruning is our answer, in the learned setting, to the open problem stated in ElGolog: A High-Level Programming Language with Memory of the Execution History. There, standard progression destroys the execution log that history-dependent tests need, and "selective forgetting" of safe-to-discard history is left open. ElGolog assumes a programmer writes the history-dependent tests. We learn them. The bounded summary of the log is simply the joint monitor state of the surviving hypotheses. This is weaker than a general forgetting operator such as Bounded Forgetting, which preserves all entailments up to quantifier rank $k$. It is exact for the rules actually retained.

Question selection. At a step where the surviving high-posterior rules disagree on whether the action just taken or about to be taken is allowed, the system may ask the expert one yes/no question: "Would doing $a$ right now be wrong?" The question is chosen to maximize expected posterior entropy reduction under a budget. The answer acts as a labeled negative or positive example. Positive-only learners otherwise lack negative examples.

This contrasts with ClearFairy: Capturing Creative Workflows through Decision Structuring, In-Situ Questioning, and Rationale Inference. ClearFairy decides when to ask based on an LLM's judgment of how strong a verbal explanation is, and it passes the full growing log to the model. It raised strong explanations from 14% to over 83% with 85% acceptance of inferred rationales. Its output, though, is natural-language rationale, not checkable rules. The DISCIPLE-1 apprentice system (DISCIPLE-1) also asks targeted corrections on concrete steps. It keeps an unbounded, growing theory.

This design deliberately stays away from natural-language rule elicitation. Verifiable Natural Language to Linear Temporal Logic Translation reports GPT grounding accuracy as low as 13–34% in its Warehouse domain, with end-to-end NL2TL accuracy of 46.2%. Operating over logged events avoids the grounding step entirely. The cost is that it requires a pre-given event vocabulary, a limitation we share with the Bayesian specification work.

Testbeds and Metrics

We use three settings.

Table-setting demonstrations. The 71-demonstration corpus from Bayesian Inference of Temporal Task Specifications from Demonstrations tests whether streaming inference matches batch accuracy. The metric is Jaccard similarity to the ground-truth specification, as in that paper. We also report wall-clock time and peak memory.

τ-bench traces. The retail and airline domains of τ-bench provide the "tacit" test. The policy documents contain many history-dependent rules, such as authenticating the user before touching their records and obtaining explicit confirmation before a consequential write. We hand-formalize these as ground-truth past-time guards over tool calls. We then hide the policy from the learner. The learner sees only traces verified successful against final database state; these are drawn from the tasks' reference actions and from filtered agent rollouts. We measure rule-recovery precision and recall against the formalized policy.

Synthetic streams. Planted guards with varied depths, windows, and distractor regularities are generated at horizons up to millions of events. They measure how memory and accuracy scale with horizon, and how recovery degrades as the planted depth exceeds the learner's bound $d$.

The SRE shell logs behind SHREC would be the ideal real-world stream. The file does not indicate that they are public, so they are treated as an opportunistic extension, not a dependency.

Baselines

The naive reference points are two. The first permits every action, which gives zero recovered rules and is the floor for recall. The second is a frequency baseline that proposes "action $a$ only after action $b$" for every pair where $b$ preceded $a$ in at least a fixed fraction of occurrences. The frequency baseline is what an engineer would hack together in an afternoon. Beating it matters most on precision, since co-occurrence will fire on habitual but non-mandatory orderings.

The strongest existing method is the batch Bayesian LTL learner of Bayesian Inference of Temporal Task Specifications from Demonstrations, with its complexity-based likelihood. Its reported result on the table-setting domain is over 90% Jaccard similarity to ground truth in roughly 10 to 90 minutes, while TempLogIn failed to terminate within 24 hours. We run it on the same traces and the same proposition vocabulary. We give it its published templates plus our past-time guard templates, so that differences come from inference, not hypothesis coverage. Its MCMC budget is matched in wall-clock to ours. Beating it means matching its Jaccard within noise on table setting while using constant memory and one pass. It also means exceeding it on streams long enough that it must be run on a window. No reported result was found on Lacuna for this method on τ-bench or on long synthetic streams, so those comparisons are new.

A sequential pattern mining baseline in the style of SHREC applies SPAM frequent sequences with the same support threshold we tune for our pruning. It represents the behavioral-knowledge-graph line. It cannot express negation or "unless," so we expect it to miss guards of the form "no write since the last confirmation."

The LLM baseline gives a frontier model all training traces within its context window and asks it to write guard rules in our formula syntax. Those rules are scored with the same recovery metric. It gets the same number of traces and a comparable token budget to our proposer.

Three ablations isolate the key ingredients. The first replaces the size-principle likelihood with a binary consistent/inconsistent likelihood. The prior work already found this distinction important, and it should matter here too, because without it "always allowed" explains everything. The second removes the depth bound, allowing monitors that keep unbounded history, to measure what the bound costs in accuracy and saves in memory. The third removes active questioning at a fixed trace budget, to measure how many expert questions substitute for how many extra demonstrations. The questioning experiments use a simulated expert who answers from the ground-truth rules. The results therefore measure query efficiency, not human burden. A small follow-up with real practitioners would be needed to make claims about the interruption tax.

Why not just…?

Why not just put all the traces in a long-context LLM and ask it for the rules? This is the most serious threat, and on τ-bench in particular the model may simply recognize customer-service conventions from pretraining. It also underlies the proposal itself, since an LLM is one of our rule proposers. The evidence that it falls short as a scorer is indirect. τ-bench reports GPT-4o at 35.2% pass^1 on airline and 61.2% on retail. The same paper notes that a pass^1 around 60% often craters below 25% at pass^8, which suggests context-held rules are not applied consistently. That concerns applying rules, not inducing them, so our LLM baseline tests induction directly. If it matches our recovery precision and recall, the contribution narrows to the bounded-memory monitor and the downstream guard. We would report it that way. The synthetic streams with non-conventional planted rules separate recognition from induction.

Why not just rerun the batch Bayesian learner on a sliding window every so often? For rules whose relevant evidence is rare, a window discards exactly the evidence that separates competing hypotheses. Repeated reruns also cost the full MCMC time each time. The synthetic experiments vary the rarity of rule-triggering events to find the crossover. If windowed batch matches us at realistic rarities, the claim reduces to efficiency.

Why not just mine frequent sequences as SHREC does? Frequent-sequence mining finds what experts usually do, not what they must not do. Its output has no negation and no "since," so it cannot state "never write since the last confirmation." The recovery metric on formalized τ-bench policy rules, many of which are prohibitions, measures this directly.

Why not just clone the expert's behavior with a sequence model or learn a reward? A cloned policy may behave well, but it externalizes nothing inspectable. It cannot separate a mandatory ordering from a habit, a point Bayesian Inference of Temporal Task Specifications from Demonstrations makes about inverse reinforcement learning. We do not claim our rules produce better behavior than cloning. We claim they produce auditable constraints. The downstream experiment below tests whether those constraints add reliability on top of a strong policy.

Decisive Checks

Three results would establish the idea.

Streaming matches batch. On table setting, streaming inference must reach the batch learner's over-90% Jaccard within noise. Its memory must stay flat as we replay the demonstrations as one long stream.

Recovery of hidden policy rules. On τ-bench, recovered guards must achieve higher precision than frequent-sequence mining at equal recall on the hand-formalized history-dependent policy rules. The comparison with the long-context LLM baseline is reported whichever way it falls.

Guards improve agent consistency. Installing the recovered guards as runtime monitors on a GPT-4o agent must raise pass^k on held-out airline tasks relative to the unguarded agent under the same prompts. The guards reject a violating tool call and return the violated rule as a message. A failure in any of the three would falsify the corresponding part of the claim.

A fourth check tests the bound itself. On synthetic streams, accuracy should degrade sharply once planted rules exceed depth $d$ and stay flat below it. If recovery instead degrades gradually with horizon, the constant-memory argument is not doing the work we claim.