azure/foundry-agent (Azure AI Foundry Agent)
This example demonstrates how to use the Azure Foundry Agent provider with promptfoo. This provider uses the @azure/ai-projects SDK and the v2 Responses agent runtime instead of the old threads/runs API.
You can run this example with:
npx promptfoo@latest init --example azure/foundry-agent
cd azure/foundry-agent
Setup
- Install the required Azure SDK packages:
npm install @azure/ai-projects @azure/identity
-
Set up your Azure credentials. The provider uses
DefaultAzureCredential, so you can authenticate via:- Azure CLI:
az login - Environment variables
- Managed Identity
- Service Principal
- Azure CLI:
-
Set your Azure AI Project URL:
export AZURE_AI_PROJECT_URL="https://your-project.services.ai.azure.com/api/projects/your-project-id"
Configuration
The provider uses the azure:foundry-agent:agent-name-or-id format. Agent names are preferred. Legacy agent IDs still work as a fallback lookup if the agent exists in the project.
providers:
- id: azure:foundry-agent:my-foundry-agent
config:
projectUrl: 'https://your-project.services.ai.azure.com/api/projects/your-project-id'
temperature: 0.7
max_tokens: 150
tests:
- vars:
question: 'What is the capital of France?'
assert:
- type: contains
value: 'Paris'
Configuration Options
These per-request settings are supported:
instructionstemperaturetop_pmax_tokens/max_completion_tokens(mapped tomax_output_tokens)response_formattoolstool_choicefunctionToolCallbacksmodelNamereasoning_effortverbositymetadatapassthroughmaxPollTimeMs
These request-time settings are ignored by the v2 runtime and should be configured on the Foundry agent instead:
tool_resourcesfrequency_penaltypresence_penaltyseedstoptimeoutMsretryOptions
Function Tool Callbacks
You can provide custom function callbacks just like with the regular Azure Assistant provider:
providers:
- id: azure:foundry-agent:my-foundry-agent
config:
projectUrl: 'https://your-project.services.ai.azure.com/api/projects/your-project-id'
functionToolCallbacks:
getCurrentWeather: |
(args) => {
const { location } = JSON.parse(args);
return `The weather in ${location} is sunny and 75°F`;
}
Differences from Regular Azure Assistant Provider
The main differences are:
- SDK Usage: Uses
@azure/ai-projectsSDK instead of direct HTTP calls - Authentication: Uses
DefaultAzureCredentialfor Azure authentication - Project URL: Requires an Azure AI Project URL instead of Azure OpenAI endpoint
- Provider Format: Uses
azure:foundry-agent:agent-name-or-idinstead ofazure:assistant:assistant-id - Runtime: Uses
responses.create(..., agent_reference)instead of threads/messages/runs
Environment Variables
AZURE_AI_PROJECT_URL: Your Azure AI Project URL (can be overridden in config)- Standard Azure credential environment variables (if not using other auth methods)
Error Handling
The provider includes the same comprehensive error handling as the regular Azure Assistant provider:
- Content filter detection and guardrails reporting
- Rate limit handling
- Service error detection
- Automatic retries for transient errors