prthm11 commited on
Commit
ea129ab
·
verified ·
1 Parent(s): 659f1ea

Update escalation_server.py

Browse files
Files changed (1) hide show
  1. escalation_server.py +12 -6
escalation_server.py CHANGED
@@ -99,7 +99,8 @@ async def explain_from_resource(concept: str, ctx: Context = CurrentContext()):
99
  and triggers teacher escalation after 3 failed attempts.
100
  """
101
  # FIX 1: Remove 'await' from ctx.get_state (it is synchronous)
102
- attempts = ctx.get_state("math_attempts") or 0
 
103
 
104
  # 1. CIRCUIT BREAKER: Enforce the 3-attempt limit
105
  if attempts >= 3:
@@ -114,7 +115,8 @@ async def explain_from_resource(concept: str, ctx: Context = CurrentContext()):
114
  )
115
 
116
  # FIX 2: Remove 'await' from ctx.set_state
117
- ctx.set_state("math_attempts", attempts + 1)
 
118
 
119
  # 2. FETCH RESOURCE
120
  material = read_resource_file()
@@ -134,14 +136,16 @@ async def generate_quick_revision(type: str = "summary", ctx: Context = CurrentC
134
  Types: 'summary' (3 key points) or 'short_notes' (condensed formulas and definitions).
135
  """
136
  # ENFORCE ATTEMPT TRACKING
137
- attempts = ctx.get_state("math_attempts") or 0
 
138
 
139
  if attempts >= 3:
140
  await ctx.disable_components(tools=["explain_from_resource", "generate_quick_revision"])
141
  return "FATAL_ERROR: TUTORING_LIMIT_REACHED. Transition to escalation immediately."
142
 
143
- ctx.set_state("math_attempts", attempts + 1)
144
-
 
145
  material = read_resource_file()
146
  return f"""
147
  <attempt>{attempts + 1}/3</attempt>
@@ -235,7 +239,9 @@ async def escalate_to_teacher(
235
  await aiosmtplib.send(msg, hostname=SMTP_SERVER, port=SMTP_PORT,
236
  username=SENDER_EMAIL, password=SENDER_PASSWORD, start_tls=True)
237
  # --- THE FIX: RESET LOGIC ---
238
- ctx.set_state("math_attempts", 0) # Reset counter to 0
 
 
239
  # await ctx.enable_components(tools=["explain_from_resource", "generate_quick_revision"]) # Re-enable tools
240
 
241
  return f"Success: {teacher_name} ({subject} Expert) has been notified."
 
99
  and triggers teacher escalation after 3 failed attempts.
100
  """
101
  # FIX 1: Remove 'await' from ctx.get_state (it is synchronous)
102
+ # attempts = ctx.get_state("math_attempts") or 0
103
+ attempts = (await ctx.get_state("math_attempts")) or 0
104
 
105
  # 1. CIRCUIT BREAKER: Enforce the 3-attempt limit
106
  if attempts >= 3:
 
115
  )
116
 
117
  # FIX 2: Remove 'await' from ctx.set_state
118
+ # ctx.set_state("math_attempts", attempts + 1)
119
+ await ctx.set_state("math_attempts", attempts + 1)
120
 
121
  # 2. FETCH RESOURCE
122
  material = read_resource_file()
 
136
  Types: 'summary' (3 key points) or 'short_notes' (condensed formulas and definitions).
137
  """
138
  # ENFORCE ATTEMPT TRACKING
139
+ # attempts = ctx.get_state("math_attempts") or 0
140
+ attempts = (await ctx.get_state("math_attempts")) or 0
141
 
142
  if attempts >= 3:
143
  await ctx.disable_components(tools=["explain_from_resource", "generate_quick_revision"])
144
  return "FATAL_ERROR: TUTORING_LIMIT_REACHED. Transition to escalation immediately."
145
 
146
+ # ctx.set_state("math_attempts", attempts + 1)
147
+ await ctx.set_state("math_attempts", attempts + 1)
148
+
149
  material = read_resource_file()
150
  return f"""
151
  <attempt>{attempts + 1}/3</attempt>
 
239
  await aiosmtplib.send(msg, hostname=SMTP_SERVER, port=SMTP_PORT,
240
  username=SENDER_EMAIL, password=SENDER_PASSWORD, start_tls=True)
241
  # --- THE FIX: RESET LOGIC ---
242
+ # ctx.set_state("math_attempts", 0) # Reset counter to 0
243
+ await ctx.set_state("math_attempts", 0)
244
+
245
  # await ctx.enable_components(tools=["explain_from_resource", "generate_quick_revision"]) # Re-enable tools
246
 
247
  return f"Success: {teacher_name} ({subject} Expert) has been notified."