Rohit-2002's picture
Update env/grader.py
2e0086b verified
Raw
History Blame Contribute Delete
1.15 kB
from .policy import check_policy
def grade(action, task, steps):
score = 0.0
# 🎯 Category
if action.category == task["expected_category"]:
score += 0.3
else:
score -= 0.3
# 🎯 Action
if action.action_type == task["expected_action"]:
score += 0.3
else:
score += 0.05
# 🎯 Response QUALITY (VERY STRICT)
if action.response_text:
text = action.response_text.lower()
if len(text) > 20:
score += 0.2
else:
score -= 0.2 # ❗ penalize short response
if "sorry" in text:
score += 0.1
# domain signals
if task["expected_category"] == "billing" and "refund" in text:
score += 0.1
if task["expected_category"] == "security" and "secure" in text:
score += 0.1
else:
score -= 0.3
# 🎯 Efficiency
if steps <= 2:
score += 0.1
else:
score -= 0.2
# 🎯 Policy penalty
violations = check_policy(action, action.category or "")
score -= 0.3 * len(violations)
return max(0.0, min(1.0, score)), str(violations)