Spaces:
Sleeping
Sleeping
Commit ·
c74d5fa
1
Parent(s): 4e9153c
phase 2 fix
Browse filesFiles changed (4)
- inference.py+6-4
- openenv.yaml+9-18
- server/environment.py+49-9
- server/grader.py+53
647 unmodified lines648649650651652653654106 unmodified lines761762763764765766767768769647 unmodified linesreset_data = reset_response.json()observation = reset_data.get("observation", {})task_name = observation.get("email_id", "email_workflow")email_subject = observation.get("subject", "")email_body = observation.get("body", "")customer_history = observation.get("customer_history", "")106 unmodified lines# Log steplog_step(step_num, action_str, reward, done, None)# Prepare final metrics# CRITICAL FIX: Use the environment's official cumulative reward instead of manual summationnormalized_score = step_data.get("info", {}).get("total_reward", sum(rewards))# Clamp just in case, though the environment already does thisnormalized_score = min(max(normalized_score, 0.0), 1.0)647 unmodified lines648649650651652653654655106 unmodified lines762763764765766767768769770771647 unmodified linesreset_data = reset_response.json()observation = reset_data.get("observation", {})info = reset_data.get("info", {})task_name = info.get("task_id", observation.get("email_id", "email_workflow"))email_subject = observation.get("subject", "")email_body = observation.get("body", "")customer_history = observation.get("customer_history", "")106 unmodified lines# Log steplog_step(step_num, action_str, reward, done, None)# PHASE 2 REQUIREMENT: Use the programmatic grader's score if available# Fallback to total_reward or manual sum for robust reportingfinal_info = step_data.get("info", {})normalized_score = final_info.get("score", final_info.get("total_reward", sum(rewards)))# Clamp just in case, though the environment already does thisnormalized_score = min(max(normalized_score, 0.0), 1.0)
156 unmodified lines157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191156 unmodified linesdescription: "Escalation bonus or penalty for appropriate decision"tasks:- id: email_001name: Easy Emaildifficulty: easydescription: >Clear billing issue. Straightforward double-charge complaintfrom good customer. Requires correct classification andappropriate urgency response.ground_truth:category: billingpriority: high- id: email_002name: Medium Emaildifficulty: mediumdescription: >Technical issue with app. Requires interpretation of problemand prioritization judgment. Customer history is important context.ground_truth:category: techpriority: medium- id: email_003name: Hard Emaildifficulty: harddescription: >Emotional complaint from enterprise customer. Requires nuancedunderstanding of tone, prior history, and business impact.Response must show empathy and urgency. Failure to prioritizeproperly could lead to business loss.ground_truth:category: complaintpriority: high156 unmodified lines157158159160161162163164165166167168169170171172173174175176177178179180181182156 unmodified linesdescription: "Escalation bonus or penalty for appropriate decision"tasks:- id: easy_refundname: Easy Refund Taskdifficulty: easydescription: Handle a straightforward billing refund request for a duplicate charge.ground_truth:category: billingpriority: high- id: medium_techname: Medium Tech Taskdifficulty: mediumdescription: Resolve a technical issue regarding app crashes and provide instructions.ground_truth:category: techpriority: medium- id: hard_escalationname: Hard Escalation Taskdifficulty: harddescription: Handle a high-value enterprise complaint that requires escalation or financial compensation.ground_truth:category: complaintpriority: high
17 unmodified lines181920212223242526293 unmodified lines32032132232332432532635 unmodified lines362363364365366367134 unmodified lines50250350450550650750850951051151251351451551651751851952017 unmodified linesfrom .grader import (calculate_step_reward, grade_workflow_completion,analyze_customer_sentiment, extract_urgency_indicators,check_escalation_requirement)def search_knowledge_base(query: str):if "refund" in query.lower():return {293 unmodified linesif not self.task_queue:self.task_queue = self._load_tasks()self.current_task = self._prepare_task_data(self.task_queue.pop(0))self.episode_count += 1# Initialize workflow state35 unmodified lines"episode_id": self.current_state.episode_id,"difficulty": self.current_task.get("difficulty", "unknown"),"email_id": self.current_task["id"],"workflow_step": 0,"max_steps": 5}134 unmodified linesreward_breakdown["escalation_bonus"] = escalation_bonusreward_breakdown.update(completion_breakdown)return {"observation": observation,"reward": step_reward,"done": done,"info": {"workflow_state": self.workflow_state.copy(),"total_reward": self.current_state.total_reward,"reward_breakdown": reward_breakdown,"step_count": self.current_state.step_count,"episode_complete": done}}def _is_episode_complete(self) -> bool:"""Check if the current episode is complete.17 unmodified lines18192021222324252627282930313233293 unmodified lines32732832933033133233333433533633733833934034134234334434535 unmodified lines381382383384385386387134 unmodified lines52252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956017 unmodified linesfrom .grader import (calculate_step_reward, grade_workflow_completion,analyze_customer_sentiment, extract_urgency_indicators,check_escalation_requirement, refund_grader, tech_grader, escalation_grader)# Mandatory Task definitions for OpenEnv validationTASKS = [{"task_id": "easy_refund", "email_id": "email_001", "difficulty": "easy"},{"task_id": "medium_tech", "email_id": "email_002", "difficulty": "medium"},{"task_id": "hard_escalation", "email_id": "email_003", "difficulty": "hard"},]def search_knowledge_base(query: str):if "refund" in query.lower():return {293 unmodified linesif not self.task_queue:self.task_queue = self._load_tasks()# Phase 2 Fix: Wrap selection in structured TASKS context# We cycle through the 3 mandatory tasks for consistent evaluationtask_idx = self.episode_count % len(TASKS)selected_task_metadata = TASKS[task_idx]task_id = selected_task_metadata["task_id"]# Find corresponding email data in current queue or database# For simplicity in this fix, we search task_queue for matching email_idemail_data = next((t for t in self.task_queue if t["id"] == selected_task_metadata["email_id"]), self.task_queue[0])self.current_task = self._prepare_task_data(email_data)self.current_task["task_id"] = task_id # Attach mandatory task_idself.episode_count += 1# Initialize workflow state35 unmodified lines"episode_id": self.current_state.episode_id,"difficulty": self.current_task.get("difficulty", "unknown"),"email_id": self.current_task["id"],"task_id": self.current_task.get("task_id"),"workflow_step": 0,"max_steps": 5}134 unmodified linesreward_breakdown["escalation_bonus"] = escalation_bonusreward_breakdown.update(completion_breakdown)info = {"workflow_state": self.workflow_state.copy(),"total_reward": self.current_state.total_reward,"reward_breakdown": reward_breakdown,"step_count": self.current_state.step_count,"episode_complete": done,"task_id": self.current_task.get("task_id")}# PHASE 2 REQUIREMENT: Return score only at endif done:info["score"] = self.compute_score()return {"observation": observation,"reward": step_reward,"done": done,"info": info}def compute_score(self) -> float:""" Programmatic score computation for OpenEnv validation. """task_id = self.current_task.get("task_id")if task_id == "easy_refund":return refund_grader(self.workflow_state)elif task_id == "medium_tech":return tech_grader(self.workflow_state)elif task_id == "hard_escalation":return escalation_grader(self.workflow_state)return 0.0def _is_episode_complete(self) -> bool:"""Check if the current episode is complete.
701 unmodified lines702703704701 unmodified linesbonus = 0.1 # Bonus for correct escalationreturn penalty, bonus701 unmodified lines702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757701 unmodified linesbonus = 0.1 # Bonus for correct escalationreturn penalty, bonusdef refund_grader(state: Dict[str, Any]) -> float:""" Programmatic grader for easy_refund task. """score = 0.0if state.get("classification") == "billing":score += 0.3if state.get("priority") == "high":score += 0.2if state.get("strategy") == "offer_refund":score += 0.3response = state.get("response")if response and "refund" in response.lower():score += 0.2return min(score, 1.0)def tech_grader(state: Dict[str, Any]) -> float:""" Programmatic grader for medium_tech task. """score = 0.0if state.get("classification") == "tech":score += 0.3if state.get("priority") in ["medium", "high"]:score += 0.2if state.get("strategy") in ["auto_resolve", "request_more_info"]:score += 0.3response = state.get("response")if response and len(response) > 20:score += 0.2return min(score, 1.0)def escalation_grader(state: Dict[str, Any]) -> float:""" Programmatic grader for hard_escalation task. """score = 0.0if state.get("classification") == "complaint":score += 0.2if state.get("priority") == "high":score += 0.2if state.get("strategy") in ["escalate_to_human", "offer_refund"]:score += 0.3# Check if escalation payload existsif state.get("escalation"):score += 0.3return min(score, 1.0)
inference.py+6-4
openenv.yaml+9-18
server/environment.py+49-9
server/grader.py+53