rohitg00/ai-engineering-from-scratch · error · ToolLoopError

model script exhausted

Error message

model script exhausted

What it means

Error "model script exhausted" thrown in rohitg00/ai-engineering-from-scratch.

Source

Thrown at certifications/claude/lessons/10-tool-use-and-agentic-loops/code/main.py:229

        try:
            tool.validate(arguments)
            if tool.mutates and not approve(tool, arguments):
                return {**result, "content": "Approval denied", "is_error": True}
            value = tool.handler(arguments)
            return {**result, "content": json.dumps(value, sort_keys=True)}
        except Exception as exc:
            return {**result, "content": f"{type(exc).__name__}: {exc}", "is_error": True}


class ScriptedModel:
    def __init__(self, responses: list[dict[str, Any]]) -> None:
        self.responses = copy.deepcopy(responses)
        self.requests: list[list[dict[str, Any]]] = []

    def create(self, messages: list[dict[str, Any]]) -> dict[str, Any]:
        self.requests.append(copy.deepcopy(messages))
        if not self.responses:
            raise ToolLoopError("model script exhausted")
        return self.responses.pop(0)


class ToolLoop:
    def __init__(
        self,
        model: ScriptedModel,
        registry: ToolRegistry,
        approve: Callable[[Tool, dict[str, Any]], bool] = lambda _tool, _args: False,
        max_turns: int = 8,
    ) -> None:
        self.model = model
        self.registry = registry
        self.approve = approve
        self.max_turns = max_turns

    def run(self, request: str) -> tuple[str, list[dict[str, Any]]]:
        messages: list[dict[str, Any]] = [{"role": "user", "content": request}]

View on GitHub (pinned to 39ea8a1c6d)

When it happens

Trigger: Thrown at certifications/claude/lessons/10-tool-use-and-agentic-loops/code/main.py:229 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of rohitg00/ai-engineering-from-scratch@39ea8a1c6d (2026-08-26). Data as JSON: /api/errors/8f55bde3022a81c0. Report an issue: GitHub.