feat(bot): add configurable history limit for conversation prompts

Added support for configurable conversation history limits through bot configuration. The bot now reads 'prompt-history' from config (defaulting to -1 for unlimited) and trims the conversation history accordingly before generating prompts. Updated announcements bot template to use history limit of 2 messages instead of the previous compact setting.
This commit is contained in:
Rodrigo Rodriguez (Pragmatismo) 2025-11-05 20:18:34 -03:00
parent b2760113af
commit 9cc1c11d66
3 changed files with 138 additions and 3 deletions

View file

@ -385,10 +385,29 @@ impl BotOrchestrator {
.await?
};
// Acquire lock briefly for history retrieval
// Get history limit from bot config (default -1 for unlimited)
let history_limit = {
let config_manager = ConfigManager::new(Arc::clone(&self.state.conn));
config_manager
.get_config(
&Uuid::parse_str(&message.bot_id).unwrap_or_default(),
"prompt-history",
None,
)
.unwrap_or_default()
.parse::<i32>()
.unwrap_or(-1)
};
// Acquire lock briefly for history retrieval with configurable limit
let history = {
let mut sm = self.state.session_manager.lock().await;
sm.get_conversation_history(session.id, user_id)?
let mut history = sm.get_conversation_history(session.id, user_id)?;
if history_limit > 0 && history.len() > history_limit as usize {
let start = history.len() - history_limit as usize;
history.drain(0..start);
}
history
};
let mut prompt = String::new();

View file

@ -1,5 +1,5 @@
name,value
prompt-compact, 10
prompt-history, 2
theme-color1,green
theme-color2,yellow
custom-logo-url,https://example.com/logo.png

1 name value
2 prompt-compact prompt-history 10 2
3 theme-color1 green
4 theme-color2 yellow
5 custom-logo-url https://example.com/logo.png

View file

@ -0,0 +1,116 @@
# BotServer Version 6.0.1 to 6.0.5 Executive Report
## Executive Summary
This report outlines the key database schema and architectural changes introduced between versions 6.0.1 and 6.0.5 of BotServer platform. The changes represent a major evolution in configuration management, knowledge base handling, and automation capabilities.
## Version-by-Version Changes
### Version 6.0.1
- **Key Change**: Introduced bot memory system
- **Details**:
- Created `bot_memories` table with key-value storage
- Added indexes for efficient memory lookups
- Supports persistent bot state management
### Version 6.0.2
- **Key Change**: Knowledge Base and Tools Management
- **Details**:
- Added `kb_documents` table for document metadata
- Created `kb_collections` for organizing documents
- Introduced `basic_tools` table for compiled BASIC tools
- Added comprehensive indexing for performance
- Implemented automatic timestamp updates via triggers
### Version 6.0.3
- **Key Change**: User KB associations and session tools
- **Details**:
- Added `user_kb_associations` to track active KBs per user
- Created `session_tool_associations` for session-specific tools
- Improved personalization and session context management
### Version 6.0.4
- **Key Change**: Comprehensive Configuration Management
- **Details**:
- Replaced .env files with database-backed configuration
- Added multi-tenancy support with `tenants` table
- Created tables for server, tenant, and bot configurations
- Added model configuration management
- Implemented connection management system
- Introduced component installation system
- Enhanced configuration security with encryption support
### Version 6.0.5
- **Key Change**: Automation Improvements
- **Details**:
- Enhanced system_automations table with name and bot_id
- Added unique constraints for data integrity
- Fixed clicks table primary key structure
- Improved scheduled automation handling
## Git Commit History (6.0.1 to 6.0.5)
## Change Statistics
- **Files Changed**: 85
- **Lines Added**: 11,457
- **Lines Removed**: 3,385
- **Key Areas Modified**:
- Documentation (+2,176 lines across 5 new files)
- Package Manager (major refactoring with facade/installer additions)
- Knowledge Base System (new embeddings, minio, qdrant modules)
- Basic Tools Compiler (+433 lines)
- Tool Keywords System (+1,200 lines across multiple files)
- Configuration System (+344 lines)
- Web Automation (+231 lines)
- c5953808 - Support legacy bootstrap and update installer
- 248ad08e - Add new KB and session association tables
- de5b651b - Refactor config loading and DB URL parsing
- 30b02658 - Add include_dir dependency for embedded migrations
- 93dab6f7 - Update PostgreSQL installer commands
- ed93f70f - Remove tables install from bootstrap
- f8d4e892 - Add progress bars and enhance bootstrap
- fa0fa390 - Add await to bootstrap start_all call
- 2af3e3a4 - Add method to start all components
- 6f305175 - Tables installation improvements
- 88ca2143 - Add package manager CLI and component system
- aa69c63c - Refactor bootstrap and package manager
- e1f91113 - Update password generator
- d970d48a - Postgres to version 18
- 88a52f17 - New bootstrap engine
- d9e0f1f2 - Knowledge management system
- a77e0d6a - Enhanced knowledge management logic
- 27d03499 - Bot package refactoring
- be1e2575 - Initial bot package refactor
## Architectural Impact
1. **Configuration Management**:
- Centralized all configuration in database
- Added encryption support for sensitive data
- Enabled multi-environment management
2. **Knowledge Base & Tools**:
- Created comprehensive document management system
- Added collection-level organization
- Improved search capabilities via indexing
- Introduced tool management system with compilation support
- Added KB embedding and vector search capabilities
3. **Automation**:
- Enhanced scheduling capabilities
- Improved data integrity with constraints
- Better bot-specific automation handling
- Added container management scripts
4. **Code Evolution**:
- Expanded package management functionality
- Added web automation capabilities
- Enhanced basic tool keywords system
- Improved documentation and examples
## Recommended Actions
1. Review configuration migration for existing deployments
2. Audit knowledge base document indexing
3. Verify automation schedules after upgrade
4. Test multi-tenancy features if applicable
5. Review new tool management system implementation
6. Evaluate container deployment scripts
7. Test web automation capabilities