"""
Toolset Distributions Module
This module defines distributions of toolsets for data generation runs.
Each distribution specifies which toolsets should be used and their probability
of being selected for any given prompt during the batch processing.
A distribution is a dictionary mapping toolset names to their selection probability (%).
Probabilities should sum to 100, but the system will normalize if they don't.
Usage:
from toolset_distributions import get_distribution, list_distributions
# Get a specific distribution
dist = get_distribution("image_gen")
# List all available distributions
all_dists = list_distributions()
"""
from typing import Dict, List, Optional
import random
from toolsets import validate_toolset
DISTRIBUTIONS = {
"default": {
"description": "All available tools, all the time",
"toolsets": {
"web": 100,
"vision": 100,
"image_gen": 100,
"terminal": 100,
"file": 100,
"moa": 100,
"browser": 100
}
},
"image_gen": {
"description": "Heavy focus on image generation with vision and web support",
"toolsets": {
"image_gen": 90,
"vision": 90,
"web": 55,
"terminal": 45,
"moa": 10
}
},
"research": {
"description": "Web research with vision analysis and reasoning",
"toolsets": {
"web": 90,
"browser": 70,
"vision": 50,
"moa": 40,
"terminal": 10
}
},
"science": {
"description": "Scientific research with web, terminal, file, and browser capabilities",
"toolsets": {
"web": 94,
"terminal": 94,
"file": 94,
"vision": 65,
"browser": 50,
"image_gen": 15,
"moa": 10
}
},
"development": {
"description": "Terminal, file tools, and reasoning with occasional web lookup",
"toolsets": {
"terminal": 80,
"file": 80,
"moa": 60,
"web": 30,
"vision": 10
}
},
"safe": {
"description": "All tools except terminal for safety",
"toolsets": {
"web": 80,
"browser": 70,
"vision": 60,
"image_gen": 60,
"moa": 50
}
},
"balanced": {
"description": "Equal probability of all toolsets",
"toolsets": {
"web": 50,
"vision": 50,
"image_gen": 50,
"terminal": 50,
"file": 50,
"moa": 50,
"browser": 50
}
},
"minimal": {
"description": "Only web tools for basic research",
"toolsets": {
"web": 100
}
},
"terminal_only": {
"description": "Terminal and file tools for code execution tasks",
"toolsets": {
"terminal": 100,
"file": 100
}
},
"terminal_web": {
"description": "Terminal and file tools with web search for documentation lookup",
"toolsets": {
"terminal": 100,
"file": 100,
"web": 100
}
},
"creative": {
"description": "Image generation and vision analysis focus",
"toolsets": {
"image_gen": 90,
"vision": 90,
"web": 30
}
},
"reasoning": {
"description": "Heavy mixture of agents usage with minimal other tools",
"toolsets": {
"moa": 90,
"web": 30,
"terminal": 20
}
},
"browser_use": {
"description": "Full browser-based web interaction with search, vision, and page control",
"toolsets": {
"browser": 100,
"web": 80,
"vision": 70
}
},
"browser_only": {
"description": "Only browser automation tools for pure web interaction tasks",
"toolsets": {
"browser": 100
}
},
"browser_tasks": {
"description": "Browser-focused distribution (browser toolset includes web_search for finding URLs since Google blocks direct browser searches)",
"toolsets": {
"browser": 97,
"vision": 12,
"terminal": 15
}
},
"terminal_tasks": {
"description": "Terminal-focused distribution with high terminal/file availability, occasional other tools",
"toolsets": {
"terminal": 97,
"file": 97,
"web": 97,
"browser": 75,
"vision": 50,
"image_gen": 10
}
},
"mixed_tasks": {
"description": "Mixed distribution with high browser, terminal, and file availability for complex tasks",
"toolsets": {
"browser": 92,
"terminal": 92,
"file": 92,
"web": 35,
"vision": 15,
"image_gen": 15
}
}
}
def get_distribution(name: str) -> Optional[Dict[str, any]]:
"""
Get a toolset distribution by name.
Args:
name (str): Name of the distribution
Returns:
Dict: Distribution definition with description and toolsets
None: If distribution not found
"""
return DISTRIBUTIONS.get(name)
def list_distributions() -> Dict[str, Dict]:
"""
List all available distributions.
Returns:
Dict: All distribution definitions
"""
return DISTRIBUTIONS.copy()
def sample_toolsets_from_distribution(distribution_name: str) -> List[str]:
"""
Sample toolsets based on a distribution's probabilities.
Each toolset in the distribution has a % chance of being included.
This allows multiple toolsets to be active simultaneously.
Args:
distribution_name (str): Name of the distribution to sample from
Returns:
List[str]: List of sampled toolset names
Raises:
ValueError: If distribution name is not found
"""
dist = get_distribution(distribution_name)
if not dist:
raise ValueError(f"Unknown distribution: {distribution_name}")
selected_toolsets = []
for toolset_name, probability in dist["toolsets"].items():
if not validate_toolset(toolset_name):
print(f"⚠️ Warning: Toolset '{toolset_name}' in distribution '{distribution_name}' is not valid")
continue
if random.random() * 100 < probability:
selected_toolsets.append(toolset_name)
if not selected_toolsets and dist["toolsets"]:
highest_prob_toolset = max(dist["toolsets"].items(), key=lambda x: x[1])[0]
if validate_toolset(highest_prob_toolset):
selected_toolsets.append(highest_prob_toolset)
return selected_toolsets
def validate_distribution(distribution_name: str) -> bool:
"""
Check if a distribution name is valid.
Args:
distribution_name (str): Distribution name to validate
Returns:
bool: True if valid, False otherwise
"""
return distribution_name in DISTRIBUTIONS
def print_distribution_info(distribution_name: str) -> None:
"""
Print detailed information about a distribution.
Args:
distribution_name (str): Distribution name
"""
dist = get_distribution(distribution_name)
if not dist:
print(f"❌ Unknown distribution: {distribution_name}")
return
print(f"\n📊 Distribution: {distribution_name}")
print(f" Description: {dist['description']}")
print(" Toolsets:")
for toolset, prob in sorted(dist["toolsets"].items(), key=lambda x: x[1], reverse=True):
print(f" • {toolset:15} : {prob:3}% chance")
if __name__ == "__main__":
"""
Demo and testing of the distributions system
"""
print("📊 Toolset Distributions Demo")
print("=" * 60)
print("\n📋 Available Distributions:")
print("-" * 40)
for name, dist in list_distributions().items():
print(f"\n {name}:")
print(f" {dist['description']}")
toolset_list = ", ".join([f"{ts}({p}%)" for ts, p in dist["toolsets"].items()])
print(f" Toolsets: {toolset_list}")
print("\n\n🎲 Sampling Examples:")
print("-" * 40)
test_distributions = ["image_gen", "research", "balanced", "default"]
for dist_name in test_distributions:
print(f"\n{dist_name}:")
samples = []
for _ in range(5):
sampled = sample_toolsets_from_distribution(dist_name)
samples.append(sorted(sampled))
print(f" Sample 1: {samples[0]}")
print(f" Sample 2: {samples[1]}")
print(f" Sample 3: {samples[2]}")
print(f" Sample 4: {samples[3]}")
print(f" Sample 5: {samples[4]}")
print("\n\n📊 Detailed Distribution Info:")
print("-" * 40)
print_distribution_info("image_gen")
print_distribution_info("research")