Represents a single evolution trace entry
| 23 | |
| 24 | @dataclass |
| 25 | class EvolutionTrace: |
| 26 | """Represents a single evolution trace entry""" |
| 27 | |
| 28 | iteration: int |
| 29 | timestamp: float |
| 30 | parent_id: str |
| 31 | child_id: str |
| 32 | parent_metrics: Dict[str, Any] |
| 33 | child_metrics: Dict[str, Any] |
| 34 | parent_code: Optional[str] = None |
| 35 | child_code: Optional[str] = None |
| 36 | parent_changes_description: Optional[str] = None |
| 37 | child_changes_description: Optional[str] = None |
| 38 | code_diff: Optional[str] = None |
| 39 | prompt: Optional[Dict[str, str]] = None |
| 40 | llm_response: Optional[str] = None |
| 41 | improvement_delta: Optional[Dict[str, float]] = None |
| 42 | island_id: Optional[int] = None |
| 43 | generation: Optional[int] = None |
| 44 | artifacts: Optional[Dict[str, Any]] = None |
| 45 | metadata: Optional[Dict[str, Any]] = None |
| 46 | |
| 47 | def to_dict(self) -> Dict[str, Any]: |
| 48 | """Convert trace to dictionary format""" |
| 49 | return {k: v for k, v in asdict(self).items() if v is not None} |
| 50 | |
| 51 | def calculate_improvement(self) -> Dict[str, float]: |
| 52 | """Calculate improvement deltas between parent and child metrics""" |
| 53 | improvement = {} |
| 54 | for key in self.child_metrics: |
| 55 | if key in self.parent_metrics: |
| 56 | parent_val = self.parent_metrics[key] |
| 57 | child_val = self.child_metrics[key] |
| 58 | if isinstance(parent_val, (int, float)) and isinstance(child_val, (int, float)): |
| 59 | improvement[key] = child_val - parent_val |
| 60 | return improvement |
| 61 | |
| 62 | |
| 63 | class EvolutionTracer: |
no outgoing calls