adeshboudh16 Claude Sonnet 4.6 commited on
Commit
ee2a25c
·
1 Parent(s): 7d107ff

fix: use .get() for all state access to prevent KeyError in graph nodes

Browse files
Files changed (2) hide show
  1. Makefile +1 -1
  2. backend/graph/nodes.py +15 -15
Makefile CHANGED
@@ -14,4 +14,4 @@ build:
14
  docker build -t ai-interviewmentor .
15
 
16
  docker-run:
17
- docker run --env-file .env -p 7860:7860 ai-interviewmentor
 
14
  docker build -t ai-interviewmentor .
15
 
16
  docker-run:
17
+ docker run --name ai-interviewmentor --env-file .env -p 7860:7860 --rm ai-interviewmentor
backend/graph/nodes.py CHANGED
@@ -32,9 +32,9 @@ MAX_TURNS = 5
32
 
33
 
34
  async def ask_question(state: InterviewState) -> dict:
35
- remaining = list(state["questions_remaining"])
36
- log.info("ask_question: turn=%d/%d, remaining=%d", state["turn_count"], MAX_TURNS, len(remaining))
37
- if not remaining or state["turn_count"] >= MAX_TURNS:
38
  log.info("ask_question: skipping (limit reached or no questions)")
39
  return {"messages": []}
40
 
@@ -50,9 +50,9 @@ async def ask_question(state: InterviewState) -> dict:
50
 
51
  return {
52
  "questions_remaining": remaining,
53
- "questions_asked": state["questions_asked"] + [question["question_text"]],
54
  "messages": [{"role": "assistant", "content": response}],
55
- "turn_count": state["turn_count"] + 1,
56
  "awaiting_counter_response": False,
57
  }
58
 
@@ -126,14 +126,14 @@ async def summarize(state: InterviewState) -> dict:
126
 
127
 
128
  async def generate_report(state: InterviewState) -> dict:
129
- log.info("generate_report: questions_asked=%d, turn_count=%d", len(state["questions_asked"]), state["turn_count"])
130
  prompt = build_report_prompt(
131
- state["topic_name"],
132
- state["questions_asked"],
133
- state["student_weak_areas"],
134
- state["conversation_summary"],
135
- state["past_best_score"],
136
- messages=state["messages"],
137
  )
138
  raw = await call_llm(prompt, max_tokens=400)
139
 
@@ -164,9 +164,9 @@ async def generate_report(state: InterviewState) -> dict:
164
  def route_after_evaluation(state: InterviewState) -> str:
165
  """Routing function for conditional edges after evaluate_answer."""
166
  verdict = state.get("last_verdict", "wrong")
167
- turn_count = state["turn_count"]
168
- questions_remaining = state["questions_remaining"]
169
- awaiting_counter = state["awaiting_counter_response"]
170
 
171
  decision = "unknown"
172
 
 
32
 
33
 
34
  async def ask_question(state: InterviewState) -> dict:
35
+ remaining = list(state.get("questions_remaining", []))
36
+ log.info("ask_question: turn=%d/%d, remaining=%d", state.get("turn_count", 0), MAX_TURNS, len(remaining))
37
+ if not remaining or state.get("turn_count", 0) >= MAX_TURNS:
38
  log.info("ask_question: skipping (limit reached or no questions)")
39
  return {"messages": []}
40
 
 
50
 
51
  return {
52
  "questions_remaining": remaining,
53
+ "questions_asked": state.get("questions_asked", []) + [question["question_text"]],
54
  "messages": [{"role": "assistant", "content": response}],
55
+ "turn_count": state.get("turn_count", 0) + 1,
56
  "awaiting_counter_response": False,
57
  }
58
 
 
126
 
127
 
128
  async def generate_report(state: InterviewState) -> dict:
129
+ log.info("generate_report: questions_asked=%d, turn_count=%d", len(state.get("questions_asked", [])), state.get("turn_count", 0))
130
  prompt = build_report_prompt(
131
+ state.get("topic_name", ""),
132
+ state.get("questions_asked", []),
133
+ state.get("student_weak_areas", []),
134
+ state.get("conversation_summary", ""),
135
+ state.get("past_best_score"),
136
+ messages=state.get("messages", []),
137
  )
138
  raw = await call_llm(prompt, max_tokens=400)
139
 
 
164
  def route_after_evaluation(state: InterviewState) -> str:
165
  """Routing function for conditional edges after evaluate_answer."""
166
  verdict = state.get("last_verdict", "wrong")
167
+ turn_count = state.get("turn_count", 0)
168
+ questions_remaining = state.get("questions_remaining", [])
169
+ awaiting_counter = state.get("awaiting_counter_response", False)
170
 
171
  decision = "unknown"
172