-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Labels
bugSomething isn't workingSomething isn't workingpythonv1.0Features being tracked for the version 1.0 GAFeatures being tracked for the version 1.0 GA
Description
Description
I have a chatbot application, with Foundry agents that are already created (and I don't want or shouldn't create agents on the fly).
If a user uploads a csv file, I want to be able to make simple data analysis questions (for example, what is the average of column x)
However, when uploading things to the Agents Client in Azure AI and using that file in the codeInterpreter I still get a: "Please upload the file, and I will analyze the data for you." answer, I have looked at multiple documentation pages and this seems to be the best approach but I cannot make it work
Code Sample
import asyncio
import os
from dotenv import load_dotenv
from azure.identity.aio import AzureCliCredential
from agent_framework import ChatAgent, ChatMessage, TextContent, DataContent
from agent_framework.azure import AzureAIAgentClient
from agent_framework import HostedCodeInterpreterTool
import os
import asyncio
from azure.ai.agents.aio import AgentsClient
from azure.ai.agents.models import FilePurpose
from azure.identity.aio import DefaultAzureCredential
import base64
async def check_models_functioning():
load_dotenv() # Load variables from .env into environment
foundry_project_endpoint = os.getenv('FOUNDRY_PROJECT_ENDPOINT')
if not foundry_project_endpoint:
raise ValueError("Missing FOUNDRY_PROJECT_ENDPOINT in environment/.env")
filename = os.getenv('SAMPLE_CSV_FILE')
async with AzureCliCredential() as cred:
agents_client = AgentsClient(endpoint=foundry_project_endpoint, credential=cred)
async with agents_client:
uploaded = await agents_client.files.upload_and_poll(
file_path=filename,
purpose=FilePurpose.AGENTS,
)
print("file_id:", uploaded.id)
# AzureCliCredential is async and should be closed properly
async with AzureCliCredential() as credential:
agent = ChatAgent(
chat_client=AzureAIAgentClient(
agent_id=os.getenv('GPT-4O-AGENT'),
project_endpoint=foundry_project_endpoint,
model_deployment_name="gpt-4o",
credential=credential,
),
instructions="You are a helpful assistant that can analyze and read attached data files using Python code.",
tools=HostedCodeInterpreterTool(inputs=[{"file_id": uploaded.id}])
)
message = ChatMessage(role='user', contents=[TextContent(f'Hello! Analyze the attached file How many records do you find here? What is the average number of X?')])
result = await agent.run(message)
print(result.text)
def main():
asyncio.run(check_models_functioning())
if __name__ == "__main__":
main()Error Messages / Stack Traces
Package Versions
agent-framework-core==1.0.0b251218, agent-framework-azure-ai==1.0.0b251218, agent-framework-anthropic==1.0.0b251223
Python Version
Python 3.10
Additional Context
No response
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't workingpythonv1.0Features being tracked for the version 1.0 GAFeatures being tracked for the version 1.0 GA
Type
Projects
Status
In Review