Skip to content

feat(agent-core,webapp): add deterministic self-narration and duplicate message filters - #450

Merged
WinterYukky merged 2 commits into
aws-samples:mainfrom
WinterYukky:feature/self-narration-dedup-1785860012
Aug 24, 2026
Merged

feat(agent-core,webapp): add deterministic self-narration and duplicate message filters#450
WinterYukky merged 2 commits into
aws-samples:mainfrom
WinterYukky:feature/self-narration-dedup-1785860012

Conversation

@WinterYukky

@WinterYukky WinterYukky commented Aug 24, 2026

Copy link
Copy Markdown
Contributor

Summary

Add deterministic, prompt-independent output-layer filters that suppress three
classes of low-value assistant text before delivery: cross-turn rehashes,
self-narration after a send, and no-information wake-up monologue. Also adds
near-duplicate/exact-duplicate delivery dedup and scaffolding-placeholder
detection, and consolidates the previous webapp-side dedup into agent-core so a
single source of truth serves every delivery path.

Motivation

Interrupted/auto-retriggered turns and timer/ack wake-ups frequently re-emit an
intro the session already sent, narrate a message it just delivered, or emit
internal monologue ("silent terminate", "routine progress"). Prompt guidance
alone did not eliminate these. A mechanical backstop at the single delivery
choke-point removes them without risking false positives on genuine reports.

Changes

  • message-dedup: char-bigram near-duplicate detection with conservative
    length + time-window gates (short messages never deduped).
  • self-narration-filter: rehash/self-narration containment + relaxed-length
    symmetric similarity, and a structurally-gated wake-up-monologue filter
    (fires only on non-user triggers that ran no new work tool).
  • placeholder-detection: end-of-turn placeholder + scaffolding-tag detection,
    shared by the orchestrator and the send tool.
  • user-delivery-dedup: window-scoped delivery/redelivery dedup backed by a
    short-lived DynamoDB log (fail-open on read errors).
  • rewind-filter: drop rewound/orphaned messages so no orphan toolUse remains.
  • Consolidate webapp dedup into agent-core; add barrel export and schema fields.

Testing

  • agent-core unit tests, measured: message-dedup 21, self-narration-filter 43,
    placeholder-detection 25, user-delivery-dedup 20, rewind-filter 16
    (125 tests for this feature; full agent-core suite 228 passing).
  • tsc and prettier --check pass for the agent-core workspace.

Notes

  • Self-contained; no dependency on other open PRs.
  • Pure, side-effect-free decision logic (no AWS SDK), unit-testable in isolation.

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

…lters

Add deterministic output-layer filters that catch three categories of
low-value end-of-turn text the model emits despite prompt guidance:

- Cross-turn rehash (A-1): end-of-turn text restates what was already sent
- Self-narration after send (A-2): narrates a just-sent tool message
- No-information wake-up monologue (A-3): internal monologue on retrigger

Supporting modules:
- message-dedup: bigram-similarity based near-duplicate detection with
  configurable time windows and length gates
- user-delivery-dedup: DDB-backed dedup log for user-facing deliveries
  (sendMessageToUser/sendMessageToAgent) to prevent cross-turn rehash
- placeholder-detection: identifies placeholder end-of-turn text that
  should be suppressed (".", "ok.", empty text, cancel boilerplate)
- rewind-filter: filters conversation history based on rewind state
  (cutoff SK) for context window management

Also adds:
- messageSKFromTimestamp + getRecentMessages helpers in messages.ts
- TTL field on MessageItem schema (for ephemeral dedup log entries)
- rewindState field on SessionItem schema
Remove internal-only references from the self-narration/dedup test suite and
comments so they are suitable for the public upstream:
- drop internal session IDs and a private repo deploy workflow from fixtures
- translate Japanese example prose in comments/fixtures to English
- retain non-ASCII literals that are functional detection patterns (monologue
  and scaffolding-tag matching) with clarifying English comments
No behavioural change; calibration thresholds preserved (228 tests pass).
@remote-swe
remote-swe Bot force-pushed the feature/self-narration-dedup-1785860012 branch from e02bc5a to 455c373 Compare August 24, 2026 06:03
@WinterYukky
WinterYukky merged commit 072ea35 into aws-samples:main Aug 24, 2026
8 checks passed
@WinterYukky
WinterYukky deleted the feature/self-narration-dedup-1785860012 branch August 24, 2026 06:21
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.

1 participant