{"record":{"id":"29dfc6a12a3464b3","repo":"xtekky/gpt4free","slug":"tool-loop-detected-function-key-0-returned-e","errorCode":null,"errorMessage":"Tool loop detected: function '{key[0]}' returned empty results {empty_counts[key]} times with the same arguments. The target is likely not indexed by this tool (e.g. a git submodule). Switch strategy: use read_file with an absolute path, or list_dir to confirm the file exists. Arguments: {key[1]}","messagePattern":"Tool loop detected: function '(.+?)' returned empty results (.+?) times with the same arguments\\. The target is likely not indexed by this tool \\(e\\.g\\. a git submodule\\)\\. Switch strategy: use read_file with an absolute path, or list_dir to confirm the file exists\\. Arguments: (.+?)","errorType":"exception","errorClass":"ToolLoopError","httpStatus":null,"severity":"error","filePath":"g4f/api/tool_loop_detection.py","lineNumber":207,"sourceCode":"                            f\"Arguments: {key[1]}\",\n                            function_name=key[0],\n                            arguments=key[1],\n                            repeats=call_counts[key],\n                        )\n\n        # Tool result message: attribute to the originating call.\n        elif role == \"tool\":\n            tool_call_id = message.get(\"tool_call_id\")\n            content = message.get(\"content\")\n            key = pending_calls.get(tool_call_id) if tool_call_id else None\n            # If we can't attribute via id, fall back to the most recent call.\n            if key is None and pending_calls:\n                # Heuristic: attribute to the last registered pending call.\n                key = next(reversed(pending_calls), None)\n            if key is not None and _is_empty_result(content):\n                empty_counts[key] = empty_counts.get(key, 0) + 1\n                if empty_counts[key] >= EMPTY_RESULT_LOOP_THRESHOLD:\n                    raise ToolLoopError(\n                        f\"Tool loop detected: function '{key[0]}' returned empty \"\n                        f\"results {empty_counts[key]} times with the same arguments. \"\n                        f\"The target is likely not indexed by this tool (e.g. a git \"\n                        f\"submodule). Switch strategy: use read_file with an absolute \"\n                        f\"path, or list_dir to confirm the file exists. Arguments: \"\n                        f\"{key[1]}\",\n                        function_name=key[0],\n                        arguments=key[1],\n                        repeats=empty_counts[key],\n                    )\n\n\ndef has_tool_loop(messages: Messages) -> Optional[ToolLoopError]:\n    \"\"\"Convenience wrapper: return the error object if a loop is detected, else None.\"\"\"\n    try:\n        detect_tool_loop(messages)\n    except ToolLoopError as e:\n        return e","sourceCodeStart":189,"sourceCodeEnd":225,"githubUrl":"https://github.com/xtekky/gpt4free/blob/973504e1770928ed5fb82f43da528f441ad9ddc3/g4f/api/tool_loop_detection.py#L189-L225","documentation":"Error \"Tool loop detected: function '{key[0]}' returned empty results {empty_counts[key]} times with the same arguments. The target is likely not indexed by this tool (e.g. a git submodule). Switch strategy: use read_file with an absolute path, or list_dir to confirm the file exists. Arguments: {key[1]}\" thrown in xtekky/gpt4free.","triggerScenarios":"Thrown at g4f/api/tool_loop_detection.py:207 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Switch to read_file with an absolute path or list_dir, since the target is likely not indexed by this tool."],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"973504e1770928ed5fb82f43da528f441ad9ddc3","analyzedAt":"2026-08-14T23:45:32.408Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}