Share via

Assistants API vs. Prompt Agents. How to access files generated by Code Interpreter tool in Prompt Agents? How to ensure file persistence of such generated files?

GenixPRO 206 Reputation points
2026-06-04T02:37:14.25+00:00

Hi.

  1. We're testing migration from Assistants API to Prompt Agents.
  2. In our previous Azure OAI Assistants implementation, Code Interpreter generated files were returned as file IDs and we could retrieve them later via. the Assistants/Files API.
  3. After migrating to Azure AI Foundry Agents / Responses API, generated files from Code Interpreter are returned as sandbox links {such as sandbox:/mnt/data/file.png}, with container_file_citation/container_id metadata. These files appear to live in a temporary container and expire quickly. Is this expected behavior for Foundry Agents Code Interpreter output?

3.1 In Assistants API, generated files resided permanently in Data files.

  1. For a production chat app, what is the recommended way to persist generated files/images so users can view them later from chat history? Is there a supported option for durable file IDs/URLs, or should our backend immediately download the container file and upload it to our own persistent storage?
  2. Note: We're testing 2 agents concurrently, and have attached memory to both respectively. However, no files are generated & saved in this memory. We've also attached vector store to each agent to process files for RAG etc.

Thnx.

Azure OpenAI in Foundry Models

1 answer

Sort by: Most helpful
  1. AI answer

    2026-06-04T02:37:49.0066667+00:00

    For Foundry Prompt Agents and the Code Interpreter tool, the behavior being observed is expected and differs from the classic Assistants API.

    1. Behavior difference vs. classic Assistants API
    • In classic Azure OpenAI Assistants, Code Interpreter output files are stored as durable “files” and exposed via file IDs that can be retrieved later through the Files API.
    • In Azure AI Foundry agents (Prompt Agents / Hosted Agents), Code Interpreter runs in a sandboxed container session. Files created there are container-scoped and exposed as sandbox paths (for example, sandbox:/mnt/data/...) plus container/file metadata. These are not automatically promoted to durable “data files” and are expected to be temporary.
    • The sandbox is a dynamic session with a limited lifetime and is isolated per session. Files in that sandbox are therefore ephemeral by design.

    Relevant behaviors:

    • Code Interpreter runs in a Microsoft-managed sandbox using dynamic sessions in Azure Container Apps.
    • Each session is isolated and has a limited lifetime (idle timeout and max duration).
    • Files in the sandbox are accessible to the Python runtime and can be returned as downloadable outputs, but they are not guaranteed to persist beyond the session.

    [Context: Code Interpreter tool for Microsoft Foundry agents – Sandboxed execution environment]

    1. How to access files generated by Code Interpreter in Prompt Agents

    For Prompt Agents / Foundry agents, the supported pattern is:

    • When Code Interpreter generates a file, the agent response includes annotations with container/file metadata (for example, content[]._meta.container_id and file IDs/names).
    • Use the container and file APIs to list and download those files while the container is still active.

    Typical flow (REST):

    1. List files in the container
    • Extract container_id from the tools/call response metadata.
    • Call the Container Files API:
        GET {project_endpoint}/containers/{container_id}/files?api-version=v1
        Authorization: Bearer {token}
      
    • The response returns file names and IDs for all files in that container.
    1. Download a specific file
    • Use the file name/ID from step 1 with the File API download endpoint (as documented under the File API download endpoint for Foundry).

    This is the recommended way to retrieve Code Interpreter outputs for Foundry agents.

    [Context: Curate intent-based toolbox in Foundry (preview) (rest-api)] [Context: Code Interpreter tool for Microsoft Foundry agents (csharp)] [Context: Code Interpreter tool for Microsoft Foundry agents (python)]

    1. Persistence model and production recommendation
    • The container sandbox is not a durable storage mechanism. Files there are tied to the session and will expire when the session/container is cleaned up.
    • There is no indication in the provided context that Foundry agents automatically convert these container files into durable, globally addressable file IDs like the classic Assistants Files API.

    For a production chat application that needs persistent access to generated files (charts, images, CSVs) from chat history, the recommended pattern based on the documented APIs is:

    1. Immediately after receiving a response that includes Code Interpreter file annotations:
      • Parse the container/file metadata from the response.
      • Call the Container Files API to list and then the File API to download the relevant files.
    2. Store the downloaded files in an application-controlled persistent store:
      • For example, Azure Blob Storage, a database, or any other long-term storage.
      • Persist the mapping between the chat message (or conversation ID) and the stored file URL/path in the app’s own data model.
    3. When rendering chat history:
      • Use the app’s own persistent URLs/paths to serve those files to users.

    This pattern ensures durability and user access independent of the sandbox lifecycle.

    1. Memory and vector stores vs. file persistence
    • The “memory” attached to agents and the vector stores used for RAG are separate concepts from Code Interpreter’s sandbox file system.
    • The context only indicates that Code Interpreter can access attached files and generate new files in the sandbox; it does not state that generated files are automatically stored into memory or vector stores.
    • Therefore, not seeing generated files “saved in memory” is consistent with the documented behavior. Memory/vector stores are for knowledge and retrieval, not for automatic file persistence.
    1. Summary
    • Yes, ephemeral sandbox file behavior for Code Interpreter outputs in Foundry agents is expected.
    • To persist files for production use:
      • Use container/file APIs to download outputs as soon as they are generated.
      • Store them in application-managed durable storage.
      • Reference those stored locations in chat history.
    • Memory and vector stores do not automatically capture or persist Code Interpreter-generated files.

    References:

    AI-generated content may be incorrect. Read our transparency notes for more information.

    Was this answer helpful?

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.