Component selector
component_selector ¶
Protocol definition for component selection strategies.
| ATTRIBUTE | DESCRIPTION |
|---|---|
ComponentSelectorProtocol | Async protocol for component selection strategies.
|
Examples:
Implement a round-robin component selector:
from gepa_adk.ports.component_selector import ComponentSelectorProtocol
class RoundRobinSelector:
async def select_components(
self, components: list[str], iteration: int, candidate_idx: int
) -> list[str]:
idx = iteration % len(components)
return [components[idx]]
selector = RoundRobinSelector()
assert isinstance(selector, ComponentSelectorProtocol)
See Also
gepa_adk.adapters.selection: Built-in component selection strategy implementations.
ComponentSelectorProtocol ¶
Bases: Protocol
flowchart TD
gepa_adk.ports.component_selector.ComponentSelectorProtocol[ComponentSelectorProtocol]
click gepa_adk.ports.component_selector.ComponentSelectorProtocol href "" "gepa_adk.ports.component_selector.ComponentSelectorProtocol"
Async protocol for component selection strategies.
Note
Adapters implementing this protocol determine which candidate components to update during mutation, enabling flexible evolution strategies.
Examples:
class MySelector:
async def select_components(
self, components: list[str], iteration: int, candidate_idx: int
) -> list[str]:
return components[:1]
Source code in src/gepa_adk/ports/component_selector.py
select_components async ¶
Select components to update for the current iteration.
| PARAMETER | DESCRIPTION |
|---|---|
components | List of available component keys (e.g. ["instruction", "input_schema"]). TYPE: |
iteration | Current global iteration number (0-based). TYPE: |
candidate_idx | Index of the candidate being evolved. TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
list[str] | List of component keys to update. |
| RAISES | DESCRIPTION |
|---|---|
ValueError | If components list is empty. |
Note
Outputs a list of component keys to update, enabling selective mutation of specific candidate components.
Examples:
selected = await selector.select_components(
components=["instruction", "schema"], iteration=1, candidate_idx=0
)