Skip to content

Support customized system prompt base#102

Merged
fridayL merged 2 commits intoMemTensor:devfrom
newmeta-ben:feat/base_prompt_params
Jul 17, 2025
Merged

Support customized system prompt base#102
fridayL merged 2 commits intoMemTensor:devfrom
newmeta-ben:feat/base_prompt_params

Conversation

@newmeta-ben
Copy link
Contributor

Description

Added parameter to mos.chat(base_prompt=) to enable base_prompt to be customised on a per-query basis.

base_prompt (str, optional): A custom base prompt to use for the chat.

  • It can be a template string with a {memories} placeholder.
  • If not provided, a default prompt is used.

Issue: #90

Summary: (Support customized system prompt base)

Fix: #(90)

Reviewer: @fridayL

Checklist:

  • I have performed a self-review of my own code | 我已自行检查了自己的代码
  • I have commented my code in hard-to-understand areas | 我已在难以理解的地方对代码进行了注释
  • I have added tests that prove my fix is effective or that my feature works | 我已添加测试以证明我的修复有效或功能正常
  • I have added necessary documentation (if applicable) | 我已添加必要的文档(如果适用)
  • I have linked the issue to this PR (if applicable) | 我已将 issue 链接到此 PR(如果适用)
  • I have mentioned the person who will review this PR | 我已提及将审查此 PR 的人

Copilot AI review requested due to automatic review settings July 16, 2025 10:04
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Support per-query custom system prompts via a new base_prompt parameter

  • Extend MOS.chat (in both CoT and non-CoT paths) and MOSCore.chat to accept and forward base_prompt
  • Update _build_system_prompt to interpolate {memories} in a provided template and maintain backward-compatible behavior
  • Add tests covering custom prompt usage in both core and high-level APIs

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

File Description
src/memos/mem_os/main.py Updated MOS.chat, _chat_with_cot_enhancement, and _generate_enhanced_response_with_context to accept and forward base_prompt
src/memos/mem_os/core.py Extended chat signature and enhanced _build_system_prompt to handle base_prompt templates and memory interpolation
tests/mem_os/test_memos_core.py Added tests for MOSCore.chat with a custom base prompt and for _build_system_prompt behavior under various scenarios
tests/mem_os/test_memos.py Added tests ensuring MOS.chat passes base_prompt correctly in both CoT-disabled and CoT-enabled modes
Comments suppressed due to low confidence (2)

src/memos/mem_os/main.py:57

  • The docstring for _chat_with_cot_enhancement is missing a description for the new base_prompt parameter. Please add an Args entry explaining its purpose and usage.
    def _chat_with_cot_enhancement(

tests/mem_os/test_memos_core.py:595

  • Consider adding a test that verifies when no base_prompt is provided to MOSCore.chat, the default system prompt ("You are a knowledgeable and helpful AI assistant.") is used and sent to the LLM.
    @patch("memos.mem_os.core.UserManager")

@CaralHsi CaralHsi requested a review from fridayL July 16, 2025 10:35
@fridayL fridayL merged commit a0990be into MemTensor:dev Jul 17, 2025
16 checks passed
tianxing02 pushed a commit to tianxing02/MemOS that referenced this pull request Feb 24, 2026
feat: Add parameter to chat functions to override the base system prompt with a custom system prompt.

Co-authored-by: chunyu li <78344051+fridayL@users.noreply.github.com>
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.

3 participants