Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
FoundryEvals connects the Agent Framework evaluation APIs to Microsoft Foundry's managed evaluation service. It provides quality, safety, tool-use, agent-behavior, and rubric evaluators, with stored reports available in the Foundry portal.
For EvalItem, local checks, custom evaluators, and conversation split strategies, see Agent evaluation.
Prerequisites
- A Microsoft Foundry project and model deployment.
- A project-scoped Foundry endpoint.
- Permission to submit evaluations and read reports.
Evaluate responses or test queries
Configure FoundryEvals, then evaluate responses already generated or let EvaluateAsync run the agent for each 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);
The .NET samples also demonstrate Foundry rubric evaluators and per-dimension quality gates.
Evaluate an agent
Pass existing responses or test queries to evaluate_agent(). Results include pass/fail counts and the Foundry report URL.
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")
Additional samples cover trace evaluation, tool-call evaluation, multi-turn evaluation, workflow evaluation, mixed providers, and custom Foundry rubrics.
Note
Microsoft Foundry evaluation integration isn't currently available for Agent Framework Go. See the Agent Framework Go repository for the latest status.
Quality gates
Pin datasets, model deployments, evaluator versions, and rubric versions when results must be comparable across runs. Use result assertion helpers to fail CI when required metrics regress.