MCPcopy Create free account
hub / github.com/astercloud/aster / shouldCompress

Method shouldCompress

pkg/agent/prompt_builder.go:166–188  ·  view source on GitHub ↗

shouldCompress 判断是否需要压缩

(prompt string, ctx *PromptContext)

Source from the content-addressed store, hash-verified

164
165// shouldCompress 判断是否需要压缩
166func (pb *PromptBuilder) shouldCompress(prompt string, ctx *PromptContext) bool {
167 if pb.compressor == nil {
168 return false
169 }
170
171 // 检查模板配置
172 if ctx.Template == nil || ctx.Template.Runtime == nil || ctx.Template.Runtime.PromptCompression == nil {
173 return false
174 }
175
176 config := ctx.Template.Runtime.PromptCompression
177 if !config.Enabled {
178 return false
179 }
180
181 // 检查长度阈值
182 maxLength := config.MaxLength
183 if maxLength == 0 {
184 maxLength = 5000 // 默认阈值
185 }
186
187 return len(prompt) > maxLength
188}
189
190// compress 执行压缩
191func (pb *PromptBuilder) compress(ctx context.Context, prompt string, pCtx *PromptContext) (string, error) {

Callers 1

BuildMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected