A fully managed platform in Microsoft Foundry for hosting, scaling, and securing AI agents built with any supported framework or model
Hi @Amol Garse
The cleanup sequence appears to be correct for the resources currently available via the documented Foundry Agent Service APIs.
Microsoft treats files uploaded to the Foundry Agent Service as persistent data and keeps them that way until you deliberately delete them. The specified procedure for cleaning up uploaded files is to delete the underlying file object, which removes the file from the Code Interpreter and its associated file-search configurations.
So this part of your cleanup is correct:
project.agents.delete_version(
agent_name=agent.name,
agent_version=agent.version,
)
openai.files.delete(file.id)
The Code Interpreter documentation states the same: applications should remove the agent version, the conversation, and the uploaded files when they are no longer needed. It doesn't include a separate operation to delete a Dataset for the assistant-* uri_file object that appears under Build > Data > Datasets.
Do not make use of the Azure Machine Learning data-asset APIs in relation to that portal entry unless Microsoft itself confirms that this managed Foundry Dataset is an AML data asset. The current Foundry documentation does not show equivalence between the two.
There is an important distinction between two objects here:
- The Files API object
This is the assistant-* file returned by openai.files.create(). Microsoft provides a supported delete operation for this object.
- The uri_file Dataset representation shown by the Foundry portal
I cannot find a currently documented Foundry Agent Service REST or Python SDK operation that independently deletes this portal Dataset representation after the underlying Files API object has been deleted.
I have not been able to locate a currently documented Foundry Agent Service REST or Python SDK operation which, on its own, deletes this portal Dataset representation after the underlying Files API object has been deleted.
I therefore do not advise using the portal's private/browser endpoints or the undocumented project routes in a production environment, since a 404 response from those routes does not prove that the Files API cleanup has failed.
A good way to verify this would be to invoke the Files API that has been documented after the file has been deleted and then check that the assistant-* file can no longer be retrieved; if the deletion has succeeded on the Files API but the entry in the Dataset still appears, this strongly indicates that you are dealing with either a portal/catalog representation which has delayed cleanup or with an internally managed resource that is separate from the Files API object.
Regarding data retention, Microsoft's current FAQ for Agent Service states that agent data such as files and vector stores continues to be retained unless it is explicitly deleted. However, I haven't found documentation outlining a separate retention or expiration period for the uri_file Dataset entries generated by the Code Interpreter, or a configurable retention policy for these entries.
You can't use the seven-day vector-store expiration that has been documented in this instance, since that behavior relates to conversation vector stores and is not applicable to Code Interpreter uri_file Dataset entries.
So for your four questions, based on the currently published API surface:
- Files API cleanup: openai.files.delete(file.id) is the documented operation and should be part of production cleanup.
- Separate Dataset deletion API: I can't find a documented/supported Agent Service API or SDK operation for independently deleting the assistant-* uri_file Dataset representation shown in the portal.
- Dataset propagation/retention period: I can't find a documented SLA or expiry period for that portal entry after deleting the Files API.
- Code Interpreter container: Code Interpreter runs in a Microsoft-managed isolated sandbox with a limited session lifetime; sessions are active for up to one hour. Generated artifacts that need to persist should therefore be downloaded before cleanup/session expiration, as you're already doing.
Since your requirement is specifically for production-grade deterministic deletion, I believe the other questions should be confirmed by the engineering team at the Foundry Agent Service: whether that Dataset entry is just an internal or catalog representation of the Files object which has been deleted, whether it undergoes an asynchronous garbage-collection period, or whether there is another deletion API that is not currently documented.
The most useful test case in this situation would be for a Microsoft moderator to escalate the issue: the Files API should return a success message when a file is deleted, the following retrieval should show that the file does not exist, but the Build > Data > Datasets section should still display assistant-<id>, of type uri_file, version 1, thus clearly identifying the discrepancy in the lifecycle.
References:
Use Code Interpreter with Microsoft Foundry agents
Foundry Agent Service FAQ - data storage and deletion
File search - file deletion behavior
Vector stores - lifecycle and expiration policies
=============================================================================
Help make this community better for everyone: If this answer helped or resolved your issue, please accept it or upvote it. If not, share more details in a comment so we can continue the discussion and find the right solution.