AgentEvalTool/backend/agenteval/evaluation/implicit_rules.py
sinohqb ffc058f951 refactor(engine): thin _run_case and _save_rule_results
Three near-identical Turn(...)+save_turn blocks (send-fail / poll-except /
happy path) collapse into one _persist_turn helper differing only by the
optional fields set. The期望→隐式规则 translation becomes a pure,
unit-testable derive_implicit_rules seam (CONTEXT: 期望与规则叠加生效),
and the rule_type→ModelPurpose map is hoisted to a module constant.
2026-07-31 14:59:50 +08:00

31 lines
1.1 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"""Translate a case's期望 (Expectation) into implicit评估规则.
期望描述"想要什么",评估规则是"怎么判定"——期望派生的隐式规则与显式规则
叠加生效CONTEXT.md。此翻译是纯逻辑独立于规则执行与持久化便于单测。
"""
from agenteval.models import EvalRuleConfig, Expectation
def derive_implicit_rules(expectation: Expectation) -> list[EvalRuleConfig]:
"""Build the implicit rule configs a case's expectation implies."""
rules: list[EvalRuleConfig] = []
if expectation.response_time_max_ms:
rules.append(
EvalRuleConfig(
type="response_time",
params={"max_ms": expectation.response_time_max_ms},
)
)
if expectation.keywords_include or expectation.keywords_exclude:
rules.append(
EvalRuleConfig(
type="keyword_match",
params={
"keywords": expectation.keywords_include,
"exclude_keywords": expectation.keywords_exclude,
},
)
)
return rules