Skip to content

What the agent is told by default: dates, shared knowledge, held questions, recent topics - #231

Merged
joslat merged 11 commits into
mainfrom
phase37/latest
Sep 28, 2026
Merged

joslat merged 11 commits into
mainfrom
phase37/latest

Conversation

@joslat

@joslat joslat commented Sep 28, 2026

Copy link
Copy Markdown
Owner

What changes

Defaults

  • Dates are on by default in every renderer (Agent Framework ContextFormatOptions, Core MemoryContextFormatterOptions, Semantic Kernel MemoryRecallSecurityOptions, WorkingMemoryOptions). A guard test keeps the four defaults together.
  • MemoryOptions.SharedRecallBudget defaults to 3, so shared knowledge gets its own budget and label.
    • Before, the split search queried twice per memory type, even in stores with no shared memory. The perf gate caught it (PERF-R-07 went from 9 to 16 queries).
    • Now ISharedCorpusProbe runs one cached existence check per store and kind, and the shared search is skipped when there is none.
    • A shared write in the same process is seen at once. A write from another process is seen within 30 seconds.

Extraction

  • An object the model wrote twice is stored once. "is a chef | chef" is no longer rendered "is a chef chef". A dangling article moves to the object (PredicateEcho).
  • A question-only turn waits for the next turn that says something. The turn is held durably: it is marked in the store and keyed to its owner, so the hold survives restarts.
    • Opt-in via ExtractionRequest.DeferIfOnlyAsking / AgentFrameworkOptions.DeferQuestionTurns.
    • At most ExtractionOptions.MaxDeferredTurns turns are held.

Profile

  • "Lately" in the profile block: the topics the person talked about most in the last WorkingMemoryOptions.RecentTopicsDays days.
    • It counts distinct facts from live user messages.
    • Off by default.

Docs

  • Every memory option is in one table, and the dates, events, shared knowledge, relationships and changes-of-mind pages are updated.

Tests

  • Integration tests that read a turn's memory straight after the turn now extract inline, removing a background-extraction race that failed alone even on main.

The model-dependent extraction switches (TemporalValidityMode.Extract, MarkCorrections, OwnPreferencesOnly) and SupersedeReplacedFacts stay opt-in.

Verification

  • Unit: 6,976 passed, 0 failed (all five non-integration test projects).
  • Integration (local Neo4j): 584 passed, 0 failed, 29 skipped (model-dependent).
  • Perf gate: PASS on both the zero and remote latency profiles against eng/perf/baselines/hermetic-S.json.
  • Samples: all build. MinimalAgent and AgentWithMemory run end to end on 03a20f7c.
  • New shared-write tests fail with the fix disabled: 10 of 10.
  • Review: one review round. Its fixes are in 0cb4e80b: held turns belong to their owner, and "Lately" counts only what the person said.

🤖 Generated with Claude Code

https://claude.ai/code/session_0139u7CNFuidKuPJBRK7auC9

joslat and others added 11 commits September 28, 2026 12:41
IncludeDates defaults to true on the four renderers that print dates (one
guard test for the twins) and SharedRecallBudget to 3: in simulated
conversations both kept every answer and improved the dated ones. The
model-dependent extraction switches and supersession stay opt-in.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0139u7CNFuidKuPJBRK7auC9
"Daniel | is a chef | chef" rendered "Daniel is a chef chef". A predicate that
ends with its own object's words, with or without a leading article, is
trimmed at write, for every fact on either write path; whole words only, and
never to an empty predicate.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0139u7CNFuidKuPJBRK7auC9
WorkingMemoryOptions.RecentTopicsDays (off by default) ends the profile block
with one line naming the owner's entities that live facts extracted in the
window mention most, counted by distinct messages (EXTRACTED_FROM provenance
with the message time), never the person (self words, their stated name).
Only what the person said counts. One read per rebuild, only when enabled;
trimmed first when the block is over budget.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0139u7CNFuidKuPJBRK7auC9
…thing (37.4)

