examples/azure/foundry-agent/README.md
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
npm install @azure/ai-projects @azure/identity
Set up your Azure credentials. The provider uses DefaultAzureCredential, so you can authenticate via:
az loginSet your Azure AI Project URL:
export AZURE_AI_PROJECT_URL="https://your-project.services.ai.azure.com/api/projects/your-project-id"
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'
These per-request settings are supported:
instructionstemperaturetop_pmax_tokens / max_completion_tokens (mapped to max_output_tokens)response_formattoolstool_choicefunctionToolCallbacksmodelNamereasoning_effortverbositymetadatapassthroughmaxPollTimeMsThese request-time settings are ignored by the v2 runtime and should be configured on the Foundry agent instead:
tool_resourcesfrequency_penaltypresence_penaltyseedstoptimeoutMsretryOptionsYou 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`;
}
The main differences are:
@azure/ai-projects SDK instead of direct HTTP callsDefaultAzureCredential for Azure authenticationazure:foundry-agent:agent-name-or-id instead of azure:assistant:assistant-idresponses.create(..., agent_reference) instead of threads/messages/runsAZURE_AI_PROJECT_URL: Your Azure AI Project URL (can be overridden in config)The provider includes the same comprehensive error handling as the regular Azure Assistant provider: