valutazione di Microsoft Foundry

FoundryEvalsconnette le API di valutazione di Agent Framework al servizio di valutazione gestito di Microsoft Foundry. Fornisce valutatori di qualità, sicurezza, utilizzo degli strumenti, comportamento degli agenti e rubriche, con report archiviati disponibili nel portale Foundry.

Per EvalItemi controlli locali, gli analizzatori personalizzati e le strategie di suddivisione delle conversazioni, vedere Valutazione dell'agente.

Prerequisites

  • Un progetto Microsoft Foundry e la distribuzione del modello.
  • Endpoint Foundry con ambito di progetto.
  • Autorizzazione per inviare valutazioni e leggere report.

Valutare le risposte o le query di test

Configurare FoundryEvals, quindi valutare le risposte già generate o consentire EvaluateAsync l'esecuzione dell'agente per ogni query.

string endpoint = Environment.GetEnvironmentVariable("FOUNDRY_PROJECT_ENDPOINT") ?? throw new InvalidOperationException("FOUNDRY_PROJECT_ENDPOINT is not set.");
string deploymentName = Environment.GetEnvironmentVariable("FOUNDRY_MODEL") ?? "gpt-4o-mini";

// WARNING: DefaultAzureCredential is convenient for development but requires careful consideration in production.
// In production, consider using a specific credential (e.g., ManagedIdentityCredential) to avoid
// latency issues, unintended credential probing, and potential security risks from fallback mechanisms.
AIProjectClient projectClient = new(new Uri(endpoint), new DefaultAzureCredential());

AIAgent agent = projectClient.AsAIAgent(
    model: deploymentName,
    instructions: "You are a helpful assistant that provides clear, accurate answers.",
    name: "QualityTestAgent");

// Configure Foundry evaluators.
FoundryEvals foundryEvals = new(projectClient, deploymentName, FoundryEvals.Relevance, FoundryEvals.Coherence);

// --- Pattern 1: Run agent, then evaluate pre-existing responses ---
string[] queries = ["What is photosynthesis?", "Explain gravity in simple terms."];

AgentResponse[] responses = new AgentResponse[queries.Length];
for (int i = 0; i < queries.Length; i++)
{
    responses[i] = await agent.RunAsync(queries[i]);
}

AgentEvaluationResults results1 = await agent.EvaluateAsync(responses, queries, foundryEvals);

Console.WriteLine("=== Pattern 1: Evaluate pre-existing responses ===");
PrintResults(results1, queries);

// --- Pattern 2: Run + evaluate in one call ---
string[] queries2 = ["What causes rain?", "Why is the sky blue?"];
AgentEvaluationResults results2 = await agent.EvaluateAsync(queries2, foundryEvals);

Console.WriteLine("=== Pattern 2: Run + evaluate in one call ===");
PrintResults(results2, queries2);

Gli esempi di .NET illustrano anche i valutatori di rubriche Foundry e le soglie di qualità per singola dimensione.

Valutare un agente

Passa risposte esistenti o query di test a evaluate_agent(). I risultati includono i conteggi di pass/fail e l'URL del report Foundry.

async def main() -> None:
    # 1. Set up the FoundryChatClient
    chat_client = FoundryChatClient(
        project_endpoint=os.environ["FOUNDRY_PROJECT_ENDPOINT"],
        model=os.environ.get("FOUNDRY_MODEL", "gpt-4o"),
        credential=AzureCliCredential(),
    )

    # 2. Create an agent with tools
    agent = Agent(
        client=chat_client,
        name="travel-assistant",
        instructions=(
            "You are a helpful travel assistant. Use your tools to answer questions about weather and flights."
        ),
        tools=[get_weather, get_flight_price],
    )

    # 3. Create the evaluator — provider config goes here, once
    evals = FoundryEvals(client=chat_client)

    # =========================================================================
    # Pattern 1: evaluate_agent(responses=...) — evaluate a response you already have
    # =========================================================================
    print("=" * 60)
    print("Pattern 1: evaluate_agent(responses=...) — evaluate existing response")
    print("=" * 60)

    query = "How much does a flight from Seattle to Paris cost?"
    response = await agent.run(query)
    print(f"Agent said: {response.text[:100]}...")

    # Pass agent= so tool definitions are extracted, queries= for the eval item context
    results = await evaluate_agent(
        agent=agent,
        responses=response,
        queries=[query],
        evaluators=FoundryEvals(
            client=chat_client,
            evaluators=[FoundryEvals.RELEVANCE, FoundryEvals.TOOL_CALL_ACCURACY],
        ),
    )

    for r in results:
        print(f"Status: {r.status}")
        print(f"Results: {r.passed}/{r.total} passed")
        print(f"Portal: {r.report_url}")
        if r.all_passed:
            print("[PASS] All passed")
        else:
            print(f"[FAIL] {r.failed} failed")

Altri esempi riguardano la valutazione della traccia, la valutazione delle chiamate agli strumenti, la valutazione a più turni, la valutazione del flusso di lavoro, i provider misti e le rubriche personalizzate di Foundry.

Annotazioni

L'integrazione della valutazione di Microsoft Foundry non è attualmente disponibile per Agent Framework Go. Vedere il repository di Agent Framework Go per lo stato più aggiornato.

Soglie di qualità

Aggiungere set di dati, distribuzioni di modelli, versioni dell'analizzatore e versioni rubriche quando i risultati devono essere confrontabili tra le esecuzioni. Usa gli helper per l'asserzione dei risultati per far fallire la CI quando si verifica una regressione nelle metriche richieste.

Passaggi successivi