Repository navigation
Description
Describe the bug
memory_search returns every matching line of every memory file in full, with no result-count cap and no per-line truncation. Two code paths that were written assuming this tool returns bounded output are therefore left unprotected:
-
MemorySearchTool.keywordSearch(agentscope-harness/src/main/java/io/agentscope/harness/agent/tool/MemorySearchTool.java:64-89) iterates allMEMORY.md+memory/*.mdfiles, appends each matching line verbatim (Source: <file>#<line>: <full line>), and only stops when the files run out. There is nomaxResultsequivalent — compareSessionSearchTool.sessionSearch, which caps atmaxResults(default 10) and truncates each preview to 200 chars (SessionSearchTool.java:77, 289-290). -
ToolResultEvictionConfig.DEFAULT_EXCLUDED_TOOLS(agentscope-harness/.../memory/compaction/ToolResultEvictionConfig.java:66-73) excludesmemory_searchfrom tool-result eviction, with the stated rationale "small/paginated results" (:61). Since the eviction layer is bypassed, an oversizedmemory_searchresult is passed straight into the next model call.
Additionally, the docs promise a cap that the code does not implement: docs/v2/en/docs/harness/memory.md:236 and docs/v2/zh/docs/harness/memory.md:235 both say memory_search returns "up to 30 hits" — there is no 30 (or any) limit in the implementation.
Impact
A long-lived agent accumulates many memory/YYYY-MM-DD.md files. A broad query (e.g. a keyword that appears in a header or boilerplate line repeated across daily ledgers) can return hundreds of untruncated lines, blowing up the tool-result content and overflowing the model context window. Because the tool is on the eviction exclusion list, nothing downstream trims it.
To Reproduce
- Create a workspace with
memory/2026-09-01.md…memory/2026-09-20.md(20 files), each containing a line## Memory Flush — 2026-09-XXplus a long content line (~1000 chars) mentioning the same keyword. - Let the agent call
memory_search(query="<keyword>")— e.g. any keyword present in the repeated header line. - Result: every header line and every long content line of all 20 files is concatenated verbatim into one tool result (observed on
main@63a6f616).
Expected behavior
- A default result cap (the docs already promise 30) and/or a
maxResultsparameter likesession_search. - Per-line preview truncation (like
session_search's 200-char preview), withmemory_getremaining the tool for fetching full context around a hit. - Either implement the cap, or — if unbounded output is intended — remove
memory_searchfromDEFAULT_EXCLUDED_TOOLS/ fix the docs, so the eviction layer can actually bound it.
Environment
- AgentScope-Java Version: 2.0.3-SNAPSHOT (main @ 63a6f61)
- Java Version: 21
- OS: macOS
Additional context
Happy to submit a PR — proposed shape: maxResults tool parameter (default 30, aligning with the docs) + per-line truncation at a fixed char budget, plus a regression test. The eviction exclusion list would then match the documented behavior.
Activity
oss-maintainer commentedon Sep 23, 2026
Issue Evaluation
Category:
bug(area/harness) | Status: Confirmed | Severity: medium-highVerified against
main@63a6f6168. All four claims in the report hold — the line references are accurate as filed.Claim-by-claim check
keywordSearchemits every matching line verbatim, no capMemorySearchTool.java:64-89—for (relativePath : memoryPaths)→for (i < lines.length)→results.add("Source: %s#%d: %s", relativePath, i + 1, lines[i]);maxResultsdoes not appear anywhere in the filesession_searchbounds itself,memory_searchdoes notSessionSearchTool.java:77limit = maxResults > 0 ? maxResults : 10;:85-86stops at the limit;:289-290truncates the preview to 200 chars +...memory_searchis excluded from tool-result evictionToolResultEvictionConfig.java:66-73; the javadoc at:61justifies it as "small/paginated results"docs/v2/en/docs/harness/memory.md:236"up to 30 hits";docs/v2/zh/docs/harness/memory.md:235"最多返回 30 条命中"Root cause.
MemorySearchTool.keywordSearchis the unbounded source; the eviction layer that would otherwise cap an oversized tool result is deliberately switched off for this tool name, so nothing downstream trims it. The "small/paginated results" premise inToolResultEvictionConfigis simply not true for this tool — it is the only one of the three search tools with neither a count cap nor a per-line budget.Impact. Grows with agent lifetime: a broad keyword repeated across
memory/YYYY-MM-DD.mdledgers (headers, boilerplate flush lines) returns every occurrence in full, in one tool result, straight into the next model call — context overflow on exactly the long-running agents the harness targets. Not a security or data-loss issue.Fix shape (as proposed in the report, and workable). Add
maxResults(default 30, matching the docs), break out of both loops once it is reached, truncate each line to a fixed preview budget likesession_search's 200 chars, leavingmemory_getas the way to pull full context around a hit.One design call belongs to maintainers, not to a bot PR. "Either implement the cap, or drop
memory_searchfromDEFAULT_EXCLUDED_TOOLS" are not equivalent: the first keeps eviction disabled for the tool, the second re-enables eviction and changes what the model sees on a follow-up turn. Both would also wantToolResultEvictionConfig.java:61's javadoc corrected, since it currently asserts boundedness that no other part of the change guarantees.No PR from us. The reporter already offered to submit one against this exact shape, so a competing automated PR would duplicate community work. Flagging the doc-vs-code mismatch and the eviction-list question above is the useful output here.
Testability: yes, no external services needed — stub
WorkspaceManager.listMemoryFilePaths/readManagedWorkspaceFileUtf8with several files containing repeated and ~1000-char matching lines, then assertmatches <= maxResults,maxResultsis honoured when set explicitly, and each emitted preview is within the char budget.Automated evaluation by github-manager-bot
aMetric commentedon Sep 23, 2026
PR submitted: #3267 — adds the
maxResultsparameter (default 30, aligning with the documented cap), per-line truncation at 500 chars with amemory_getpointer, and a truncation note when results are capped. 8 new regression tests + full agentscope-harness module suite (1051 tests) pass locally.fix(harness): bound memory_search results with maxResults and line tr…
fix(harness): test-before-cap loop so an extra match is never missed (a…
fix(harness): bound memory_search results with maxResults and line tr…
fix(harness): bound memory_search results with maxResults and line tr…
fix(harness): bound memory_search results with maxResults and line tr…