Use TypeSafe judgments as agent tools and evaluation metrics. These integrations ship in the main package.
Import Microsoft.Extensions.AI, Microsoft.Extensions.AI.Evaluation, TypeSafeAI.Extensions.AI, and TypeSafeAI.Extensions.AI.Evaluation.
This example assumes using TypeSafeAI; is in scope and apiKey contains your TypeSafe AI API key.
1 2 3 4 5 6 7 8 91011121314151617
usingvarclient=newTypeSafeClient(apiKey);varquestions=newDictionary<string,Question>{["relevant"]=newNoulQuestion("Is the response relevant to the question?")};// Expose fixed, reviewed questions to the calling agent; only state is supplied at invocation.varfunction=TypeSafeAIFunctions.Create(client,questions,"judge_relevance","Judge relevance.");varresult=awaitfunction.InvokeAsync(newAIFunctionArguments{["state"]="Question: hello. Response: hello."});// The same judgment produces numeric evaluation metrics without a generative judge.varevaluator=newTypeSafeEvaluator(client,questions,newTypeSafeEvaluatorOptions{Interpret=TypeSafeInterpretations.ByQuestion(newDictionary<string,Func<TypeSafeMetricContext,EvaluationMetricInterpretation?>>{["relevant"]=TypeSafeInterpretations.NoulAtLeast(0.8),}),});varevaluation=awaitevaluator.EvaluateAsync([newChatMessage(ChatRole.User,"hello")],newChatResponse(newChatMessage(ChatRole.Assistant,"hello")));