Component selector
component_selector ¶
Adapter implementations for component selection strategies.
This module provides concrete implementations of the ComponentSelectorProtocol, allowing different strategies for selecting which components of a candidate to update during evolution.
| ATTRIBUTE | DESCRIPTION |
|---|---|
RoundRobinComponentSelector | Cycles through components sequentially. Defined in TYPE: |
AllComponentSelector | Selects all components every time. TYPE: |
create_component_selector | Create a component selector strategy from a string alias. TYPE: |
Examples:
Creating a selector via factory:
from gepa_adk.adapters.selection.component_selector import create_component_selector
selector = create_component_selector("round_robin")
Using a selector directly:
from gepa_adk.adapters.selection.component_selector import AllComponentSelector
selector = AllComponentSelector()
components = await selector.select_components(["a", "b"], 1, 0)
See Also
ComponentSelectorProtocol: Port protocol these adapters implement.
Notes
RoundRobinComponentSelector is the engine's default, so it lives beside its protocol in gepa_adk.ports.defaults, where both the engine and the adapters may import it under ADR-000; this module re-exports it so its import path and isinstance checks keep working.
These adapters implement component selection strategies that may maintain internal state for cycling (like RoundRobin) while remaining stateless with respect to the engine.
RoundRobinComponentSelector ¶
Selects components in a round-robin fashion.
This selector cycles through the list of components one by one, maintaining state per candidate index to ensure consistent rotation.
| ATTRIBUTE | DESCRIPTION |
|---|---|
_next_index | Mapping of candidate_idx to next component index. TYPE: |
Examples:
selector = RoundRobinComponentSelector()
# First call selects first component
c1 = await selector.select_components(["a", "b"], 1, 0) # ["a"]
# Second call selects second component
c2 = await selector.select_components(["a", "b"], 2, 0) # ["b"]
Notes
Alternates through components sequentially, ensuring balanced evolution across all candidate parts.
Source code in src/gepa_adk/ports/defaults.py
__init__ ¶
Initialize the round-robin selector.
Notes
Creates empty index tracking dictionary for per-candidate rotation state.
select_components async ¶
Select a single component to update using round-robin logic.
| PARAMETER | DESCRIPTION |
|---|---|
components | List of available component keys. TYPE: |
iteration | Current global iteration number (unused by this strategy). TYPE: |
candidate_idx | Index of the candidate being evolved. TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
list[str] | List containing the single selected component key. |
| RAISES | DESCRIPTION |
|---|---|
ValueError | If components list is empty. |
Examples:
Notes
Outputs one component per call, advancing the rotation index for the specified candidate.
Source code in src/gepa_adk/ports/defaults.py
AllComponentSelector ¶
Selects all available components for simultaneous update.
This selector returns the full list of components every time, enabling simultaneous evolution of all parts of the candidate.
Examples:
selector = AllComponentSelector()
all_comps = await selector.select_components(["a", "b"], 1, 0)
# Returns ["a", "b"]
Notes
Always returns all components, enabling comprehensive mutations across the entire candidate in a single iteration.
Source code in src/gepa_adk/adapters/selection/component_selector.py
select_components async ¶
Select all components to update.
| PARAMETER | DESCRIPTION |
|---|---|
components | List of available component keys. TYPE: |
iteration | Current global iteration number (unused). TYPE: |
candidate_idx | Index of the candidate being evolved (unused). TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
list[str] | List containing all component keys. |
| RAISES | DESCRIPTION |
|---|---|
ValueError | If components list is empty. |
Examples:
Notes
Outputs the complete component list unchanged, enabling simultaneous evolution of all candidate parts.
Source code in src/gepa_adk/adapters/selection/component_selector.py
create_component_selector ¶
create_component_selector(
selector_type: str,
) -> ComponentSelectorProtocol
Create a component selector strategy from a string alias.
| PARAMETER | DESCRIPTION |
|---|---|
selector_type | Name of the selector strategy. Supported values: - 'round_robin', 'roundrobin': Round-robin cycling. - 'all', 'all_components': All components simultaneously. TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
ComponentSelectorProtocol | Instance of requested component selector. |
| RAISES | DESCRIPTION |
|---|---|
ValueError | If selector_type is unknown. |
Examples:
# Create round-robin selector
selector = create_component_selector("round_robin")
# Create all-components selector
selector = create_component_selector("all")
Notes
Supports flexible string aliases with normalization for common variations (underscores, hyphens, case-insensitive).