{"record":{"id":"0e16f9a484321e09","repo":"rohitg00/ai-engineering-from-scratch","slug":"tool-use-stop-without-calls","errorCode":null,"errorMessage":"tool_use stop without calls","messagePattern":"tool_use stop without calls","errorType":"exception","errorClass":"ToolLoopError","httpStatus":null,"severity":"error","filePath":"certifications/claude/lessons/10-tool-use-and-agentic-loops/code/main.py","lineNumber":262,"sourceCode":"        self.max_turns = max_turns\n\n    def run(self, request: str) -> tuple[str, list[dict[str, Any]]]:\n        messages: list[dict[str, Any]] = [{\"role\": \"user\", \"content\": request}]\n        for _ in range(self.max_turns):\n            response = self.model.create(messages)\n            blocks = response.get(\"content\")\n            if not isinstance(blocks, list):\n                raise ToolLoopError(\"response content must be a list\")\n            messages.append({\"role\": \"assistant\", \"content\": copy.deepcopy(blocks)})\n            reason = response.get(\"stop_reason\")\n            if reason == \"end_turn\":\n                text = \"\".join(block.get(\"text\", \"\") for block in blocks if block.get(\"type\") == \"text\")\n                return text, messages\n            if reason != \"tool_use\":\n                raise ToolLoopError(f\"unsupported stop reason: {reason}\")\n            calls = [block for block in blocks if block.get(\"type\") == \"tool_use\"]\n            if not calls:\n                raise ToolLoopError(\"tool_use stop without calls\")\n            results = [self.registry.execute(block, self.approve) for block in calls]\n            messages.append({\"role\": \"user\", \"content\": results})\n        raise ToolLoopError(\"maximum turns exceeded\")\n\n\ndef demo() -> tuple[str, list[dict[str, Any]]]:\n    add = Tool(\n        \"add\",\n        \"Add two integers.\",\n        {\"type\": \"object\", \"required\": [\"a\", \"b\"], \"additionalProperties\": False, \"properties\": {\"a\": {\"type\": \"integer\"}, \"b\": {\"type\": \"integer\"}}},\n        lambda data: data[\"a\"] + data[\"b\"],\n    )\n    model = ScriptedModel([\n        {\"stop_reason\": \"tool_use\", \"content\": [{\"type\": \"tool_use\", \"id\": \"call_1\", \"name\": \"add\", \"input\": {\"a\": 7, \"b\": 8}}]},\n        {\"stop_reason\": \"end_turn\", \"content\": [{\"type\": \"text\", \"text\": \"The total is 15.\"}]},\n    ])\n    return ToolLoop(model, ToolRegistry([add])).run(\"Add 7 and 8\")\n","sourceCodeStart":244,"sourceCodeEnd":280,"githubUrl":"https://github.com/rohitg00/ai-engineering-from-scratch/blob/39ea8a1c6d0b61f071226eff7ede4d4105fed820/certifications/claude/lessons/10-tool-use-and-agentic-loops/code/main.py#L244-L280","documentation":"Error \"tool_use stop without calls\" thrown in rohitg00/ai-engineering-from-scratch.","triggerScenarios":"Thrown at certifications/claude/lessons/10-tool-use-and-agentic-loops/code/main.py:262 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"39ea8a1c6d0b61f071226eff7ede4d4105fed820","analyzedAt":"2026-08-26T03:13:46.626Z","schemaVersion":2},"datasetVersion":"2026-08-26T07:17:17.940Z"}