{"record":{"id":"944c23ebd35d8f51","repo":"jumpserver/jumpserver","slug":"maximum-web-search-count-exceeded","errorCode":null,"errorMessage":"Maximum web search count exceeded.","messagePattern":"Maximum web search count exceeded\\.","errorType":"exception","errorClass":"AgentLimitError","httpStatus":null,"severity":"error","filePath":"apps/chat_ai/agents/runner.py","lineNumber":705,"sourceCode":"                        if not query:\n                            messages.append(self._tool_message(\n                                tool_call,\n                                {'error': 'The original user question cannot form a public web query.'},\n                            ))\n                            continue\n                        signature = json.dumps(\n                            {'tool': name, 'query': query},\n                            sort_keys=True,\n                            ensure_ascii=False,\n                        )\n                        if signature in web_search_signatures:\n                            messages.append(self._tool_message(\n                                tool_call, {'error': 'Duplicate web search was blocked.'}\n                            ))\n                            continue\n                        web_search_signatures.add(signature)\n                        if web_search_count >= self.max_web_search_calls:\n                            raise AgentLimitError('Maximum web search count exceeded.')\n                        web_search_count += 1\n                        yield sse_event('web_search_start', {'query': query, 'action': action})\n                        try:\n                            result = await web_search.search(query, self.agent_run)\n                        except WebSearchError as exc:\n                            error = sanitize_text(str(exc))[:512]\n                            yield sse_event('web_search_result', {\n                                'query': query,\n                                'action': action,\n                                'ok': False,\n                                'error': error,\n                                'sources': [],\n                            })\n                            messages.append(self._tool_message(tool_call, {'error': error}))\n                            continue\n                        sources = [\n                            {'title': item['title'], 'url': item['url']}\n                            for item in result['results']","sourceCodeStart":687,"sourceCodeEnd":723,"githubUrl":"https://github.com/jumpserver/jumpserver/blob/6ec464fabd61b95912d539455a3a5f15f5c59fe0/apps/chat_ai/agents/runner.py#L687-L723","documentation":"Raised by the agent runner's stream loop when the model attempts more web search tool calls than allowed by max_web_search_calls. It is a hard safety limit that aborts the run to bound cost and latency. Duplicate identical searches are blocked separately before this check.","triggerScenarios":"POST to the conversation stream endpoint (stream_message/regenerate/branch/background) and the assistant issues more distinct web_search tool calls than the configured max_web_search_calls within a single agent run.","commonSituations":"Low max_web_search_calls setting combined with an agent prompt that encourages broad research; long multi-step tasks where the model keeps issuing new queries; a search tool returning poor results causing the model to retry with different queries.","solutions":["Increase max_web_search_calls for the agent/profile configuration.","Tighten the agent system prompt so it batches or limits searches per step.","Cache or improve search result quality so the model stops re-querying.","Catch AgentLimitError in the consumer and surface a friendly 'search limit reached' message."],"exampleFix":"# before\nrunner = AgentRunner(..., max_web_search_calls=2)\n\n# after\nrunner = AgentRunner(..., max_web_search_calls=8)","handlingStrategy":"validation","validationCode":"if agent_run.web_search_count >= runner.max_web_search_calls:\n    raise UserError('Web search limit reached; narrow your question.')","typeGuard":"def web_search_budget_left(runner) -> bool:\n    return runner.web_search_count < runner.max_web_search_calls","tryCatchPattern":"try:\n    async for event in runner.stream(...):\n        ...\nexcept AgentLimitError as exc:\n    if 'web search' in str(exc):\n        yield sse_event('error', {'message': 'Web search limit reached.'})","preventionTips":["Set max_web_search_calls proportional to task complexity.","Prompt the model to plan queries before searching.","Log search counts per run to tune the limit."],"tags":["agent","web-search","rate-limit","chat-ai"],"backgroundTag":"rate-limit-exceeded","analyzedSha":"6ec464fabd61b95912d539455a3a5f15f5c59fe0","analyzedAt":"2026-08-28T11:33:00.925Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}