Skip to content

Commit b6a3da3

Browse files
authored
add error handling for when agents don't submit a guess (#255)
* add error handling for when agents don't submit a guess * CR
1 parent 29cd76f commit b6a3da3

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

kaggle_environments/envs/llm_20_questions/llm_20_questions.py

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -99,13 +99,15 @@ def interpreter(state, env):
9999
if active1 is not None:
100100
guessed = False
101101
if active1.observation.role == "guesser":
102-
if active1.observation.turnType == "ask":
102+
if not active1.action:
103+
active1.status = "ERROR"
104+
elif active1.observation.turnType == "ask":
103105
active1.observation.questions.append(active1.action)
104106
inactive1.observation.questions.append(active1.action)
105107
elif active1.observation.turnType == "guess":
106108
active1.observation.guesses.append(active1.action)
107109
inactive1.observation.guesses.append(active1.action)
108-
if keyword_guessed(active1.action):
110+
if active1.action and keyword_guessed(active1.action):
109111
guessed = True
110112
score = 20 - int(step / 3)
111113
active1.reward = score
@@ -120,12 +122,14 @@ def interpreter(state, env):
120122
active1.observation.keyword = keyword
121123
active1.observation.category = category
122124
response = active1.action
123-
if response.lower().__contains__("yes"):
125+
if not response:
126+
active1.status = "ERROR"
127+
elif response.lower().__contains__("yes"):
124128
response = "yes"
125129
elif response.lower().__contains__("no"):
126130
response = "no"
127131
else:
128-
response = "maybe"
132+
active1.status = "ERROR"
129133
active1.observation.answers.append(response)
130134
inactive1.observation.answers.append(response)
131135

@@ -151,13 +155,15 @@ def interpreter(state, env):
151155
if active2 is not None:
152156
guessed = False
153157
if active2.observation.role == "guesser":
154-
if active2.observation.turnType == "ask":
158+
if not active2.action:
159+
active2.status = "ERROR"
160+
elif active2.observation.turnType == "ask":
155161
active2.observation.questions.append(active2.action)
156162
inactive2.observation.questions.append(active2.action)
157163
elif active2.observation.turnType == "guess":
158164
active2.observation.guesses.append(active2.action)
159165
inactive2.observation.guesses.append(active2.action)
160-
if keyword_guessed(active2.action):
166+
if active2.action and keyword_guessed(active2.action):
161167
guessed = True
162168
score = 20 - int(step / 3)
163169
active2.reward = score
@@ -172,12 +178,14 @@ def interpreter(state, env):
172178
active2.observation.keyword = keyword
173179
active2.observation.category = category
174180
response = active2.action
175-
if response.lower().__contains__("yes"):
181+
if not response:
182+
active2.status = "ERROR"
183+
elif response.lower().__contains__("yes"):
176184
response = "yes"
177185
elif response.lower().__contains__("no"):
178186
response = "no"
179187
else:
180-
response = "maybe"
188+
active2.status = "ERROR"
181189
active2.observation.answers.append(response)
182190
inactive2.observation.answers.append(response)
183191

0 commit comments

Comments
 (0)