@aws-cdk/aws-bedrock-agentcore-alpha 2.252.0-alpha.0 → 2.253.0-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (61) hide show
  1. package/.jsii +11191 -7249
  2. package/.jsii.tabl.json.gz +0 -0
  3. package/.warnings.jsii.js +30 -0
  4. package/README.md +422 -0
  5. package/lib/evaluation/custom-evaluator.d.ts +153 -0
  6. package/lib/evaluation/custom-evaluator.js +256 -0
  7. package/lib/evaluation/data-source.d.ts +106 -0
  8. package/lib/evaluation/data-source.js +156 -0
  9. package/lib/evaluation/evaluator-base.d.ts +82 -0
  10. package/lib/evaluation/evaluator-base.js +55 -0
  11. package/lib/evaluation/evaluator-config.d.ts +195 -0
  12. package/lib/evaluation/evaluator-config.js +184 -0
  13. package/lib/evaluation/evaluator.d.ts +68 -0
  14. package/lib/evaluation/evaluator.js +90 -0
  15. package/lib/evaluation/online-evaluation-base.d.ts +96 -0
  16. package/lib/evaluation/online-evaluation-base.js +55 -0
  17. package/lib/evaluation/online-evaluation.d.ts +134 -0
  18. package/lib/evaluation/online-evaluation.js +388 -0
  19. package/lib/evaluation/perms.d.ts +34 -0
  20. package/lib/evaluation/perms.js +53 -0
  21. package/lib/evaluation/types.d.ts +461 -0
  22. package/lib/evaluation/types.js +229 -0
  23. package/lib/evaluation/validation-helpers.d.ts +133 -0
  24. package/lib/evaluation/validation-helpers.js +349 -0
  25. package/lib/gateway/gateway-base.js +1 -1
  26. package/lib/gateway/gateway.js +2 -2
  27. package/lib/gateway/inbound-auth/authorizer.js +4 -4
  28. package/lib/gateway/inbound-auth/custom-claim.js +1 -1
  29. package/lib/gateway/interceptor.js +1 -1
  30. package/lib/gateway/outbound-auth/api-key.js +1 -1
  31. package/lib/gateway/outbound-auth/credential-provider.js +1 -1
  32. package/lib/gateway/protocol.js +2 -2
  33. package/lib/gateway/targets/schema/api-schema.js +4 -4
  34. package/lib/gateway/targets/schema/tool-schema.js +4 -4
  35. package/lib/gateway/targets/target-base.js +1 -1
  36. package/lib/gateway/targets/target-configuration.js +6 -6
  37. package/lib/gateway/targets/target.js +1 -1
  38. package/lib/index.d.ts +9 -0
  39. package/lib/index.js +13 -1
  40. package/lib/memory/memory-strategy.js +1 -1
  41. package/lib/memory/memory.js +2 -2
  42. package/lib/memory/strategies/managed-strategy.js +1 -1
  43. package/lib/memory/strategies/self-managed-strategy.js +8 -5
  44. package/lib/network/network-configuration.js +4 -4
  45. package/lib/policy/policy-base.js +1 -1
  46. package/lib/policy/policy-engine-base.js +1 -1
  47. package/lib/policy/policy-engine.js +1 -1
  48. package/lib/policy/policy-statement.js +5 -5
  49. package/lib/policy/policy-types.js +1 -1
  50. package/lib/policy/policy.js +1 -1
  51. package/lib/runtime/inbound-auth/custom-claim.js +1 -1
  52. package/lib/runtime/inbound-auth/runtime-authorizer-configuration.js +1 -1
  53. package/lib/runtime/observability.js +2 -2
  54. package/lib/runtime/runtime-artifact.js +1 -1
  55. package/lib/runtime/runtime-base.js +1 -1
  56. package/lib/runtime/runtime-endpoint-base.js +1 -1
  57. package/lib/runtime/runtime-endpoint.js +1 -1
  58. package/lib/runtime/runtime.js +1 -1
  59. package/lib/tools/browser.js +2 -2
  60. package/lib/tools/code-interpreter.js +2 -2
  61. package/package.json +10 -9
