FoundationAgents/MetaGPT · error · ValueError

Invalid goto action {step}

Error message

Invalid goto action {step}

What it means

MetaGPT's execute_action raises this when a step classified as goto fails to match r'goto ?\[(.+)\]'. The expected format is 'goto [https://example.com]'; any deviation (missing brackets, empty URL) makes the regex search return None.

Source

Thrown at metagpt/utils/a11y_tree.py:73

        await click_element(page, get_backend_node_id(element_id, accessibility_tree))
        await type_text(page, text)
    elif func == "press":
        match = re.search(r"press ?\[(.+)\]", step)
        if not match:
            raise ValueError(f"Invalid press action {step}")
        key = match.group(1)
        await key_press(page, key)
    elif func == "scroll":
        # up or down
        match = re.search(r"scroll ?\[?(up|down)\]?", step)
        if not match:
            raise ValueError(f"Invalid scroll action {step}")
        direction = match.group(1)
        await scroll_page(page, direction)
    elif func == "goto":
        match = re.search(r"goto ?\[(.+)\]", step)
        if not match:
            raise ValueError(f"Invalid goto action {step}")
        url = match.group(1)
        await page.goto(url)
    elif func == "new_tab":
        page = await browser_ctx.new_page()
    elif func == "go_back":
        await page.go_back()
    elif func == "go_forward":
        await page.go_forward()
    elif func == "tab_focus":
        match = re.search(r"tab_focus ?\[(\d+)\]", step)
        if not match:
            raise ValueError(f"Invalid tab_focus action {step}")
        page_number = int(match.group(1))
        page = browser_ctx.pages[page_number]
        await page.bring_to_front()
    elif func == "close_tab":
        await page.close()
        if len(browser_ctx.pages) > 0:

View on GitHub (pinned to 11cdf466d0)

Solutions

  1. Reformat the step as 'goto [https://example.com]' with square brackets.
  2. Inspect the full LLM response to see whether the closing bracket was lost in extraction.
  3. Strengthen the prompt's action-format examples for goto.
  4. Validate the step with re.search(r'goto ?\[(.+)\]', step) before dispatching.

Example fix

# before
await execute_action(page, 'goto https://example.com')  # raises Invalid goto action

# after
await execute_action(page, 'goto [https://example.com]')
Defensive patterns

Strategy: validation

Validate before calling

import re

def is_valid_goto(step: str) -> bool:
    return bool(re.search(r"goto ?\[(.+)\]", step))

Try / catch

try:
    await execute_action(page, step)
except ValueError as e:
    if 'Invalid goto action' in str(e):
        # re-extract URL and reformat as goto [<url>]

Prevention

When it happens

Trigger: execute_action(page, 'goto https://example.com') without brackets; 'goto []' with empty URL; 'goto (https://example.com)' with parentheses; unbalanced brackets from LLM markdown formatting.

Common situations: LLM emits a bare URL or wraps it in parentheses/quotes instead of square brackets. Also occurs when URL text contains ']' early, truncating the capture, or when the step extraction (extract_step) clipped the closing bracket.

Related errors


AI-assisted analysis of FoundationAgents/MetaGPT@11cdf466d0 (2026-08-14). Data as JSON: /api/errors/2ddafadc8872d828. Report an issue: GitHub.