Skip to content

AutoGPT is the vision of accessible AI for everyone, to use and to build on. Our mission is to provide the tools, so that you can focus on what matters.

fix(backend/copilot): drop transient-intent + generic-knowledge from dream memory (#13391)

Nicholas Tindle5bc369010448
diff --git a/autogpt_platform/backend/backend/copilot/dream/orchestrator.py b/autogpt_platform/backend/backend/copilot/dream/orchestrator.py
index 2f53c875aa..a8aa72a525 100644
--- a/autogpt_platform/backend/backend/copilot/dream/orchestrator.py
+++ b/autogpt_platform/backend/backend/copilot/dream/orchestrator.py
@@ -20,7 +20,9 @@ import asyncio
import logging
import re
import uuid as uuidlib
+from collections.abc import Sequence
from datetime import datetime, timezone
+from typing import TypeVar
from backend.copilot.config import ChatConfig
from backend.util.feature_flag import Flag, is_feature_enabled
@@ -60,6 +62,7 @@ from .schemas import (
DreamPassResult,
DreamPassUsage,
PhaseUsage,
+ ProposedFinding,
RecombinationOutput,
)
@@ -98,6 +101,83 @@ def _resolve_lock_ttl(transport_is_local: bool) -> int:
return LOCAL_LOCK_TTL_SECONDS if transport_is_local else DEFAULT_LOCK_TTL_SECONDS
+# High-precision filter for "transient intent" facts — content that
+# records what the user is ASKING/wants to KNOW rather than a durable
+# fact about them. The sanitize prompt is told to drop these, but
+# prompt-only sanitization leaks them (#13388: "User is asking how
+# Kubernetes works", "User is interested in knowing which PRs are open"),
+# so this is a deterministic belt-and-suspenders gate.
+#
+# Deliberately NARROW to knowledge-seeking intent. We do NOT match goals
+# like "user wants to create/build X" — those are legitimate durable
+# memories. Generic world-knowledge pollution ("Kubernetes uses pods…")
+# is left to the sanitize prompt: it needs LLM judgment (is the subject
+# the user?) that a regex can't do without false-positives.
+#
+# Interrogative complements are the sharp edge — several verbs are durable
+# aspirations on their own but transient questions once they take a
+# question word:
+# * ``asking`` — "asking FOR weekly reports" / "asking the agent TO
+# monitor PRs" are durable requests (semantically like "wants X"), so
+# only interrogative ``asking HOW/WHAT/…`` counts as transient.
+# * ``learn``/``understand``/``find out`` — "wants to learn Spanish",
+# "wants to understand distributed systems", "wants to find out about
+# new markets" are durable skill/aspiration GOALS; they only read as
+# transient with an interrogative ("wants to learn HOW X works").
+# * ``curious`` — "curious ABOUT X" is transient, but "curious by nature"
+# is a durable personality trait, so a ``curious about`` complement is
+# required (mirroring ``confused about``/``unsure about``).
+# ``know`` stays complement-free: "wants to know X" is transient curiosity
+# regardless of phrasing (there is no durable "wants to know" aspiration —
+# that role is served by ``learn``).
+# Known limitation (nice-to-have, low frequency): a standing notification
+# preference phrased "wants to know when X happens" is dropped; separating
+# it from a one-off "wants to know when the deploy is" isn't reliably
+# regex-able, so it's left to the sanitize prompt + human review.
+#
+# Subject scope: the gate deliberately anchors on the generic ``user``
+# subject only. Name-phrased transient intent ("Nick is asking how the
+# auth flow works") is intentionally NOT matched here — broadening the
+# subject to arbitrary proper nouns would risk false-positives on
+# non-user entities ("Kubernetes is asking for more nodes"), so
+# name-first phrasing is left to the sanitize prompt's LLM judgment. The
+# leading auxiliary allows perfect-progressive forms ("has been asking").
+_TRANSIENT_INTENT_RE = re.compile(
+ r"^(the\s+)?user\s+(?:(?:is|has|was)\s+(?:been\s+)?)?"
+ r"(asking\s+(how|what|why|whether|if|when|where|who|which|about)\b"
+ r"|wondering\b"
+ r"|curious\s+about\b"
+ r"|confused\s+about\b"
+ r"|unsure\s+about\b"
+ r"|trying\s+to\s+understand\b"
+ r"|interested\s+in\s+(knowing|understanding)\b"
+ r"|interested\s+in\s+learning\s+(how|what|why|whether|if|when|where)\b"
+ r"|wants?\s+to\s+know\b"
+ r"|wants?\s+to\s+(understand|find\s+out)\s+(how|what|why|whether|if|when|where)\b"
+ r"|wants?\s+to\s+learn\s+(how|what|why|whether|if|when|where)\b"
+ r"|asked\s+(how|what|why|whether|if|when|where|about)\b)",
+ re.IGNORECASE,
+)
+
+
+def _is_transient_intent(content: str) -> bool:
+ """True when ``content`` reads as a question/knowledge-seeking intent
+ rather than a durable fact about the user."""
+ return bool(_TRANSIENT_INTENT_RE.match(content.strip()))
+
+
+_ContentItem = TypeVar("_ContentItem", ConsolidatedFact, ProposedFinding)
+
+
+def _drop_transient_intent(
+ items: Sequence[_ContentItem],
+) -> tuple[list[_ContentItem], int]:
+ """Filter ConsolidatedFact / ProposedFinding items whose ``.content``
+ is a transient intent. Returns (kept, dropped_count)."""
+ kept = [it for it in items if not _is_transient_intent(it.content)]
+ return kept, len(items) - len(kept)
+
+
# Intra-pass near-duplicate write rejection (#13387). The consolidate
# prompt asks the model to merge near-duplicates, but a single pass still
# emits the same fact phrased 2-3 ways ("Nick uses Terminus on iPhone for
@@ -358,18 +438,29 @@ def _clamp_operations(
elif active_fact_count > 0:
demotion_cap = min(MAX_DEMOTIONS_PER_PASS, max(1, active_fact_count * 5 // 100))
+ # Drop transient-intent pollution ("user is asking…") before the cap
+ # slice so a leaked question never displaces a real fact (#13388).
+ writes, w_intent_dropped = _drop_transient_intent(ops.writes)
+ proposals, p_intent_dropped = _drop_transient_intent(ops.proposals)
+ if w_intent_dropped or p_intent_dropped:
+ logger.info(
+ "Dream clamp: dropped %d transient-intent write(s) and %d "
+ "proposal(s) (questions captured as facts)",
+ w_intent_dropped,
+ p_intent_dropped,
+ )
# Collapse intra-pass near-duplicate writes before the cap slice so the
# cap counts distinct facts, not paraphrases of one (#13387).
- writes, w_dropped = _dedupe_near_duplicate_writes(ops.writes)
- if w_dropped:
+ writes, w_dup_dropped = _dedupe_near_duplicate_writes(writes)
+ if w_dup_dropped:
logger.info(
"Dream clamp: collapsed %d near-duplicate write(s) into their "
"canonical (longest) phrasing",
- w_dropped,
+ w_dup_dropped,
)
return DreamOperations(
writes=writes[:MAX_WRITES_PER_PASS],
- proposals=ops.proposals[:MAX_PROPOSALS_PER_PASS],
+ proposals=proposals[:MAX_PROPOSALS_PER_PASS],
demotions=demotions[:demotion_cap],
entity_invalidations=ops.entity_invalidations[
:MAX_ENTITY_INVALIDATIONS_PER_PASS
diff --git a/autogpt_platform/backend/backend/copilot/dream/orchestrator_test.py b/autogpt_platform/backend/backend/copilot/dream/orchestrator_test.py
index 9e4539bbe6..2ea955a7dd 100644
--- a/autogpt_platform/backend/backend/copilot/dream/orchestrator_test.py
+++ b/autogpt_platform/backend/backend/copilot/dream/orchestrator_test.py
@@ -700,6 +700,151 @@ async def test_partial_failure_still_charges_completed_phases(mocker):
_ = MagicMock # keep import for editor convenience; not directly used
+class TestTransientIntentFilter:
+ """#13388: transient-intent 'facts' (questions captured as memory) are
+ dropped deterministically; durable facts and goals are kept; generic
+ world-knowledge is intentionally NOT handled here (prompt's job)."""
+
+ @pytest.mark.parametrize(
+ "content",
+ [
+ "User is asking how Kubernetes works",
+ # 'asking' is transient only for interrogative questions, not
+ # durable 'asking FOR/TO' requests (#3622917532).
+ "User is asking how to deploy",
+ "User is interested in knowing which Pull Requests they currently have open",
+ "The user is wondering about the deploy timeline",
+ "user wants to know the markup on credits",
+ "User asked whether the migration is risky",
+ "User is curious about lighthouse restorations",
+ "User is trying to understand the auth flow",
+ # 'learn'/'understand'/'find out'/'interested in learning' ARE
+ # transient when followed by an interrogative (a question, not a
+ # durable skill goal / aspiration).
+ "User wants to learn how Kubernetes networking works",
+ "User is interested in learning what the credit markup is",
+ "User wants to understand how the auth flow works",
+ "User wants to find out what the credit markup is",
+ # 'confused about' / 'unsure about' require the 'about' complement
+ # and drop the transient question form (#3623648910 / #3623648918).
+ "User is confused about the auth flow",
+ "User is unsure about the migration risk",
+ # 'asking' interrogatives beyond 'how' — 'which' / 'about' branches
+ # must fire too (#3623648935).
+ "User is asking which regions are cheapest",
+ "User asked about the credit markup",
+ # Perfect-progressive auxiliary ('has been asking') must be caught
+ # by the widened leading-auxiliary group (#3623648975).
+ "User has been asking how the auth flow works",
+ ],
+ )
+ def test_flags_transient_intent(self, content):
+ assert orchestrator_mod._is_transient_intent(content) is True
+
+ @pytest.mark.parametrize(
+ "content",
+ [
+ # Durable goals — NOT transient, must be kept.
+ "User wants to create Bluesky blocks",
+ "User is migrating auth to Better Auth",
+ "User is building a leaf-blower-simulator game",
+ # Durable SKILL goals / aspirations — 'learn/understand/find out
+ # <thing>' with no interrogative is an aspiration, not a question
+ # (review FP fixes #3622917532 / #3622917546).
+ "User wants to learn Spanish",
+ "User is interested in learning Rust as their next language",
+ "User wants to understand distributed systems",
+ "User wants to find out about new markets to expand into",
+ # Durable REQUESTS — 'asking for/to' is semantically 'wants X',
+ # not a knowledge-seeking question (#3622917532).
+ "User is asking for weekly reports",
+ "User is asking the agent to monitor open PRs",
+ # Durable personality trait — 'curious by nature' needs no
+ # 'about' complement, so it must survive (#3622917543).
+ "User is curious by nature",
+ # 'confused'/'unsure' without the 'about' complement are durable
+ # traits, not questions — keep-pins the complement guard so a
+ # future broadening fails loudly (#3623648910).
+ "User is confused by nature",
+ # Name-subject scope guard: the deterministic gate only covers the
+ # generic 'user' subject; name-phrased transient intent is left to
+ # the sanitize prompt, so it must NOT be dropped here
+ # (#3623649071 / #3623649079).
+ "Nick is asking how to scale the cluster",
+ # Bare 'interested in <noun>' must never match — pins the carve-out
+ # so a future broadening of the regex fails loudly here.
+ "User is interested in lighthouses",
+ "User is interested in knowledge graphs",
+ # Durable facts about the user.
+ "Nick's favorite deployment region is us-east1",
+ "Nick prefers Python for backend services",
+ # Generic world-knowledge — left to the sanitize PROMPT, the
+ # code filter must NOT drop these (would risk false positives).
+ "Kubernetes uses pods as the smallest unit",
+ "Better Auth supports dual JWT validation",
+ ],
+ )
+ def test_keeps_durable_facts_goals_and_generic_knowledge(self, content):
+ assert orchestrator_mod._is_transient_intent(content) is False
+
+ def test_clamp_drops_transient_writes_and_proposals(self):
+ ops = DreamOperations(
+ writes=[
+ ConsolidatedFact(
+ content="User is asking how K8s works", confidence=0.5
+ ),
+ ConsolidatedFact(content="Nick prefers Python", confidence=0.9),
+ ],
+ proposals=[
+ ProposedFinding(
+ content="User wants to know the credit markup",
+ confidence=0.5,
+ rationale="x",
+ source_fact_uuids=["f1"],
+ ),
+ ProposedFinding(
+ content="Nick and Sarah both work on auth",
+ confidence=0.6,
+ rationale="y",
+ source_fact_uuids=["f2"],
+ ),
+ ],
+ summary_for_user="ok",
+ )
+ clamped = orchestrator_mod._clamp_operations(ops, active_fact_count=50)
+ assert [w.content for w in clamped.writes] == ["Nick prefers Python"]
+ assert [p.content for p in clamped.proposals] == [
+ "Nick and Sarah both work on auth"
+ ]
+
+ def test_drop_transient_intent_returns_kept_and_count(self):
+ """Directly pins both outputs of _drop_transient_intent so an
+ off-by-one in the dropped_count feeding logger.info is caught."""
+ items = [
+ ConsolidatedFact(content="User is asking how K8s works", confidence=0.5),
+ ConsolidatedFact(content="Nick prefers Python", confidence=0.9),
+ ConsolidatedFact(
+ content="User wants to know the credit markup", confidence=0.4
+ ),
+ ConsolidatedFact(content="Nick deploys to us-east1", confidence=0.8),
+ ]
+ kept, dropped_count = orchestrator_mod._drop_transient_intent(items)
+ assert [k.content for k in kept] == [
+ "Nick prefers Python",
+ "Nick deploys to us-east1",
+ ]
+ assert dropped_count == 2
+
+ def test_drop_transient_intent_empty_and_none_dropped(self):
+ """No transient items → all kept, zero dropped."""
+ items = [
+ ConsolidatedFact(content="Nick prefers Python", confidence=0.9),
+ ]
+ kept, dropped_count = orchestrator_mod._drop_transient_intent(items)
+ assert [k.content for k in kept] == ["Nick prefers Python"]
+ assert dropped_count == 0
+
+
class TestNearDuplicateWriteDedup:
"""#13387: a single pass that emits the same fact phrased multiple ways
is collapsed to the longest (canonical) phrasing; genuinely distinct
diff --git a/autogpt_platform/backend/backend/copilot/dream/prompts.py b/autogpt_platform/backend/backend/copilot/dream/prompts.py
index e442639fdf..bb922b39ff 100644
--- a/autogpt_platform/backend/backend/copilot/dream/prompts.py
+++ b/autogpt_platform/backend/backend/copilot/dream/prompts.py
@@ -230,6 +230,17 @@ SANITIZE_SYSTEM = (
" * Reject any proposal whose content starts with first-person "
'("I think", "I believe", "In my opinion") — those are not user '
"memories.\n"
+ " * Reject any write OR proposal that records a TRANSIENT INTENT "
+ "rather than a durable fact: content describing what the user is "
+ "asking, wants to know, is curious/wondering about, or is trying to "
+ "understand is a question, not a memory. Drop it. (A user GOAL — "
+ "'wants to build X', 'is migrating to Y' — IS durable; keep those.)\n"
+ " * Reject GENERIC WORLD KNOWLEDGE that isn't about the user: "
+ "definitions or tutorial facts the assistant explained in passing "
+ "(e.g. 'Kubernetes uses pods as the smallest unit', 'X works by …') "
+ "are not memories ABOUT THE USER. Keep a fact only when its subject "
+ "is the user, their projects, the people/orgs they work with, or "
+ "their stated preferences.\n"
" * Write a short ``summary_for_user`` (1-3 sentences) describing "
"what the pass found.\n\n"
"JSON SCHEMA (your response MUST match this DreamOperations shape):\n"
diff --git a/autogpt_platform/backend/backend/copilot/dream/prompts_test.py b/autogpt_platform/backend/backend/copilot/dream/prompts_test.py
index 3f1dc8881c..6997b5e764 100644
--- a/autogpt_platform/backend/backend/copilot/dream/prompts_test.py
+++ b/autogpt_platform/backend/backend/copilot/dream/prompts_test.py
@@ -125,6 +125,18 @@ def test_sanitize_prompt_includes_known_fact_uuids_for_demotion_guard():
assert str(MAX_WRITES_PER_PASS) in sys
+def test_sanitize_prompt_rejects_transient_intent_and_generic_knowledge():
+ """#13388: the sanitize prompt must instruct dropping transient-intent
+ ('user is asking…') and generic world-knowledge facts, while keeping
+ durable user goals."""
+ bundle = _build_bundle()
+ sys = build_sanitize_prompt(bundle, "{}", "{}")[0]["content"].lower()
+ assert "transient intent" in sys
+ assert "generic world knowledge" in sys
+ # Keeps goals — the rule explicitly carves them out.
+ assert "goal" in sys
+
+
def test_sanitize_prompt_surfaces_stale_fact_candidates():
"""The staleness heuristics flag candidates for the sanitizer to
judge. If this section drops out of the prompt, P0.3a fails