Evolution result
evolution_result ¶
Protocol definition for evolution result types.
Defines a shared protocol that both EvolutionResult and MultiAgentEvolutionResult satisfy structurally, enabling engine and utility code to accept either result type without type unions.
This is the project's first data-attribute protocol. Existing protocols in ports/ are method-only. Data annotations were chosen here because the shared surface consists of frozen dataclass fields — data annotations match the structural reality exactly.
| ATTRIBUTE | DESCRIPTION |
|---|---|
EvolutionResultProtocol | Protocol for evolution result types that both single-agent and multi-agent results satisfy. TYPE: |
Examples:
Type-annotate a function that accepts any result type:
from gepa_adk.ports import EvolutionResultProtocol
def summarize(result: EvolutionResultProtocol) -> str:
pct = result.improvement * 100
return f"Improved by {pct:.1f}% over {result.total_iterations} iterations"
Verify protocol compliance at runtime:
from gepa_adk.domain.models import EvolutionResult
from gepa_adk.ports import EvolutionResultProtocol
result = EvolutionResult(
original_score=0.5,
final_score=0.8,
evolved_components={"instruction": "Be helpful"},
iteration_history=[],
total_iterations=5,
)
assert isinstance(result, EvolutionResultProtocol)
assert result.schema_version == 1
See Also
gepa_adk.domain.models.EvolutionResult: Single-agent evolution result (frozen dataclass).gepa_adk.domain.models.MultiAgentEvolutionResult: Multi-agent evolution result (frozen dataclass).gepa_adk.ports.adapter: Adapter protocol that produces evolution results.
Note
The protocol deliberately excludes mode-specific fields (valset_score, primary_agent). Consumers needing those fields should use the concrete result types directly.
EvolutionResultProtocol ¶
Bases: Protocol
flowchart TD
gepa_adk.ports.evolution_result.EvolutionResultProtocol[EvolutionResultProtocol]
click gepa_adk.ports.evolution_result.EvolutionResultProtocol href "" "gepa_adk.ports.evolution_result.EvolutionResultProtocol"
Protocol for evolution result types.
Both EvolutionResult and MultiAgentEvolutionResult satisfy this protocol structurally. Consumers that need the common shape program against this protocol; consumers that need mode-specific data (valset_score, primary_agent) use the concrete type.
| ATTRIBUTE | DESCRIPTION |
|---|---|
schema_version | Schema version for forward-compatible serialization. TYPE: |
stop_reason | Why the evolution run terminated. TYPE: |
original_score | Starting performance score (baseline). TYPE: |
final_score | Ending performance score (best achieved). TYPE: |
evolved_components | Maps component names to their final evolved text values. TYPE: |
iteration_history | Chronological list of iteration records. TYPE: |
total_iterations | Number of iterations performed. TYPE: |
Examples:
Accept any evolution result type:
from gepa_adk.ports import EvolutionResultProtocol
def log_result(result: EvolutionResultProtocol) -> None:
print(f"Score: {result.original_score} -> {result.final_score}")
print(f"Improved: {result.improved} ({result.improvement:+.2f})")
Runtime isinstance check:
from gepa_adk.domain.models import MultiAgentEvolutionResult
from gepa_adk.ports import EvolutionResultProtocol
result = MultiAgentEvolutionResult(
evolved_components={"agent.instruction": "Be precise"},
original_score=0.4,
final_score=0.7,
primary_agent="agent",
iteration_history=[],
total_iterations=8,
)
assert isinstance(result, EvolutionResultProtocol)
assert result.schema_version == 1