Binary file
package/.warnings.jsii.js CHANGED
@@ -238,6 +238,36 @@ const VALIDATORS = { _aws_cdk_aws_bedrock_agentcore_alpha_MemoryProps: function
238
238
  finally {
239
239
  visitedObjects.delete(p);
240
240
  }
241
+ }, _aws_cdk_aws_bedrock_agentcore_alpha_OnlineEvaluationBaseProps: function _aws_cdk_aws_bedrock_agentcore_alpha_OnlineEvaluationBaseProps(p) {
242
+ if (p == null)
243
+ return;
244
+ visitedObjects.add(p);
245
+ try {
246
+ if (p.filters != null)
247
+ for (const o of p.filters)
248
+ if (!visitedObjects.has(o))
249
+ module.exports._aws_cdk_aws_bedrock_agentcore_alpha_FilterConfig(o);
250
+ }
251
+ finally {
252
+ visitedObjects.delete(p);
253
+ }
254
+ }, _aws_cdk_aws_bedrock_agentcore_alpha_OnlineEvaluationConfigProps: function _aws_cdk_aws_bedrock_agentcore_alpha_OnlineEvaluationConfigProps(p) {
255
+ if (p == null)
256
+ return;
257
+ visitedObjects.add(p);
258
+ try {
259
+ if (p.evaluators != null)
260
+ for (const o of p.evaluators)
261
+ if (!visitedObjects.has(o))
262
+ module.exports._aws_cdk_aws_bedrock_agentcore_alpha_EvaluatorReference(o);
263
+ if (p.filters != null)
264
+ for (const o of p.filters)
265
+ if (!visitedObjects.has(o))
266
+ module.exports._aws_cdk_aws_bedrock_agentcore_alpha_FilterConfig(o);
267
+ }
268
+ finally {
269
+ visitedObjects.delete(p);
270
+ }
241
271
  } };
242
272
  function print(name, deprecationMessage) {
243
273
  const deprecated = process.env.JSII_DEPRECATED;
package/README.md CHANGED
@@ -122,6 +122,18 @@ This construct library facilitates the deployment of Bedrock AgentCore primitive
122
122
  - [Type-Safe Policy Builder](#type-safe-policy-builder)
123
123
  - [PolicyEngine with KMS Encryption](#policyengine-with-kms-encryption)
124
124
  - [Policy Validation Modes](#policy-validation-modes)
125
+ - [Online Evaluation](#online-evaluation)
126
+ - [Online Evaluation Properties](#online-evaluation-properties)
127
+ - [Basic Online Evaluation Creation](#basic-online-evaluation-creation)
128
+ - [Built-in Evaluators](#built-in-evaluators)
129
+ - [Custom Evaluators](#custom-evaluators)
130
+ - [LLM-as-a-Judge Evaluator](#llm-as-a-judge-evaluator)
131
+ - [Code-Based Evaluator](#code-based-evaluator)
132
+ - [Using Custom Evaluators with Online Evaluation](#using-custom-evaluators-with-online-evaluation)
133
+ - [Data Source Configuration](#data-source-configuration)
134
+ - [Sampling and Filtering](#sampling-and-filtering)
135
+ - [Online Evaluation with Custom Execution Role](#online-evaluation-with-custom-execution-role)
136
+ - [Online Evaluation IAM Permissions](#online-evaluation-iam-permissions)
125
137
 
126
138
  ## AgentCore Runtime
127
139
 
@@ -2594,6 +2606,8 @@ memory.addMemoryStrategy(agentcore.MemoryStrategy.usingBuiltInSemantic());
2594
2606
 
2595
2607
  A policy engine is a collection of policies that evaluates and authorizes agent tool calls. When associated with a gateway, the policy engine intercepts all agent requests and determines whether to allow or deny each action based on the defined policies.
2596
2608
 
2609
+ For more information, see the [Policy in Amazon Bedrock AgentCore documentation](https://docs.aws.amazon.com/bedrock-agentcore/latest/devguide/policy.html).
2610
+
2597
2611
  ### PolicyEngine Properties
2598
2612
 
2599
2613
  | Name | Type | Required | Description |
@@ -2639,6 +2653,13 @@ permit(
2639
2653
 
2640
2654
  Create a policy engine and add policies to it.
2641
2655
 
2656
+ #### Policy Engine Mode
2657
+
2658
+ When associating a policy engine with a gateway, you can control the enforcement behavior using `PolicyEngineMode`:
2659
+
2660
+ - `PolicyEngineMode.LOG_ONLY` (default) — evaluates actions and adds traces but does not enforce decisions. Use this mode for testing and validation before enabling enforcement.
2661
+ - `PolicyEngineMode.ENFORCE` — actively allows or denies agent operations based on Cedar policy evaluation.
2662
+
2642
2663
  ```typescript fixture=default
2643
2664
 
2644
2665
  // Create a Policy engine
@@ -2651,6 +2672,7 @@ const gateway = new agentcore.Gateway(this, "MyGateway", {
2651
2672
  gatewayName: "my-gateway",
2652
2673
  policyEngineConfiguration: {
2653
2674
  policyEngine: policyEngine,
2675
+ mode: agentcore.PolicyEngineMode.ENFORCE, // Default is LOG_ONLY
2654
2676
  },
2655
2677
  });
2656
2678
 
@@ -2780,6 +2802,63 @@ const conditionalPolicy = new agentcore.Policy(this, "ConditionalPolicy", {
2780
2802
  // };
2781
2803
  ```
2782
2804
 
2805
+ #### Policy with Exclusions (unless)
2806
+
2807
+ Use `unless` clauses to exclude specific conditions from a policy. The policy applies when the `unless` conditions are NOT met:
2808
+
2809
+ ```typescript fixture=default
2810
+ declare const policyEngine: agentcore.PolicyEngine;
2811
+ declare const gateway: agentcore.Gateway;
2812
+
2813
+ // Allow access unless the user is suspended
2814
+ const policyWithUnless = new agentcore.Policy(this, "UnlessPolicy", {
2815
+ policyEngine: policyEngine,
2816
+ policyName: "unless_suspended",
2817
+ statement: agentcore.PolicyStatement.permit()
2818
+ .forPrincipal('AgentCore::OAuthUser')
2819
+ .onAllActions()
2820
+ .onResource('AgentCore::Gateway', gateway.gatewayArn)
2821
+ .unless()
2822
+ .principalAttribute('suspended').equalTo(true)
2823
+ .done(),
2824
+ description: "Allow all actions unless user is suspended",
2825
+ validationMode: agentcore.PolicyValidationMode.FAIL_ON_ANY_FINDINGS,
2826
+ });
2827
+
2828
+ // Generated Cedar:
2829
+ // permit(
2830
+ // principal is AgentCore::OAuthUser,
2831
+ // action,
2832
+ // resource == AgentCore::Gateway::"arn:..."
2833
+ // )
2834
+ // unless {
2835
+ // principal.suspended == true
2836
+ // };
2837
+ ```
2838
+
2839
+ You can combine `when` and `unless` clauses in the same policy:
2840
+
2841
+ ```typescript fixture=default
2842
+ declare const policyEngine: agentcore.PolicyEngine;
2843
+ declare const gateway: agentcore.Gateway;
2844
+
2845
+ // Allow engineers unless they are on probation
2846
+ policyEngine.addPolicy("CombinedConditions", {
2847
+ statement: agentcore.PolicyStatement.permit()
2848
+ .forPrincipal('AgentCore::OAuthUser')
2849
+ .onAllActions()
2850
+ .onResource('AgentCore::Gateway', gateway.gatewayArn)
2851
+ .when()
2852
+ .principalAttribute('department').equalTo('Engineering')
2853
+ .done()
2854
+ .unless()
2855
+ .principalAttribute('status').equalTo('probation')
2856
+ .done(),
2857
+ description: "Allow engineers unless on probation",
2858
+ validationMode: agentcore.PolicyValidationMode.FAIL_ON_ANY_FINDINGS,
2859
+ });
2860
+ ```
2861
+
2783
2862
  #### Forbid (Deny) Policy
2784
2863
 
2785
2864
  Use `forbid` to explicitly deny access. Forbid policies override permit policies.
@@ -2925,3 +3004,346 @@ policyEngine.grantRead(lambdaRole);
2925
3004
  policyEngine.grantEvaluate(lambdaRole);
2926
3005
 
2927
3006
  ```
3007
+
3008
+ ## Online Evaluation
3009
+
3010
+ The Online Evaluation construct enables continuous monitoring and assessment of your agent's performance using live traffic. It automatically samples agent traces from CloudWatch Logs or Agent Endpoints and applies built-in evaluators to assess quality metrics like helpfulness, correctness, and safety.
3011
+
3012
+ ### Online Evaluation Properties
3013
+
3014
+ | Name | Type | Required | Description |
3015
+ |------|------|----------|-------------|
3016
+ | `onlineEvaluationConfigName` | `string` | Yes | The name of the online evaluation configuration. Must start with a letter and can contain a-z, A-Z, 0-9, _ (underscore). Maximum 48 characters |
3017
+ | `evaluators` | `EvaluatorReference[]` | Yes | The list of built-in evaluators to apply during evaluation. Minimum 1, maximum 10 |
3018
+ | `dataSource` | `DataSourceConfig` | Yes | The data source configuration specifying where to read agent traces from |
3019
+ | `executionRole` | `iam.IRole` | No | The IAM role for evaluation. If not provided, a role will be created automatically |
3020
+ | `description` | `string` | No | Description of the evaluation configuration. Maximum 200 characters |
3021
+ | `samplingPercentage` | `number` | No | Percentage of traces to sample (0.01-100). Default: 10 |
3022
+ | `filters` | `FilterConfig[]` | No | Filters to determine which traces to evaluate. Use `FilterValue.string()`, `FilterValue.number()`, or `FilterValue.boolean()` for typed filter values. Maximum 5 |
3023
+ | `sessionTimeout` | `Duration` | No | Duration of inactivity before a session is considered complete (1-1440 minutes). Default: `Duration.minutes(15)` |
3024
+ | `tags` | `{ [key: string]: string }` | No | Tags for the evaluation configuration |
3025
+
3026
+ ### Basic Online Evaluation Creation
3027
+
3028
+ Create an online evaluation configuration with built-in evaluators:
3029
+
3030
+ ```typescript fixture=default
3031
+ const evaluation = new agentcore.OnlineEvaluationConfig(this, 'MyEvaluation', {
3032
+ onlineEvaluationConfigName: 'my_evaluation',
3033
+ evaluators: [
3034
+ agentcore.EvaluatorReference.builtin(agentcore.BuiltinEvaluator.HELPFULNESS),
3035
+ agentcore.EvaluatorReference.builtin(agentcore.BuiltinEvaluator.CORRECTNESS),
3036
+ ],
3037
+ dataSource: agentcore.DataSourceConfig.fromCloudWatchLogs({
3038
+ logGroupNames: ['/aws/bedrock-agentcore/my-agent'],
3039
+ serviceNames: ['my-agent.default'],
3040
+ }),
3041
+ });
3042
+ ```
3043
+
3044
+ ### Built-in Evaluators
3045
+
3046
+ Amazon Bedrock AgentCore provides 13 built-in evaluators that assess different aspects of agent performance:
3047
+
3048
+ **Session-Level Evaluators:**
3049
+
3050
+ - `GOAL_SUCCESS_RATE` - Evaluates whether the conversation successfully meets the user's goals
3051
+
3052
+ **Trace-Level Evaluators:**
3053
+
3054
+ - `HELPFULNESS` - How useful and valuable the agent's response is
3055
+ - `CORRECTNESS` - Whether the information is factually accurate
3056
+ - `FAITHFULNESS` - Whether the response is faithful to the provided context
3057
+ - `HARMFULNESS` - Whether the response contains harmful content
3058
+ - `STEREOTYPING` - Detects content that makes generalizations about individuals or groups
3059
+ - `REFUSAL` - Whether the agent appropriately refuses harmful requests
3060
+ - `COHERENCE` - Whether the response is logically coherent
3061
+ - `RESPONSE_RELEVANCE` - Whether the response appropriately addresses the user's query
3062
+ - `CONCISENESS` - Whether the response is appropriately concise
3063
+ - `INSTRUCTION_FOLLOWING` - How well the agent follows system instructions
3064
+
3065
+ **Tool Call-Level Evaluators:**
3066
+
3067
+ - `TOOL_SELECTION_ACCURACY` - Whether the agent selected the appropriate tool
3068
+ - `TOOL_PARAMETER_ACCURACY` - How accurately the agent extracts parameters from user queries
3069
+
3070
+ ```typescript fixture=default
3071
+ const evaluation = new agentcore.OnlineEvaluationConfig(this, 'ComprehensiveEval', {
3072
+ onlineEvaluationConfigName: 'comprehensive_evaluation',
3073
+ evaluators: [
3074
+ // Session level
3075
+ agentcore.EvaluatorReference.builtin(agentcore.BuiltinEvaluator.GOAL_SUCCESS_RATE),
3076
+ // Trace level - quality
3077
+ agentcore.EvaluatorReference.builtin(agentcore.BuiltinEvaluator.HELPFULNESS),
3078
+ agentcore.EvaluatorReference.builtin(agentcore.BuiltinEvaluator.CORRECTNESS),
3079
+ agentcore.EvaluatorReference.builtin(agentcore.BuiltinEvaluator.COHERENCE),
3080
+ // Trace level - safety
3081
+ agentcore.EvaluatorReference.builtin(agentcore.BuiltinEvaluator.HARMFULNESS),
3082
+ agentcore.EvaluatorReference.builtin(agentcore.BuiltinEvaluator.STEREOTYPING),
3083
+ // Tool call level
3084
+ agentcore.EvaluatorReference.builtin(agentcore.BuiltinEvaluator.TOOL_SELECTION_ACCURACY),
3085
+ ],
3086
+ dataSource: agentcore.DataSourceConfig.fromCloudWatchLogs({
3087
+ logGroupNames: ['/aws/bedrock-agentcore/my-agent'],
3088
+ serviceNames: ['my-agent.default'],
3089
+ }),
3090
+ });
3091
+ ```
3092
+
3093
+ ### Custom Evaluators
3094
+
3095
+ Custom evaluators let you define evaluation logic tailored to your specific use cases. You can create custom evaluators using two strategies:
3096
+
3097
+ - **LLM-as-a-Judge**: Uses a foundation model with custom instructions and a rating scale to assess agent performance.
3098
+ - **Code-based**: Uses a Lambda function for custom evaluation logic.
3099
+
3100
+ | Property | Type | Required | Description |
3101
+ |---|---|---|---|
3102
+ | `evaluatorName` | `string` | Yes | Name of the evaluator. Must start with a letter, a-z, A-Z, 0-9, _ only. Maximum 48 characters |
3103
+ | `evaluatorConfig` | `EvaluatorConfig` | Yes | Configuration defining how the evaluator assesses performance |
3104
+ | `level` | `EvaluationLevel` | Yes | The level at which the evaluator operates: `TOOL_CALL`, `TRACE`, or `SESSION` |
3105
+ | `description` | `string` | No | Description of the evaluator. Maximum 200 characters |
3106
+
3107
+ #### LLM-as-a-Judge Evaluator
3108
+
3109
+ Create a custom evaluator that uses a foundation model to assess agent performance:
3110
+
3111
+ ```typescript fixture=default
3112
+ // LLM-as-a-Judge with categorical rating scale
3113
+ const categoricalEvaluator = new agentcore.Evaluator(this, 'CategoricalEvaluator', {
3114
+ evaluatorName: 'domain_accuracy_evaluator',
3115
+ level: agentcore.EvaluationLevel.SESSION,
3116
+ description: 'Evaluates domain-specific accuracy of agent responses',
3117
+ evaluatorConfig: agentcore.EvaluatorConfig.llmAsAJudge({
3118
+ instructions: 'Evaluate whether the agent response is accurate within the healthcare domain.',
3119
+ modelId: 'us.anthropic.claude-sonnet-4-6',
3120
+ ratingScale: agentcore.EvaluatorRatingScale.categorical([
3121
+ { label: 'Accurate', definition: 'The response contains factually correct healthcare information.' },
3122
+ { label: 'Inaccurate', definition: 'The response contains incorrect or misleading healthcare information.' },
3123
+ ]),
3124
+ }),
3125
+ });
3126
+
3127
+ // LLM-as-a-Judge with numerical rating scale and inference config
3128
+ const numericalEvaluator = new agentcore.Evaluator(this, 'NumericalEvaluator', {
3129
+ evaluatorName: 'response_quality_evaluator',
3130
+ level: agentcore.EvaluationLevel.TRACE,
3131
+ evaluatorConfig: agentcore.EvaluatorConfig.llmAsAJudge({
3132
+ instructions: 'Rate the overall quality of the agent response on a scale of 1 to 5.',
3133
+ modelId: 'us.anthropic.claude-sonnet-4-6',
3134
+ ratingScale: agentcore.EvaluatorRatingScale.numerical([
3135
+ { label: 'Poor', definition: 'Inadequate response.', value: 1 },
3136
+ { label: 'Below Average', definition: 'Partially addresses the query.', value: 2 },
3137
+ { label: 'Average', definition: 'Adequately addresses the query.', value: 3 },
3138
+ { label: 'Good', definition: 'Well-structured and accurate response.', value: 4 },
3139
+ { label: 'Excellent', definition: 'Outstanding response exceeding expectations.', value: 5 },
3140
+ ]),
3141
+ inferenceConfig: {
3142
+ maxTokens: 1024,
3143
+ temperature: 0.1,
3144
+ },
3145
+ }),
3146
+ });
3147
+ ```
3148
+
3149
+ The `modelId` accepts standard Bedrock model IDs and cross-region inference profile IDs with region prefixes (e.g., `us.`, `eu.`, `global.`).
3150
+
3151
+ > **Instructions placeholders:** Instructions must contain placeholders appropriate for the evaluation level (e.g., `{context}`, `{available_tools}` for SESSION level). Evaluators using reference-input placeholders (e.g., `{expected_tool_trajectory}`, `{assertions}`) are only compatible with on-demand evaluation, not online evaluation. See the [custom evaluators documentation](https://docs.aws.amazon.com/bedrock-agentcore/latest/devguide/custom-evaluators.html) for allowed placeholders per level.
3152
+
3153
+ #### Code-Based Evaluator
3154
+
3155
+ Create a custom evaluator that uses a Lambda function for evaluation logic:
3156
+
3157
+ ```typescript fixture=default
3158
+ declare const evalFunction: lambda.IFunction;
3159
+
3160
+ const codeEvaluator = new agentcore.Evaluator(this, 'CodeEvaluator', {
3161
+ evaluatorName: 'custom_code_evaluator',
3162
+ level: agentcore.EvaluationLevel.TOOL_CALL,
3163
+ description: 'Evaluates tool call accuracy using custom logic',
3164
+ evaluatorConfig: agentcore.EvaluatorConfig.codeBased({
3165
+ lambdaFunction: evalFunction,
3166
+ timeout: cdk.Duration.seconds(30),
3167
+ }),
3168
+ });
3169
+ ```
3170
+
3171
+ For code-based evaluators, the construct automatically grants the `bedrock-agentcore.amazonaws.com` service principal permission to invoke the Lambda function, scoped to the specific evaluator resource with `aws:SourceAccount` and `aws:SourceArn` conditions for confused deputy prevention.
3172
+
3173
+ #### Using Custom Evaluators with Online Evaluation
3174
+
3175
+ Custom evaluators are used in `OnlineEvaluationConfig` via `EvaluatorReference.custom()`, alongside built-in evaluators:
3176
+
3177
+ ```typescript fixture=default
3178
+ declare const customEvaluator: agentcore.Evaluator;
3179
+
3180
+ const evaluation = new agentcore.OnlineEvaluationConfig(this, 'MixedEvaluation', {
3181
+ onlineEvaluationConfigName: 'mixed_evaluation',
3182
+ evaluators: [
3183
+ // Built-in evaluators
3184
+ agentcore.EvaluatorReference.builtin(agentcore.BuiltinEvaluator.HELPFULNESS),
3185
+ agentcore.EvaluatorReference.builtin(agentcore.BuiltinEvaluator.CORRECTNESS),
3186
+ // Custom evaluator
3187
+ agentcore.EvaluatorReference.custom(customEvaluator),
3188
+ ],
3189
+ dataSource: agentcore.DataSourceConfig.fromCloudWatchLogs({
3190
+ logGroupNames: ['/aws/bedrock-agentcore/my-agent'],
3191
+ serviceNames: ['my-agent.default'],
3192
+ }),
3193
+ });
3194
+ ```
3195
+
3196
+ ### Data Source Configuration
3197
+
3198
+ Online evaluation supports two types of data sources:
3199
+
3200
+ **AgentCore Runtime Data Source (Recommended):**
3201
+
3202
+ For runtimes created within your CDK app, use `fromAgentRuntimeEndpoint()` which automatically derives the CloudWatch log group and service name:
3203
+
3204
+ ```typescript fixture=default
3205
+ const repository = new ecr.Repository(this, 'TestRepository', {
3206
+ repositoryName: 'test-agent-runtime',
3207
+ });
3208
+
3209
+ const runtime = new agentcore.Runtime(this, 'MyRuntime', {
3210
+ runtimeName: 'my_agent',
3211
+ agentRuntimeArtifact: agentcore.AgentRuntimeArtifact.fromEcrRepository(repository, 'v1.0.0'),
3212
+ });
3213
+
3214
+ // Using default endpoint (simplest)
3215
+ const evaluation = new agentcore.OnlineEvaluationConfig(this, 'RuntimeEval', {
3216
+ onlineEvaluationConfigName: 'runtime_evaluation',
3217
+ evaluators: [
3218
+ agentcore.EvaluatorReference.builtin(agentcore.BuiltinEvaluator.HELPFULNESS),
3219
+ ],
3220
+ dataSource: agentcore.DataSourceConfig.fromAgentRuntimeEndpoint(runtime),
3221
+ });
3222
+ ```
3223
+
3224
+ You can also specify a specific endpoint:
3225
+
3226
+ ```typescript fixture=default
3227
+ declare const runtime: agentcore.Runtime;
3228
+
3229
+ // Using a specific endpoint construct
3230
+ const prodEndpoint = runtime.addEndpoint('PROD');
3231
+ const evaluation = new agentcore.OnlineEvaluationConfig(this, 'ProdEval', {
3232
+ onlineEvaluationConfigName: 'prod_evaluation',
3233
+ evaluators: [
3234
+ agentcore.EvaluatorReference.builtin(agentcore.BuiltinEvaluator.CORRECTNESS),
3235
+ ],
3236
+ dataSource: agentcore.DataSourceConfig.fromAgentRuntimeEndpoint(runtime, prodEndpoint),
3237
+ });
3238
+
3239
+ // Or using endpoint name as string
3240
+ const stagingEval = new agentcore.OnlineEvaluationConfig(this, 'StagingEval', {
3241
+ onlineEvaluationConfigName: 'staging_evaluation',
3242
+ evaluators: [
3243
+ agentcore.EvaluatorReference.builtin(agentcore.BuiltinEvaluator.CORRECTNESS),
3244
+ ],
3245
+ dataSource: agentcore.DataSourceConfig.fromAgentRuntimeEndpointName(runtime, 'STAGING'),
3246
+ });
3247
+ ```
3248
+
3249
+ **CloudWatch Logs Data Source:**
3250
+
3251
+ For external agents or when you need to specify log groups directly:
3252
+
3253
+ ```typescript fixture=default
3254
+ const evaluation = new agentcore.OnlineEvaluationConfig(this, 'CloudWatchEval', {
3255
+ onlineEvaluationConfigName: 'cloudwatch_evaluation',
3256
+ evaluators: [
3257
+ agentcore.EvaluatorReference.builtin(agentcore.BuiltinEvaluator.HELPFULNESS),
3258
+ ],
3259
+ dataSource: agentcore.DataSourceConfig.fromCloudWatchLogs({
3260
+ logGroupNames: [
3261
+ '/aws/bedrock-agentcore/agent1',
3262
+ '/aws/bedrock-agentcore/agent2',
3263
+ ],
3264
+ serviceNames: ['agent1.default'],
3265
+ }),
3266
+ });
3267
+ ```
3268
+
3269
+ ### Sampling and Filtering
3270
+
3271
+ Configure sampling percentage and filters to control which traces are evaluated:
3272
+
3273
+ ```typescript fixture=default
3274
+ const evaluation = new agentcore.OnlineEvaluationConfig(this, 'FilteredEval', {
3275
+ onlineEvaluationConfigName: 'filtered_evaluation',
3276
+ evaluators: [
3277
+ agentcore.EvaluatorReference.builtin(agentcore.BuiltinEvaluator.HELPFULNESS),
3278
+ ],
3279
+ dataSource: agentcore.DataSourceConfig.fromCloudWatchLogs({
3280
+ logGroupNames: ['/aws/bedrock-agentcore/my-agent'],
3281
+ serviceNames: ['my-agent.default'],
3282
+ }),
3283
+ // Sample 25% of traces
3284
+ samplingPercentage: 25,
3285
+ // Only evaluate traces matching these filters
3286
+ filters: [
3287
+ {
3288
+ key: 'user.region',
3289
+ operator: agentcore.FilterOperator.EQUAL,
3290
+ value: agentcore.FilterValue.string('us-east-1'),
3291
+ },
3292
+ {
3293
+ key: 'session.duration',
3294
+ operator: agentcore.FilterOperator.GREATER_THAN,
3295
+ value: agentcore.FilterValue.number(60),
3296
+ },
3297
+ ],
3298
+ // Consider sessions complete after 30 minutes of inactivity
3299
+ sessionTimeout: cdk.Duration.minutes(30),
3300
+ });
3301
+ ```
3302
+
3303
+ ### Online Evaluation with Custom Execution Role
3304
+
3305
+ Provide a custom IAM role for the evaluation execution:
3306
+
3307
+ ```typescript fixture=default
3308
+ const executionRole = new iam.Role(this, 'EvaluationRole', {
3309
+ assumedBy: new iam.ServicePrincipal('bedrock-agentcore.amazonaws.com'),
3310
+ description: 'Custom role for online evaluation',
3311
+ });
3312
+
3313
+ // Add required permissions
3314
+ executionRole.addToPolicy(new iam.PolicyStatement({
3315
+ actions: [
3316
+ 'logs:DescribeLogGroups',
3317
+ 'logs:GetQueryResults',
3318
+ 'logs:StartQuery',
3319
+ ],
3320
+ resources: ['arn:aws:logs:*:*:log-group:/aws/bedrock-agentcore/*'],
3321
+ }));
3322
+
3323
+ const evaluation = new agentcore.OnlineEvaluationConfig(this, 'CustomRoleEval', {
3324
+ onlineEvaluationConfigName: 'custom_role_evaluation',
3325
+ evaluators: [
3326
+ agentcore.EvaluatorReference.builtin(agentcore.BuiltinEvaluator.HELPFULNESS),
3327
+ ],
3328
+ dataSource: agentcore.DataSourceConfig.fromCloudWatchLogs({
3329
+ logGroupNames: ['/aws/bedrock-agentcore/my-agent'],
3330
+ serviceNames: ['my-agent.default'],
3331
+ }),
3332
+ executionRole: executionRole,
3333
+ });
3334
+ ```
3335
+
3336
+ ### Online Evaluation IAM Permissions
3337
+
3338
+ Grant IAM permissions to manage or read evaluation configurations:
3339
+
3340
+ ```typescript fixture=default
3341
+ declare const evaluation: agentcore.OnlineEvaluationConfig;
3342
+ declare const role: iam.IRole;
3343
+
3344
+ // Grant specific permissions
3345
+ evaluation.grant(role,
3346
+ 'bedrock-agentcore:GetOnlineEvaluationConfig',
3347
+ 'bedrock-agentcore:UpdateOnlineEvaluationConfig',
3348
+ );
3349
+ ```
@@ -0,0 +1,153 @@
1
+ /**
2
+ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance
5
+ * with the License. A copy of the License is located at
6
+ *
7
+ * http://www.apache.org/licenses/LICENSE-2.0
8
+ *
9
+ * or in the 'license' file accompanying this file. This file is distributed on an 'AS IS' BASIS, WITHOUT WARRANTIES
10
+ * OR CONDITIONS OF ANY KIND, express or implied. See the License for the specific language governing permissions
11
+ * and limitations under the License.
12
+ */
13
+ import type { Construct } from 'constructs';
14
+ import { type IEvaluator, EvaluatorBase } from './evaluator-base';
15
+ import type { EvaluatorConfig } from './evaluator-config';
16
+ import type { EvaluationLevel, EvaluatorAttributes } from './types';
17
+ /**
18
+ * Properties for creating an Evaluator.
19
+ */
20
+ export interface EvaluatorProps {
21
+ /**
22
+ * The name of the evaluator.
23
+ *
24
+ * Must be unique within your account. Valid characters are a-z, A-Z, 0-9, _ (underscore).
25
+ * Must start with a letter and can be up to 48 characters long.
26
+ *
27
+ * @pattern ^[a-zA-Z][a-zA-Z0-9_]{0,47}$
28
+ */
29
+ readonly evaluatorName: string;
30
+ /**
31
+ * The configuration that defines how the evaluator assesses agent performance.
32
+ *
33
+ * Use `EvaluatorConfig.llmAsAJudge()` for model-based evaluation or
34
+ * `EvaluatorConfig.codeBased()` for Lambda-based evaluation.
35
+ */
36
+ readonly evaluatorConfig: EvaluatorConfig;
37
+ /**
38
+ * The level at which the evaluator assesses agent performance.
39
+ *
40
+ * Determines what granularity of data the evaluator operates on:
41
+ * tool call, trace (single request-response), or session (full conversation).
42
+ */
43
+ readonly level: EvaluationLevel;
44
+ /**
45
+ * The description of the evaluator.
46
+ *
47
+ * @default - No description
48
+ * @maxLength 200
49
+ */
50
+ readonly description?: string;
51
+ }
52
+ /**
53
+ * A custom evaluator for Amazon Bedrock AgentCore.
54
+ *
55
+ * Custom evaluators enable you to define evaluation logic tailored to your specific
56
+ * use cases. Supports two evaluation strategies:
57
+ * - **LLM-as-a-Judge**: Uses a foundation model with custom instructions and a rating scale.
58
+ * - **Code-based**: Uses a Lambda function for custom evaluation logic.
59
+ *
60
+ * Custom evaluators are used with `OnlineEvaluationConfig` via `EvaluatorReference.custom()`.
61
+ *
62
+ * @resource AWS::BedrockAgentCore::Evaluator
63
+ *
64
+ * @example
65
+ * // Create a custom LLM-as-a-Judge evaluator
66
+ * const evaluator = new agentcore.Evaluator(this, 'MyEvaluator', {
67
+ * evaluatorName: 'my_custom_evaluator',
68
+ * level: agentcore.EvaluationLevel.SESSION,
69
+ * evaluatorConfig: agentcore.EvaluatorConfig.llmAsAJudge({
70
+ * instructions: 'Evaluate whether the agent response is helpful and accurate.',
71
+ * modelId: 'us.anthropic.claude-sonnet-4-6',
72
+ * ratingScale: agentcore.EvaluatorRatingScale.categorical([
73
+ * { label: 'Good', definition: 'The response is helpful and accurate.' },
74
+ * { label: 'Bad', definition: 'The response is not helpful or contains errors.' },
75
+ * ]),
76
+ * }),
77
+ * });
78
+ *
79
+ * // Use the custom evaluator in an online evaluation configuration
80
+ * new agentcore.OnlineEvaluationConfig(this, 'MyEvaluation', {
81
+ * onlineEvaluationConfigName: 'my_evaluation',
82
+ * evaluators: [
83
+ * agentcore.EvaluatorReference.builtin(agentcore.BuiltinEvaluator.HELPFULNESS),
84
+ * agentcore.EvaluatorReference.custom(evaluator),
85
+ * ],
86
+ * dataSource: agentcore.DataSourceConfig.fromCloudWatchLogs({
87
+ * logGroupNames: ['/aws/bedrock-agentcore/my-agent'],
88
+ * serviceNames: ['my-agent.default'],
89
+ * }),
90
+ * });
91
+ */
92
+ export declare class Evaluator extends EvaluatorBase {
93
+ /** Uniquely identifies this class. */
94
+ static readonly PROPERTY_INJECTION_ID: string;
95
+ /**
96
+ * Import an existing Evaluator by its ID.
97
+ *
98
+ * @param scope - The construct scope
99
+ * @param id - Construct identifier
100
+ * @param evaluatorId - The evaluator ID to import
101
+ * @returns An IEvaluator reference
102
+ */
103
+ static fromEvaluatorId(scope: Construct, id: string, evaluatorId: string): IEvaluator;
104
+ /**
105
+ * Import an existing Evaluator by its ARN.
106
+ *
107
+ * @param scope - The construct scope
108
+ * @param id - Construct identifier
109
+ * @param evaluatorArn - The evaluator ARN to import
110
+ * @returns An IEvaluator reference
111
+ */
112
+ static fromEvaluatorArn(scope: Construct, id: string, evaluatorArn: string): IEvaluator;
113
+ /**
114
+ * Import an existing Evaluator from its attributes.
115
+ *
116
+ * @param scope - The construct scope
117
+ * @param id - Construct identifier
118
+ * @param attrs - The evaluator attributes
119
+ * @returns An IEvaluator reference
120
+ */
121
+ static fromEvaluatorAttributes(scope: Construct, id: string, attrs: EvaluatorAttributes): IEvaluator;
122
+ /**
123
+ * The ARN of the evaluator.
124
+ * @attribute
125
+ */
126
+ readonly evaluatorArn: string;
127
+ /**
128
+ * The unique identifier of the evaluator.
129
+ * @attribute
130
+ */
131
+ readonly evaluatorId: string;
132
+ /**
133
+ * The name of the evaluator.
134
+ * @attribute
135
+ */
136
+ readonly evaluatorName: string;
137
+ /**
138
+ * The lifecycle status of the evaluator.
139
+ * @attribute
140
+ */
141
+ readonly status?: string;
142
+ /**
143
+ * The timestamp when the evaluator was created.
144
+ * @attribute
145
+ */
146
+ readonly createdAt?: string;
147
+ /**
148
+ * The timestamp when the evaluator was last updated.
149
+ * @attribute
150
+ */
151
+ readonly updatedAt?: string;
152
+ constructor(scope: Construct, id: string, props: EvaluatorProps);
153
+ }