Prompt Chain

Test Azure AI Foundry agents with automated evaluation

A promptfoo example for evaluating Azure AI Foundry agents through the newer v2 Responses runtime.

Works with azurepromptfoo

92
Spark score
out of 100
Updated 14 days ago
Version 0.121.18

Add to Favorites

Why it matters

Integrate and test Azure AI Foundry agents using the v2 Responses runtime with promptfoo's evaluation framework, enabling developers to validate agent behavior, function callbacks, and responses against assertions before deployment.

Outcomes

What it gets done

01

Configure Azure AI Foundry agent provider with project URL and authentication credentials

02

Define test cases with variables and assertions to validate agent responses

03

Implement custom function tool callbacks for agent capabilities like weather lookups

04

Handle errors including content filters, rate limits, and service failures with automatic retries

Install

Add it to your toolbox

Run in your project directory:

curl -fsSL https://spark.entire.vc/get/pfoo-foundry-agent | bash

Steps

Steps in the chain

01
Install required Azure SDK packages
02
Set up Azure credentials
03
Set Azure AI Project URL

Overview

Foundry Agent

A promptfoo example for evaluating Azure AI Foundry agents through the v2 Responses runtime, using the @azure/ai-projects SDK and DefaultAzureCredential authentication. Use it to test an agent hosted in Azure AI Foundry's v2 runtime. Requires the Azure SDK packages, a project URL, and standard Azure credential authentication - not a plain Azure OpenAI endpoint.

What it does

This promptfoo example demonstrates the Azure Foundry Agent provider, which uses the @azure/ai-projects SDK and the v2 Responses agent runtime instead of the older threads/runs API used by the regular Azure Assistant provider. It targets an agent already defined in an Azure AI Foundry project via a provider ID in the form azure:foundry-agent:agent-name-or-id, with agent names preferred over legacy agent IDs.

When to use - and when NOT to

Use this example when you want to evaluate an agent hosted in Azure AI Foundry through the newer v2 runtime rather than the classic Assistant threads/runs API. It requires @azure/ai-projects and @azure/identity installed, an Azure AI Project URL, and DefaultAzureCredential-compatible authentication (Azure CLI login, environment variables, Managed Identity, or a Service Principal) - it is not usable against a plain Azure OpenAI endpoint the way the regular Assistant provider is.

Inputs and outputs

Per-request settings the v2 runtime supports include instructions, temperature, top_p, max_tokens/max_completion_tokens (mapped internally to max_output_tokens), response_format, tools, tool_choice, functionToolCallbacks, modelName, reasoning_effort, verbosity, metadata, passthrough, and maxPollTimeMs:

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'

Settings like tool_resources, frequency_penalty, presence_penalty, seed, stop, timeoutMs, and retryOptions are ignored by the v2 runtime and must instead be configured directly on the Foundry agent, not in the promptfoo config.

Integrations

Custom function tool callbacks work the same way as the regular Assistant provider, defined inline per provider config as a JavaScript function that parses the tool call's arguments and returns a result string, for example a getCurrentWeather callback that reads a location argument and returns a canned weather description for it. Scaffold the example with npx promptfoo@latest init --example azure/foundry-agent, then set AZURE_AI_PROJECT_URL (or pass projectUrl in config) before running an eval. The provider carries the same comprehensive error handling as the Assistant provider: content filter and guardrails detection, rate limit handling, service error detection, and automatic retries for transient failures.

Who it's for

Teams evaluating agents already built in Azure AI Foundry's v2 Responses runtime who need promptfoo test coverage without reimplementing the SDK authentication and error-handling logic themselves. Compared to the regular Azure Assistant provider, the biggest practical differences to plan for are the SDK (@azure/ai-projects instead of direct HTTP calls), the DefaultAzureCredential-based authentication, and the project-URL-based configuration in place of an Azure OpenAI endpoint.

Source README

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

  1. Install the required Azure SDK packages:
npm install @azure/ai-projects @azure/identity
  1. Set up your Azure credentials. The provider uses DefaultAzureCredential, so you can authenticate via:

    • Azure CLI: az login
    • Environment variables
    • Managed Identity
    • Service Principal
  2. 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:

  • instructions
  • temperature
  • top_p
  • max_tokens / max_completion_tokens (mapped to max_output_tokens)
  • response_format
  • tools
  • tool_choice
  • functionToolCallbacks
  • modelName
  • reasoning_effort
  • verbosity
  • metadata
  • passthrough
  • maxPollTimeMs

These request-time settings are ignored by the v2 runtime and should be configured on the Foundry agent instead:

  • tool_resources
  • frequency_penalty
  • presence_penalty
  • seed
  • stop
  • timeoutMs
  • retryOptions

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:

  1. SDK Usage: Uses @azure/ai-projects SDK instead of direct HTTP calls
  2. Authentication: Uses DefaultAzureCredential for Azure authentication
  3. Project URL: Requires an Azure AI Project URL instead of Azure OpenAI endpoint
  4. Provider Format: Uses azure:foundry-agent:agent-name-or-id instead of azure:assistant:assistant-id
  5. 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

FAQ

Common questions

Discussion

Questions & comments · 0

Sign In Sign in to leave a comment.