irregular6612 commited on
Commit
d8f91b8
·
1 Parent(s): f60d821

fix(cp2): extract_action handles punctuation-wrapped field tokens (e.g. 'up?')

Browse files
proteus/agents/parsing.py CHANGED
@@ -33,9 +33,10 @@ def extract_action(text: str, valid: list[str]) -> str | None:
33
  # Strategy 1: last ACTION: <token> field.
34
  field_matches = _ACTION_FIELD.findall(text)
35
  for raw in reversed(field_matches):
36
- token = raw.strip().strip(".!,;:'\"`").lower()
37
- # take the first word of the field value
38
- first = token.split()[0] if token.split() else ""
 
39
  if first in valid_set:
40
  return first
41
 
 
33
  # Strategy 1: last ACTION: <token> field.
34
  field_matches = _ACTION_FIELD.findall(text)
35
  for raw in reversed(field_matches):
36
+ # First alphabetic run of the field value, ignoring any wrapping
37
+ # punctuation (e.g. "up?", "up." -> "up").
38
+ match = _WORD.search(raw)
39
+ first = match.group(0).lower() if match else ""
40
  if first in valid_set:
41
  return first
42
 
tests/agents/test_parsing.py CHANGED
@@ -18,3 +18,9 @@ def test_bare_word_fallback_when_no_action_field():
18
 
19
  def test_returns_none_when_no_valid_action():
20
  assert extract_action("no idea", VALID) is None
 
 
 
 
 
 
 
18
 
19
  def test_returns_none_when_no_valid_action():
20
  assert extract_action("no idea", VALID) is None
21
+
22
+
23
+ def test_action_field_with_trailing_question_mark():
24
+ # LLMs often append "?"; the field token must still be extracted, not
25
+ # fall through to a later prose word.
26
+ assert extract_action("ACTION: up?\nThen move right", VALID) == "up"