Azure AI Agent Service maintains references to removed connections despite no active usage

I’m facing an issue where my Azure AI Agent Service seems to keep references to deleted connections even when they’re not being used anywhere.

When I check for existing agents using agent_service.agents.get_all_agents(), it returns empty results as expected:

{'object': 'list', 'data': [], 'first_id': None, 'last_id': None, 'has_more': False}

But after removing an Azure AI search connection with this command:

az ml connection delete -n search-connection-demo --resource-group demo-rg --workspace-name demo-workspace-01

The agent_service.agents.get_all_agents() method starts failing with a JSON decode error:

DecodeError: JSON is invalid: Expecting value: line 1 column 1 (char 0)
Content: Exception Type: ServiceInvocationException
Message: Service invocation failed!
Status Code: 404 NotFound
Error Code: UserError/NotFoundError
Reason Phrase: Connection search-connection-demo can't be found in this workspace

The strange part is that I don’t have any agents configured, so there shouldn’t be any references to this connection. Even when I create a new connection with a different name, operations like get_all_agents() or list_files() continue to fail because the service is still looking for the old connection name.

Right now my only solution is to avoid deleting the original connection entirely. Has anyone encountered this behavior before? Is there a way to clear these phantom references?

I’ve hit this same issue with Azure ML workspaces. Deleted resources leave metadata references that don’t get cleaned up properly. The Agent Service keeps its own config state that doesn’t sync when you delete connections through CLI. What worked for me: check the workspace config files directly. There’s usually leftover references in the workspace metadata that need manual cleanup. Try recreating the entire Agent Service instance instead of just making a new connection. The service initialization gets stuck on the original connection config even after you delete it. Also, hit the REST API directly to query agent service status and see what connections it thinks exist. That’s how I tracked down my phantom reference.

yeah, you’re probably right about the cache. try refreshing the whole workspace - that usually clears out ghost connections. also check if any dependent services are still holding onto those old refs. good luck!