Adapter
adapter ¶
Protocol definitions for async adapters.
Note
This module defines the core protocol interface that connects gepa-adk's evolution engine to external evaluation systems.
EvaluationBatch dataclass ¶
Bases: Generic[Trajectory, RolloutOutput]
flowchart TD
gepa_adk.ports.adapter.EvaluationBatch[EvaluationBatch]
click gepa_adk.ports.adapter.EvaluationBatch href "" "gepa_adk.ports.adapter.EvaluationBatch"
Container for evaluation outputs and scores.
| ATTRIBUTE | DESCRIPTION |
|---|---|
outputs | Per-example outputs produced during evaluation. TYPE: |
scores | Per-example normalized scores (higher is better). TYPE: |
trajectories | Optional per-example execution traces. TYPE: |
objective_scores | Optional multi-objective scores per example. TYPE: |
metadata | Optional per-example scorer metadata. When provided, metadata[i] corresponds to outputs[i] and scores[i] (index-aligned). Metadata dicts may contain scorer-specific fields like 'feedback', 'actionable_guidance', or 'dimension_scores' from CriticScorer implementations. TYPE: |
inputs | Optional per-example input text that was used to generate each output. Used by make_reflective_dataset to provide context for reflection. When provided, inputs[i] corresponds to the input that produced outputs[i]. TYPE: |
Examples:
Create a batch with optional traces:
batch = EvaluationBatch(
outputs=["ok", "ok"],
scores=[0.9, 0.8],
trajectories=[{"trace": 1}, {"trace": 2}],
)
Create a batch with inputs for reflection:
batch = EvaluationBatch(
outputs=["Hello!", "Good morrow!"],
scores=[0.3, 0.9],
inputs=["I am the King", "I am your friend"],
)
Note
All fields are immutable once created due to frozen=True. Use this as the standard return type from adapter evaluations. When metadata is not None, len(metadata) must equal len(outputs) and len(scores).
Source code in src/gepa_adk/ports/adapter.py
AsyncGEPAAdapter ¶
Bases: Protocol[DataInst, Trajectory, RolloutOutput]
flowchart TD
gepa_adk.ports.adapter.AsyncGEPAAdapter[AsyncGEPAAdapter]
click gepa_adk.ports.adapter.AsyncGEPAAdapter href "" "gepa_adk.ports.adapter.AsyncGEPAAdapter"
Protocol for async GEPA adapters used by the evolution engine.
Implementations provide evaluation, reflection dataset generation, and proposal updates for candidate component texts.
Examples:
Implement a minimal adapter:
class MyAdapter:
async def evaluate(self, batch, candidate, capture_traces=False):
return EvaluationBatch(outputs=[], scores=[])
async def make_reflective_dataset(
self, candidate, eval_batch, components_to_update
):
return {component: [] for component in components_to_update}
async def propose_new_texts(
self, candidate, reflective_dataset, components_to_update
):
return {
component: candidate[component]
for component in components_to_update
}
Note
Adapters must implement all three async methods to satisfy the protocol. Use runtime_checkable for isinstance() checks.
Source code in src/gepa_adk/ports/adapter.py
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 | |
evaluate async ¶
evaluate(
batch: list[DataInst],
candidate: dict[str, str],
capture_traces: bool = False,
) -> EvaluationBatch[Trajectory, RolloutOutput]
Evaluate a candidate over a batch of inputs.
| PARAMETER | DESCRIPTION |
|---|---|
batch | Input data instances to evaluate. TYPE: |
candidate | Component name to text mapping. TYPE: |
capture_traces | Whether to capture execution traces. TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
EvaluationBatch[Trajectory, RolloutOutput] | Evaluation results with outputs, scores, and optional traces. |
Examples:
Basic evaluation:
Note
Output and score lists must have the same length as the input batch. Set capture_traces=True to enable reflection.
Source code in src/gepa_adk/ports/adapter.py
make_reflective_dataset async ¶
make_reflective_dataset(
candidate: dict[str, str],
eval_batch: EvaluationBatch[Trajectory, RolloutOutput],
components_to_update: list[str],
) -> Mapping[str, Sequence[Mapping[str, Any]]]
Build reflective datasets from evaluation traces.
| PARAMETER | DESCRIPTION |
|---|---|
candidate | Current candidate components. TYPE: |
eval_batch | Evaluation results with traces. TYPE: |
components_to_update | Components to generate datasets for. TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
Mapping[str, Sequence[Mapping[str, Any]]] | Mapping of component name to reflective examples. |
Examples:
Build datasets for specific components:
Note
Only call this method when eval_batch contains trajectories. Each component receives its own list of reflective examples.
Source code in src/gepa_adk/ports/adapter.py
propose_new_texts async ¶
propose_new_texts(
candidate: dict[str, str],
reflective_dataset: Mapping[
str, Sequence[Mapping[str, Any]]
],
components_to_update: list[str],
) -> dict[str, str]
Propose updated component texts from reflective datasets.
| PARAMETER | DESCRIPTION |
|---|---|
candidate | Current candidate components. TYPE: |
reflective_dataset | Reflective examples per component. TYPE: |
components_to_update | Components to propose updates for. TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
dict[str, str] | Mapping of component name to new proposed text. |
Examples:
Generate new component texts:
Note
Outputs should contain improved text for each requested component. The evolution engine uses these as mutation candidates.