Skip to content

feat(prompt):guide llm read session history#3263

Closed
aiguozhi123456 wants to merge 2 commits intoHKUDS:mainfrom
aiguozhi123456:main
Closed

feat(prompt):guide llm read session history#3263
aiguozhi123456 wants to merge 2 commits intoHKUDS:mainfrom
aiguozhi123456:main

Conversation

@aiguozhi123456
Copy link
Copy Markdown
Contributor

@aiguozhi123456 aiguozhi123456 commented Apr 17, 2026

Summary

Enable the LLM to locate and read the full session history file on demand, mitigating context loss caused by prompt compression in multi-turn conversations.

Motivation

In long-running sessions, early messages are often compressed or dropped to fit within the context window. Once discarded, those details are irrecoverable from the LLM's perspective, leading to:

  • Repeated user prompts ("I already told you...").
  • Broken continuity across turns.
  • Hallucinated reconstructions of prior context.

By surfacing the exact session file path in the system prompt, we give the LLM a way to pull the original, uncompressed history when it needs to recall something that no longer fits in the active context.

Changes

  • context.py: Add chat_id parameter to build_system_prompt() and _get_identity(), thread it into the identity template.
  • identity.md: Add one line — Session file: {{ workspace_path }}/sessions/{{ channel }}_{{ chat_id }}.jsonl — with a short grep usage hint.
  • Tests: 3 new cases — exact path with channel+chat_id, None fallback (sessions/_.jsonl), and full build_messages integration.

Prompt Caching Impact

None. channel + chat_id are constant within a session, so the system prompt stays stable across turns.

@aiguozhi123456 aiguozhi123456 mentioned this pull request Apr 17, 2026
7 tasks
@aiguozhi123456
Copy link
Copy Markdown
Contributor Author

aiguozhi123456 commented Apr 17, 2026

我记得runtime context有辨认session所需信息的,当然也可以再改改,指出有辨认信息的事实。
补充:这下应该没问题了。

…file path

- Add chat_id parameter to build_system_prompt and _get_identity
- Render channel_chat_id.jsonl in identity.md so LLM can locate
  the exact session file without guessing
- Use grep-focused description to keep prompt concise
@Re-bin
Copy link
Copy Markdown
Collaborator

Re-bin commented Apr 18, 2026

Hi,感谢PR,可以把description补充一下不

- Test exact session path rendered with channel + chat_id
- Test graceful fallback when channel/chat_id are None
- Test build_messages passes chat_id to system prompt
@aiguozhi123456
Copy link
Copy Markdown
Contributor Author

aiguozhi123456 commented Apr 18, 2026

Hi,感谢PR,可以把description补充一下不

@Re-bin 收到,已经补充了。
BTW, 请问为什么要硬编码
You are nanobot, a helpful AI assistant.
可能不利于角色扮演。
更新: 看到了,已经修了。34e8f97

@aiguozhi123456
Copy link
Copy Markdown
Contributor Author

aiguozhi123456 commented Apr 19, 2026

1.我对于session中内容的理解有点问题
2.针对的问题已在#3304 中更合理地修复了。
遂关闭此pr。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants