#6007·deer-flow

[feat] Return hit-centered excerpts and source offsets from history_search

Author: ZJPexCreated Sep 28, 2026Updated Sep 28, 2026
Labelsneeds-triage

Before you start

Problem / motivation

history_search can find a matching message but return an excerpt that does not contain the match. After retrieval, it currently uses the first 600 characters of each source as excerpt.

For example, if Needle appears at character offset 5000 in a long message, searching for needle can return the correct source ID while showing only unrelated opening text. The caller then has to page through history_read to find the relevant passage. This affects both active messages and compacted history.

Proposed solution

Return one excerpt of at most 600 characters near a locatable keyword match, together with its character range in the readable source:

  • excerpt_start: zero-based inclusive start.
  • excerpt_end: exclusive end.
  • excerpt_match: whether the excerpt contains a fully located query-term match.

The offsets should use the same Unicode character counting as history_read(offset=...), so source_text[excerpt_start:excerpt_end] == excerpt. They must not be UTF-8 byte offsets or positions in the casefolded string.

With enough surrounding text, a six-character Needle starting at offset 5000 would produce a 600-character excerpt spanning [4703, 5303). The caller can continue reading with history_read(source_id, offset=4703).

Preserve the existing query terms, OR matching, optional role filter, ranking, eight-result limit, source IDs, and scope/lifecycle restrictions. Choose the earliest locatable match; the excerpt does not need to include every query term. Keep active substring matching and archived FTS matching distinct.

If a match cannot be located reliably, return the beginning of the readable source and set excerpt_match=false. This includes FTS normalization that cannot be mapped precisely, or a term that cannot fit completely within the excerpt. Repeated archive versions, truncation, and active/archive overlap must use the same readable source version as history_read.

Affected area(s)

  • Agents / LangGraph (graph, prompts, langgraph.json)
  • Docs

Alternatives considered

  • Keep the opening excerpt and page through the source manually: preserves current behavior but makes late matches expensive to inspect.
  • Return both an opening excerpt and a matching excerpt: adds output without being necessary to inspect the match.
  • Generate summaries with an LLM or add vector retrieval: introduces costs and changes retrieval behavior beyond this task-scoped lexical search improvement.

Additional context

This is a follow-up to the existing role-filter capability, not another role-filter request or a long-term memory change. It requires no new dependency or model call. Retrieved text remains untrusted historical data and does not grant current authorization.

Related work (checked on 2026-09-28): #5926 added role filtering and explicitly preserved the existing 600-character excerpts. #5378 provides the broader context-management and history-recall background. #5398 concerns authorized cross-session conversation retrieval. This proposal focuses on locating a match within an already-retrieved task-history source and returning offsets compatible with history_read; no direct duplicate was found in the issue search.