Models
models ¶
Domain models for the gepa-adk evolution engine.
This module contains the core domain models used throughout the evolution engine. All models are dataclasses following hexagonal architecture principles with no external dependencies.
Terminology
- component: An evolvable unit with a name and text (e.g., instruction)
- component_text: The current text content of a component being evolved
- trial: One performance record {feedback, trajectory}
- feedback: Critic evaluation {score, feedback_text, feedback_*} (stochastic)
- trajectory: Execution record {input, output, trace} (deterministic)
| ATTRIBUTE | DESCRIPTION |
|---|---|
EvolutionConfig | Configuration parameters for evolution runs. TYPE: |
IterationRecord | Immutable record of a single iteration. TYPE: |
EvolutionResult | Immutable outcome of a completed evolution run. TYPE: |
Candidate | Mutable candidate holding components being evolved. TYPE: |
Note
These models are pure data containers with validation logic. They have no knowledge of infrastructure concerns like databases or APIs.
VideoFileInfo dataclass ¶
Metadata for a validated video file.
This is an immutable record containing validated metadata about a video file. Created by VideoBlobService.validate_video_file() after checking that the file exists, is within size limits, and has a valid MIME type.
| ATTRIBUTE | DESCRIPTION |
|---|---|
path | Absolute path to the video file. TYPE: |
size_bytes | File size in bytes. TYPE: |
mime_type | MIME type of the video (e.g., "video/mp4"). TYPE: |
Examples:
Creating video file info:
from gepa_adk.domain.models import VideoFileInfo
info = VideoFileInfo(
path="/data/video.mp4",
size_bytes=1024000,
mime_type="video/mp4",
)
print(f"File: {info.path}, Size: {info.size_bytes}, Type: {info.mime_type}")
Note
A frozen dataclass ensuring immutability after validation. Instances cannot be modified once created, guaranteeing consistency of validated file metadata.
Source code in src/gepa_adk/domain/models.py
EvolutionConfig dataclass ¶
Configuration parameters for an evolution run.
Defines the parameters that control how evolution proceeds, including iteration limits, concurrency settings, and stopping criteria.
| ATTRIBUTE | DESCRIPTION |
|---|---|
max_iterations | Maximum number of evolution iterations. 0 means just evaluate baseline without evolving. TYPE: |
max_concurrent_evals | Number of concurrent batch evaluations. Must be at least 1. TYPE: |
min_improvement_threshold | Minimum score improvement to accept a new candidate. Set to 0.0 to accept any improvement. TYPE: |
patience | Number of iterations without improvement before stopping early. Set to 0 to disable early stopping. TYPE: |
reflection_model | Model identifier for reflection/mutation operations. TYPE: |
frontier_type | Frontier tracking strategy for Pareto selection (default: INSTANCE). TYPE: |
acceptance_metric | Aggregation method for acceptance decisions on iteration evaluation batches. "sum" uses sum of scores (default, aligns with upstream GEPA). "mean" uses mean of scores (legacy behavior). TYPE: |
use_merge | Enable merge proposals for genetic crossover. Defaults to False. TYPE: |
max_merge_invocations | Maximum number of merge attempts per run. Defaults to 10. Must be non-negative. TYPE: |
reflection_prompt | Custom reflection/mutation prompt template. If provided, this template is used instead of the default when the reflection model proposes improved text. Required placeholders: - {component_text}: The current component text being evolved - {trials}: Trial data with feedback and trajectory for each test case If None or empty string, the default prompt template is used. TYPE: |
stop_callbacks | List of stopper callbacks for custom stop conditions. Each callback receives a StopperState and returns True to signal stop. Defaults to an empty list. TYPE: |
Examples:
Creating a configuration with defaults:
from gepa_adk.domain.models import EvolutionConfig
config = EvolutionConfig(max_iterations=100, patience=10)
print(config.max_iterations) # 100
print(config.reflection_model) # ollama_chat/gpt-oss:20b
Note
All numeric parameters are validated in post_init to ensure they meet their constraints. Invalid values raise ConfigurationError.
Source code in src/gepa_adk/domain/models.py
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 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 | |
__post_init__ ¶
Validate configuration parameters after initialization.
| RAISES | DESCRIPTION |
|---|---|
ConfigurationError | If any parameter violates its constraints. |
Note
Operates automatically after dataclass init completes. Validates all fields and raises ConfigurationError with context on failure.
Source code in src/gepa_adk/domain/models.py
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 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 | |
IterationRecord dataclass ¶
Captures metrics for a single evolution iteration.
This is an immutable record of what happened during one iteration of the evolution process. Records are created by the engine and stored in EvolutionResult.iteration_history.
| ATTRIBUTE | DESCRIPTION |
|---|---|
iteration_number | 1-indexed iteration number for human readability. TYPE: |
score | Score achieved in this iteration (typically in [0.0, 1.0]). TYPE: |
component_text | The component_text that was evaluated in this iteration (e.g., the instruction text for the "instruction" component). TYPE: |
evolved_component | The name of the component that was evolved in this iteration (e.g., "instruction", "output_schema"). Used for tracking which component changed in round-robin evolution strategies. TYPE: |
accepted | Whether this proposal was accepted as the new best. TYPE: |
objective_scores | Optional per-example multi-objective scores from the valset evaluation. None when adapter does not provide objective scores. Each dict maps objective name to score value. Index-aligned with evaluation batch examples. TYPE: |
Examples:
Creating an iteration record:
from gepa_adk.domain.models import IterationRecord
record = IterationRecord(
iteration_number=1,
score=0.85,
component_text="Be helpful",
evolved_component="instruction",
accepted=True,
)
print(record.score) # 0.85
print(record.evolved_component) # "instruction"
print(record.accepted) # True
Note
An immutable record that captures iteration metrics. Once created, IterationRecord instances cannot be modified, ensuring historical accuracy of the evolution trace.
Source code in src/gepa_adk/domain/models.py
EvolutionResult dataclass ¶
Outcome of a completed evolution run.
Contains the final results after evolution completes, including all evolved component values, performance metrics, and full history.
| ATTRIBUTE | DESCRIPTION |
|---|---|
original_score | Starting performance score (baseline). TYPE: |
final_score | Ending performance score (best achieved). TYPE: |
evolved_components | Dictionary mapping component names to their final evolved text values. Keys include "instruction" and optionally "output_schema" or other components. Access individual components via TYPE: |
iteration_history | Chronological list of iteration records. TYPE: |
total_iterations | Number of iterations performed. TYPE: |
valset_score | Score on validation set used for acceptance decisions. None if no validation set was used. TYPE: |
trainset_score | Score on trainset used for reflection diagnostics. None if not computed. TYPE: |
objective_scores | Optional per-example multi-objective scores from the best candidate's final evaluation. None when no objective scores were tracked. Each dict maps objective name to score value. Index-aligned with evaluation batch examples. TYPE: |
Examples:
Creating and analyzing a result:
from gepa_adk.domain.models import EvolutionResult, IterationRecord
result = EvolutionResult(
original_score=0.60,
final_score=0.85,
evolved_components={"instruction": "Be helpful and concise"},
iteration_history=[],
total_iterations=10,
)
print(result.evolved_components["instruction"]) # "Be helpful and concise"
print(result.improvement) # 0.25
print(result.improved) # True
Note
As a frozen dataclass, EvolutionResult instances cannot be modified.
Source code in src/gepa_adk/domain/models.py
319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 | |
improvement property ¶
Calculate the score improvement from original to final.
| RETURNS | DESCRIPTION |
|---|---|
float | The difference between final_score and original_score. |
float | Positive values indicate improvement, negative indicates degradation. |
Note
Override is not needed since frozen dataclasses support properties.
improved property ¶
Check if the final score is better than the original.
| RETURNS | DESCRIPTION |
|---|---|
bool | True if final_score > original_score, False otherwise. |
Note
Only returns True for strict improvement, not equal scores.
Candidate dataclass ¶
Represents an instruction candidate being evolved.
Unlike GEPA's simple dict[str, str] type alias, this class provides richer state tracking for async scenarios including lineage and metadata.
| ATTRIBUTE | DESCRIPTION |
|---|---|
components | Component name to text value mapping. Common keys include 'instruction' (main agent prompt) and 'output_schema'. TYPE: |
generation | Generation number in the evolution lineage (0 = initial). TYPE: |
parent_id | ID of the parent candidate for lineage tracking (legacy field, retained for compatibility). TYPE: |
parent_ids | Multi-parent indices for merge operations. None for seed candidates, [single_idx] for mutations, [idx1, idx2] for merges. TYPE: |
metadata | Extensible metadata dict for async tracking and debugging. TYPE: |
Examples:
Creating a candidate:
from gepa_adk.domain.models import Candidate
candidate = Candidate(
components={"instruction": "Be helpful"},
generation=0,
)
print(candidate.components["instruction"]) # Be helpful
print(candidate.generation) # 0
Note
A mutable candidate representation with richer state tracking than GEPA's simple dict. Components and metadata can be modified during the evolution process. Use generation and parent_id to track lineage.
Source code in src/gepa_adk/domain/models.py
MultiAgentEvolutionResult dataclass ¶
Outcome of a completed multi-agent evolution run.
Contains evolved component_text for all agents in the group, along with performance metrics and evolution history.
| ATTRIBUTE | DESCRIPTION |
|---|---|
evolved_components | Mapping of agent name to evolved component_text. TYPE: |
original_score | Starting performance score (baseline). TYPE: |
final_score | Ending performance score (best achieved). TYPE: |
primary_agent | Name of the agent whose output was used for scoring. TYPE: |
iteration_history | Chronological list of iteration records. TYPE: |
total_iterations | Number of iterations performed. TYPE: |
Examples:
Creating and analyzing a multi-agent result:
from gepa_adk.domain.models import MultiAgentEvolutionResult, IterationRecord
result = MultiAgentEvolutionResult(
evolved_components={
"generator": "Generate high-quality code",
"critic": "Review code thoroughly",
},
original_score=0.60,
final_score=0.85,
primary_agent="generator",
iteration_history=[],
total_iterations=10,
)
print(result.improvement) # 0.25
print(result.improved) # True
print(result.agent_names) # ["critic", "generator"]
Note
An immutable result container for multi-agent evolution. Once created, MultiAgentEvolutionResult instances cannot be modified. Use computed properties like improvement, improved, and agent_names to analyze results without modifying the underlying data.
Source code in src/gepa_adk/domain/models.py
449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 | |
improvement property ¶
Calculate the score improvement from original to final.
| RETURNS | DESCRIPTION |
|---|---|
float | The difference between final_score and original_score. |
float | Positive values indicate improvement, negative indicates degradation. |
Note
Override is not needed since frozen dataclasses support properties.
improved property ¶
Check if the final score is better than the original.
| RETURNS | DESCRIPTION |
|---|---|
bool | True if final_score > original_score, False otherwise. |
Note
Only returns True for strict improvement, not equal scores.
agent_names property ¶
Get sorted list of evolved agent names.
| RETURNS | DESCRIPTION |
|---|---|
list[str] | Sorted list of agent names from evolved_components keys. |
Note
Outputs a new list each time, sorted alphabetically for consistent ordering regardless of insertion order.