[BUG] Memory prefetch drops short sentences from the search, so relevant memories are never retrieved
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
调研方向
从 python/packages/kagent-adk/src/kagent/adk/tools/prefetch_memory_tool.py 开始,重点查看 _split_sentences 及其调用方的回退逻辑。追踪返回的查询如何用于记忆搜索,然后检查现有的句子拆分和预取行为测试。完成标准是:复现中的短句会参与搜索;运行此工具相关的测试。
由索引模型根据 Issue 内容生成。
描述
📋 Prerequisites
- I have searched the existing issues to avoid creating a duplicate
- By submitting this issue, you agree to follow our Code of Conduct
- I am using the latest version of the software
- I have tried to clear cache/cookies or used incognito mode (if ui-related)
- I can consistently reproduce this issue
🎯 Affected Service(s)
App Service
🚦 Impact/Severity
Minor inconvenience
🐛 Bug Description
PrefetchMemoryTool in python/packages/kagent-adk/src/kagent/adk/tools/prefetch_memory_tool.py loads relevant past context at the start of a conversation by splitting the first user message into sentences and searching memory for each one. _split_sentences drops any sentence shorter than _MIN_SENTENCE_CHARS (30):
def _split_sentences(text: str) -> list[str]:
sentences = re.split(r"(?<=[.!?])\s+", text.strip())
return [s.strip() for s in sentences if len(s.strip()) >= _MIN_SENTENCE_CHARS]
The docstring says it "falls back to the full text as a single query ... if the message is short enough to search as-is", but that fallback lives in the caller and only fires when the returned list is completely empty:
queries = _split_sentences(first_text.strip())
if not queries:
queries = [first_text.strip()]
So when a multi-sentence message mixes long and short sentences, the short ones are silently dropped and never searched, and because the list is non-empty the full-text fallback does not run either. A memory relevant only to the short sentence is therefore never retrieved.
🔄 Steps To Reproduce
- Enable agent memory and prefetch.
- Start a conversation whose first message mixes a long sentence with a short one, e.g. "Remember: prod is down. Fix it now please immediately." ("Remember: prod is down." is 23 characters, under the 30-char threshold.)
- Only the long sentence is searched against memory; the short one is dropped.
Minimal reproduction of the splitting function in isolation:
from kagent.adk.tools.prefetch_memory_tool import _split_sentences
print(_split_sentences("Remember: prod is down. Fix it now please immediately."))
# -> ['Fix it now please immediately.']
# "Remember: prod is down." is never searched, and because the list is non-empty
# the caller's full-text fallback does not run, so that context is lost.
🤔 Expected Behavior
The short sentence should still contribute to the memory search. Reasonable options:
- Keep every sentence as a query (a 23-character sentence like "Remember: prod is down." is meaningful), or
- When some sentences are filtered out, also include the full message as an additional query, so no part of the message is lost, or
- Only apply the length filter when it still leaves the message fully covered.
📱 Actual Behavior
For "Remember: prod is down. Fix it now please immediately.", only "Fix it now please immediately." is searched against memory. "Remember: prod is down." is silently dropped, and the whole-message fallback does not fire because the query list is non-empty. Any memory relevant only to "prod is down" is never retrieved, with no error or log.
💻 Environment
- Application version: latest
main - Affected component: Python ADK runtime (
kagent-adk), memory prefetch - File:
python/packages/kagent-adk/src/kagent/adk/tools/prefetch_memory_tool.py(_split_sentences) - OS: not OS-specific (pure Python logic)
🔧 CLI Bug Report
No response
🔍 Additional Context
This is provider-independent (it runs before any model or embedding call) and affects any agent with memory enabled. The current _MIN_SENTENCE_CHARS = 30 threshold has no fallback for the partial-drop case, only for the all-dropped case.
- Did it work before? This is the behavior since the prefetch tool's sentence-splitting was introduced; not a recent regression.
- Workarounds: none from config; it needs a code change.
I would like to work on this.
📋 Logs
No response
📷 Screenshots
No response
🙋 Are you willing to contribute?
- I am willing to submit a PR to fix this issue
- 主要语言
- Go
- 星标
- 4.1k
- 派生
- 859
- 平均合并
- 1 天 8 小时
- 30 天内合并 PR
- 169
环境准备
在浏览器里用你自己的 GitHub 账号启动这个项目的开发容器。
- 没有 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
kagent-dev/kagent 的其他 Issue
-
[BUG]可能已有人在做 @helloxjade 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 65/100
kagent-dev/kagent#3385 · 1 条评论 ·
维护者通常 1 天内回复
-
[BUG] Go Ollama adapter does not send tool_name on tool result messages可能已有人在做 @mandipadk 于 1 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 68/100
kagent-dev/kagent#3371 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 78/100
kagent-dev/kagent#3247 ·
维护者通常 1 天内回复
-
[BUG] Ollama ModelConfig options: integer coercion crashes on decimal strings, and boolean options only accept exact "true"可能已有人在做 @piyush182004 于 10 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 78/100
kagent-dev/kagent#3245 · 2 条评论 · 已指派 1 人 ·
维护者通常 1 天内回复
-
ui: useAgentInstances(true) turns an all_creators refusal into a page error可能重新可做 @suryakant-source 于 10 天前认领,目前没有进行中的 PR。 未关闭
难度 2/5 1-3 小时 新手友好度 72/100
kagent-dev/kagent#3212 · 1 条评论 ·
维护者通常 1 天内回复
查看 kagent-dev/kagent 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 78/100
维护者通常 1 天内回复
-
orchestration.migration.data.tasks.retry values are ignored by the 8.8 data migration job可能已有人在做 @irisfield 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 78/100
camunda/camunda-platform-helm#7773 ·
维护者通常 1 天内回复
-
Add missing unit tests for IsAdmissionPolicyName and IsCertManagerResourceName可能已有人在做 @a1h8 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 82/100
kubernetes-sigs/security-profiles-operator#3644 ·
维护者通常 1 天内回复
-
[Bug]: Anthropic Responses converter forwards empty text blocks, upstream rejects with 400可能已有人在做 @david-choi-querypie 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 76/100
维护者通常 1 天内回复
-
[DOCS]: enforce_admins description understates what it covers and omits push restrictions可能已有人在做 @dav-tb 今天认领。 未关闭
难度 1/5 1 小时以内 新手友好度 78/100
integrations/terraform-provider-github#3707 · 1 条评论 ·
维护者通常 1 天内回复