A Python project for exploring Azure OpenAI with Microsoft's Agent Framework.
This project provides a starting point for building AI agents with Microsoft Agent Framework, Microsoft's SDK for building AI agents in Python. It is configured to work with Azure OpenAI services.
- Python 3.10 or higher
- An Azure account with access to Azure AI Foundry
- An Azure OpenAI resource with a deployed model
Run the setup script to create a Python virtual environment and install dependencies:
chmod +x setup.sh
./setup.shThis script will:
- Create a
.venvdirectory if it doesn't exist - Activate the virtual environment
- Install all packages from
requirements.txt
Copy the example environment file and fill in your Azure OpenAI credentials:
cp .env.example .envEdit the .env file with your values:
OPENAI_BASE_URL=https://your-resource-name.openai.azure.com/
OPENAI_API_KEY=your-api-key
OPENAI_CHAT_MODEL_ID=your-deployment-name
To obtain the required environment variables, follow these steps:
- Go to Azure AI Foundry
- Sign in with your Azure account
- Create a new project or select an existing one
- Navigate to your project dashboard
- Go to Deployments in the left sidebar
- Click + Deploy model and select Deploy base model
- Choose a model (e.g.,
gpt-4o,gpt-4o-mini, orgpt-35-turbo) - Configure the deployment settings and click Deploy
- Note the Deployment name - this is your
OPENAI_CHAT_MODEL_ID
- In your project, go to Overview or Settings
- Find the Azure OpenAI connection details
- Copy the Endpoint URL - this is your
OPENAI_BASE_URL - Copy the API Key - this is your
OPENAI_API_KEY
Alternatively, you can find these values in the Azure Portal:
- Go to Azure Portal
- Navigate to your Azure OpenAI resource
- Go to Keys and Endpoint in the left sidebar
- Copy the endpoint and one of the keys
After setting up the environment and configuring your credentials, run the example:
source .venv/bin/activate
python example.pyThe example demonstrates:
- Creating a chat client configured for Azure OpenAI
- Building a ChatAgent with custom instructions
- Getting a simple response from the agent
- Using streaming responses
After running the setup script, activate the virtual environment in future sessions:
source .venv/bin/activateTo deactivate the virtual environment:
deactivate