Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

[BUG] Memory prefetch drops short sentences from the search, so relevant memories are never retrieved

未关闭 适合新手
#3,428 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
84/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
python
领域
ai

调研方向

从 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
  1. Enable agent memory and prefetch.
  2. 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.)
  3. 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

环境准备

在 Codespaces 中打开

在浏览器里用你自己的 GitHub 账号启动这个项目的开发容器。

  • 没有 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

kagent-dev/kagent 的其他 Issue

查看 kagent-dev/kagent 的全部 Issue

相似的 Issue

更多 Go Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。