Repository navigation
Rules a bot states about itself in a conversation become learnings candidates an admin promotes - #92
Merged
Merged
Conversation
…ndidates an admin promotes With agent_learnings on (request flag or LOOM_MEMORY_EXTRACT_AGENT_LEARNINGS, default off), the extraction call also returns the assistant's standing rules about its own behaviour as about="agent" facts. They are never written as memories: each becomes a pending assistant_turn candidate in loom.learnings_queue for (org, namespace, agent), keyed by agent and memory key, with the end user and session as a supporter and a rationale quoting the assistant turn. A restatement in another session adds a supporter. Promotion through learnings.review writes the rule as the agent's memory (user_id '-'). Migration 062 adds learnings_queue.agent and supporter_users; a user erasure deletes every version of the candidates that user backs. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
A candidate is keyed by (agent, memory key, normalised rule text), so a different rule under one key is a sibling, never a supporter of the first wording. The candidate row is written once at filing (version 1, below any review); each session's support is a row in the new loom.learnings_supporters table, counted by learnings.list as distinct users and sessions. A rule keeps the extractor's key through the settle passes. A token bound to one end user files for its signed agent and cannot turn filing on (the request field is dropped and named in ignored_args); the pin rides deferred payloads. Promotion's source_trace is learning:<candidate_id>. A user erasure deletes the user's supporter rows and every candidate the user filed with its supporters. The dashboard shows agent, source kind, users and sessions, and what promoting a bot rule does. The migration is renumbered to 059; the setting is documented as experimental. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
The migration is renumbered to 060 after main's 059. Signed-off-by: zlareb1 <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]>
A user erasure finds the candidates a user filed from the earliest loom.learnings_supporters row (argMin(user_id, created_at), millisecond created_at), so it no longer depends on a queue column surviving a merge; filed_by_user is gone. A supporter row is written once, before the candidate row, and candidates are deleted before the supporter rows that name their filer. A token bound to one end user that names no agent files nothing. With the switch off, an about="agent" fact is the user's before the settle passes. Promotion uses the supporters' mean confidence and a single branch for its identity and trace. The supporter list uses groupArraySorted, the queue payload stores only the resolved learning agent, and X-Loom-Ignored-Args carries an op's own ignored fields. The dashboard labels source kinds, says "every agent in this namespace" for a rule with no agent, and shows the rationale's user turn before the rule. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
The analyzer statement corpus is regenerated over both sides. Signed-off-by: zlareb1 <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]>
The candidate row holds the rule, agent, key, status and decision and no user's words. Each loom.learnings_supporters row (now a plain MergeTree) stores its own user's bounded quotes, and learnings.list shows the earliest remaining supporter's. A user erasure deletes that user's supporter rows; a bot-rule candidate left with none is deleted when pending, and keeps its decision with the rule blanked when decided. The filer concept is gone. Only LOOM_MEMORY_EXTRACT_AGENT_LEARNINGS turns filing on; a request can only turn it off, and agent_learnings=true while the setting is off is named in ignored_args. The handler takes the learning agent as a parameter, and a replay with none stored files nothing. supporter_users is dropped from the wire. CI's integration job runs with the setting on. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
learnings.review answers 404 for an assistant_turn candidate an erasure blanked. The user erasure step deletes only pending rows of an unsupported pending candidate, so a review landing in between survives and the reopened step blanks it. Filing writes the candidate again when an erasure removed it between the read and this session's supporter row. A quote that reads as a credential is stored blank, and a rule that reads as one is never filed. learning_agent is renamed rule_agent (the stored payload key stays), and the docs say how to roll back. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
Signed-off-by: zlareb1 <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]>
The saga runs the learnings step among the user steps, checkpoints it, and reruns it from learnings residue on resume. The test's fake access key is built at runtime so the secrets gate does not read it as leaked, and the learnings reference is regenerated. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
…supporter The decided delete of an unsupported bot-rule candidate is bounded to the newest version the step read, so a review landing after the blank write survives for the reopened step to blank. Filing writes the version-1 candidate row with every new supporter, keeping its proposal time, instead of re-reading it. The dashboard says when a rule went with a user erasure and its decision stands. The payload key is rule_agent, __all__ is sorted, and the saga test resumes from a real verify.residue census. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
The pending delete of an unsupported bot-rule candidate re-checks for supporter rows when it runs, so a filing that landed after the step read the candidate keeps it. learning_candidates counts only rules that wrote a row, the candidate row's confidence_avg is a fixed 1.0 (the supporters' mean is read), and the docs say how the version-1 rewrite and the org-wide count of unsupported candidates behave. A two-session test interleaves a filing with the erasure step on a real ClickHouse. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
The candidate row stores confidence_avg 0.0 (learnings.list and promotion read the supporters' mean); a decided rule with no supporters left lists 0 users and 0 confidence. Filing names new_supporter and judges the supporter's confidence inline. Predicate comments and the erasure doc read more plainly, and the test helpers pass the supported set through. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
Signed-off-by: zlareb1 <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]>
quotes() reads the whole user turn and rule span with reads_high before bounding them, so a key or token the cut would split still blanks the quote. learnings.review answers 404 for a bot-rule candidate with no supporter left, pending or blanked. Small cleanups: ignored for the dropped request flag, assistant_rules.SOURCE_KIND without an alias, a required result in header_value, and the docs' learning_candidates wording. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
The extractor is not asked for the assistant's rules when the messages hold no assistant turn (a user-only call, an observation replay). The dashboard shows a bot rule's agent line and Promote warning only when the server sends an agent. The ignored-args body and header share one merge, the setting and predicate comments are shorter, and an integration case checks the coverage sweep does not write the rule back as a user fact. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
Signed-off-by: zlareb1 <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]>
The migration is renumbered to 061 after main's 060. Signed-off-by: zlareb1 <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
A memory row at user_id '-' never reaches a read bounded to one user, so learnings.review now defaults an assistant_turn rule to the namespace's knowledge (learning://<id>, authored by and tagged agent:<agent>), which context.pack, knowledge.search and loom_search serve to every user; destination is None unless given, memory stays the default for other producers, and the SDK leaves it unset. memory.lineage names the approver from the row's actor and counts a rule's supporters from their rows, review reads supporter_stats directly, and the MCP descriptions name both kinds of learning. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
… row `destination` leads with its default so the generated reference keeps it, `promoted_to_shared` and the promotion docstrings state that the row is the agent's namespace-wide row that reads bounded to one user do not serve, and the feature page says lineage finds a memory promotion by its candidate id. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
…ed as not settings Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
The settings catalog from main now declares memory_extract_agent_learnings, live, with its default pinned. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
…e bot A rule the assistant states about itself is filed before memory.bulk_set, so it skipped the blacklist. Filing now refuses a rule that matches a pattern for the org or namespace, and stores a matching quote blank, the way a quote that reads as a credential is. A rule promoted to knowledge no longer passes the candidate's agent as the document's author: the review token decides the author, and only the agent:<agent> tag names the bot. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
…earnings Signed-off-by: zlareb1 <[email protected]>
The agent '-' names no bot, so promoting its rule to knowledge no longer tags it `agent:-`. The learnings.list description says promoting a candidate writes it to shared, and the review's `destination` comment reads as one sentence with its default. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
… override CI's integration job no longer sets LOOM_MEMORY_EXTRACT_AGENT_LEARNINGS for every test. The test module installs a deployment override of memory_extract_agent_learnings with a platform-admin token, waits until the listing shows it in force, and clears it on teardown, so every other test runs with the shipping default and the module no longer skips on a default server. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
handle_memory_set_from_messages settles whether learnings are on from one read of memory_extract_agent_learnings and the request, reports the ignored argument from that read, and passes the result into the workflow state, so an override landing mid-call cannot make ignored_args contradict what the extraction did. The integration module builds on control_plane_url, waits for the override with eventually and authenticates through LOOM_API_KEY, as the settings override test does. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
context.pack, memory.stack and loom_search leave out a knowledge document promoted from an assistant_turn candidate when its agent tag names another agent; a rule for every agent and every other document serve every agent. The dashboard's Promote note names the agents a rule reaches. The rollback steps delete the assistant_turn candidates an older build would promote as the approver's memory, the reviews page names the 404 for an erased bot rule, and the learnings.review description and destination comment name the conversation-seeded case. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
…pport counts one row per session - The decided-candidate delete in the learnings user step matches each candidate against the version read for it, so a late review on a candidate read at an older version than another survives. - supporter_stats collapses to one row per (candidate, user, session) first: a session two racing filings both wrote counts once in the mean confidence and the supporter list, and the quotes are one row's pair with a deterministic tie-break. - The Promote note names the reads that leave out another bot's rule, and says knowledge.search finds it for anyone who can read the namespace. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
The A/B numbers predate the agreed-request prompt clause and the user_requested filter, so the page no longer states them; the PR body keeps the measurement. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
…e as user-requested
"you" before always, never or don't opens an imperative only after can, could,
would or will ("Could you always ..."); "You never told me you escalate
refunds over $500." states a fact, so the bot's rule is still filed.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
Main's memory webhooks take migration 063, so this branch's migration is now 064_learnings_agent_and_supporters.sql, and its rolling-upgrade rule is rule 15 after main's rule 14. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
…the rest of the page Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
…r its status, and the user-request filter reads clauses, "do not" and "want you to" rule_promoted no longer requires status 'promoted': only a knowledge promotion writes the learning:// document and a later reject leaves it, so the rule is still served and its restatements are not filed again. user_requested also reads an ask word that opens a clause after a comma or semicolon, folds "do not" into "don't" and treats "want/need you to" as an imperative opener. Its docstring keeps only what it adds; the opener and question rules stay in their helpers. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
…s", and a second review of a promoted rule is documented as rejecting it
A clause that opens with never or don't usually leaves out its subject ("I called
twice, never got my refund"), so it no longer drops the bot's rule as user_requested.
The rule_promoted comment and the review docs say that rejecting a promoted rule
leaves its document served.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…r, so "Will you always escalate refunds?" still files the bot's rule Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
…stion asks for a rule only when it names the user as "me" or "us" Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
…ger erasure steps no longer claim to sit outside the census Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
… in two lines, and the English-only request filter is documented Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
…ing filed The user_requested filter and the asked quote read the user turn before the first cited assistant turn over last_messages and messages together, so a request sent in last_messages with the agreement in messages is dropped as user_requested instead of filed as the bot's rule. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
…led, and each supporter row names its writer user_requested drops a rule only when the request asks for the behaviour to happen or not as the rule says, with "only" and "anything but" read as positive. A supporter row stores the writing actor, and learnings.list reports the distinct writers beside users and sessions, so many user_ids sent by one token read as one source. The unrelated docstring edit on _extract_request_pins is dropped. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
…earnings Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
…t and two doc pages Split the user_requested grammar into a list and say the rollback has no migration to undo. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
…a decided rule's restatement is counted as a drop The recovery passes read the rules as the session's facts when the model returned no user fact, so a preference, cost or age left out of the user's turns is still written. Filing counts a restatement of a decided candidate under reason `decided`, and the cited indices into the merged context get their own name. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
…ore its earliest cited turn Citation repair scores only user turns, so on a rule it could only move the citation onto a user turn and the rule was then dropped as citing no assistant turn. Rules now skip it. The agreed-request check and the supporter's user quote read the user turn before the earliest cited assistant turn, whatever order the model cited them in. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
…the judge verdict is parsed once per fact Every version of an assistant_turn candidate carries the agent, key and source kind its id is derived from, so the IN subquery needs no FINAL. judge_verdict() parses the verdict and judged_confidence() takes it, so source_trace and the stored confidence read the same value. The assistant_rules docstring names the citation helpers and the agreed-request filter. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
…usion no longer files an agreed rule "Please always answer me in French, not English." read as negative because of the later "not", so the agreed rule was filed as a bot-wide rule. The request's polarity is now read from the ask word that opens it, and the rule's from the word after "assistant". "replies" and "reply" now share a stem. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
…e setting states its rollout constraint The user_requested filter is removed: its English parsing had no measurement behind it, and the prompt clause plus the reviewer cover the same case. The memory_extract_agent_learnings description now says to turn it on only once every replica's build erases loom.learnings_supporters. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
…ling, and the docs state the racing first filings Two sessions that first file one rule at once, differing only in case or a trailing period, may leave either wording; the docs and the comment say so. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
…ing paragraph The supporter-first rewrite sentence now comes straight before the erasure claim it supports, and the wording rule follows it. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
This was referenced Oct 21, 2026
5 of 9 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Changelog category (leave one):
Changelog entry (one or two sentences a user of Loom can read without the diff; the release pull request collects these into the release notes):
With
LOOM_MEMORY_EXTRACT_AGENT_LEARNINGSon (off by default; turn it on once every replica runs this build), a rule a chat bot states about itself becomes a pending learnings candidate instead of a memory. An admin'slearnings.reviewpublishes it to the namespace's knowledge for that bot.Why
memory.set_from_messagesfiles every extracted fact under the request's user. A statement the assistant makes about its own standing behaviour ("I escalate any refund over $500 to a human") was either written as that user's fact or dropped. Writing it as an agent-level memory would be worse: an end user can talk a bot into saying anything, and an agent-level row reaches every user of the bot. The learnings review queue already exists for this kind of decision, but nothing filed candidates into it.The extraction output already says whose fact each item is (
about:userorother). This adds a third value,agent, asked for by a prompt block appended only when the setting is on. No extra model call: the relation backfill skips rules, since a rule is never keyed by a relation or written as a memory.The setting ships off: an older build does not erase
loom.learnings_supporters, so it is turned on only once no older replica serves (docs/architecture/rolling-upgrades.mdrule 15), and a later release can flip the default with an entry inserver/settings/_history.py. An A/B check on a hosted model (43 conversations) backs turning it on. Before this change, with 2 runs per arm: on, all 10 bot rules were filed for review in both runs; off, about half were stored as the user's memory and the rest dropped. Recall of the 109 user facts was 108 and 107 on, 106 and 105 off; no user fact was filed as a bot rule; input tokens rose by 1.6% and latency did not change. The one reproducible false positive was a request the bot agreed to: the user asked "always answer me in French", the bot agreed, and the rule "The assistant always answers the user in French" was filed. That is the user's preference, so the prompt block now says behaviour the assistant agrees to at the user's request is a fact about the user, never anabout="agent"rule. A run of the shipped block (Tests) filed no rule for that conversation. No check after the prompt reads the user's request: a rule the model still returns for one is filed as a pending candidate, and the reviewer rejects it.loom.bulk_writemovesabout="agent"facts out of the batch before anything is written.server/memory/app/assistant_learnings.pyfiles them.agent_learnings=falseturns it off for that call.agent_learnings=truewhile the setting is off is ignored, and named inignored_argsand theX-Loom-Ignored-Argsheader. The op reads the setting once per call, so what the extraction does and whatignored_argsreports agree even when an override lands mid-call; a deferred replay reads it again when it runs. Coding captures never get the block, nor does a request whose messages hold no assistant turn (a user-only call, an observation replay).(org, namespace, agent, memory_key, normalised rule text). Normalisation folds case and spacing and drops a trailing period, nothing more.learnings.listshows andlearnings.reviewpromotes. Two sessions that first file the same rule at once, differing only in case or a trailing period, leave either wording.learnings_repo.rule_promoted: one count of liveloom.documents FINALrows whosesource_uriislearning://<candidate_id>of a candidate by org, namespace, agent and key, run only for a rule with no candidate yet; the queue side readsloom.learnings_queuewithout FINAL, since every version of a candidate carries the agent, key and source kind its id is derived from). The check reads no status: only a knowledge promotion writes that document, and rejecting a promoted candidate leaves it, so a rule rejected after its promotion is still served and still stops new filings until its document is deleted. Deleting that document withknowledge.deleteis the revision path: a new wording under the key is then filed as a new pending candidate; the promoted wording itself stays decided and its restatements are counted under reasondecided. A promoted rule is served back to the bot, which restates it in its own words; without the check each restatement would wait for review again. A rule rejected before any promotion is never served back, so it does not stop a different rule under its key; restated word for word it folds to the same candidate, which is skipped as decided and counted inloom.memory_drops(stagelearnings.file, reasondecided), so a rejected rule that keeps coming back shows there. The skip is counted inloom.memory_drops(stagelearnings.file, reasonalready_promoted). Only a knowledge promotion stops new filings under its key: a rule promoted withdestination="memory"leaves nolearning://<candidate_id>document, so each restatement of it is filed as a new pending candidate.extraction.mdsays so.proposed_value), the agent, the key, the status and the decision, and no user's words.loom.learnings_supporterstable, a plain append-only MergeTree. The row records the principal that wrote it (actor,writer_actor(): the request's token, or in a replay the enqueuer stamped on the queue row), because a token not pinned to one user can send anyuser_id. It holds that user's own bounded quotes:askedis the user turn before the cited assistant turn, which may be inlast_messages(up to 200 characters), andsaidis the cited evidence span when a cited assistant turn contains it, else that assistant turn (up to 400), sosaidnever quotes a user's words.source_message_indicesname no assistant turn is not something the assistant said: it is never filed, and the drop is counted inloom.memory_drops(stagelearnings.file, reasonno_assistant_turn). Without this, a user's own sentence markedabout="agent"would reach the reviewer asAssistant: "...".confidence_avg0.0, not judged on the candidate (the supporters' mean is what is read; a decided rule with no supporters left lists 0). Any review's newer version outranks the rewrite, so a decision is never undone.sensitivity.reads_high, checked on the whole text before it is cut to length) is stored blank, and a rule that reads as one is never filed, its drop counted inloom.memory_drops(stagelearnings.file, reasonsensitive).memory.bulk_set, so filing runs the blacklist (Refuse) itself: a rule that matches a pattern for the org or namespace is never filed, and a quote that matches one is stored blank. Quotes are checked whole, before their spacing is folded and they are cut to length, so a pattern the cut would split still matches. Each match counts its pattern's hit and is logged, asmemory.bulk_setdoes for the entries it drops.learnings.reviewchecks the blacklist again before it promotes a rule, to either destination: a pattern added after filing answers 422BLACKLISTED, asmemory.setdoes, and nothing is written.knowledge.upsertchecks no blacklist, so without this the default knowledge destination would publish the rule.learnings.listcounts support at read time, after collapsing the supporter rows to one per (user, session), its earliest.supporter_countis the distinct users,supporter_sessionsis the distinct (user, session) pairs, andsupporter_writersis the distinct actors that wrote those rows, so a reviewer sees when many users came from one token. The review queue shows "2 users, 3 sessions, 1 writer".supporterslists the first 50 as six-part entries, andconfidence_avgis the mean over the supporters.rationaleshows the earliest remaining supporter's quotes, both from one row; a tie on time goes to the lowest (user_id, session_id).user_id='-'does not:memory.searchwith auser_idfilters on it exactly, and a read bounded to one user never serves'-'rows. The existing path that does reach them is the namespace's knowledge. Solearnings.reviewwithdestinationunset (nowNone) publishes anassistant_turnrule throughknowledge.upsert(learning://<candidate_id>, taggedagent:<agent>), and every user's reads of that bot find it:context.pack(include_knowledge=true)(withread_scope=own_usertoo),memory.stack,loom_searchandmemory.ask(its knowledge passages and its whole-document route).agent:<agent>tag names the bot, and a rule for agent'-'(every agent in the namespace) gets no agent tag. The document's author is the reviewer's identity, taken from the review's token.source_classisderived, the nearest class a knowledge write may declare, soknowledge.search(source_classes=["asserted"])does not return a rule a model extracted from users' conversations.assistant_rules.serves_agent: a document taggedsource-kind:assistant_turnandagent:<x>serves only agent x and a namespace-wide read). Over HTTP, a read under agent*,memory.ask's default, spans every agent as memory reads do and is served every bot's rules; a read under no agent (-,loom_search's default) is served no rule promoted for a named bot, so a bot names its agent there; a rule for every agent is still served. Over MCP an unnamedagentis the client's, so those reads serve that agent's rules;loom_searchnow passes itsagentto the fan-out, and the recorded MCP answers intests/unit/fixtures/loom_search_mcp_answers.jsoncarry it. Amemory.askprecedent's shape includes the agent whose rules the read is served when a pinned token makes it differ from the body'sagent, so two bots' tokens for one user never share a precedent. Each asks knowledge for itstop_kas before (memory.ask's whole-document route for its 20). Only when that first pass held another bot's rule and itstop_kis belowknowledge.search's cap does it ask again (a pass short oftop_kasks too: withcollapse_sectionson, knowledge folds sibling chunks before it cuts totop_k, so a short pass can still leave hits out) for four times itstop_k(at most that cap,MAX_SEARCH_TOP_K, which itstop_kbound also reads), drop those rules and keeptop_k, so another bot's rules ranked first do not empty its knowledge section. If that second search fails, the first pass's served hits answer and a warning is logged; one helper (agent_rules.served_hits, besiderequest_rule_agentinserver/memory/app/agent_rules.py) holds this for all four reads. A read whose first pass holds no rule promoted for another agent runs the same one knowledge query as before; the second, wider query runs only when such a rule was dropped, whether or not the setting is on now (a rule promoted while it was on keeps its tags, and any namespace writer can upsert a document with them). Nosystem.query_logcomparison was taken. The candidate belongs to one bot, so a promotion stays that bot's decision. Other documents,agent:tags on them included, are served as before.knowledge.searchis not filtered by agent; a bot finds its own rules withknowledge.search(tags=["agent:<agent>"]).memoryas their default, and the Python SDK'sreviewleavesdestinationunset unless given.destination="memory"still writes the agent's memory row throughmemory.set(agent=<candidate agent>, user_id='-', session_id='-'). Namespace-wide reads find that row; reads bounded to one user do not.source_traceislearning:<candidate_id>, and a new trace prefix mapslearning:tosource_classextracted. The approver is the row'sactor, andmemory.lineagereports that actor aspromoted_by, withsupporter_countfrom the supporter rows.read_user_id), the candidate's agent is the token'sagent_principal, never the body'sagent. A pinned token that names no agent files nothing. Any other token, anown_usertoken without a pin included, files for the body'sagent.agent_rules.request_rule_agent): a pinned token is served its signed agent's rules whateveragentthe body sends, and no rule promoted for a named bot when it names no agent (a rule for every agent is still served).loom mint-token --read-user-id) carries no agent claim, so it names no agent: it files no bot's rule and is served no rule promoted for a named bot. A bot that needs its own promoted rules for one user reads with an end-user token its issuer signed for that agent, or with an unpinned token. This PR does not add an agent claim to Loom-minted tokens:agent_principalalso carries the agent's collection grants, so minting it is an authorization change of its own.rule_agent).rule_agent, stripped before the replay validates the request). The handler is the only caller ofextraction_queue.enqueue/payload_forthat stores one; any other enqueue stores none and its replay files nothing.'', which files nothing.learnings.qualitykeeps counting the conversation seeder by default, because it reports extraction quality.source_kind="assistant_turn"reads the bot rules.*andknowledge.searchalso find it; or for every agent, for a rule with none.Scope and risk
bench/was run.064_learnings_agent_and_supporters.sqladdsagenttoloom.learnings_queueand createsloom.learnings_supporters(MergeTree, ORDER BY(org, namespace, candidate_id, user_id, session_id)). A supporter row carries the whole identity tuple and the writingactor: itsagentis the candidate's, the bot the rule was said to, so a row read on its own (an erasure audit, a raw-row check) names its bot without a join on a candidate that may already be deleted. It is additive and takes the next free number on main (063 ismemory_webhooks).learnings_queue.deletein the user saga) deletes that user's supporter rows, and their quotes with them. No candidate row holds a user's words.assistant_turncandidate that has no supporter left but still holds its rule. Each delete is bounded to what the step read, so a review landing after the read survives (holding the rule), the census counts it, and the reopened step blanks it. A pending candidate loses only itspendingrows, and only while no supporter row names it. A decided one loses only its rows that hold the rule at a version no newer than the one it read for that candidate.retention-and-erasure.md. Restricting it to the erased user's candidates would mean carrying their ids through the saga's checkpoint, and this PR does not do that.pipeline_errors(learnings_queue_failed:<key>) and the rule is dropped. It is never written as a memory.arg_check.attachkeeps an op's ownignored_argsbeside the transport's unknown keys instead of overwriting them, andX-Loom-Ignored-Argslists them too. Onlymemory.set_from_messagesreturns them through this path today.tests/integration/test_assistant_turn_learnings.pyturns the setting on through a runtime override (admin/settings.set) and clears it after; while it is on, other integration tests run with it on too, and no other integration test's fake-LLM assistant turn opens a sentence with "I always" or "I never", so none files a rule.Compatibility, rollout and rollback
memory.set_from_messagesgainsagent_learnings: bool | None(hidden from the MCP schema; it can only turn filing off). Its response gainslearning_candidates: int(rules that wrote a new candidate or this session's support of one) andignored_args: list[str].learnings.listrows gainagent,supporter_sessionsandsupporter_writers.learnings.review.destinationdefaults to unset (was'memory'): unset promotes anassistant_turnrule to knowledge and every other producer to memory, as before; the Python SDK'sreview()no longer sendsdestinationunless given.destination="memory"fromreview(); upgrade it, or passdestination="knowledge", before promotingassistant_turnrules.LOOM_MEMORY_EXTRACT_AGENT_LEARNINGS(defaultfalse), declared in the settings catalog and live: a runtime override takes effect on the next extraction. Run migration 064 before the new build serves; N-1 tolerates the column and the table.loom settings set memory_extract_agent_learnings true) only once every replica runs this build. An N-1 erasure saga does not eraseloom.learnings_supporters, the table where users' quotes live.docs/architecture/rolling-upgrades.md(rule 15) anddocs/operations/upgrades.mdname this step and the rollback step.assistant_turncandidates only after the rollout completes. Until then an N-1 replica can serve the review, and it promotes the rule as the approver's own memory (agent='-',user_id=<approver>), because the older build defaults tomemoryand takes its seeder path.assistant_turncandidates with the stored count (0) and no rationale.assistant_turncandidate takes its seeder path. The rule is written as the approver's own memory (agent='-',user_id=<approver>), not to knowledge, and the status row it writes has noagent.memory.askunder aread_user_id-pinned token gets a new precedent key after the upgrade, a one-time cache miss, even with the setting off; N-1 and N do not share those keys during the rollout.loom.learnings_supporters(ALTER TABLE loom.learnings_supporters DELETE WHERE 1, or per org), because an older build's erasure does not cover that table and its rows hold users' quotes. Then delete theassistant_turncandidates (ALTER TABLE loom.learnings_queue DELETE WHERE source_kind = 'assistant_turn'): an older build lists a pending one and, on promote, takes its seeder path, writing the bot's rule as the approver's own memory (agent='-',user_id=<approver>). Theagentcolumn and the emptied tables stay. The older build has no per-agent filter on knowledge reads, so it serves a promoted bot rule to every agent in the namespace; to prevent that, delete the documents taggedsource-kind:assistant_turnwithknowledge.deletebefore rolling back, or accept the wider serving. Both docs pages say so.Tests
Unit:
tests/unit/test_assistant_learnings.pycovers:about, and the prompt block on and off in both prompt sizes;rule_promotedon clickhouse-local counting a candidate, promoted or rejected after its promotion, only while its document is live), a promoted rule rejected later still stopping a reworded restatement, and a rejected rule not stopping a different rule under its key;agent, aread_user_idtoken, an unpinned token), a request unable to turn filing on (both setting values), and a replay filing for the stored agent or for none;test_ask_shape_hashes_the_identity_the_token_pinsintests/unit/test_memory_ask_precedents.pynow computes the body naming alice under alice's token; an unpinned body naming alice is served every bot's rules and the pinned token none, so it no longer shares the pinned shape;ignored_argsin the body and inX-Loom-Ignored-Args;loom.bulk_writenever passing a rule tomemory.bulk_set;learnings.listcounting users, sessions and writers, and showing the earliest supporter's quotes;supporter_statson clickhouse-local counting a session with two rows once (count and mean), counting one writer behind two users, and taking both quotes from one supporter when two start at the same millisecond;learnings.reviewwriting(agent, '-', '-')withlearning:<id>and the supporters' mean confidence, a knowledge promotion naming the bot only in its tag, with no supporter data on the status row, and a blanked rule answering 404;*), and a rule for every agent or any other document serving every agent;memory.askwith an unpinned token and the default agent serving support-bot's rule in its knowledge passages and whole-document route, one knowledge query each;MAX_SEARCH_TOP_Kwith another bot's rule among them answering without a second query;context.pack,memory.stack,loom_search, andmemory.ask's knowledge passages and whole-document route, a token signed for support-bot whose body names sales-bot: three sales-bot rules ranked first are dropped, support-bot's own rule and a plain document filltop_k, and the wider knowledge query runs only after the first pass dropped a rule;saidfalling back to the cited assistant turn when the evidence is not in it;askedquoting the user turn before the earliest cited assistant turn, and a user turn fromlast_messages;user_preference_*row.The erasure unit tests run the learnings user step on clickhouse-local, with both tables created from
schemas/schema.sqland the step's own statements executed, and assert on the rows read back. They cover: the user step deleting only the user's supporter rows; an unsupported pending candidate losing itspendingrows while an unsupported rejected one keeps a blank-rule decision written before its other rows go; a review landing between the read and the delete surviving the first run and being blanked when the step reopens; a review landing after the blank write surviving the decided delete; a late review on the older of two decided candidates surviving, since each is bounded by its own read version; and a candidate a filing backed after the read surviving the pending delete. They also cover the step traces, the census in both scopes and the classification.Integration, against a private server and ClickHouse on the fake LLM with the setting turned on by a runtime override (
tests/integration/test_assistant_turn_learnings.py, distinct user turns per user):learnings.listand absent frommemory.search. Restating it in the same session changes nothing; another session and another user give 2 users and 3 sessions with the first user's quote. Promotion publishes it to knowledge.context.pack(include_knowledge)finds it for alice (read_scope=own_user) and for another user,knowledge.searchwithagent:support-botfinds it, and withagent:other-botfinds nothing, andcontext.packforother-botdoes not carry it. A supporter after the decision does not reopen it.read_user_id(no agent) is not served the bot's promoted rule that the admin token's read finds, and itsmemory.set_from_messagesfiles no candidate.OPTIMIZE TABLE loom.learnings_queue FINAL, keeps the rejection with the rule blanked. The same rule stated again does not come back as pending.coverage_sweep=trueand several statements the first pass cites nowhere, the rule is filed once and none of the written memories holds it.begin_erasure+run_saga): the learnings step runs after the memory steps and beforeverify.residue, is checkpointed, and the census is clean. With a stray unsupported candidate left behind, a resumed run's realverify.residuefails the saga with{"loom.learnings_queue": 1}. The recovery run given that census reruns the checkpointed learnings step (other steps stay skipped) and completes clean.The branch is merged with the latest main, including the settings catalog and its ratchet tests. The learnings erasure step's clickhouse-local race tests are in
tests/unit/test_erasure_learnings_step.py.A/B on a hosted model, one run of the shipped prompt block with the setting on over the same 43 conversations: 10 of 10 bot rules filed for review and none stored as a memory; 1 false rule, an assistant's persona line in a casual chat ("Assistant is a big video game fan ...") filed as a candidate, which review rejects; no rule for the "always answer me in French" conversation, whose preference was stored as the user's memory; user-fact recall 107 of 109 (the two misses are a wedding and a city, not rules); no user fact filed as a bot rule; 578,204 input and 10,955 output tokens for the run.
Measured with
system.query_logon ClickHouse 26.9 (one replica, one part per insert; rows, bytes and memory are the most of the runs, duration the median). Seed: orgacme, namespacenswith 60,000 queue rows (50,000 candidates, a second version for every fifth one, 60%assistant_turnover 20 agents and 2,000 keys), 500,000 queue rows in another namespace, 60,000loom.documentsrows; forsupporter_stats, a page of 100 candidates.rule_promoted, queue read with FINAL (before)rule_promoted, queue read without FINAL (this head)supporter_stats, 20,000 supporters spread over the 100 candidatessupporter_stats, one candidate with 20,000 supporters, 99 with 50rule_promotedstill reads the namespace's queue rows (60,000 rows in 5 ms for the subquery alone): agent and key are not in the queue's sort key, and a skip index onmemory_keywould need a migration and a mutation to cover existing parts, which this read does not justify. Insupporter_statsmost of the time goes to carrying each supporter's quotes through the per-session grouping; taking the quotes in a separate join on the earliest row cut the skewed case to 37 ms but not the spread one (38 ms), so the statement is unchanged. Both stay underlearnings.list's 80 ms budget at 20,000 supporters on one page. The command: seed the three tables withINSERT ... SELECT FROM numbers(...), run each statement with alog_comment,SYSTEM FLUSH LOGS, thenSELECT log_comment, max(read_rows), formatReadableSize(max(read_bytes)), formatReadableSize(max(memory_usage)), median(query_duration_ms) FROM system.query_log WHERE type = 'QueryFinish' AND log_comment LIKE 'measure_%' GROUP BY log_comment.make formatandmake lintare clean on this head, and the settings, schema and reference generators report their files current.schemas/schema.sqlmatches a dump of a ClickHouse migrated from empty through 064 (the only difference is the dumping user's name inDEFINER), andtests/analyzer/shapes.txtgains the shapes the corpus renders: the changedloom.learnings_queuelist and find statements, the erasure counts and deletes onloom.learnings_supporters, and the check for candidates whose supporters were erased;make lintchecks it current. The rule-promoted check and the supporter count and existence lookups are not in the corpus; their clickhouse-local unit tests check them. The unit suite (with the settings ratchet tests and the census counts), the integration suite and the mixed-version run have no result on this head yet: CI'spytest unit + coverage,pytest integrationandbuilds N-1 and N on one ClickHousejobs are the record, and the checklist box below stays unchecked until they pass.AI assistance in the code (leave one; writing this description with AI is fine):
AI-generated (an agent wrote most of the diff): Claude Code. It checked the extraction output shape, the queue's identity and dedup, where user text lives and its erasure, the N-1 shapes and the promotion identity against the code and the tests above.
I can explain every line of this diff and how it interacts with the rest of Loom.
Checklist
make format-check,make lint,make typecheckandmake test-unitpass; the integration suite passes if server behaviour changed.docs/reference/configuration.mdand thedocs/reference/tables (python scripts/codegen/docs_reference.py), the reach manifest,schemas/schema.sql(make schema-dump) and the Codex plugin copies (python3 scripts/codegen/agent_plugin_sync.py).schemas/schema.sqlis the dump of a ClickHouse migrated from empty through 064 andmake schema-checkpasses against it.main; no merged migration is edited.hooks/,lib/,bin/,skills/,.mcp.json, the Codexplugin-defaults.json) bumps both plugin manifests' version, and no other open PR uses that version.npm --prefix frontend run build) and its tests pass, iffrontend/changed.docs/describe the system as it now is, and this description names any operator steps and wire changes.tests/unit/test_public_copy.py).git commit -s), as CONTRIBUTING.md asks.🤖 Generated with Claude Code