Evaluator L2 construct
A custom evaluator for Amazon Bedrock AgentCore.
Custom evaluators enable you to define evaluation logic tailored to your specific use cases. Supports two evaluation strategies:
- LLM-as-a-Judge: Uses a foundation model with custom instructions and a rating scale.
- Code-based: Uses a Lambda function for custom evaluation logic.
Custom evaluators are used with OnlineEvaluationConfig via EvaluatorReference.custom().
| CloudFormation | AWS::BedrockAgentCore::Evaluator |
|---|---|
| L1 type | CfnEvaluator |
| Source | lib/evaluation/custom-evaluator.ts |
| Type last changed |
Example
// Create a custom LLM-as-a-Judge evaluator
const evaluator = new agentcore.Evaluator(this, 'MyEvaluator', {
evaluatorName: 'my_custom_evaluator',
level: agentcore.EvaluationLevel.SESSION,
evaluatorConfig: agentcore.EvaluatorConfig.llmAsAJudge({
instructions: 'Evaluate whether the agent response is helpful and accurate.',
modelId: 'us.anthropic.claude-sonnet-4-6',
ratingScale: agentcore.EvaluatorRatingScale.categorical([
{ label: 'Good', definition: 'The response is helpful and accurate.' },
{ label: 'Bad', definition: 'The response is not helpful or contains errors.' },
]),
}),
});
// Use the custom evaluator in an online evaluation configuration
new agentcore.OnlineEvaluationConfig(this, 'MyEvaluation', {
onlineEvaluationConfigName: 'my_evaluation',
evaluators: [
agentcore.EvaluatorReference.builtin(agentcore.BuiltinEvaluator.HELPFULNESS),
agentcore.EvaluatorReference.custom(evaluator),
],
dataSource: agentcore.DataSourceConfig.fromCloudWatchLogs({
logGroupNames: ['/aws/bedrock-agentcore/my-agent'],
serviceNames: ['my-agent.default'],
}),
});
# Create a custom LLM-as-a-Judge evaluator
evaluator = agentcore.Evaluator(self, "MyEvaluator",
evaluator_name="my_custom_evaluator",
level=agentcore.EvaluationLevel.SESSION,
evaluator_config=agentcore.EvaluatorConfig.llm_as_a_judge(
instructions="Evaluate whether the agent response is helpful and accurate.",
model_id="us.anthropic.claude-sonnet-4-6",
rating_scale=agentcore.EvaluatorRatingScale.categorical([agentcore.CategoricalRatingOption(label="Good", definition="The response is helpful and accurate."), agentcore.CategoricalRatingOption(label="Bad", definition="The response is not helpful or contains errors.")
])
)
)
# Use the custom evaluator in an online evaluation configuration
agentcore.OnlineEvaluationConfig(self, "MyEvaluation",
online_evaluation_config_name="my_evaluation",
evaluators=[
agentcore.EvaluatorReference.builtin(agentcore.BuiltinEvaluator.HELPFULNESS),
agentcore.EvaluatorReference.custom(evaluator)
],
data_source=agentcore.DataSourceConfig.from_cloud_watch_logs(
log_group_names=["/aws/bedrock-agentcore/my-agent"],
service_names=["my-agent.default"]
)
)
// Create a custom LLM-as-a-Judge evaluator
Evaluator evaluator = Evaluator.Builder.create(this, "MyEvaluator")
.evaluatorName("my_custom_evaluator")
.level(EvaluationLevel.SESSION)
.evaluatorConfig(EvaluatorConfig.llmAsAJudge(LlmAsAJudgeOptions.builder()
.instructions("Evaluate whether the agent response is helpful and accurate.")
.modelId("us.anthropic.claude-sonnet-4-6")
.ratingScale(EvaluatorRatingScale.categorical(List.of(CategoricalRatingOption.builder().label("Good").definition("The response is helpful and accurate.").build(), CategoricalRatingOption.builder().label("Bad").definition("The response is not helpful or contains errors.").build())))
.build()))
.build();
// Use the custom evaluator in an online evaluation configuration
// Use the custom evaluator in an online evaluation configuration
OnlineEvaluationConfig.Builder.create(this, "MyEvaluation")
.onlineEvaluationConfigName("my_evaluation")
.evaluators(List.of(EvaluatorReference.builtin(BuiltinEvaluator.HELPFULNESS), EvaluatorReference.custom(evaluator)))
.dataSource(DataSourceConfig.fromCloudWatchLogs(CloudWatchLogsDataSourceConfig.builder()
.logGroupNames(List.of("/aws/bedrock-agentcore/my-agent"))
.serviceNames(List.of("my-agent.default"))
.build()))
.build();
// Install: dotnet add package Amazon.CDK.AWS.Bedrock.Agentcore.Alpha
// Create a custom LLM-as-a-Judge evaluator
var evaluator = new Evaluator(this, "MyEvaluator", new EvaluatorProps {
EvaluatorName = "my_custom_evaluator",
Level = EvaluationLevel.SESSION,
EvaluatorConfig = EvaluatorConfig.LlmAsAJudge(new LlmAsAJudgeOptions {
Instructions = "Evaluate whether the agent response is helpful and accurate.",
ModelId = "us.anthropic.claude-sonnet-4-6",
RatingScale = EvaluatorRatingScale.Categorical(new [] { new CategoricalRatingOption { Label = "Good", Definition = "The response is helpful and accurate." }, new CategoricalRatingOption { Label = "Bad", Definition = "The response is not helpful or contains errors." } })
})
});
// Use the custom evaluator in an online evaluation configuration
// Use the custom evaluator in an online evaluation configuration
new OnlineEvaluationConfig(this, "MyEvaluation", new OnlineEvaluationConfigProps {
OnlineEvaluationConfigName = "my_evaluation",
Evaluators = new [] { EvaluatorReference.Builtin(BuiltinEvaluator.HELPFULNESS), EvaluatorReference.Custom(evaluator) },
DataSource = DataSourceConfig.FromCloudWatchLogs(new CloudWatchLogsDataSourceConfig {
LogGroupNames = new [] { "/aws/bedrock-agentcore/my-agent" },
ServiceNames = new [] { "my-agent.default" }
})
});
// Install: go get github.com/aws/aws-cdk-go/awsbedrockagentcorealpha/v2
// Create a custom LLM-as-a-Judge evaluator
evaluator := agentcore.NewEvaluator(this, jsii.String("MyEvaluator"), &EvaluatorProps{
EvaluatorName: jsii.String("my_custom_evaluator"),
Level: agentcore.EvaluationLevel_SESSION(),
EvaluatorConfig: agentcore.EvaluatorConfig_LlmAsAJudge(&LlmAsAJudgeOptions{
Instructions: jsii.String("Evaluate whether the agent response is helpful and accurate."),
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 and accurate."),
},
&CategoricalRatingOption{
Label: jsii.String("Bad"),
Definition: jsii.String("The response is not helpful or contains errors."),
},
}),
}),
})
// Use the custom evaluator in an online evaluation configuration
// Use the custom evaluator in an online evaluation configuration
agentcore.NewOnlineEvaluationConfig(this, jsii.String("MyEvaluation"), &OnlineEvaluationConfigProps{
OnlineEvaluationConfigName: jsii.String("my_evaluation"),
Evaluators: []EvaluatorReference{
agentcore.EvaluatorReference_Builtin(agentcore.BuiltinEvaluator_HELPFULNESS()),
agentcore.EvaluatorReference_Custom(evaluator),
},
DataSource: agentcore.DataSourceConfig_FromCloudWatchLogs(&CloudWatchLogsDataSourceConfig{
LogGroupNames: []*string{
jsii.String("/aws/bedrock-agentcore/my-agent"),
},
ServiceNames: []*string{
jsii.String("my-agent.default"),
},
}),
})
Initializer
new Evaluator(scope: Construct, id: string, props: EvaluatorProps)
Evaluator(scope: Construct, id: str, props: EvaluatorProps)
new Evaluator(Construct scope, String id, EvaluatorProps props)
new Evaluator(Construct scope, string id, EvaluatorProps props)
NewEvaluator(Scope Construct, Id *string, Props EvaluatorProps)
Construct Props
descriptionoptionalstringdescriptionoptionalstrdescriptionoptionalStringDescriptionoptionalstringDescriptionoptional*string #Default: No description
evaluatorConfigEvaluatorConfigevaluator_configEvaluatorConfigevaluatorConfigEvaluatorConfigEvaluatorConfigEvaluatorConfigEvaluatorConfigEvaluatorConfig required #Use EvaluatorConfig.llmAsAJudge() for model-based evaluation or EvaluatorConfig.codeBased() for Lambda-based evaluation.
evaluatorNamestringevaluator_namestrevaluatorNameStringEvaluatorNamestringEvaluatorName*string required #Must be unique within your account. Valid characters are a-z, A-Z, 0-9, _ (underscore). Must start with a letter and can be up to 48 characters long.
levelEvaluationLevellevelEvaluationLevellevelEvaluationLevelLevelEvaluationLevelLevelEvaluationLevel required #Determines what granularity of data the evaluator operates on: tool call, trace (single request-response), or session (full conversation).
tagsoptional{ [key: string]: string }tagsoptionaltyping.Mapping[str, str]tagsoptionalMap<String, String>TagsoptionalIDictionary<string, string>Tagsoptional*map[string]*string #Default: No tags
A list of key:value pairs of tags to apply to this Evaluator resource.
Properties
createdAtmay be undefinedstringcreated_atmay be undefinedstrcreatedAtmay be undefinedStringCreatedAtmay be undefinedstringCreatedAtmay be undefined*string #envResourceEnvironmentenvResourceEnvironmentenvResourceEnvironmentEnvResourceEnvironmentEnvResourceEnvironment #notes
For resources that are created and managed in a Stack (those created by creating new class instances like new Role(), new Bucket(), etc.), this is always the same as the environment of the stack they belong to.
For referenced resources (those obtained from referencing methods like Role.fromRoleArn(), Bucket.fromBucketName(), etc.), they might be different than the stack they were imported into.
evaluatorRefEvaluatorReferenceevaluator_refEvaluatorReferenceevaluatorRefEvaluatorReferenceEvaluatorRefEvaluatorReferenceEvaluatorRefEvaluatorReference #PROPERTY_INJECTION_IDstringPROPERTY_INJECTION_IDstrPROPERTY_INJECTION_IDStringPROPERTY_INJECTION_IDstringPROPERTY_INJECTION_ID*string static #statusmay be undefinedstringstatusmay be undefinedstrstatusmay be undefinedStringStatusmay be undefinedstringStatusmay be undefined*string #updatedAtmay be undefinedstringupdated_atmay be undefinedstrupdatedAtmay be undefinedStringUpdatedAtmay be undefinedstringUpdatedAtmay be undefined*string #Methods
applyCrossStackReferenceStrength(strength: ReferenceStrength): voiddef apply_cross_stack_reference_strength(self, strength: ReferenceStrength) -> Nonepublic void applyCrossStackReferenceStrength(ReferenceStrength strength)public void ApplyCrossStackReferenceStrength(ReferenceStrength strength)func ApplyCrossStackReferenceStrength(Strength ReferenceStrength) #notes · 1 parameter
When set, any cross-stack reference to this resource will use the specified mechanism instead of the global default determined by the @aws-cdk/core:defaultCrossStackReferences context key. This is useful for selectively weakening specific references to avoid the "deadly embrace" problem without changing the app-wide default.
Parameters
strengthstrengthstrengthstrengthStrength— - The reference strength to use for this resource.
applyRemovalPolicy(policy: RemovalPolicy): voiddef apply_removal_policy(self, policy: RemovalPolicy) -> Nonepublic void applyRemovalPolicy(RemovalPolicy policy)public void ApplyRemovalPolicy(RemovalPolicy policy)func ApplyRemovalPolicy(Policy RemovalPolicy) #notes
The Removal Policy controls what happens to this resource when it stops being managed by CloudFormation, either because you've removed it from the CDK application or because you've made a change that requires the resource to be replaced.
The resource can be deleted (RemovalPolicy.DESTROY), or left in your AWS account for data recovery and cleanup later (RemovalPolicy.RETAIN).
fromEvaluatorArn(scope: Construct, id: string, evaluatorArn: string): IEvaluator@staticmethod def from_evaluator_arn(scope: Construct, id: str, evaluator_arn: str) -> IEvaluatorpublic static IEvaluator fromEvaluatorArn(Construct scope, String id, String evaluatorArn)public static IEvaluator FromEvaluatorArn(Construct scope, string id, string evaluatorArn)func FromEvaluatorArn(Scope Construct, Id *string, EvaluatorArn *string) IEvaluator static #3 parameters · returns
Parameters
scopescopescopescopeScope— - The construct scope.ididididId— - Construct identifier.evaluatorArnevaluator_arnevaluatorArnevaluatorArnEvaluatorArn— - The evaluator ARN to import.
Returns: An IEvaluator reference
fromEvaluatorAttributes(scope: Construct, id: string, attrs: EvaluatorAttributes): IEvaluator@staticmethod def from_evaluator_attributes(scope: Construct, id: str, attrs: EvaluatorAttributes) -> IEvaluatorpublic static IEvaluator fromEvaluatorAttributes(Construct scope, String id, EvaluatorAttributes attrs)public static IEvaluator FromEvaluatorAttributes(Construct scope, string id, EvaluatorAttributes attrs)func FromEvaluatorAttributes(Scope Construct, Id *string, Attrs EvaluatorAttributes) IEvaluator static #3 parameters · returns
Parameters
scopescopescopescopeScope— - The construct scope.ididididId— - Construct identifier.attrsattrsattrsattrsAttrs— - The evaluator attributes.
Returns: An IEvaluator reference
fromEvaluatorId(scope: Construct, id: string, evaluatorId: string): IEvaluator@staticmethod def from_evaluator_id(scope: Construct, id: str, evaluator_id: str) -> IEvaluatorpublic static IEvaluator fromEvaluatorId(Construct scope, String id, String evaluatorId)public static IEvaluator FromEvaluatorId(Construct scope, string id, string evaluatorId)func FromEvaluatorId(Scope Construct, Id *string, EvaluatorId *string) IEvaluator static #3 parameters · returns
Parameters
scopescopescopescopeScope— - The construct scope.ididididId— - Construct identifier.evaluatorIdevaluator_idevaluatorIdevaluatorIdEvaluatorId— - The evaluator ID to import.
Returns: An IEvaluator reference
grant(grantee: IGrantable, ...actions: string[]): Grantdef grant(self, grantee: IGrantable, actions: str) -> Grantpublic Grant grant(IGrantable grantee, String actions)public Grant Grant(IGrantable grantee, string actions)func Grant(Grantee IGrantable, Actions *string) Grant #[disable-awslint:no-grants]
2 parameters · returns
Parameters
granteegranteegranteegranteeGrantee— - The IAM principal to grant permissions to.actionsactionsactionsactionsActions— - The actions to grant.
Returns: An IAM Grant object representing the granted permissions
isConstruct(x: any): boolean@staticmethod def is_construct(x: Any) -> boolpublic static Boolean isConstruct(Object x)public static bool IsConstruct(object x)func IsConstruct(X interface{}) *bool static #notes · 1 parameter · returns
Use this method instead of instanceof to properly detect Construct instances, even when the construct library is symlinked.
Explanation: in JavaScript, multiple copies of the constructs library on disk are seen as independent, completely different libraries. As a consequence, the class Construct in each copy of the constructs library is seen as a different class, and an instance of one class will not test as instanceof the other class. npm install will not create installations like this, but users may manually symlink construct libraries together or use a monorepo tool: in those cases, multiple copies of the constructs library can be accidentally installed, and instanceof will behave unpredictably. It is safest to avoid using instanceof, and using this type-testing method instead.
Parameters
xxxxX— Any object.
Returns: true if x is an object created from a class which extends Construct.
isOwnedResource(construct: IConstruct): boolean@staticmethod def is_owned_resource(construct: IConstruct) -> boolpublic static Boolean isOwnedResource(IConstruct construct)public static bool IsOwnedResource(IConstruct construct)func IsOwnedResource(Construct IConstruct) *bool static #isResource(construct: IConstruct): boolean@staticmethod def is_resource(construct: IConstruct) -> boolpublic static Boolean isResource(IConstruct construct)public static bool IsResource(IConstruct construct)func IsResource(Construct IConstruct) *bool static #toString(): stringdef to_string(self, ) -> strpublic String toString()public string ToString()func ToString() *string #with(...mixins: IMixin[]): IConstructdef with(self, mixins: IMixin) -> IConstructpublic IConstruct with(IMixin mixins)public IConstruct With(IMixin mixins)func With(Mixins IMixin) IConstruct #Mixins are applied in order. The list of constructs is captured at the start of the call, so constructs added by a mixin will not be visited. Use multiple with() calls if subsequent mixins should apply to added constructs.