@@ -162,8 +162,8 @@ def propose_component_texts(
162162
163163 # Otherwise, route to appropriate proposers
164164 # Separate react_module components from regular instruction components
165- react_module_components = [c for c in components_to_update if c .startswith ("react_module" )]
166- instruction_components = [c for c in components_to_update if not c .startswith ("react_module" )]
165+ react_module_components = [c for c in components_to_update if c .startswith (REACT_MODULE_PREFIX )]
166+ instruction_components = [c for c in components_to_update if not c .startswith (REACT_MODULE_PREFIX )]
167167
168168 results : dict [str , str ] = {}
169169
@@ -234,8 +234,8 @@ def build_program(self, candidate: dict[str, str]):
234234 continue
235235
236236 # Build module key
237- prefix = module_path .removeprefix ("self." ) if module_path != "self" else ""
238- module_key = "react_module" if prefix == "" else f"react_module: { prefix } "
237+ normalized_path = module_path .removeprefix ("self." ) if module_path != "self" else ""
238+ module_key = REACT_MODULE_PREFIX if normalized_path == "" else f"{ REACT_MODULE_PREFIX } : { normalized_path } "
239239
240240 # Check if this module was optimized
241241 if module_key not in candidate :
@@ -342,16 +342,19 @@ def make_reflective_dataset(
342342 logger .info (f"Processing component: { pred_name } " )
343343
344344 # Handle ReAct module components - use extract predictor for final outputs
345- if pred_name .startswith ("react_module" ):
345+ if pred_name .startswith (REACT_MODULE_PREFIX ):
346346 # Extract the target path from the key
347- target_path = pred_name .replace ( "react_module:" , " " ) if ":" in pred_name else ""
347+ target_path = pred_name .removeprefix ( f" { REACT_MODULE_PREFIX } : " ) if ":" in pred_name else ""
348348
349349 # Find the ReAct module by traversing program structure (same as regular predictors)
350350 react_module = None
351351 for module_path , m in program .named_sub_modules ():
352- clean_path = module_path .removeprefix ("self." )
353- # For top-level ReAct (target_path=""), match "self" or empty string
354- if isinstance (m , ReAct ) and (clean_path == target_path or (target_path == "" and clean_path == "self" )):
352+ if not isinstance (m , ReAct ):
353+ continue
354+
355+ # Normalize path (same pattern as build_program)
356+ normalized_path = module_path .removeprefix ("self." ) if module_path != "self" else ""
357+ if normalized_path == target_path :
355358 react_module = m
356359 break
357360
@@ -392,7 +395,7 @@ def make_reflective_dataset(
392395 continue
393396
394397 # For ReAct modules, use LAST extract invocation (has trajectory + final outputs)
395- if pred_name .startswith ("react_module" ):
398+ if pred_name .startswith (REACT_MODULE_PREFIX ):
396399 selected = trace_instances [- 1 ]
397400 logger .debug (f" Using LAST extract call ({ len (trace_instances )} total) with trajectory + final outputs" )
398401 if "trajectory" in selected [1 ]:
@@ -485,7 +488,7 @@ def make_reflective_dataset(
485488 items .append (d )
486489
487490 # Log exact reflective example that reflection LM will see
488- if pred_name .startswith ("react_module" ) and len (items ) == 1 :
491+ if pred_name .startswith (REACT_MODULE_PREFIX ) and len (items ) == 1 :
489492 logger .info (f" First reflective example for { pred_name } :" )
490493 logger .info (f" Inputs: { list (d ['Inputs' ].keys ())} " )
491494 if "trajectory" in d ["Inputs" ]:
0 commit comments