Azure OpenAI

Updated

Use Azure OpenAI as the LLM in a Conversational AI Platform agent.

Preview documentation

You're reading the Conversational AI Platform (Preview) docs. Switch to Main.

Azure OpenAI service provides REST API access to OpenAI's powerful language models through Microsoft Azure's secure infrastructure.

Sample configuration

The following example shows how to configure Azure OpenAI as the agent's LLM when you create or update an agent. For a complete example, see Create an agent and start a session.

Azure OpenAI supports BYOK only. It isn't available in managed mode. Store your Azure OpenAI API key in a secret set, and refer to it from the agent. For details, see Use your own provider keys.

from agora_agent import Agent, AzureOpenAI, secret_ref

# client is your configured Agora client
agent = (
    Agent(client=client)
    .with_stt(...)  # configure your ASR vendor
    .with_llm(
        AzureOpenAI(
            api_key=secret_ref("support_prod", "azure_openai"),
            endpoint="https://your-resource-name.openai.azure.com",
            deployment_name="YOUR_DEPLOYMENT_NAME",
            api_version="AZURE_API_VERSION",
            model="gpt-4o-mini",
            max_history=32,
            failure_message="Please hold on a second.",
            system_messages=[
                {"role": "system", "content": "You are a friendly support agent for Acme. Keep your answers short."}
            ],
        )
    )
    .with_tts(...)  # configure your TTS vendor
)
import { Agent, AzureOpenAI, secretRef } from 'agora-agents';

// client is your configured Agora client
const agent = new Agent({ client })
  .withStt(/* configure your ASR vendor */)
  .withLlm(
    new AzureOpenAI({
      apiKey: secretRef('support_prod', 'azure_openai'),
      endpoint: 'https://your-resource-name.openai.azure.com',
      deploymentName: 'YOUR_DEPLOYMENT_NAME',
      apiVersion: 'AZURE_API_VERSION',
      model: 'gpt-4o-mini',
      maxHistory: 32,
      failureMessage: 'Please hold on a second.',
      systemMessages: [
        { role: 'system', content: 'You are a friendly support agent for Acme. Keep your answers short.' },
      ],
    }),
  )
  .withTts(/* configure your TTS vendor */);
// client is your configured Agora client
maxHistory := 32
agent := agentkit.NewAgent(client).
	WithStt( /* configure your ASR vendor */ ).
	WithLlm(vendors.NewAzureOpenAI(vendors.AzureOpenAIOptions{
		APIKey:         agentkit.SecretRef("support_prod", "azure_openai"),
		Endpoint:       "https://your-resource-name.openai.azure.com",
		DeploymentName: "YOUR_DEPLOYMENT_NAME",
		APIVersion:     "AZURE_API_VERSION",
		Model:          "gpt-4o-mini",
		MaxHistory:     &maxHistory,
		FailureMessage: "Please hold on a second.",
		SystemMessages: []map[string]interface{}{
			{"role": "system", "content": "You are a friendly support agent for Acme. Keep your answers short."},
		},
	})).
	WithTts( /* configure your TTS vendor */ )

Set credential.mode to byok and credential.fields.api_key to a reference to the key. In the following example, the key is stored as azure_openai in the support_prod set:

"llm": {
  "credential": {
    "mode": "byok",
    "fields": {
      "api_key": "$secrets.support_prod.azure_openai"
    }
  },
  "vendor": "azure",
  "style": "openai",
  "model": "gpt-4o-mini",
  "url": "https://your-resource-name.openai.azure.com/openai/deployments/YOUR_DEPLOYMENT_NAME/chat/completions?api-version=AZURE_API_VERSION",
  "max_history": 32,
  "failure_message": "Please hold on a second."
}

Set the system prompt and the greeting with the agent's instructions and greeting, not in the llm block.

Key parameters

The llm block takes the following fields. In the SDKs, the LLM class sets them from its options. The SDK builds the endpoint URL from the resource endpoint, the deployment name, and the API version, and sets the vendor to azure.

llm
vendorstring
required

Set to azure.

credentialobject
required

Set mode to byok and fields.api_key to a $secrets.<set>.<key> reference to your Azure OpenAI API key. Find your API key in the Azure portal under your OpenAI resource.

stylestring
optional

Set to openai.

modelstring
required

Use the deployment name you created in Azure, not the base model name.

urlstring
required

Replace your-resource-name with your Azure resource name and YOUR_DEPLOYMENT_NAME with your model deployment name.

For complete llm block options, see Create an agent. For advanced configuration options, deployment setup, and detailed parameter descriptions, see the Azure OpenAI API documentation.