Skip to content

Python + Foundry: Sending Dynamic Files to Code Interpreter in Foundry #45140

@mitokic

Description

@mitokic

This was initially logged in the Microsoft Agent Framework GH. But they told me to log it here instead since this is a Foundry specific request. microsoft/agent-framework#3816

My request has to do with connecting to code interpreter inside of a custom Microsoft Agent Framework agent. While it's about building a custom agent in Agent Framework, I think the feature idea should apply more broadly to code interpreter tool use across Foundry.

When using HostedCodeInterpreterTool with a AzureAIClient in Python, you always have to specify the file IDs the code interpreter tool has access to when initializing the agent. This restricts adding any new file IDs in the future, because every time you add a new file ID and re-run the agent locally it will create a new agent version.

I think there should be an option to make the file IDs dynamic. Meaning at agent runtime you could feed it a list of file IDs to use. Each time the agent is called a different set of file IDs can be fed for analysis by code interpreter. Without always incrementing the agent version.

This could open up new ways to use the code interpreter. Making it more of a general-purpose data analysis engine that can be fed files from other agents/workflows orchestrators that could call a subagent as a tool that just has access to code interpreter and can be fed new file IDs at run time.

Right now, the only way I know of having this dynamic code interpreter functionality is by using AzureOpenAIResponsesClient instead of AzureAIClient. Both are connected to the same Foundry resource in Azure, but the AzureOpenAIResponsesClient client lets me pass new file IDs to the agent at runtime without always creating new agent version, since AzureOpenAIResponsesClient agents are not automatically saved in Foundry as "prompt" agent like AzureAIClient are. This works well but forces me to use the specific "Azure OpenAI Files" datastore within Foundry V1 instead of the newer datasets store within Foundry V2.

Is there a way to do this in AzureAIClient instead of AzureOpenAIResponsesClient without always creating a new agent version at runtime? If not, will the "Azure OpenAI Files" datastore within Foundry V1 be supported long term for use within AzureOpenAIResponsesClient agents? Will the "Azure OpenAI Files" datastore within Foundry V1 eventually be viewable within the Foundry V2 UI? Right now you can only see it within Foundry V1.

Code Example in Agent Framework

import os
from agent_framework import HostedCodeInterpreterTool 
from agent_framework.azure import AzureAIClient
from azure.identity.aio import AzureCliCredential

ci = HostedCodeInterpreterTool(inputs=[{"file_id": "assistant-123"}, 
                                       {"file_id": "assistant-456"}, 
                                       {"file_id": "assistant-789"}])

# Run the agent
async with AzureCliCredential() as credential:
    client = AzureAIClient(
        credential=credential,
        project_endpoint=os.environ["AZURE_AI_FOUNDRY_PROJECT_ENDPOINT"],
        model_deployment_name=os.environ["AZURE_AI_FOUNDRY_MODEL_DEPLOYMENT_NAME"],
        agent_name= "CI-Agent-Test-1",
        agent_description="An agent to analyze csv files using code interpreter tool"
    )

    async with client.as_agent(
        instructions="""You are a helper that analyzes csv files using a code interpreter tool.""",
        tools=[ci]
    ) as agent:
        result = await agent.run("Summarize the files")
        print(f"Response: {result.text}\n")


# The above code works well. But if you comment out or add a new file id in the list, it will always create a new agent version in Foundry. Which is not ideal!

Metadata

Metadata

Assignees

No one assigned

    Labels

    customer-reportedIssues that are reported by GitHub users external to the Azure organization.needs-triageWorkflow: This is a new issue that needs to be triaged to the appropriate team.questionThe issue doesn't require a change to the product in order to be resolved. Most issues start as that

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions