{"record":{"id":"ed86b6f23f4652f3","repo":"microsoft/autogen","slug":"run-failed-run-last-error","errorCode":null,"errorMessage":"Run failed: {run.last_error}","messagePattern":"Run failed: (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/packages/autogen-ext/src/autogen_ext/agents/azure/_azure_ai_agent.py","lineNumber":719,"sourceCode":"                    thread_id=self.thread_id,\n                    agent_id=self._get_agent_id,\n                )\n            )\n        )\n\n        # Wait for run completion by polling\n        while True:\n            run = await cancellation_token.link_future(\n                asyncio.ensure_future(\n                    self._project_client.agents.runs.get(\n                        thread_id=self.thread_id,\n                        run_id=run.id,\n                    )\n                )\n            )\n\n            if run.status == RunStatus.FAILED:\n                raise ValueError(f\"Run failed: {run.last_error}\")\n\n            # If the run requires action (function calls), execute tools and continue\n            if run.status == RunStatus.REQUIRES_ACTION and run.required_action is not None:\n                tool_calls: List[FunctionCall] = []\n                submit_tool_outputs = getattr(run.required_action, \"submit_tool_outputs\", None)\n                if submit_tool_outputs and hasattr(submit_tool_outputs, \"tool_calls\"):\n                    for required_tool_call in submit_tool_outputs.tool_calls:\n                        if required_tool_call.type == \"function\":\n                            tool_calls.append(\n                                FunctionCall(\n                                    id=required_tool_call.id,\n                                    name=required_tool_call.function.name,\n                                    arguments=required_tool_call.function.arguments,\n                                )\n                            )\n\n                # Add tool call message to inner messages\n                tool_call_msg = ToolCallRequestEvent(source=self.name, content=tool_calls)","sourceCodeStart":701,"sourceCodeEnd":737,"githubUrl":"https://github.com/microsoft/autogen/blob/027ecf0a379bcc1d09956d46d12d44a3ad9cee14/python/packages/autogen-ext/src/autogen_ext/agents/azure/_azure_ai_agent.py#L701-L737","documentation":"During run polling in on_messages_stream, if the Azure AI agent run reaches RunStatus.FAILED, the agent raises ValueError embedding run.last_error (the service-side error, e.g. content_filter, rate_limit, invalid tool definition). This is the service rejecting/failing the run; the message text is whatever Azure reported.","triggerScenarios":"Any on_messages_stream call where the Azure run fails server-side: content policy violations, quota/rate limits, malformed tool definitions registered on the service agent, expired threads, or model deployment errors.","commonSituations":"Prompts tripping content filters; hitting token-per-minute quotas; a deployment that was disabled or deleted; tool definitions referencing invalid resources (e.g. bing grounding connection not configured).","solutions":["Read run.last_error in the message: content_filter → adjust prompt; rate_limit → back off and retry; invalid_request → fix the referenced tool/resource.","For rate limits, retry with exponential backoff and fewer parallel agents.","Verify the deployment exists and the project connection has access to the tools configured on the agent.","For content filter hits, rephrase the input or the agent instructions."],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"try:\n    resp = await agent.on_messages(msgs, ct)\nexcept ValueError as e:\n    err = str(e)\n    if \"rate_limit\" in err:\n        await asyncio.sleep(backoff); retry = True\n    elif \"content_filter\" in err:\n        adjust_prompt(); retry = False\n    else:\n        raise","preventionTips":["Read run.last_error in the message to classify: rate limit vs content filter vs config.","Back off and retry on rate_limit/quota errors.","Keep deployment and tool-connection configuration valid; deleted deployments fail every run."],"tags":["azure","run-failure","retryable","azure-ai-agent"],"backgroundTag":null,"analyzedSha":"027ecf0a379bcc1d09956d46d12d44a3ad9cee14","analyzedAt":"2026-08-15T03:38:00.719Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}