FoundationAgents/MetaGPT · error · TimeoutException

Function timed out after {self.role_timeout} seconds

Error message

Function timed out after {self.role_timeout} seconds

What it means

TimeoutException raised by the @async_timeout decorator on Experimenter roles when the wrapped coroutine exceeds self.role_timeout seconds (asyncio.wait_for). State is saved and the exception propagates so the MCTS search can treat the node as failed rather than hang forever.

Source

Thrown at metagpt/ext/sela/experimenter.py:55

}}
```
"""


class TimeoutException(Exception):
    pass


def async_timeout():
    def decorator(func):
        async def wrapper(self, *args, **kwargs):
            try:
                result = await asyncio.wait_for(func(self, *args, **kwargs), timeout=self.role_timeout)
            except asyncio.TimeoutError:
                text = f"Function timed out after {self.role_timeout} seconds"
                mcts_logger.error(text)
                self.save_state()
                raise TimeoutException(text)
            return result

        return wrapper

    return decorator


class Experimenter(DataInterpreter):
    node_id: str = "0"
    start_task_id: int = 1
    state_saved: bool = False
    role_dir: str = SERDESER_PATH.joinpath("team", "environment", "roles", "Experimenter")
    role_timeout: int = 1000

    def get_node_name(self):
        return f"Node-{self.node_id}"

    def get_next_instruction(self):

View on GitHub (pinned to 11cdf466d0)

Solutions

  1. Increase role_timeout in the experiment config / Experimenter(..., role_timeout=N)
  2. Reduce dataset size or task complexity so the experiment finishes sooner
  3. Check LLM provider latency and API quota — repeated slow calls are the usual cause

Example fix

# before
di = Experimenter(node_id="0", role_timeout=300)

# after
di = Experimenter(node_id="0", role_timeout=1200)
Defensive patterns

Strategy: try-catch

Try / catch

from metagpt.ext.sela.experimenter import TimeoutException
try:
    score = await di.run(...)
except TimeoutException:
    score = None  # mark node as failed, continue search

Prevention

When it happens

Trigger: A DataInterpreter/Experimenter run (code generation + execution loop) that does not finish within role_timeout, e.g. long LLM calls, retries, or generated code stuck in slow execution.

Common situations: Default role_timeout too small for big datasets or slow LLM endpoints; network latency to the LLM provider; a runaway generated script.

Understand the failure class

Related errors


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