agents.common.models.task_analysis.branchingΒΆ
Task branching and decomposition analysis.
This module analyzes how tasks can be broken down into subtasks, identifying parallel execution opportunities, sequential dependencies, and optimal decomposition strategies.
ClassesΒΆ
Types of task branches and execution patterns. |
|
Individual branch in task decomposition. |
|
Complete task breakdown into subtasks and execution branches. |
Module ContentsΒΆ
- class agents.common.models.task_analysis.branching.BranchTypeΒΆ
-
Types of task branches and execution patterns.
- SEQUENTIALΒΆ
Tasks that must be executed in order
- PARALLELΒΆ
Tasks that can be executed simultaneously
- CONDITIONALΒΆ
Tasks that depend on conditions or outcomes
- ITERATIVEΒΆ
Tasks that repeat with feedback loops
- CONVERGENTΒΆ
Multiple branches that merge into one
- DIVERGENTΒΆ
One task that splits into multiple branches
- INDEPENDENTΒΆ
Completely independent execution streams
- DEPENDENTΒΆ
Branches with complex interdependencies
Initialize self. See help(type(self)) for accurate signature.
- class agents.common.models.task_analysis.branching.TaskBranch(/, **data)ΒΆ
Bases:
pydantic.BaseModel
Individual branch in task decomposition.
Represents a single execution path or subtask within a larger task decomposition, including its dependencies, requirements, and characteristics.
- Parameters:
data (Any)
- branch_idΒΆ
Unique identifier for this branch
- nameΒΆ
Human-readable name for the branch
- descriptionΒΆ
Detailed description of what this branch accomplishes
- branch_typeΒΆ
Type of execution pattern for this branch
- estimated_effortΒΆ
Relative effort required (1-10 scale)
- estimated_durationΒΆ
Expected time to complete
- prerequisitesΒΆ
Other branches that must complete first
- enablesΒΆ
Branches that this branch enables
- resources_neededΒΆ
Specific resources required for this branch
- parallel_compatibleΒΆ
Whether this can run in parallel with others
Example
# Finding Wimbledon winner's birthday - first branch winner_branch = TaskBranch( branch_id="find_winner", name="Find Recent Wimbledon Winner", description="Look up the most recent Wimbledon championship winner", branch_type=BranchType.SEQUENTIAL, estimated_effort=3, estimated_duration=timedelta(minutes=5), prerequisites=[], enables=["find_birthday"], resources_needed=["web_search", "sports_database"] ) # Cancer research - complex branch research_branch = TaskBranch( branch_id="mechanism_research", name="Research Cancer Mechanisms", description="Deep investigation into cellular mechanisms of cancer development", branch_type=BranchType.ITERATIVE, estimated_effort=10, estimated_duration=timedelta(weeks=52), prerequisites=["literature_review", "lab_setup"], resources_needed=["research_lab", "expert_oncologists", "funding"] )
Create a new model by parsing and validating input data from keyword arguments.
Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.
self is explicitly positional-only to allow self as a field name.
- get_duration_category()ΒΆ
Get duration category classification.
- Returns:
String describing duration category
- Return type:
- get_effort_category()ΒΆ
Get effort category classification.
- Returns:
String describing effort category
- Return type:
- has_dependencies()ΒΆ
Check if this branch has prerequisite dependencies.
- Returns:
True if branch has prerequisites
- Return type:
- is_enabling()ΒΆ
Check if this branch enables other branches.
- Returns:
True if branch enables others
- Return type:
- is_high_risk()ΒΆ
Check if this is a high-risk branch.
- Returns:
True if risk level is 4 or 5
- Return type:
- is_likely_to_succeed(threshold=0.7)ΒΆ
Check if branch is likely to succeed.
- model_configΒΆ
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class agents.common.models.task_analysis.branching.TaskDecomposition(/, **data)ΒΆ
Bases:
pydantic.BaseModel
Complete task breakdown into subtasks and execution branches.
Analyzes how a complex task can be decomposed into manageable subtasks, identifying execution patterns, dependencies, and optimization opportunities.
- Parameters:
data (Any)
- task_descriptionΒΆ
Original task being decomposed
- branchesΒΆ
List of individual execution branches
- execution_patternΒΆ
Overall execution pattern
- critical_pathΒΆ
Sequence of branches on the critical path
- parallelization_opportunitiesΒΆ
Groups of branches that can run in parallel
- bottlenecksΒΆ
Branches that are likely to be bottlenecks
- total_estimated_effortΒΆ
Sum of all branch efforts
- estimated_duration_sequentialΒΆ
Duration if executed sequentially
- estimated_duration_optimalΒΆ
Duration with optimal parallelization
Example
# Simple factual lookup task decomposition = TaskDecomposition.decompose_task( task_description="Find the birthday of the most recent Wimbledon winner", complexity_hint="simple_research" ) # Complex research task decomposition = TaskDecomposition.decompose_task( task_description="Develop a cure for cancer", complexity_hint="breakthrough_research" ) print(f"Branches: {len(decomposition.branches)}") print(f"Critical path: {decomposition.critical_path}") print(f"Parallelizable: {decomposition.parallelization_opportunities}")
Create a new model by parsing and validating input data from keyword arguments.
Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.
self is explicitly positional-only to allow self as a field name.
- calculate_parallelization_speedup()ΒΆ
Calculate potential speedup from parallelization.
- Returns:
Speedup ratio (sequential_time / optimal_time)
- Return type:
- classmethod create_simple_sequential(task_description, branch_descriptions, effort_estimates=None, duration_estimates=None)ΒΆ
Create a simple sequential task decomposition.
- Parameters:
task_description (str) β Description of the overall task
branch_descriptions (list[str]) β List of branch descriptions
effort_estimates (list[int] | None) β Optional effort estimates (defaults to 3 for all)
duration_estimates (list[datetime.timedelta] | None) β Optional duration estimates (defaults to 1 hour each)
- Returns:
TaskDecomposition with sequential branches
- Return type:
- find_independent_branches()ΒΆ
Find branches with no dependencies.
- find_terminal_branches()ΒΆ
Find branches that donβt enable anything else.
- get_complexity_metrics()ΒΆ
Get various complexity metrics for the decomposition.
- get_dependency_graph()ΒΆ
Get dependency graph as adjacency list.
- get_enables_graph()ΒΆ
Get enables graph as adjacency list.
- get_execution_recommendations()ΒΆ
Get recommendations for optimal execution.
- validate_decomposition_consistency()ΒΆ
Validate that decomposition is internally consistent.
- Returns:
Self if validation passes
- Raises:
ValueError β If decomposition has inconsistencies
- Return type: