Skip to content

feat: support memory compression - #3079

Draft
undertaker86001 wants to merge 20 commits into
higress-group:mainfrom
undertaker86001:issue-3077
Draft

undertaker86001 wants to merge 20 commits into
higress-group:mainfrom
undertaker86001:issue-3077

Conversation

@undertaker86001

@undertaker86001 undertaker86001 commented Oct 31, 2025 •

Copy link
Copy Markdown
Member

Ⅰ. Describe what this PR did

Related to issue-3077

Ⅱ. Does this pull request fix one issue?

Ⅲ. Why don't you add test cases (unit test/integration test)?

Ⅳ. Describe how to verify it

Ⅴ. Special notes for reviews

@CLAassistant

CLAassistant commented Oct 31, 2025 •

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
1 out of 2 committers have signed the CLA.

✅ johnlanni
❌ kaori-seasons


kaori-seasons seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You have signed the CLA already but the status is still pending? Let us recheck it.

@undertaker86001 undertaker86001 changed the title [ISSUES#3077] support memory compression feat: support memory compression Nov 3, 2025
@@ -0,0 +1,161 @@
# AI Context Compressor 插件集成指南

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

这个需求应该不需要一个独立的压缩插件,第一版本只需要实现工具输出的压缩即可,统一在ai-proxy插件中实现

contentChan := make(chan string, 1)
errChan := make(chan error, 1)

go func() {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

插件里不支持goroutine

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

好的,这里只是想提升读取的性能所以做的优化.

saveContextTool := tool{
Type: "function",
Function: function{
Name: MemoryToolSaveContext,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

这个tool似乎没有用到?而且应该不需要通过工具的方式触发让llm输出要存储到内存到内容?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

是的,可以改进

4. 长度控制在500字符以内

工具输出内容:
%s

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

是否应该同时给出工具输出对应的输入,这样LLM在发现某次工具调用的输出被压缩掉后,根据这里的信息可以再查找到。


// TransformResponseBody 处理DeepSeek API响应,确保token计算符合DeepSeek标准
// DeepSeek使用OpenAI兼容的API格式,但需要特别处理reasoning tokens
func (m *deepseekProvider) TransformResponseBody(ctx wrapper.HttpContext, apiName ApiName, body []byte) ([]byte, error) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

这个为什么改在deepseek provider里?

}

// Step 1: Check if there are compressed references that need to be restored
needRetrievalIds := c.extractCompressedContextIds(request.Messages)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

这个逻辑有点问题,不是把每个工具输出分别压缩替换,而是将指定数量的历史(根据配置的保留最近多少工具数)的工具输出一次性做压缩替换

@johnlanni
johnlanni marked this pull request as ready for review November 26, 2025 14:36
@johnlanni
johnlanni marked this pull request as draft November 26, 2025 14:36

This branch has not been deployed

No deployments
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.

4 participants