The durable redesign of the deferral pulled in review round 8. The memory
service decides (every entry point gets it); the host only consents
(AgentFrameworkOptions.DeferQuestionTurns sets ExtractionRequest.DeferIfOnlyAsking).
A waiting turn is marked on its stored message: it survives a restart, stays
in its store and session, is gone when forgotten, and the marks clear only
when the releasing extraction succeeds; at most MaxDeferredTurns wait. The
E2 context window reaches up to the last target, so the agent's reply between
a waiting question and its telling turn is context.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0139u7CNFuidKuPJBRK7auC9
…ge, relationships, changes of mind (37.3)

A new docs/configuration/memory-options.md lists each switch with its default;
getting-started, agent-framework, memory-map, schema and architecture say what
the memory now does and store (occurred_on, date precision, entity owner_key,
the predicate trim), with the known limits.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0139u7CNFuidKuPJBRK7auC9
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0139u7CNFuidKuPJBRK7auC9
… in the baseline

The perf gate caught the cost of SharedRecallBudget on by default: an
owner-scoped recall searches twice per memory type (PERF-R-07: 9 -> 16
queries), in every store, shared knowledge or not. It stays opt-in (3 is the
measured value) until the shared search is skipped where there is nothing
shared. IncludeDates stays on. The baseline records PERF-W-08's 15th query,
the restated-relationship read justified in #230, so later changes are gated
against the current shape.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0139u7CNFuidKuPJBRK7auC9
…nts what the person said

Deferral: a waiting turn is marked for its owner (the session when there is
none) and read by an index seek; the owner's next telling turn in any session
releases it (a session ending on a question no longer strands it; one agent's
shared session id never releases Alice's words into Bob's extraction); any
failure while deferring extracts the turn now; "please ..." and "help me ..."
are told, not held; waiting turns are counted as the user's messages.
Lately: distinct facts from live user messages (a released batch and the
agent's words no longer inflate it), the naming exclusion by the same keys as
the name lookup, case-blind entity match, rebuilt at least daily. The predicate
trim moves a dangling article to the object. A dated recalled turn is
deduplicated against the live thread by what was said.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0139u7CNFuidKuPJBRK7auC9
…t; on by default (37.1b)

With SharedRecallBudget set, every owner-scoped recall searched twice per
memory type, shared knowledge or not (the perf gate caught it: PERF-R-07 9 ->
16 queries). ISharedCorpusProbe answers whether the store holds shared memory
of a kind (Neo4j: one EXISTS per store and kind, a seek on owner_key for facts
and entities; "none" cached 30 s, "some" 10 min); without any, the shared
search is skipped, and a probe that cannot answer leaves it in place. With the
cost gone where nothing is shared, SharedRecallBudget defaults to 3 again. The
perf gate passes unchanged.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0139u7CNFuidKuPJBRK7auC9
Three tests read what a turn stored right after it returned; with
ExtractInBackground on by default (since #229) that was a race they lost when
run on their own (warm runs won it, so full-suite runs passed). They are about
owner stamping, provenance and trust, not background timing.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0139u7CNFuidKuPJBRK7auC9
The shared-corpus check cached "none" for 30 seconds, so in a store without shared
knowledge, a book taught and then asked about straight away was not recalled until
the window expired. Every repository path that writes an owner-less fact, entity or
preference (single, batch, fused, derived) now tells the check before the write, and
it answers "some" at once; a "some" that turns out wrong only costs one empty search.
Only a write from another process still waits out the window.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0139u7CNFuidKuPJBRK7auC9
Copilot AI lite review requested due to automatic review settings September 28, 2026 13:12

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

Unresolved critical shared-probe race and multiple moderate deferral, recall, and topic-correctness issues remain.

Review effort: Lite
Findings: 1 High severity · 3 Medium severity · 3 Low severity

Open (7)
What changed in this PR

Adds date rendering, shared-memory budgeting, deferred question extraction, predicate cleanup, and recent-topic profile context.

Changes:

  • Enables dates and shared recall by default with cached probing.
  • Adds durable deferred question turns and predicate normalization.
  • Adds “Lately” topics, tests, query updates, and documentation.
File Summary
tests/​AgentMemory.Tests.Unit/​Services/​WorkingMemoryTests.cs Tests recent-topic rendering and budgeting.
tests/​AgentMemory.Tests.Unit/​Services/​SharedKnowledgeBoundaryTests.cs Tests shared recall probing and defaults.
tests/​AgentMemory.Tests.Unit/​Services/​MemoryServiceExtractionContextTests.cs Tests deferred-turn context selection.
tests/​AgentMemory.Tests.Unit/​Services/​DeferredQuestionTurnsTests.cs Tests durable question deferral.
tests/​AgentMemory.Tests.Unit/​Services/​DatesInContextTests.cs Tests date defaults.
tests/​AgentMemory.Tests.Unit/​Queries/​CypherQuerySnapshotTests.cs Updates query inventory tests.
tests/​AgentMemory.Tests.Unit/​Queries/​CypherQuerySnapshot.snap Adds query snapshots.
tests/​AgentMemory.Tests.Unit/​Infrastructure/​SchemaBootstrapperTests.cs Updates schema tests.
tests/​AgentMemory.Tests.Unit/​Extraction/​WithinExtractionCurrentValueTests.cs Tests predicate normalization paths.
tests/​AgentMemory.Tests.Unit/​Extraction/​PredicateEchoTests.cs Tests duplicate predicate cleanup.
tests/​AgentMemory.Tests.Unit/​Extraction/​OnlyAsksTests.cs Tests question-only detection.
tests/​AgentMemory.Tests.Unit/​AgentFramework/​HistoryThreadDedupTests.cs Tests dated-turn deduplication.
tests/​AgentMemory.Tests.Unit/​AgentFramework/​ExtractFromUserOnlyTests.cs Tests deferral option wiring.
tests/​AgentMemory.Tests.Unit.SemanticKernel/​Neo4jTextSearchTests.cs Tests Semantic Kernel date defaults.
tests/​AgentMemory.Tests.Integration/​Services/​SharedCorpusProbeIntegrationTests.cs Tests shared-corpus caching and writes.
tests/​AgentMemory.Tests.Integration/​Services/​RecentTopicsIntegrationTests.cs Tests recent-topic behavior.
tests/​AgentMemory.Tests.Integration/​Repositories/​DeferredExtractionIntegrationTests.cs Tests persisted deferral.
tests/​AgentMemory.Tests.Integration/​AgentFramework/​StoredPromptInjectionCrossSessionIntegrationTests.cs Makes extraction deterministic.
tests/​AgentMemory.Tests.Integration/​AgentFramework/​PersistExtractFullTurnIntegrationTests.cs Uses deterministic inline extraction.
tests/​AgentMemory.Tests.Integration/​AgentFramework/​MemoryOwnerScopingAgentIntegrationTests.cs Uses deterministic inline extraction.
src/​AgentMemory.SemanticKernel/​MemoryRecallSecurityOptions.cs Enables date rendering.
src/​AgentMemory.Neo4j/​Services/​Neo4jWorkingMemoryService.cs Builds recent-topic profile context.
src/​AgentMemory.Neo4j/​Services/​Neo4jSharedCorpusProbe.cs Caches shared-memory existence.
src/​AgentMemory.Neo4j/​Repositories/​Neo4jPreferenceRepository.Fused.cs Tracks fused shared writes.
src/​AgentMemory.Neo4j/​Repositories/​Neo4jPreferenceRepository.cs Tracks shared preference writes.
src/​AgentMemory.Neo4j/​Repositories/​Neo4jMessageRepository.cs Persists deferred markers.
src/​AgentMemory.Neo4j/​Repositories/​Neo4jFactRepository.Fused.cs Tracks fused shared writes.
src/​AgentMemory.Neo4j/​Repositories/​Neo4jFactRepository.cs Tracks shared fact writes.
src/​AgentMemory.Neo4j/​Repositories/​Neo4jEntityRepository.Fused.cs Tracks fused shared writes.
src/​AgentMemory.Neo4j/​Repositories/​Neo4jEntityRepository.cs Tracks shared entity writes.
src/​AgentMemory.Neo4j/​Queries/​WorkingMemoryQueries.cs Adds recent-topic queries.
src/​AgentMemory.Neo4j/​Queries/​SchemaQueries.cs Adds the deferred-message index.
src/​AgentMemory.Neo4j/​Queries/​MessageQueries.cs Adds deferral queries.
src/​AgentMemory.Neo4j/​Infrastructure/​ServiceCollectionExtensions.cs Registers shared probing.
src/​AgentMemory.Core/​Services/​MemoryService.cs Coordinates deferred extraction.
src/​AgentMemory.Core/​Services/​MemoryContextFormatterOptions.cs Enables date rendering.
src/​AgentMemory.Core/​Services/​LongTermMemoryService.cs Applies shared budgets and probing.
src/​AgentMemory.Core/​Services/​ISharedCorpusProbe.cs Defines the probe contract.
src/​AgentMemory.Core/​Extraction/​PredicateEcho.cs Removes repeated predicate objects.
src/​AgentMemory.Core/​Extraction/​PersistenceStage.cs Applies predicate cleanup before persistence.
src/​AgentMemory.Core/​Extraction/​ExtractionNoveltyGate.cs Detects question-only turns.
src/​AgentMemory.AgentFramework/​TurnExtraction.cs Wires question deferral.
src/​AgentMemory.AgentFramework/​Mapping/​MafTypeMapper.cs Deduplicates recalled turns.
src/​AgentMemory.AgentFramework/​ContextFormatOptions.cs Enables date rendering.
src/​AgentMemory.AgentFramework/​AgentFrameworkOptions.cs Adds deferral configuration.
src/​AgentMemory.Abstractions/​Repositories/​IMessageRepository.cs Adds deferred-message APIs.
src/​AgentMemory.Abstractions/​Options/​WorkingMemoryOptions.cs Adds recent-topic settings.
src/​AgentMemory.Abstractions/​Options/​MemoryOptions.cs Defaults shared recall budgeting.
src/​AgentMemory.Abstractions/​Options/​ExtractionOptions.cs Adds deferred-turn limits.
src/​AgentMemory.Abstractions/​Domain/​Extraction/​ExtractionRequest.cs Adds request-level deferral control.
eng/​perf/​baselines/​hermetic-S.json Updates the performance baseline.
docs/​schema.md Documents schema and predicate behavior.
docs/​README.md Links configuration documentation.
docs/​memory-map.md Documents capability defaults.
docs/​getting-started.md Documents configuration behavior.
docs/​configuration/​memory-options.md Adds the options reference.
docs/​architecture.md Updates architecture details.
docs/​agent-framework.md Documents framework behavior.
CHANGELOG.md Records user-visible changes.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

var record = await cursor.SingleAsync().ConfigureAwait(false);
return record["shared"].As<bool>();
}, cancellationToken).ConfigureAwait(false);
_answers[key] = (shared, now + (shared ? SomeFor : NoneFor));
Comment on lines +112 to 115
var anyShared = _sharedCorpus is null || await HasSharedAsync(kind).ConfigureAwait(false);
var sharedTask = anyShared && _sharedRecallBudget > 0
? search(SharedScopes.SharedOnly, _sharedRecallBudget.Value)
: Task.FromResult<IReadOnlyList<(T Item, double Score)>>(Array.Empty<(T, double)>());
Comment on lines +67 to +68
WHERE f.invalidated_at IS NULL AND m.role = 'user' AND m.invalidated_at IS NULL
AND m.timestamp >= datetime($since)
private readonly INeo4jTransactionRunner _tx;
private readonly IMemoryStoreContext? _store;
private readonly TimeProvider _time;
private readonly ConcurrentDictionary<(string? Store, SharedKind Kind), (bool Shared, DateTimeOffset Until)> _answers = new();
Comment on lines +43 to +44
- An object the model repeated at the end of its predicate is stored once ("is a chef | chef" becomes
"is a | chef").
Comment thread docs/schema.md

On create, the incoming id becomes the persisted `id`. On match, the existing id is retained, mutable fields are updated, valid windows are coalesced, and `invalidated_at` is reset for live re-assertion.

Before the merge, a predicate that ends with its own object's words (with or without a leading article) is trimmed, so a model's `Daniel | is a chef | chef` is stored as `Daniel | is a | chef` and renders "Daniel is a chef" once. `works at | Acme` is unchanged, and a predicate is never trimmed to empty.
Comment on lines +26 to +28
private const string EntityQuery = "RETURN EXISTS { MATCH (e:Entity {owner_key: '*'}) } AS shared";
private const string FactQuery = "RETURN EXISTS { MATCH (f:Fact {owner_key: '*'}) } AS shared";
private const string PreferenceQuery = "RETURN EXISTS { MATCH (p:Preference) WHERE p.owner_id IS NULL } AS shared";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants