{"record":{"id":"1fd782bfd753ffd4","repo":"FoundationAgents/MetaGPT","slug":"invalid-press-action-step","errorCode":null,"errorMessage":"Invalid press action {step}","messagePattern":"Invalid press action (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"metagpt/utils/a11y_tree.py","lineNumber":60,"sourceCode":"        if not (step.endswith(\"[0]\") or step.endswith(\"[1]\")):\n            step += \" [1]\"\n\n        match = re.search(r\"type ?\\[(\\d+)\\] ?\\[(.+)\\] ?\\[(\\d+)\\]\", step)\n        if not match:\n            raise ValueError(f\"Invalid type action {step}\")\n        element_id, text, enter_flag = (\n            match.group(1),\n            match.group(2),\n            match.group(3),\n        )\n        if enter_flag == \"1\":\n            text += \"\\n\"\n        await click_element(page, get_backend_node_id(element_id, accessibility_tree))\n        await type_text(page, text)\n    elif func == \"press\":\n        match = re.search(r\"press ?\\[(.+)\\]\", step)\n        if not match:\n            raise ValueError(f\"Invalid press action {step}\")\n        key = match.group(1)\n        await key_press(page, key)\n    elif func == \"scroll\":\n        # up or down\n        match = re.search(r\"scroll ?\\[?(up|down)\\]?\", step)\n        if not match:\n            raise ValueError(f\"Invalid scroll action {step}\")\n        direction = match.group(1)\n        await scroll_page(page, direction)\n    elif func == \"goto\":\n        match = re.search(r\"goto ?\\[(.+)\\]\", step)\n        if not match:\n            raise ValueError(f\"Invalid goto action {step}\")\n        url = match.group(1)\n        await page.goto(url)\n    elif func == \"new_tab\":\n        page = await browser_ctx.new_page()\n    elif func == \"go_back\":","sourceCodeStart":42,"sourceCodeEnd":78,"githubUrl":"https://github.com/FoundationAgents/MetaGPT/blob/11cdf466d042aece04fc6cfd13b28e1a70341b1f/metagpt/utils/a11y_tree.py#L42-L78","documentation":"MetaGPT's browser agent parses LLM-emitted action strings (e.g. 'press [Enter]') inside execute_action in metagpt/utils/a11y_tree.py. When the action is classified as a press but the regex r'press ?\\[(.+)\\]' fails to match the step text, this ValueError is raised. It means the LLM output deviated from the expected 'press [<key>]' format.","triggerScenarios":"execute_action(page, 'press') or 'press Enter' without square brackets; 'press[space' with unbalanced brackets; an LLM response like 'press \"Enter\"' using quotes instead of brackets; trailing characters that break the (.+) capture after the closing bracket.","commonSituations":"LLM action hallucination where the model omits the bracket syntax, includes extra prose around the action, or emits an empty key. Also occurs when a custom action_splitter mangles the extracted step so the leading 'press [...]' fragment is truncated.","solutions":["Check the raw LLM response and the extracted step string; log it before execute_action is called.","Make the action conform: use exactly 'press [Enter]' / 'press [Control+a]' with square brackets.","Tighten the prompt/instruction template so the model always emits press actions in bracket form.","Pre-validate the step with your own regex before calling execute_action, and re-ask the LLM on mismatch."],"exampleFix":"# before\nawait execute_action(page, 'press Enter')  # raises Invalid press action\n\n# after\nawait execute_action(page, 'press [Enter]')","handlingStrategy":"validation","validationCode":"import re\n\ndef is_valid_press(step: str) -> bool:\n    return bool(re.search(r\"press ?\\[(.+)\\]\", step))","typeGuard":null,"tryCatchPattern":"try:\n    await execute_action(page, step)\nexcept ValueError as e:\n    if 'Invalid press action' in str(e):\n        # log step, re-ask the LLM with format instructions\n        ...","preventionTips":["Prompt the LLM with explicit press [<key>] examples including brackets.","Validate the step string against the action regex before calling execute_action.","Log the raw model response so malformed actions are diagnosable."],"tags":["metagpt","browser-agent","llm-output","regex","validation"],"backgroundTag":null,"analyzedSha":"11cdf466d042aece04fc6cfd13b28e1a70341b1f","analyzedAt":"2026-08-14T23:20:02.994Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}