PresetManager
Centralized manager for loading, storing, and applying chatbot behavior presets.
USAGE
PresetManager()
The PresetManager
class serves as the central registry and orchestrator for all behavior presets in the Talk Box system. It provides comprehensive functionality for preset lifecycle management including loading default presets, adding custom presets, applying presets to chatbot configurations, and managing preset collections for different domains or teams.
The manager automatically loads a curated library of default presets covering common use cases like customer support, technical advisory, creative writing, and data analysis. It also provides flexible APIs for adding custom presets, removing presets, and applying preset configurations to chatbot instances with proper precedence handling.
The class is designed to be extensible and can be integrated with external preset sources like databases, configuration files, or remote preset repositories. It handles preset validation, conflict resolution, and provides comprehensive preset discovery and introspection capabilities.
Notes
The PresetManager takes no initialization parameters. Default presets are automatically loaded during initialization, and the manager is ready for immediate use.
Returns
PresetManager
-
A new PresetManager instance with default presets loaded and ready for use.
Core Preset Operations
The PresetManager provides comprehensive preset management capabilities:
get_preset()
: Retrieve presets by nameadd_preset()
: Add custom presetsremove_preset()
: Remove presetslist_presets()
: List available presetsapply_preset()
: Apply presets to configurations
Default Preset Library
The manager includes a comprehensive library of default presets:
"customer_support"
: Polite, professional customer service interactions"technical_advisor"
: Authoritative technical guidance with detailed explanations"creative_writer"
: Imaginative storytelling and creative content generation"data_analyst"
: Analytical, evidence-based data insights and interpretation"legal_advisor"
: Professional legal information with appropriate disclaimers
Each default preset is carefully crafted with appropriate tone, expertise areas, verbosity levels, constraints, and system prompts for optimal performance in their respective domains.
Configuration Application
When presets are applied to chatbot configurations, the manager handles intelligent merging where existing configuration values take precedence over preset defaults. This allows for preset-based initialization while preserving explicit user settings.
Examples
Basic preset management operations
Get and use presets from the default library:
import talk_box as tb
# Create a preset manager (loads defaults automatically)
= tb.PresetManager()
manager
# List available presets
= manager.list_presets()
available_presets print(f"Available presets: {', '.join(available_presets)}")
# Get a specific preset
= manager.get_preset("technical_advisor")
tech_preset if tech_preset:
print(f"Tech preset tone: {tech_preset.tone}")
print(f"Expertise: {tech_preset.expertise}")
print(f"Constraints: {', '.join(tech_preset.constraints)}")
# Apply preset to a chatbot
= ChatBot().preset("technical_advisor") bot
Adding custom presets for specialized domains
Create and register custom presets for specific business needs:
# Create a custom preset for e-commerce support
= tb.Preset(
ecommerce_preset ="ecommerce_support",
name="helpful",
tone="product_knowledge,order_management,returns",
expertise="detailed",
verbosity=["policy_compliant", "customer_first", "solution_oriented"],
constraints="You are an e-commerce customer support specialist. Help customers "
system_prompt"with orders, products, returns, and general shopping questions. "
"Always prioritize customer satisfaction while following company policies."
)
# Add to manager
= tb.PresetManager()
manager
manager.add_preset(ecommerce_preset)
# Verify it was added
if "ecommerce_support" in manager.list_presets():
print("✅ E-commerce preset successfully added")
# Use the custom preset
= tb.ChatBot().preset("ecommerce_support") ecommerce_bot
Building domain-specific preset collections
Create specialized preset collections for different teams or applications:
# Educational presets
= [
educational_presets
tb.Preset(="math_tutor",
name="patient",
tone="mathematics,problem_solving,step_by_step_explanation",
expertise="thorough",
verbosity=["show_work", "encourage_learning", "no_direct_answers"],
constraints="You are a math tutor. Guide students through problems step-by-step."
system_prompt
),
tb.Preset(="science_teacher",
name="enthusiastic",
tone="physics,chemistry,biology,scientific_method",
expertise="descriptive",
verbosity=["age_appropriate", "safety_conscious", "experiment_focused"],
constraints="You are a science teacher who makes science exciting and accessible."
system_prompt
),
tb.Preset(="language_coach",
name="encouraging",
tone="grammar,vocabulary,pronunciation,cultural_context",
expertise="detailed",
verbosity=["culturally_sensitive", "progressive_difficulty"],
constraints="You are a language learning coach. Provide clear explanations and practice."
system_prompt
)
]
# Add all educational presets
= tb.PresetManager()
manager for preset in educational_presets:
manager.add_preset(preset)
# Create specialized chatbots
= tb.ChatBot().preset("math_tutor").temperature(0.3)
math_bot = tb.ChatBot().preset("science_teacher").temperature(0.7)
science_bot = tb.ChatBot().preset("language_coach").temperature(0.5)
language_bot
print(f"Created {len(educational_presets)} educational chatbots")
Preset application with configuration merging
Understand how presets merge with explicit configuration settings:
= tb.PresetManager()
manager
# Start with base configuration
= {
base_config "model": "gpt-4-turbo",
"temperature": 0.5,
"max_tokens": None, # Will be filled by preset
"tools": ["web_search"],
"preset": None,
"persona": None
}
# Apply technical advisor preset
= manager.apply_preset("technical_advisor", base_config)
tech_config
print("Configuration after applying preset:")
for key, value in tech_config.items():
if value != base_config.get(key):
print(f" {key}: {base_config.get(key)} → {value}")
else:
print(f" {key}: {value} (unchanged)")
# Note: Existing values in base_config take precedence over preset values
# Only None or missing values get filled from the preset
Dynamic preset management and updates
Manage presets dynamically during application runtime:
= tb.PresetManager()
manager
# Check if preset exists before removal
if manager.get_preset("legal_advisor"):
print("Legal advisor preset is available")
# Remove preset (returns True if removed)
if manager.remove_preset("legal_advisor"):
print("Legal advisor preset removed")
else:
print("Failed to remove preset")
# Add updated version
= tb.Preset(
updated_legal_preset ="legal_advisor_v2",
name="professional",
tone="legal_information,compliance,risk_assessment",
expertise="comprehensive",
verbosity=["disclaimer_required", "no_personal_advice", "cite_sources"],
constraints="You are a legal information assistant. Provide general legal "
system_prompt"information with appropriate disclaimers and source citations."
)
manager.add_preset(updated_legal_preset)print(f"Updated preset collection: {len(manager.list_presets())} presets available")
Preset validation and quality assurance
The PresetManager can be extended with validation workflows to ensure preset quality, consistency checks, and comprehensive validation of all presets in the collection.
Integration with external preset sources
The manager can be extended to work with external preset sources such as JSON files, databases, or remote APIs for loading and synchronizing preset collections.
Preset performance monitoring and analytics
Advanced implementations can track preset usage patterns, popularity metrics, and performance analytics to optimize preset collections and identify improvement opportunities.
Advanced Features
Preset Inheritance: Future versions may support preset inheritance where specialized presets can extend base presets with additional or overridden configuration.
Conditional Logic: System prompts can include conditional logic based on context or user characteristics for dynamic behavior adaptation.
Preset Versioning: Consider implementing version management for presets to handle updates and rollbacks in production environments.
Team Collaboration: The manager can be extended to support team-based preset sharing and collaborative preset development workflows.
Performance Optimization: Large preset collections can benefit from lazy loading and caching strategies for improved performance.
Integration Notes
- Thread Safety:
PresetManager
is not thread-safe; use external synchronization for concurrent access - Memory Usage: all presets are stored in memory; consider external storage for large collections
- Persistence: the manager doesn’t automatically persist changes; implement external persistence as needed
- Validation: consider implementing comprehensive preset validation for production use
- Namespace Management: use clear naming conventions to avoid preset name conflicts
The PresetManager
class provides a robust foundation for managing chatbot behavior templates, enabling consistent deployment of specialized AI assistants across different domains and use cases.