# CodeBasedOptions

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

Uses a Lambda function to implement custom evaluation logic.

Used as argument in: [EvaluatorConfig.codeBased](https://docs.aws.amazon.com/cdk/api/v2/docs/@aws-cdk_aws-bedrock-agentcore-alpha.EvaluatorConfig.html#codebased)

- Source: [`lib/evaluation/evaluator-config.ts`](https://github.com/aws/aws-cdk/blob/v2.278.0/packages/@aws-cdk/aws-bedrock-agentcore-alpha/lib/evaluation/evaluator-config.ts#L87)

## Example

TypeScript:

```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:

```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:

```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());
```

C# / .NET:

```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
});
```

Golang:

```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

- `lambdaFunction`: [IFunction](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_lambda.IFunction.html) (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.

- `timeout`: [Duration](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.Duration.html) — 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.
