Download testing/agent_evaluation/evolution.py from yuhanqin/ut-evaluation: direct link, hf CLI and curl.
- Browser
- Download file 2.45 kB
-
https://huggingface.co/datasets/yuhanqin/ut-evaluation/resolve/main/testing/agent_evaluation/evolution.py
- Command line
-
hf download hf://datasets/yuhanqin/ut-evaluation/testing/agent_evaluation/evolution.py
-
curl -L -o evolution.py https://huggingface.co/datasets/yuhanqin/ut-evaluation/resolve/main/testing/agent_evaluation/evolution.py
2.45 kB
| """Feedback normalization and a deliberately conservative candidate generator.""" | |
| from __future__ import annotations | |
| import uuid | |
| from dataclasses import dataclass | |
| from typing import Any | |
| from .ports import LLMCompletionBackend | |
| from .models import FeedbackRecord, ScoreRecord, SkillBundle, stable_hash | |
| def normalize_feedback(scores: list[ScoreRecord]) -> list[FeedbackRecord]: | |
| feedback = [] | |
| for score in scores: | |
| if score.result_kind != "assessment": | |
| continue | |
| if score.status != "success" or score.score is None or score.score >= 1: | |
| continue | |
| feedback.append(FeedbackRecord( | |
| feedback_id=f"feedback-{uuid.uuid4().hex[:12]}", | |
| run_id=score.run_id, | |
| case_id=score.case_id, | |
| evaluator_id=score.evaluator_id, | |
| failure_type=score.evaluator_id, | |
| root_cause="unknown", | |
| explanation=score.explanation, | |
| evidence_refs=score.evidence_refs, | |
| suggested_change=None, | |
| )) | |
| return feedback | |
| class CandidateSkill: | |
| candidate_id: str | |
| base_skill_hash: str | |
| content: str | |
| feedback_ids: list[str] | |
| status: str = "draft_unreviewed" | |
| def to_dict(self) -> dict[str, Any]: | |
| return { | |
| "candidate_id": self.candidate_id, | |
| "base_skill_hash": self.base_skill_hash, | |
| "candidate_hash": stable_hash(self.content.encode()), | |
| "content": self.content, | |
| "feedback_ids": self.feedback_ids, | |
| "status": self.status, | |
| } | |
| def propose_candidate(skill: SkillBundle, feedback: list[FeedbackRecord], backend: LLMCompletionBackend | None = None) -> CandidateSkill | None: | |
| if not feedback: | |
| return None | |
| if backend is not None: | |
| result = backend.complete( | |
| f"Base skill:\n{skill.content}\nFeedback:\n" + "\n".join(item.explanation for item in feedback), | |
| output_schema={"type": "object", "required": ["content"], "properties": {"content": {"type": "string"}}}, | |
| ) | |
| content = str(result["content"]) | |
| else: | |
| content = skill.content.rstrip() + "\n\n## Evaluation clarifications\n- Complete every required workflow step before reporting success.\n- Preserve fixture and validation evidence for audit.\n" | |
| return CandidateSkill(f"candidate-{uuid.uuid4().hex[:12]}", skill.bundle_hash, content, [item.feedback_id for item in feedback]) | |