Compute effective tool configuration for a step. Applies filtering rules to determine which tools and submodules are available for the current step: - If both plan and step specify enabled tools, uses intersection - If only one specifies, uses that list - If
(
cls,
all_tools: List[Dict[str, Any]],
context: Dict[str, Any],
step_config: Optional[Dict[str, Any]] = None,
)
| 42 | |
| 43 | @classmethod |
| 44 | def compute( |
| 45 | cls, |
| 46 | all_tools: List[Dict[str, Any]], |
| 47 | context: Dict[str, Any], |
| 48 | step_config: Optional[Dict[str, Any]] = None, |
| 49 | ) -> EffectiveToolConfig: |
| 50 | """Compute effective tool configuration for a step. |
| 51 | |
| 52 | Applies filtering rules to determine which tools and submodules |
| 53 | are available for the current step: |
| 54 | - If both plan and step specify enabled tools, uses intersection |
| 55 | - If only one specifies, uses that list |
| 56 | - If neither specifies, all tools are available |
| 57 | |
| 58 | Args: |
| 59 | all_tools: Complete list of available tool definitions. |
| 60 | context: Workflow context containing plan-level settings. |
| 61 | step_config: Optional step-specific configuration. |
| 62 | |
| 63 | Returns: |
| 64 | EffectiveToolConfig with filtered tools and submodules. |
| 65 | """ |
| 66 | |
| 67 | def normalize_enabled_list(value: Any) -> Optional[List[str]]: |
| 68 | if value is None: |
| 69 | return None |
| 70 | if isinstance(value, (list, tuple, set)): |
| 71 | return [str(v) for v in value] |
| 72 | return [str(value)] |
| 73 | |
| 74 | def compute_effective_set( |
| 75 | plan_key: str, |
| 76 | step_key: str, |
| 77 | ) -> Optional[Set[str]]: |
| 78 | """Compute effective enabled set from plan and step configs.""" |
| 79 | plan_enabled = normalize_enabled_list(context.get(plan_key)) |
| 80 | step_enabled = ( |
| 81 | normalize_enabled_list(step_config.get(step_key)) |
| 82 | if step_config |
| 83 | else None |
| 84 | ) |
| 85 | |
| 86 | if plan_enabled is not None and step_enabled is not None: |
| 87 | return set(plan_enabled) & set(step_enabled) |
| 88 | elif step_enabled is not None: |
| 89 | return set(step_enabled) |
| 90 | elif plan_enabled is not None: |
| 91 | return set(plan_enabled) |
| 92 | return None |
| 93 | |
| 94 | # Compute effective tools |
| 95 | tools_enabled = compute_effective_set( |
| 96 | ContextKeys.ENABLED_TOOLS, ContextKeys.ENABLED_TOOLS |
| 97 | ) |
| 98 | if tools_enabled is None: |
| 99 | effective_tools = all_tools |
| 100 | else: |
| 101 | effective_tools = [ |