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)
manager = tb.PresetManager()
# List available presets
available_presets = manager.list_presets()
print(f"Available presets: {', '.join(available_presets)}")
# Get a specific preset
tech_preset = manager.get_preset("technical_advisor")
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
bot = ChatBot().preset("technical_advisor")Adding custom presets for specialized domains
Create and register custom presets for specific business needs:
# Create a custom preset for e-commerce support
ecommerce_preset = tb.Preset(
name="ecommerce_support",
tone="helpful",
expertise="product_knowledge,order_management,returns",
verbosity="detailed",
constraints=["policy_compliant", "customer_first", "solution_oriented"],
system_prompt="You are an e-commerce customer support specialist. Help customers "
"with orders, products, returns, and general shopping questions. "
"Always prioritize customer satisfaction while following company policies."
)
# Add to manager
manager = tb.PresetManager()
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
ecommerce_bot = tb.ChatBot().preset("ecommerce_support")Building domain-specific preset collections
Create specialized preset collections for different teams or applications:
# Educational presets
educational_presets = [
tb.Preset(
name="math_tutor",
tone="patient",
expertise="mathematics,problem_solving,step_by_step_explanation",
verbosity="thorough",
constraints=["show_work", "encourage_learning", "no_direct_answers"],
system_prompt="You are a math tutor. Guide students through problems step-by-step."
),
tb.Preset(
name="science_teacher",
tone="enthusiastic",
expertise="physics,chemistry,biology,scientific_method",
verbosity="descriptive",
constraints=["age_appropriate", "safety_conscious", "experiment_focused"],
system_prompt="You are a science teacher who makes science exciting and accessible."
),
tb.Preset(
name="language_coach",
tone="encouraging",
expertise="grammar,vocabulary,pronunciation,cultural_context",
verbosity="detailed",
constraints=["culturally_sensitive", "progressive_difficulty"],
system_prompt="You are a language learning coach. Provide clear explanations and practice."
)
]
# Add all educational presets
manager = tb.PresetManager()
for preset in educational_presets:
manager.add_preset(preset)
# Create specialized chatbots
math_bot = tb.ChatBot().preset("math_tutor").temperature(0.3)
science_bot = tb.ChatBot().preset("science_teacher").temperature(0.7)
language_bot = tb.ChatBot().preset("language_coach").temperature(0.5)
print(f"Created {len(educational_presets)} educational chatbots")Preset application with configuration merging
Understand how presets merge with explicit configuration settings:
manager = tb.PresetManager()
# 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
tech_config = manager.apply_preset("technical_advisor", base_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 presetDynamic preset management and updates
Manage presets dynamically during application runtime:
manager = tb.PresetManager()
# 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
updated_legal_preset = tb.Preset(
name="legal_advisor_v2",
tone="professional",
expertise="legal_information,compliance,risk_assessment",
verbosity="comprehensive",
constraints=["disclaimer_required", "no_personal_advice", "cite_sources"],
system_prompt="You are a legal information assistant. Provide general legal "
"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:
PresetManageris 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.