Integrate Azure OpenAI with Agency Swarm to ensure secure data processing and enhanced privacy.
Many organizations prioritize data privacy and are cautious about sharing their data with any third-parties. By leveraging Azure OpenAI, you can ensure that your data is processed only within your own secure Azure environment, and not even shared with OpenAI itself.
Running OpenAI models on Azure is the same as deploying your own open source model on any other cloud provider.
To use Azure OpenAI, you need to configure the client to connect to your Azure OpenAI resource as follows:
Copy
Ask AI
import osfrom openai import AsyncAzureOpenAI# Create a custom AsyncOpenAI client for Azureazure_agent = AsyncAzureOpenAI( api_key=os.getenv("AZURE_OPENAI_KEY"), azure_endpoint=os.getenv("AZURE_ENDPOINT"), api_version=os.getenv("AZURE_API_VERSION"),)
2
Update Agent Model Parameters
Set the model parameter inside each agent to use your custom client and model:
Copy
Ask AI
from agency_swarm import Agent, OpenAIChatCompletionsModel# Define your agent and pass the custom client into the modelazure_agent = Agent( name="AzureAgent", instructions="You are a helpful assistant", model=OpenAIChatCompletionsModel( model="gpt-4.1", openai_client=azure_agent, ),)
Model deployment name might be different from the standard OpenAI model names. It is set by you when you deploy a model to Azure.
3
Run Your Agency
After configuring the client and updating the agents, you can run your agency as usual: