feat(agent): implement memory consolidation and context management

- Introduced a memory consolidator to summarize older messages when the context window exceeds a specified limit, preserving key facts and tool results.
- Enhanced the AgentEngine to utilize the new token estimator and memory consolidator for improved context window management.
- Implemented logic to compress message history when approaching token limits, ensuring efficient use of context.
- Added unit tests for the memory consolidator and token estimator to validate functionality and performance.
- Updated tool execution to validate parameters against JSON schema before execution, improving error handling and robustness.
This commit is contained in:
wizardchen
2026-03-19 22:01:42 +08:00
committed by lyingbug
parent 9f4fb39e10
commit 0851d6d656
13 changed files with 1487 additions and 6 deletions
@@ -102,6 +102,11 @@ func (s *agentService) CreateAgentEngine(
// Create tool registry
toolRegistry := tools.NewToolRegistry()
// Apply configurable tool output size limit
if config.MaxToolOutputChars > 0 {
toolRegistry.SetMaxToolOutputSize(config.MaxToolOutputChars)
}
// Register tools
if err := s.registerTools(ctx, toolRegistry, config, rerankModel, chatModel, sessionID); err != nil {
return nil, fmt.Errorf("failed to register tools: %w", err)