I’m having trouble with Azure AI Agent Service maintaining references to removed connections. Even when my agent service has no active agents (confirmed by running client.agents.get_agent_list() which returns an empty result), deleting an Azure AI Search connection breaks all agent operations.
# This works fine and shows empty agents list
result = client.agents.get_agent_list()
print(result) # Returns: {'object': 'list', 'data': [], 'first_id': None, 'last_id': None, 'has_more': False}
The issue starts after removing the connection using Azure CLI:
az ml connection delete -n search-connection-main --resource-group my-resource-group --workspace-name my-workspace
After deletion, any agent operation fails with a 404 error:
DecodeError: JSON is invalid - Connection search-connection-main can't be found in this workspace
Status Code: 404 NotFound
Error Code: UserError/NotFoundError
Even creating a new connection with different name doesn’t help. The service still tries to access the deleted connection for basic operations like get_agent_list() or list_files(). My current workaround is keeping the original connection alive, but this seems wrong. Has anyone found a proper solution for this reference issue?
The Azure AI Agent Service maintains persistent references to deleted Azure AI Search connections, causing 404 errors even after the connection is removed using the Azure CLI and despite an empty agent list (client.agents.get_agent_list() returning an empty list). Creating a new connection does not resolve the issue; the service continues to attempt access to the deleted connection. The current workaround involves keeping the original connection active, which is undesirable.
Understanding the “Why” (The Root Cause):
The Azure AI Agent Service appears to cache connection metadata internally. The standard Azure CLI az ml connection delete command does not trigger a complete cleanup of these internal references. The SDK and CLI operate at different levels of abstraction, resulting in a disconnect between the apparent deletion at the CLI level and the persistent references within the service’s configuration. This is a common issue with cloud services that maintain internal caches or persistent configurations.
Step-by-Step Guide:
Automate Connection Management: Instead of directly addressing the cleanup problem (which may be unreliable or impossible), focus on creating a fully automated workflow for managing Azure AI Search connections within your Azure AI Agent Service. This approach avoids the underlying issue entirely. This workflow should encompass the entire lifecycle: creation, usage, and deletion.
Implement a Wrapper Script or Function: Write a script (Python, Bash, etc.) or a function that encapsulates the connection management. This script will:
Create Connection: Create the Azure AI Search connection using the Azure CLI or SDK. Capture the connection’s details (name, ID, etc.).
Agent Operations: Perform all necessary agent operations using the connection.
Delete Connection: Delete the connection using the Azure CLI.
Verification: Add a verification step after deletion. This step can poll the Azure AI Agent Service (using client.agents.get_agent_list() or similar) until it confirms the absence of any references to the deleted connection. Implement retry logic with timeouts to handle potential transient delays. If references persist after a defined period, the script should alert you to the problem.
Error Handling: Implement robust error handling to catch and report any failures during connection creation, deletion, or verification.
Integrate into Your Workflow: Integrate the automated connection management script into your existing deployment or operational processes.
Common Pitfalls & What to Check Next:
Insufficient Retry Logic: Ensure your verification step includes sufficient retry logic with appropriate timeout periods. The cleanup process within the Azure AI Agent Service might not be instantaneous.
Network Issues: Network connectivity problems can interfere with the verification process. Monitor network connectivity during the automation workflow.
Azure Service Issues: Occasional service disruptions within Azure could impact the cleanup. Monitor Azure service health status.
Permissions: Ensure your service principal or user has the necessary permissions to create, use, and delete Azure AI Search connections and to access the Azure AI Agent Service.
Still running into issues? Share your (sanitized) config files, the exact command you ran, and any other relevant details. The community is here to help!
sounds like the agent service is holding onto old connection refs. maybe try clearing config files in your local .azure dir or just restart your python session. these services can sometimes keep old metadata even after deleting via cli.