[Bug]: memory_search treats the whole query as one literal phrase, multi-keyword queries never match
Environment
| agentscope-harness | develop-21b4781fdb (also present on current main, same code path) |
| filesystem | E2B sandbox filesystem (also reproducible with local filesystem) |
Problem
MemorySearchTool.keywordSearch compiles the whole query as a single literal substring:
// MemorySearchTool.java
Pattern pattern = Pattern.compile(Pattern.quote(query), Pattern.CASE_INSENSITIVE);
...
if (pattern.matcher(lines[i]).find()) { ... }
So a query with multiple keywords must appear contiguously, including the exact separator, in a single memory line. Anything else never matches. This is especially painful for Chinese users, who naturally separate keywords with spaces.
Repro
MEMORY.md contains:
- 用户要求创作诗歌并以 Markdown 文件形式交付,交付物为《秋日书怀》(七言律诗)
Tool calls in one session:
| query | result |
|---|---|
秋日书怀 七言律诗 |
No matching memories found ❌ (both words ARE on the same line) |
诗歌 Markdown 交付 |
No matching memories found ❌ |
Markdown |
Found 4 matches ✅ (single word works) |
The first query fails because the line contains 《秋日书怀》(七言律诗, not the literal string 秋日书怀 七言律诗 (with a space).
Expected
Split the query into keywords (whitespace/punctuation) and match lines containing ALL keywords, falling back to ANY keyword when nothing matches all. Single-keyword behavior stays unchanged.
Suggested fix
Tokenize in keywordSearch (or in a dedicated matcher): split on [\\s,,;;||、/\\\\]+, match lines containing every token (AND), fall back to any-token matches (OR) ordered by hit count. Happy to submit a PR if maintainers agree with this direction.
Issue Evaluation
Category: bug | Status: Confirmed
Verified against current main (8ca0080ed):
MemorySearchTool.keywordSearch(agentscope-harness/.../tool/MemorySearchTool.java:69,78) compiles the whole raw query viaPattern.quote(query)and requires it as one contiguous, case-insensitive substring of a single line. No tokenization/trimming happens upstream (lines 52–62).- The reported Chinese example fails by construction (brackets between the two terms), while a single-word query works — consistent with the repro table.
- This contradicts the tool's own contract: the parameter is documented as "Keywords to search for" (line 54), docs describe a "keyword scan" (
docs/v2/en|zh/.../harness/memory.md), andMEMORY_RECALL_GUIDANCEdoes not instruct single-phrase queries. Code is the outlier. - No semantic/vector fallback exists in the harness;
SessionSearchToolhas the same literal-matching limitation.
Severity: Medium-low (silent false negatives degrade memory recall; workaround = single keyword or grep_files).
Fix direction: the proposed tokenize → AND-match → OR-fallback ranked by hit count fits the current structure and preserves single-keyword behavior; output format (Source: <file>#<line>: <text>) must stay unchanged for the memory_get workflow. Two edge cases for the PR: (1) a query consisting only of separators (e.g. full-width ,) tokenizes to an empty list — must fall back to the raw phrase; (2) consider applying the same matcher to SessionSearchTool in a follow-up.
The reporter offered to submit a PR — a fix is therefore being prepared; reply /approve here if you would like the bot to go ahead and generate the PR first.
Automated evaluation by github-manager-bot
Status: 72 h feedback window expired — no automated PR will be generated, the proposal window here is closed
The evaluation CTA above (5757396704, posted 2026-09-21T08:12:07Z) reached its 72-hour feedback limit at 2026-09-24T08:12:07Z with no own-line /approve, /revise, or /reject command in the thread, so per our workflow we skip PR generation and no competing PR will be filed from this proposal window. No action is needed from anyone.
This is a timing stand-down, not a verdict on the report. The diagnosis stands as recorded and was re-checked against current main (fefc196f49) before this notice: MemorySearchTool.keywordSearch still compiles the whole raw query as one literal (Pattern.quote(query) at agentscope-harness/.../agent/tool/MemorySearchTool.java:69, matched at :78) while the parameter is still documented as "Keywords to search for in memory files" (:54). The code remains the outlier, not the report.
Why the bot did not open anything even while the window was live: this fix surface is already contested, and the reporter's own offer is one of the three paths. The issue body ends "Happy to submit a PR if maintainers agree with this direction", and two community PRs against the same matcher are open and unmerged as of this check — #3056 ("feat(harness): support multi-keyword search modes", CryoThrust, head 4135998967, last updated 2026-09-11T16:48:43Z) and #3062 ("feat(harness): 为记忆与会话检索增加可选多关键词匹配模式", wzq-xzwj, head 70d6de0bcc, last updated 2026-09-18T14:04:39Z). Neither links this issue, so neither retires the report on its own; but a third PR from the bot would have been a duplicate-fix collision rather than a contribution, and which matching semantics ship — AND-required, OR-fallback, or an opt-in mode flag — is a maintainers' call those two PRs already put in front of them.
We are not opening a PR for #3230: the reporter has offered to own this change, and both open PRs are further along the same path than anything filed here today would be.
What is still genuinely open, and is not answered by #3056 or #3062 alone:
- Default or opt-in. Whether multi-keyword matching becomes the default behaviour of
memory_searchor stays behind a mode flag is the one design question the three proposals answer differently, and it cannot be resolved from the issue text. SessionSearchTool. It carries the same literal-matching limitation. Whether it moves in the same change or in a follow-up is unstated in both open PRs.- The documented contract. A short docs note stating today's single-phrase behaviour would close the user-facing half of this report with no code change at all.
None of these is a defect the bot could have settled inside this window. If the remaining work is to be tracked separately, opening a fresh issue for each gives it its own evaluation and its own reply window. A maintainer asking in this thread for the bot to take the change on is still an invitation — what this notice closes is the automated waiting period, not the possibility of a bot PR later.
Automated by github-manager-bot
Follow-up on resolution path: PR #3062 ("为记忆与会话检索增加可选多关键词匹配模式") is the most advanced existing proposal — CI green, 18 integration-level tests, docs updated — and its matchMode=all/any covers the repro table in this issue (space-separated multi-keyword queries become matchable once the model passes the mode, which the tool schema advertises).
Two open points before this can be closed:
- Default vs opt-in remains a maintainers' call, as the bot noted. #3062 ships opt-in (
phrasedefault); if that's the accepted semantics, this issue's repro is fixed viamatchModerather than by default behavior change — worth a maintainer decision on whether that satisfies this report. - #3062
Closes #3054, not this issue. If/when it merges, the repro above should be re-verified againstmatchMode=all, and this issue closed manually or via an explicit link.
Suggested tweak on #3062 (commented there): make the query param description explicitly mandate whitespace-separated keywords so the model self-separates punctuation-separated input before calling.