prthm11 commited on
Commit
9fe4467
·
verified ·
1 Parent(s): 86e9e71

Update escalation_server.py

Browse files
Files changed (1) hide show
  1. escalation_server.py +14 -13
escalation_server.py CHANGED
@@ -104,12 +104,13 @@ async def explain_from_resource(concept: str, ctx: Context = CurrentContext()):
104
  and triggers teacher escalation after 3 failed attempts.
105
  """
106
  # FIX 1: Remove 'await' from ctx.get_state (it is synchronous)
107
- # attempts = ctx.get_state("math_attempts") or 0
108
- attempts = (await ctx.get_state("math_attempts")) or 0
109
 
110
  # 1. CIRCUIT BREAKER: Enforce the 3-attempt limit
111
  if attempts >= 3:
112
- await ctx.disable_components(tools=["explain_from_resource", "generate_quick_revision"])
 
113
  return (
114
  "FATAL_ERROR: TUTORING_LIMIT_REACHED. "
115
  "Internal tutoring tools have been deactivated for this session. "
@@ -119,9 +120,8 @@ async def explain_from_resource(concept: str, ctx: Context = CurrentContext()):
119
  "3. Execute get_teacher_info and escalate_to_teacher."
120
  )
121
 
122
- # FIX 2: Remove 'await' from ctx.set_state
123
- # ctx.set_state("math_attempts", attempts + 1)
124
- await ctx.set_state("math_attempts", attempts + 1)
125
 
126
  # 2. FETCH RESOURCE
127
  material = read_resource_file()
@@ -129,7 +129,7 @@ async def explain_from_resource(concept: str, ctx: Context = CurrentContext()):
129
  # 3. STRUCTURED RESPONSE
130
  # Note: We return the prompt back to the LLM so it can generate the explanation
131
  return f"""
132
- <attempt>{attempts + 1}/3</attempt>
133
  <content>{material}</content>
134
  <instruction>Explain {concept} concisely. Use LaTeX.</instruction>
135
  """
@@ -141,19 +141,20 @@ async def generate_quick_revision(type: str = "summary", ctx: Context = CurrentC
141
  Types: 'summary' (3 key points) or 'short_notes' (condensed formulas and definitions).
142
  """
143
  # ENFORCE ATTEMPT TRACKING
144
- # attempts = ctx.get_state("math_attempts") or 0
145
- attempts = (await ctx.get_state("math_attempts")) or 0
146
 
147
  if attempts >= 3:
148
- await ctx.disable_components(tools=["explain_from_resource", "generate_quick_revision"])
 
149
  return "FATAL_ERROR: TUTORING_LIMIT_REACHED. Transition to escalation immediately."
150
 
151
- # ctx.set_state("math_attempts", attempts + 1)
152
- await ctx.set_state("math_attempts", attempts + 1)
153
 
154
  material = read_resource_file()
155
  return f"""
156
- <attempt>{attempts + 1}/3</attempt>
157
  <material>{material}</material>
158
  <request>Create a {type} for quick revision.</request>
159
  <format_requirements>
 
104
  and triggers teacher escalation after 3 failed attempts.
105
  """
106
  # FIX 1: Remove 'await' from ctx.get_state (it is synchronous)
107
+ attempts = ctx.get_state("math_attempts") or 0
108
+ # attempts = (await ctx.get_state("math_attempts")) or 0
109
 
110
  # 1. CIRCUIT BREAKER: Enforce the 3-attempt limit
111
  if attempts >= 3:
112
+ # await ctx.disable_components(tools=["explain_from_resource", "generate_quick_revision"])
113
+ await ctx.disable_components(names=["explain_from_resource", "generate_quick_revision"])
114
  return (
115
  "FATAL_ERROR: TUTORING_LIMIT_REACHED. "
116
  "Internal tutoring tools have been deactivated for this session. "
 
120
  "3. Execute get_teacher_info and escalate_to_teacher."
121
  )
122
 
123
+ new_attempts = attempts + 1
124
+ ctx.set_state("math_attempts", new_attempts)
 
125
 
126
  # 2. FETCH RESOURCE
127
  material = read_resource_file()
 
129
  # 3. STRUCTURED RESPONSE
130
  # Note: We return the prompt back to the LLM so it can generate the explanation
131
  return f"""
132
+ <attempt>{new_attempts}/3</attempt>
133
  <content>{material}</content>
134
  <instruction>Explain {concept} concisely. Use LaTeX.</instruction>
135
  """
 
141
  Types: 'summary' (3 key points) or 'short_notes' (condensed formulas and definitions).
142
  """
143
  # ENFORCE ATTEMPT TRACKING
144
+ attempts = ctx.get_state("math_attempts") or 0
145
+ # attempts = (await ctx.get_state("math_attempts")) or 0
146
 
147
  if attempts >= 3:
148
+ # await ctx.disable_components(tools=["explain_from_resource", "generate_quick_revision"])
149
+ await ctx.disable_components(names=["explain_from_resource", "generate_quick_revision"])
150
  return "FATAL_ERROR: TUTORING_LIMIT_REACHED. Transition to escalation immediately."
151
 
152
+ new_attempts = attempts + 1
153
+ ctx.set_state("math_attempts", new_attempts)
154
 
155
  material = read_resource_file()
156
  return f"""
157
+ <attempt>{new_attempts}/3</attempt>
158
  <material>{material}</material>
159
  <request>Create a {type} for quick revision.</request>
160
  <format_requirements>