a8924e301e
- Improved the message consolidation logic to preserve the current turn's user query and all subsequent assistant/tool messages, ensuring better context retention. - Updated the CompressContext function to reflect the new consolidation strategy, maintaining the system prompt and relevant recent messages. - Refactored the context manager to support optional message repository for improved context rebuilding from persistent storage. - Added comprehensive tests to validate the new consolidation behavior and ensure correct message handling across various scenarios.
19 lines
528 B
Go
19 lines
528 B
Go
package llmcontext
|
|
|
|
import (
|
|
"github.com/Tencent/WeKnora/internal/types/interfaces"
|
|
)
|
|
|
|
// NewContextManagerFromConfig creates a ContextManager.
|
|
// messageRepo is optional — when provided, context will be rebuilt from
|
|
// the persistent messages table if the cache (Redis/memory) is empty.
|
|
func NewContextManagerFromConfig(
|
|
storage ContextStorage,
|
|
messageRepo interfaces.MessageRepository,
|
|
) interfaces.ContextManager {
|
|
if storage == nil {
|
|
storage = NewMemoryStorage()
|
|
}
|
|
return NewContextManager(storage, messageRepo)
|
|
}
|