Darshan03 commited on
Commit
06a80a2
·
1 Parent(s): 83dd0f8

revert: restore original rewards and env logic, keep grader normalization in inference only

Browse files
Files changed (2) hide show
  1. server/my_environment.py +6 -10
  2. training/rewards.py +12 -19
server/my_environment.py CHANGED
@@ -269,14 +269,12 @@ class SupportEnvironment(Environment):
269
  feedback = f"Syntax Error: {error_msg}"
270
  reward -= 4.0
271
  elif func_name == "respond":
272
- # Agent has provided a final response to the customer
273
  feedback = "Task concluded by Agent response."
274
  self._tools_used.add("respond")
275
- self._done = True
276
- # Gate bonuses by grader_score: no bonus if agent skipped required tools
277
- grader = self._calculate_grader_score()
278
  reward += self._scenario.get("intent_rewards", {}).get("respond", 0)
279
- reward += 10.0 * grader # Resolution bonus scaled by tool coverage
 
280
  elif func_name in ACTION_REGISTRY:
281
  # Execute standard backend tool logic
282
  try:
@@ -289,8 +287,7 @@ class SupportEnvironment(Environment):
289
  self._tools_used.add(func_name)
290
  if func_name == "escalate_to_human":
291
  self._done = True
292
- grader = self._calculate_grader_score()
293
- reward += 10.0 * grader
294
  feedback += " Task Escalated."
295
  except Exception as e:
296
  # Handle backend execution failures
@@ -306,10 +303,9 @@ class SupportEnvironment(Environment):
306
  if self._step_count >= self.max_turns:
307
  self._done = True
308
 
309
- # Efficiency bonus (also gated by grader_score)
310
  if self._done and self._step_count <= self._scenario.get("optimal_steps", 99):
311
- grader = self._calculate_grader_score()
312
- reward += 3.0 * grader
313
 
314
  info = {}
315
  if self._done:
 
269
  feedback = f"Syntax Error: {error_msg}"
270
  reward -= 4.0
271
  elif func_name == "respond":
272
+ # Success resolution: Agent has provided a final response to the customer
273
  feedback = "Task concluded by Agent response."
274
  self._tools_used.add("respond")
 
 
 
275
  reward += self._scenario.get("intent_rewards", {}).get("respond", 0)
276
+ self._done = True
277
+ reward += 10.0 # Major success bonus
278
  elif func_name in ACTION_REGISTRY:
279
  # Execute standard backend tool logic
280
  try:
 
287
  self._tools_used.add(func_name)
288
  if func_name == "escalate_to_human":
289
  self._done = True
290
+ reward += 10.0
 
291
  feedback += " Task Escalated."
292
  except Exception as e:
293
  # Handle backend execution failures
 
303
  if self._step_count >= self.max_turns:
304
  self._done = True
305
 
306
+ # Efficiency bonus
307
  if self._done and self._step_count <= self._scenario.get("optimal_steps", 99):
308
+ reward += 3.0
 
309
 
310
  info = {}
311
  if self._done:
training/rewards.py CHANGED
@@ -192,29 +192,22 @@ def total_reward(environments, **kwargs):
192
 
193
  r = []
194
  for i in range(len(environments)):
195
- grader = float(enriched["grader_score"][i]) # [0.0, 1.0] from env
196
-
197
- # --- Core signal: grader-based task success (dominates) ---
198
- # If grader is 0.0 (no correct tools used), this drives total strongly negative.
199
- # If grader is 1.0 (perfect tool coverage), this gives +3.0.
200
- task_signal = (grader * 5.0) - 2.0 # range: [-2.0, +3.0]
201
-
202
- # --- Auxiliary signals (small shaping, never override task_signal) ---
203
- aux = (
204
- r3[i] * 0.1 + # format compliance
205
- r4[i] * 0.1 + # conciseness
206
- r5[i] * 0.3 + # repetition penalty (important for loops)
207
- r6[i] * 0.2 + # step efficiency
208
- r7[i] * 0.5 + # invalid action penalty (strong)
209
- r8[i] * 0.3 + # completion/politeness
210
- r9[i] * 0.5 # action alignment (strong)
211
  )
212
 
213
- total = task_signal + aux
214
-
215
- # PPO-safe clipping
216
  total = max(-5.0, min(5.0, total))
217
  r.append(total)
218
 
219
  return r
220
 
 
 
192
 
193
  r = []
194
  for i in range(len(environments)):
195
+ total = (
196
+ r1[i] * 2.0 + # Success is paramount
197
+ r2[i] * 1.0 +
198
+ r3[i] * 0.5 +
199
+ r4[i] * 0.5 +
200
+ r5[i] * 0.7 +
201
+ r6[i] * 0.8 +
202
+ r7[i] * 1.5 +
203
+ r8[i] * 1.0 +
204
+ r9[i] * 1.2 # Action alignment weight
 
 
 
 
 
 
205
  )
206
 
207
+ # PPO-safe clipping to prevent reward scale drift
 
 
208
  total = max(-5.0, min(5.0, total))
209
  r.append(total)
210
 
211
  return r
212
 
213
+