CodeBasedOptions Struct
Options for configuring a code-based custom evaluator using a Lambda function.
Uses a Lambda function to implement custom evaluation logic.
| Source | lib/evaluation/evaluator-config.ts |
|---|
Example
ts
// LLM-as-a-Judge evaluator
const llmConfig = agentcore.EvaluatorConfig.llmAsAJudge({
instructions: 'Evaluate whether the agent response is helpful.',
modelId: 'us.anthropic.claude-sonnet-4-6',
ratingScale: agentcore.EvaluatorRatingScale.categorical([
{ label: 'Good', definition: 'The response is helpful.' },
{ label: 'Bad', definition: 'The response is not helpful.' },
]),
});
// Code-based evaluator
declare const myEvalFunction: lambda.IFunction;
const codeConfig = agentcore.EvaluatorConfig.codeBased({
lambdaFunction: myEvalFunction,
});
python
# Code-based evaluator
# my_eval_function: lambda.IFunction
# LLM-as-a-Judge evaluator
llm_config = agentcore.EvaluatorConfig.llm_as_a_judge(
instructions="Evaluate whether the agent response is helpful.",
model_id="us.anthropic.claude-sonnet-4-6",
rating_scale=agentcore.EvaluatorRatingScale.categorical([agentcore.CategoricalRatingOption(label="Good", definition="The response is helpful."), agentcore.CategoricalRatingOption(label="Bad", definition="The response is not helpful.")
])
)
code_config = agentcore.EvaluatorConfig.code_based(
lambda_function=my_eval_function
)
java
// Code-based evaluator
IFunction myEvalFunction;
// LLM-as-a-Judge evaluator
EvaluatorConfig llmConfig = EvaluatorConfig.llmAsAJudge(LlmAsAJudgeOptions.builder()
.instructions("Evaluate whether the agent response is helpful.")
.modelId("us.anthropic.claude-sonnet-4-6")
.ratingScale(EvaluatorRatingScale.categorical(List.of(CategoricalRatingOption.builder().label("Good").definition("The response is helpful.").build(), CategoricalRatingOption.builder().label("Bad").definition("The response is not helpful.").build())))
.build());
EvaluatorConfig codeConfig = EvaluatorConfig.codeBased(CodeBasedOptions.builder()
.lambdaFunction(myEvalFunction)
.build());
csharp
// Install: dotnet add package Amazon.CDK.AWS.Bedrock.Agentcore.Alpha
// Code-based evaluator
IFunction myEvalFunction;
// LLM-as-a-Judge evaluator
var llmConfig = EvaluatorConfig.LlmAsAJudge(new LlmAsAJudgeOptions {
Instructions = "Evaluate whether the agent response is helpful.",
ModelId = "us.anthropic.claude-sonnet-4-6",
RatingScale = EvaluatorRatingScale.Categorical(new [] { new CategoricalRatingOption { Label = "Good", Definition = "The response is helpful." }, new CategoricalRatingOption { Label = "Bad", Definition = "The response is not helpful." } })
});
var codeConfig = EvaluatorConfig.CodeBased(new CodeBasedOptions {
LambdaFunction = myEvalFunction
});
go
// Install: go get github.com/aws/aws-cdk-go/awsbedrockagentcorealpha/v2
// Code-based evaluator
var myEvalFunction IFunction
// LLM-as-a-Judge evaluator
llmConfig := agentcore.EvaluatorConfig_LlmAsAJudge(&LlmAsAJudgeOptions{
Instructions: jsii.String("Evaluate whether the agent response is helpful."),
ModelId: jsii.String("us.anthropic.claude-sonnet-4-6"),
RatingScale: agentcore.EvaluatorRatingScale_Categorical([]CategoricalRatingOption{
&CategoricalRatingOption{
Label: jsii.String("Good"),
Definition: jsii.String("The response is helpful."),
},
&CategoricalRatingOption{
Label: jsii.String("Bad"),
Definition: jsii.String("The response is not helpful."),
},
}),
})
codeConfig := agentcore.EvaluatorConfig_CodeBased(&CodeBasedOptions{
LambdaFunction: myEvalFunction,
})
Properties
lambdaFunctionIFunctionlambda_functionIFunctionlambdaFunctionIFunctionLambdaFunctionIFunctionLambdaFunctionIFunction required #The Lambda function used for evaluation.
The function will be granted invoke permissions for the bedrock-agentcore.amazonaws.com service principal, scoped to this specific evaluator resource.
timeoutoptionalDurationtimeoutoptionalDurationtimeoutoptionalDurationTimeoutoptionalDurationTimeoutoptionalDuration #The timeout for the Lambda function invocation during evaluation.
Default: The AgentCore evaluation service's default Lambda timeout is used
When not specified, the AgentCore evaluation service uses its default timeout for Lambda-based evaluators.