Skip to content

Commit 497b2c3

Browse files
feat: robust template (#15)
1 parent 9c65dad commit 497b2c3

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

balrog/agents/robust_naive.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ def act(self, obs, prev_action=None):
3333
naive_instruction = """
3434
You must choose exactly one of the listed actions and output it strictly in the following format:
3535
36-
<|ACTION|>YOUR_CHOSEN_ACTION</|ACTION|>
36+
<|ACTION|>YOUR_CHOSEN_ACTION<|END|>
3737
38-
You must not output any other text before or after these tags. No explanation, no reasoning, just the action within these tags.
38+
Replace YOUR_CHOSEN_ACTION with the chosen action. Output no other text, explanation, or reasoning.
3939
""".strip()
4040

4141
if messages and messages[-1].role == "user":
@@ -46,7 +46,7 @@ def act(self, obs, prev_action=None):
4646
return final_answer
4747

4848
def _extract_final_answer(self, answer):
49-
"""Extract the action from the completion by looking for <|ACTION|> ... </|ACTION|> tags.
49+
"""Extract the action from the completion by looking for <|ACTION|> and <|END|> tags.
5050
5151
Args:
5252
answer (LLMResponse): The response from the LLM.
@@ -55,12 +55,12 @@ def _extract_final_answer(self, answer):
5555
LLMResponse: The sanitized response containing just the extracted action.
5656
"""
5757
completion_text = answer.completion
58-
# Use a regex to find the text inside <|ACTION|> and </|ACTION|>
59-
match = re.search(r"<\|ACTION\|>(.*?)</\|ACTION\|>", completion_text, re.DOTALL)
58+
# Use a regex to find the text inside <|ACTION|> and <|END|>
59+
match = re.search(r"<\|ACTION\|>(.*?)<\|END\|>", completion_text, re.DOTALL)
6060
if match:
6161
extracted_action = match.group(1).strip()
6262
else:
63-
# If no match is found, fallback to the original completion (or handle error)
63+
# If no match is found, fallback to the original completion or handle as needed
6464
extracted_action = completion_text.strip()
6565

6666
final_answer = copy.deepcopy(answer)

0 commit comments

Comments
 (0)