diff --git a/metagpt/utils/repair_llm_raw_output.py b/metagpt/utils/repair_llm_raw_output.py index 5c57693f74..e9e18a6f6b 100644 --- a/metagpt/utils/repair_llm_raw_output.py +++ b/metagpt/utils/repair_llm_raw_output.py @@ -349,10 +349,9 @@ def extract_state_value_from_output(content: str) -> str: """ content = content.strip() # deal the output cases like " 0", "0\n" and so on. pattern = ( - r"(? 0 else "-1" return state diff --git a/tests/metagpt/utils/test_repair_llm_raw_output.py b/tests/metagpt/utils/test_repair_llm_raw_output.py index 7a29ea3ee2..683b20508e 100644 --- a/tests/metagpt/utils/test_repair_llm_raw_output.py +++ b/tests/metagpt/utils/test_repair_llm_raw_output.py @@ -386,3 +386,15 @@ class Game{\n +int score\n +list tiles\n +function move_ assert output.startswith('{\n"Implementation approach"') and output.endswith( '"Anything UNCLEAR": "The requirement is clear to me."\n}' ) + + +def test_extract_state_value_from_output(): + from metagpt.utils.repair_llm_raw_output import extract_state_value_from_output + + # single-digit states and the "-1" no-op state are returned as-is + assert extract_state_value_from_output("0") == "0" + assert extract_state_value_from_output(" 3\n") == "3" + assert extract_state_value_from_output("-1") == "-1" + # multi-digit state indices (>= 10) must be kept whole, not split into digits + assert extract_state_value_from_output("10") == "10" + assert extract_state_value_from_output("The next state is 12.") == "12"