Azure AI Agent Service保留已删除连接引用致代理操作失败
问题分析与解决方案
问题现象
- Azure AI Agents服务无代理时,调用
project_client.agents.list_agents()可正常返回空结果:{'object': 'list', 'data': [], 'first_id': None, 'last_id': None, 'has_more': False}
- 执行以下命令删除指定Azure AI Search连接后:
再次调用az ml connection delete -n mmai-hub04-fvye-connection-AISearch --resource-group mmai04-rg --workspace-name mmai-hub04-prj01-fvyeproject_client.agents.list_agents()触发404错误,提示无法找到已删除的连接,错误详情如下:DecodeError: JSON is invalid: Expecting value: line 1 column 1 (char 0) Content: Exception Type: ServiceInvocationException Message: Service invocation failed! Request: GET account-rp.vienna-eastus.svc/rp/workspaces/subscriptions/eca2eddb-0f0c-4351-a634-52751499eeea/resourceGroups/mmai04-rg/providers/Microsoft.MachineLearningServices/workspaces/mmai-hub04-prj01-fvye/connections/mmai-hub04-fvye-connection-AISearch Status Code: 404 NotFound Error Code: UserError/NotFoundError Reason Phrase: Connection mmai-hub04-fvye-connection-AISearch can't be found in this workspace Response Body: { "error": { "code": "UserError", "severity": null, "message": "Connection mmai-hub04-fvye-connection-AISearch can't be found in this workspace", "messageFormat": null, "messageParameters": null, "referenceCode": null, "detailsUri": null, "target": null, "details": [], "innerError": { "code": "NotFoundError", "innerError": null }, "debugInfo": null, "additionalInfo": null }, "correlation": { "operation": "00a4a960f4e36533e697a9470a71a936", "request": "41751bf0ad5eda6a" }, "environment": "eastus", "location": "eastus", "time": "2024-12-31T11:58:31.2013859+00:00", "componentName": "account-rp", "statusCode": 404 } - 创建新的Azure AI Search连接后,
list_agents()、list_files()等代理操作仍因找不到原连接失败,仅保留原连接可临时解决问题。
解决步骤
1. 清理工作空间内的连接引用残留
登录Azure机器学习工作室,进入目标工作空间,检查代理模板、环境配置或全局设置中是否存在对已删除连接mmai-hub04-fvye-connection-AISearch的引用,清理相关配置。
同时使用Azure CLI查询工作空间内所有连接资源,确认无残留引用:
az ml connection list --resource-group mmai04-rg --workspace-name mmai-hub04-prj01-fvye --query "[].{name:name, type:type}"
2. 重置客户端会话
重新初始化project_client实例,清除客户端缓存的旧连接信息:
from azure.ai.ml import MLClient from azure.identity import DefaultAzureCredential ml_client = MLClient( DefaultAzureCredential(), subscription_id="eca2eddb-0f0c-4351-a634-52751499eeea", resource_group_name="mmai04-rg", workspace_name="mmai-hub04-prj01-fvye" ) project_client = ml_client.agents
3. 排查服务后台配置
在Azure门户进入Azure AI Agents对应的资源,检查是否有默认连接配置绑定了已删除的连接名称。若无法手动清理,可提交Azure支持工单,请求排查后台引用残留。
4. 通过Azure资源管理器清理残留
访问Azure资源管理器,定位到目标工作空间的connections节点,确认已删除连接不存在后,检查agents、flows等资源的配置文件,手动删除对原连接的引用。
内容的提问来源于stack exchange,提问作者Mauro Minella
相关产品推荐
相关产品推荐

