This module provides programmatic access to the TNFR Pattern Cookbook, a comprehensive library of validated operator sequences organized by application domain.
The TNFR Pattern Cookbook offers ready-to-use, battle-tested operator sequences validated against TNFR Grammar 2.0. Each recipe includes:
from tnfr.recipes import TNFRCookbook
# Initialize the cookbook
cookbook = TNFRCookbook()
# Get a specific recipe
recipe = cookbook.get_recipe("therapeutic", "crisis_intervention")
print(f"Sequence: {' → '.join(recipe.sequence)}")
print(f"Health: {recipe.health_metrics.overall_health:.3f}")
print(f"Use cases: {recipe.use_cases}")
# List high-quality recipes
high_quality = cookbook.list_recipes(min_health=0.85)
for r in high_quality:
print(f"{r.name} ({r.domain}): {r.health_metrics.overall_health:.3f}")
# Search for recipes
results = cookbook.search_recipes("team")
for r in results:
print(f"Found: {r.name}")
# Get recommendation
recommended = cookbook.recommend_recipe(
context="Need to facilitate learning breakthrough",
constraints={"min_health": 0.80}
)
if recommended:
print(f"Recommended: {recommended.name}")The cookbook covers 4 major application domains with 21+ validated recipes:
⭐ = Highest health score in domain
Main class providing access to all recipes.
get_recipe(domain: str, use_case: str) -> CookbookRecipe
Get a specific recipe by domain and use case identifier.
recipe = cookbook.get_recipe("therapeutic", "crisis_intervention")list_recipes(domain: str = None, min_health: float = 0.0, max_length: int = None, pattern_type: str = None) -> List[CookbookRecipe]
List recipes with optional filtering.
# All therapeutic recipes with health > 0.80
recipes = cookbook.list_recipes(
domain="therapeutic",
min_health=0.80
)
# Short sequences across all domains
short = cookbook.list_recipes(max_length=8)
# Regenerative patterns only
regen = cookbook.list_recipes(pattern_type="regenerative")search_recipes(query: str) -> List[CookbookRecipe]
Search recipes by text query (case-insensitive).
# Find all team-related recipes
team_recipes = cookbook.search_recipes("team")
# Find crisis management patterns
crisis = cookbook.search_recipes("crisis")recommend_recipe(context: str, constraints: Dict[str, Any] = None) -> Optional[CookbookRecipe]
Get recipe recommendation based on context description.
recommended = cookbook.recommend_recipe(
context="Need to help new team collaborate on innovation project",
constraints={
"min_health": 0.80,
"max_length": 12,
"domain": "organizational" # optional
}
)get_all_domains() -> List[str]
Get list of all available domains.
domains = cookbook.get_all_domains()
# ['therapeutic', 'educational', 'organizational', 'creative']get_domain_summary(domain: str) -> Dict[str, Any]
Get summary statistics for a domain.
summary = cookbook.get_domain_summary("therapeutic")
print(f"Recipes: {summary['recipe_count']}")
print(f"Avg Health: {summary['average_health']:.3f}")
print(f"Patterns: {summary['patterns']}")Data class representing a validated recipe.
recipe = cookbook.get_recipe("educational", "conceptual_breakthrough")
print(f"Name: {recipe.name}")
print(f"Domain: {recipe.domain}")
print(f"Sequence: {' → '.join(recipe.sequence)}")
print(f"Health: {recipe.health_metrics.overall_health:.3f}")
print(f"Pattern: {recipe.pattern_type}")
for use_case in recipe.use_cases:
print(f"- {use_case}")See examples/pattern_cookbook_demo.py for comprehensive usage examples including:
For detailed recipe documentation including:
See: AGENTS.md — Operator Composition
from tnfr.recipes import TNFRCookbook
from tnfr.operators.grammar import validate_sequence_with_health
cookbook = TNFRCookbook()
recipe = cookbook.get_recipe("therapeutic", "process_therapy")
# Validate the sequence
result = validate_sequence_with_health(recipe.sequence)
print(f"Valid: {result.passed}")
print(f"Health: {result.health_metrics.overall_health:.3f}")from tnfr.recipes import TNFRCookbook
# Cookbook can serve as base for sequence generation
# See sequence_generator documentation for detailsAll recipes in the cookbook meet these quality standards:
To contribute new recipes:
See cookbook documentation for detailed contribution guidelines.
Part of the TNFR Python Engine. See LICENSE.md.