Skip to content
v2.277.0

CodeBasedOptions Struct ​

Options for configuring a code-based custom evaluator using a Lambda function.

Uses a Lambda function to implement custom evaluation logic.

Example ​

ts
declare const evalFunction: lambda.IFunction;

const codeEvaluator = new agentcore.Evaluator(this, 'CodeEvaluator', {
  evaluatorName: 'custom_code_evaluator',
  level: agentcore.EvaluationLevel.TOOL_CALL,
  description: 'Evaluates tool call accuracy using custom logic',
  evaluatorConfig: agentcore.EvaluatorConfig.codeBased({
    lambdaFunction: evalFunction,
    timeout: cdk.Duration.seconds(30),
  }),
});
python
# eval_function: lambda.IFunction


code_evaluator = agentcore.Evaluator(self, "CodeEvaluator",
    evaluator_name="custom_code_evaluator",
    level=agentcore.EvaluationLevel.TOOL_CALL,
    description="Evaluates tool call accuracy using custom logic",
    evaluator_config=agentcore.EvaluatorConfig.code_based(
        lambda_function=eval_function,
        timeout=cdk.Duration.seconds(30)
    )
)
java
IFunction evalFunction;


Evaluator codeEvaluator = Evaluator.Builder.create(this, "CodeEvaluator")
        .evaluatorName("custom_code_evaluator")
        .level(EvaluationLevel.TOOL_CALL)
        .description("Evaluates tool call accuracy using custom logic")
        .evaluatorConfig(EvaluatorConfig.codeBased(CodeBasedOptions.builder()
                .lambdaFunction(evalFunction)
                .timeout(Duration.seconds(30))
                .build()))
        .build();
csharp
// Install: dotnet add package Amazon.CDK.Lib
IFunction evalFunction;


var codeEvaluator = new Evaluator(this, "CodeEvaluator", new EvaluatorProps {
    EvaluatorName = "custom_code_evaluator",
    Level = EvaluationLevel.TOOL_CALL,
    Description = "Evaluates tool call accuracy using custom logic",
    EvaluatorConfig = EvaluatorConfig.CodeBased(new CodeBasedOptions {
        LambdaFunction = evalFunction,
        Timeout = Duration.Seconds(30)
    })
});
go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
var evalFunction IFunction


codeEvaluator := agentcore.NewEvaluator(this, jsii.String("CodeEvaluator"), &EvaluatorProps{
	EvaluatorName: jsii.String("custom_code_evaluator"),
	Level: agentcore.EvaluationLevel_TOOL_CALL(),
	Description: jsii.String("Evaluates tool call accuracy using custom logic"),
	EvaluatorConfig: agentcore.EvaluatorConfig_CodeBased(&CodeBasedOptions{
		LambdaFunction: evalFunction,
		Timeout: cdk.Duration_Seconds(jsii.Number(30)),
	}),
})

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.