Notatka
Dostęp do tej strony wymaga autoryzacji. Może spróbować zalogować się lub zmienić katalogi.
Dostęp do tej strony wymaga autoryzacji. Możesz spróbować zmienić katalogi.
FoundryEvals łączy interfejsy API oceny platformy Agent Framework z zarządzaną usługą oceny Microsoft Foundry. Udostępnia ewaluatory jakości, bezpieczeństwa, korzystania z narzędzi, zachowania agenta oraz oparte na rubrykach, a zapisane raporty są dostępne w portalu Foundry.
Informacje na temat EvalItem, lokalnych kontroli, niestandardowych modułów oceny i strategii podziału rozmowy znajdziesz w sekcji Ocena agenta.
Wymagania wstępne
- Projekt i wdrożenie modelu Microsoft Foundry.
- Punkt końcowy Foundry w zakresie projektu.
- Uprawnienie do przesyłania ocen i odczytywania raportów.
Ocena odpowiedzi lub zapytań testowych
Skonfiguruj FoundryEvals, a następnie oceń już wygenerowane odpowiedzi lub pozwól EvaluateAsync uruchomić agenta dla każdego zapytania.
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);
Przykłady platformy .NET pokazują również ewaluatory rubric w Foundry oraz bramki jakości dla poszczególnych wymiarów.
Oceń agenta
Przekaż istniejące odpowiedzi lub zapytania testowe do evaluate_agent(). Wyniki obejmują liczbę wyników pozytywnych i negatywnych oraz adres URL raportu 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")
Dodatkowe przykłady obejmują ocenę śladów, ocenę wywołań narzędzi, ocenę wieloturową, ocenę przepływu pracy, mieszanych dostawców oraz niestandardowe kryteria oceny Foundry.
Uwaga / Notatka
Integracja oceny Microsoft Foundry nie jest obecnie dostępna dla platformy Agent Framework Go. Aktualny status znajdziesz w repozytorium Agent Framework dla Go.
Bramy jakości
Przypnij zestawy danych, wdrożenia modeli, wersje ewaluatorów i wersje rubryk, gdy wyniki muszą być porównywalne między uruchomieniami. Użyj pomocników asercji wyników, aby spowodować niepowodzenie procesu CI, gdy wymagane metryki ulegną regresji.