feat(agent): enhance message consolidation and context management
- 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.
This commit is contained in:
@@ -293,7 +293,11 @@ func (e *AgentEngine) executeLoop(
|
||||
// the API-reported usage from the previous round plus a BPE delta
|
||||
// for newly appended messages (assistant reply + tool results).
|
||||
currentTokens := e.estimateCurrentTokens(messages)
|
||||
beforeLen := len(messages)
|
||||
messages = e.manageContextWindow(ctx, messages, state.CurrentRound+1, currentTokens)
|
||||
if len(messages) < beforeLen {
|
||||
currentTokens = e.tokenEstimator.EstimateMessages(messages)
|
||||
}
|
||||
|
||||
logger.Infof(ctx, "[Agent][Round-%d/%d] Starting: %d messages, %d tools, est_tokens=%d",
|
||||
state.CurrentRound+1, e.config.MaxIterations, len(messages), len(tools), currentTokens)
|
||||
|
||||
Reference in New Issue
Block a user