Items marked (preview) in this article are currently in public preview. This preview is provided without a service-level agreement, and we don’t recommend it for production workloads. Certain features might not be supported or might have constrained capabilities. For more information, see Supplemental Terms of Use for Microsoft Azure Previews.
Prerequisites
- Complete the cloud evaluation prerequisites and client setup.
- Stored response IDs for response evaluation, or an Application Insights resource connected to your Foundry project for trace evaluation.
- OpenTelemetry spans that meet the trace data requirements when you evaluate traces.
Evaluate interactions by response ID
Retrieve and evaluate Foundry agent responses by response IDs using theazure_ai_responses data source type. Use this scenario to evaluate specific agent interactions after they occur.
A response ID is a unique identifier returned each time a Foundry agent generates a response. You can collect response IDs from agent interactions by using the Responses API or from your application’s trace logs. Provide the IDs inline as file content.
Agent response evaluations (
azure_ai_responses) support only file_content for providing response IDs. The file_id source type isn’t supported and returns a 400 Bad Request error.Collect response IDs
Each call to the Responses API returns a response object with a uniqueid field. Collect these IDs from your application’s interactions, or generate them directly:
Create evaluation and run
Evaluate traces (preview)
Evaluate agent interactions that Application Insights already captured. Use theazure_ai_traces data source type. This scenario is useful for post-deployment evaluation of real production traffic. You select traces from your monitoring pipeline and run evaluators against them without replaying any requests.
Trace evaluation is the recommended approach for evaluating agents not built with the Microsoft Foundry Agent Service - including LangChain and custom frameworks. As long as your agent emits OpenTelemetry spans following the GenAI semantic conventions to Application Insights, trace evaluation can assess its interactions by using the same evaluators available for Foundry agents.
- By trace IDs - Evaluate specific agent interactions by providing their
operation_Idvalues from Application Insights. - By agent filter - Automatically discover and evaluate recent traces for a given agent, without manually collecting trace IDs.
Intelligent sampling
Trace evaluation supports intelligent sampling, which selects a representative subset of traces for evaluation instead of evaluating every captured trace. Turn on the Intelligent sampling toggle in the Foundry portal when you configure a trace evaluation run. Intelligent sampling reduces evaluation cost while preserving trace diversity - ensuring that edge cases, error paths, and varied conversation patterns are included in the evaluated set.How intelligent sampling works
The sampling algorithm uses a MinHash farthest-first diversity approach that runs in multiple stages:- Exact deduplication - Removes duplicate traces from the pool.
- Hard filters - Removes broken sessions, truncated traces, and malformed tool calls that aren’t suitable for evaluation.
- Aggregation - Combines trace-level signals into a unified representation.
- MinHash farthest-first selection - Computes locality-sensitive hashes (MinHash signatures) of user text to estimate similarity between traces, then iteratively selects the most dissimilar trace from the remaining pool. Each successive pick maximizes distance from all previously selected traces.
- Evaluation and benchmarks - Maximizes coverage of the input distribution so evaluation scores reflect real-world diversity.
- Rubric generation - Produces more focused and actionable rubrics by exposing diverse conversation patterns.
- Finetuning dataset curation - Selects traces that help models learn more efficiently.
Intelligent sampling example
Trace data requirements
Trace evaluation requires your agent to emit spans that follow the OpenTelemetry semantic conventions for generative AI. Specifically, the evaluation service readsinvoke_agent spans from Application Insights and extracts conversation data from their attributes.
The following span attributes are used:
If
gen_ai.input.messages and gen_ai.output.messages are empty or missing, quality evaluators (coherence, fluency, relevance, intent resolution) return score=None. Safety evaluators (violence, self-harm, sexual, hate/unfairness) can still produce scores with partial data but they might not produce meaningful results.[tracing] extra to enable automatic span emission:
Prerequisites for trace evaluation
In addition to the general prerequisites, trace evaluation requires:- An Application Insights resource connected to your Foundry project. See Set up tracing in Microsoft Foundry.
- The project’s managed identity must have the Log Analytics Reader role on both the Application Insights resource and its linked Log Analytics workspace. If the tables that store your traces are protected (their protection level is set to Protected), also assign the Privileged Monitoring Data Reader role at the same scopes so the service can read the protected trace tables.
- The
azure-monitor-queryPython package (only needed if you collect trace IDs manually).
APPINSIGHTS_RESOURCE_ID— The Application Insights resource ID (for example,/subscriptions/<subscription_id>/resourceGroups/<rg_name>/providers/Microsoft.Insights/components/<resource_name>).AGENT_ID— The agent identifier emitted by the tracing integration (gen_ai.agent.idattribute), used to filter traces. Format:agent-name:version.TRACE_LOOKBACK_HOURS— (Optional) Number of hours to look back when querying traces. Defaults to1.
Option A: Evaluate by agent filter
The simplest approach is to let the service automatically discover and evaluate recent traces for a specific agent. You don’t need to manually collect trace IDs.invoke_agent spans by the gen_ai.agent.id attribute, samples up to max_traces unique trace IDs, and evaluates all spans from those traces.
Option B: Evaluate by trace IDs
For more control, collect specific trace IDs from Application Insights and evaluate them. This method is useful when you want to evaluate a curated set of interactions, such as traces flagged by alerts or sampled for quality review.Collect trace IDs from Application Insights
Query Application Insights foroperation_Id values from your agent’s traces. Each operation_Id represents a complete agent interaction:
Create evaluation and run with trace IDs
Set up evaluators and data mappings
When you evaluate traces, the service automatically extracts conversation data from the OpenTelemetry span attributes. Use these field names directly indata_mapping (without the item. or sample. prefixes used in other scenarios):
Next steps
- To poll for completion and interpret results, see Get cloud evaluation results.
- For a complete runnable example, see sample_evaluations_builtin_with_traces.py on GitHub.