-
Notifications
You must be signed in to change notification settings - Fork 63
feat(eval): add eval evaluator CLI commands (CRUD + LLaJ/code-based) #1822
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
a1b48bb
feat(eval): add eval evaluator CLI commands (CRUD + LLaJ/code-based)
b27c4e2
fix(eval): lowercase 'builtin' in list --type filter
ace623b
refactor(eval): merge --rating-scale-json into --rating-scale
5cfff82
refactor(eval): address review — per-subcommand dirs, type aliases, d…
2e73cd0
refactor(eval): use shared IO utilities
eb724bb
refactor(eval): address review — modeled errors, fixture-backed tests
7696310
docs(eval): drop stale --type and --yes from the README examples
122b13f
test(eval): cover inferenceConfig preservation on update
c0338a9
fix(eval): enforce --timeout range, assert the real not-found error
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,156 @@ | ||
| import { | ||
| CreateEvaluatorCommand, | ||
| DeleteEvaluatorCommand, | ||
| GetEvaluatorCommand, | ||
| ListEvaluatorsCommand, | ||
| UpdateEvaluatorCommand, | ||
| type CreateEvaluatorRequest, | ||
| type CreateEvaluatorResponse, | ||
| type DeleteEvaluatorResponse, | ||
| type EvaluatorConfig, | ||
| type GetEvaluatorResponse, | ||
| type ListEvaluatorsResponse, | ||
| type UpdateEvaluatorResponse, | ||
| } from "@aws-sdk/client-bedrock-agentcore-control"; | ||
| import { InputValidationError } from "../errors"; | ||
| import type { CodeBasedUpdate, CoreEvalClient, LlmAsAJudgeUpdate } from "../handlers/eval/types"; | ||
| import type { AwsClients, CoreOptions } from "./types"; | ||
| import { toClientConfig } from "./utils"; | ||
|
|
||
| export class EvalClient implements CoreEvalClient { | ||
| constructor(private readonly clients: AwsClients) {} | ||
|
|
||
| async createEvaluator( | ||
| request: CreateEvaluatorRequest, | ||
| options: CoreOptions, | ||
| ): Promise<CreateEvaluatorResponse> { | ||
| return this.clients.control(toClientConfig(options)).send(new CreateEvaluatorCommand(request)); | ||
| } | ||
|
|
||
| // updateLlmAsAJudgeEvaluator rebuilds the full llmAsAJudge config from the | ||
| // current evaluator, overlays the provided fields, and sends it. UpdateEvaluator | ||
| // replaces the entire evaluatorConfig union, and the llmAsAJudge arm requires | ||
| // instructions + ratingScale + modelConfig together, so a partial update would | ||
| // otherwise drop the fields the caller didn't pass. | ||
| async updateLlmAsAJudgeEvaluator( | ||
| id: string, | ||
| update: LlmAsAJudgeUpdate, | ||
| options: CoreOptions, | ||
| ): Promise<UpdateEvaluatorResponse> { | ||
| const control = this.clients.control(toClientConfig(options)); | ||
| const current = await control.send(new GetEvaluatorCommand({ evaluatorId: id })); | ||
|
|
||
| // Reject a type mismatch before merging: UpdateEvaluator replaces the whole | ||
| // evaluatorConfig union, so merging into the wrong arm would silently convert | ||
| // a code-based evaluator into an LLM-as-a-Judge one. | ||
| if (!current.evaluatorConfig || !("llmAsAJudge" in current.evaluatorConfig)) { | ||
| throw new InputValidationError(`Evaluator "${id}" is not an LLM-as-a-Judge evaluator`, { | ||
| meta: { evaluatorId: id }, | ||
| }); | ||
| } | ||
| const existing = current.evaluatorConfig.llmAsAJudge; | ||
|
|
||
| const instructions = update.instructions ?? existing?.instructions; | ||
| const ratingScale = update.ratingScale ?? existing?.ratingScale; | ||
| // Preserve the existing Bedrock model config (inferenceConfig, | ||
| // additionalModelRequestFields, ...) and override only the model id, so an | ||
| // update that touches other fields does not drop model tuning. | ||
| const existingModel = | ||
| existing?.modelConfig && "bedrockEvaluatorModelConfig" in existing.modelConfig | ||
| ? existing.modelConfig.bedrockEvaluatorModelConfig | ||
| : undefined; | ||
| const modelId = update.model ?? existingModel?.modelId; | ||
|
|
||
| if (!instructions || !ratingScale || !modelId) { | ||
| throw new InputValidationError( | ||
| `Evaluator "${id}" is missing configuration required to update it: ` + | ||
| `instructions, rating scale, and model are all required`, | ||
| { meta: { evaluatorId: id } }, | ||
| ); | ||
| } | ||
|
|
||
| const evaluatorConfig: EvaluatorConfig = { | ||
| llmAsAJudge: { | ||
| instructions, | ||
| ratingScale, | ||
| modelConfig: { bedrockEvaluatorModelConfig: { ...existingModel, modelId } }, | ||
| }, | ||
| }; | ||
|
|
||
| return control.send( | ||
| new UpdateEvaluatorCommand({ | ||
| evaluatorId: id, | ||
| evaluatorConfig, | ||
| kmsKeyArn: update.kmsKeyArn, | ||
| clientToken: update.clientToken, | ||
| }), | ||
| ); | ||
| } | ||
|
|
||
| // updateCodeBasedEvaluator mirrors updateLlmAsAJudgeEvaluator: it merges the | ||
| // provided lambda ARN / timeout over the current codeBased config so unset | ||
| // fields are preserved across the union-replacing UpdateEvaluator call. | ||
| async updateCodeBasedEvaluator( | ||
| id: string, | ||
| update: CodeBasedUpdate, | ||
| options: CoreOptions, | ||
| ): Promise<UpdateEvaluatorResponse> { | ||
| const control = this.clients.control(toClientConfig(options)); | ||
| const current = await control.send(new GetEvaluatorCommand({ evaluatorId: id })); | ||
|
|
||
| // Same union-replacement hazard as updateLlmAsAJudgeEvaluator: reject a type | ||
| // mismatch instead of converting the evaluator to code-based. | ||
| if (!current.evaluatorConfig || !("codeBased" in current.evaluatorConfig)) { | ||
| throw new InputValidationError(`Evaluator "${id}" is not a code-based evaluator`, { | ||
| meta: { evaluatorId: id }, | ||
| }); | ||
| } | ||
| const existing = current.evaluatorConfig.codeBased; | ||
| const existingLambda = | ||
| existing && "lambdaConfig" in existing ? existing.lambdaConfig : undefined; | ||
|
|
||
| const lambdaArn = update.lambdaArn ?? existingLambda?.lambdaArn; | ||
| if (!lambdaArn) { | ||
| throw new InputValidationError( | ||
| `Evaluator "${id}" is missing configuration required to update it: a Lambda ARN is required`, | ||
| { meta: { evaluatorId: id } }, | ||
| ); | ||
| } | ||
| const lambdaTimeoutInSeconds = update.timeout ?? existingLambda?.lambdaTimeoutInSeconds; | ||
|
|
||
| const evaluatorConfig: EvaluatorConfig = { | ||
| codeBased: { lambdaConfig: { ...existingLambda, lambdaArn, lambdaTimeoutInSeconds } }, | ||
| }; | ||
|
|
||
| return control.send( | ||
| new UpdateEvaluatorCommand({ | ||
| evaluatorId: id, | ||
| evaluatorConfig, | ||
| kmsKeyArn: update.kmsKeyArn, | ||
| clientToken: update.clientToken, | ||
| }), | ||
| ); | ||
| } | ||
|
|
||
| async getEvaluator(id: string, options: CoreOptions): Promise<GetEvaluatorResponse> { | ||
| return this.clients | ||
| .control(toClientConfig(options)) | ||
| .send(new GetEvaluatorCommand({ evaluatorId: id })); | ||
| } | ||
|
|
||
| async listEvaluators( | ||
| nextToken: string | undefined, | ||
| maxResults: number | undefined, | ||
| options: CoreOptions, | ||
| ): Promise<ListEvaluatorsResponse> { | ||
| return this.clients | ||
| .control(toClientConfig(options)) | ||
| .send(new ListEvaluatorsCommand({ nextToken, maxResults })); | ||
| } | ||
|
|
||
| async deleteEvaluator(id: string, options: CoreOptions): Promise<DeleteEvaluatorResponse> { | ||
| return this.clients | ||
| .control(toClientConfig(options)) | ||
| .send(new DeleteEvaluatorCommand({ evaluatorId: id })); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
src/handlers/eval/evaluator/__fixtures__/CreateEvaluatorCommand.6577d746bc507a1f.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| { | ||
| "evaluatorArn": "arn:aws:bedrock-agentcore:us-west-2:685197708687:evaluator/agentcore_cli_eval_fixture_llaj-IFK4y04Eae", | ||
| "evaluatorId": "agentcore_cli_eval_fixture_llaj-IFK4y04Eae", | ||
| "createdAt": { | ||
| "$date": "2026-07-28T22:35:10.520Z" | ||
| }, | ||
| "status": "ACTIVE" | ||
| } |
8 changes: 8 additions & 0 deletions
8
src/handlers/eval/evaluator/__fixtures__/CreateEvaluatorCommand.ac8dfb5c513183ed.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| { | ||
| "evaluatorArn": "arn:aws:bedrock-agentcore:us-west-2:685197708687:evaluator/agentcore_cli_eval_fixture_code-KnZOVbDFFG", | ||
| "evaluatorId": "agentcore_cli_eval_fixture_code-KnZOVbDFFG", | ||
| "createdAt": { | ||
| "$date": "2026-07-28T22:35:10.771Z" | ||
| }, | ||
| "status": "ACTIVE" | ||
| } |
8 changes: 8 additions & 0 deletions
8
src/handlers/eval/evaluator/__fixtures__/CreateEvaluatorCommand.c831d79d64c9b9ff.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| { | ||
| "evaluatorArn": "arn:aws:bedrock-agentcore:us-west-2:685197708687:evaluator/agentcore_cli_eval_fixture_tuned-oATpVrAtsP", | ||
| "evaluatorId": "agentcore_cli_eval_fixture_tuned-oATpVrAtsP", | ||
| "createdAt": { | ||
| "$date": "2026-07-28T22:35:13.640Z" | ||
| }, | ||
| "status": "ACTIVE" | ||
| } |
5 changes: 5 additions & 0 deletions
5
src/handlers/eval/evaluator/__fixtures__/DeleteEvaluatorCommand.335f855e3abfbf62.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| { | ||
| "evaluatorArn": "arn:aws:bedrock-agentcore:us-west-2:685197708687:evaluator/agentcore_cli_eval_fixture_tuned-oATpVrAtsP", | ||
| "evaluatorId": "agentcore_cli_eval_fixture_tuned-oATpVrAtsP", | ||
| "status": "DELETING" | ||
| } |
5 changes: 5 additions & 0 deletions
5
src/handlers/eval/evaluator/__fixtures__/DeleteEvaluatorCommand.6312984a1050d730.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| { | ||
| "evaluatorArn": "arn:aws:bedrock-agentcore:us-west-2:685197708687:evaluator/agentcore_cli_eval_fixture_code-KnZOVbDFFG", | ||
| "evaluatorId": "agentcore_cli_eval_fixture_code-KnZOVbDFFG", | ||
| "status": "DELETING" | ||
| } |
5 changes: 5 additions & 0 deletions
5
src/handlers/eval/evaluator/__fixtures__/DeleteEvaluatorCommand.7b3e57666160ba0b.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| { | ||
| "evaluatorArn": "arn:aws:bedrock-agentcore:us-west-2:685197708687:evaluator/agentcore_cli_eval_fixture_llaj-IFK4y04Eae", | ||
| "evaluatorId": "agentcore_cli_eval_fixture_llaj-IFK4y04Eae", | ||
| "status": "DELETING" | ||
| } |
57 changes: 57 additions & 0 deletions
57
src/handlers/eval/evaluator/__fixtures__/GetEvaluatorCommand.335f855e3abfbf62.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| { | ||
| "evaluatorArn": "arn:aws:bedrock-agentcore:us-west-2:685197708687:evaluator/agentcore_cli_eval_fixture_tuned-oATpVrAtsP", | ||
| "evaluatorId": "agentcore_cli_eval_fixture_tuned-oATpVrAtsP", | ||
| "evaluatorName": "agentcore_cli_eval_fixture_tuned", | ||
| "evaluatorConfig": { | ||
| "llmAsAJudge": { | ||
| "instructions": "Judge from {context} whether the agent was both correct and polite.", | ||
| "ratingScale": { | ||
| "numerical": [ | ||
| { | ||
| "definition": "Fails to meet expectations", | ||
| "value": 1, | ||
| "label": "Poor" | ||
| }, | ||
| { | ||
| "definition": "Partially meets expectations", | ||
| "value": 2, | ||
| "label": "Fair" | ||
| }, | ||
| { | ||
| "definition": "Meets expectations", | ||
| "value": 3, | ||
| "label": "Good" | ||
| }, | ||
| { | ||
| "definition": "Exceeds expectations", | ||
| "value": 4, | ||
| "label": "Very Good" | ||
| }, | ||
| { | ||
| "definition": "Far exceeds expectations", | ||
| "value": 5, | ||
| "label": "Excellent" | ||
| } | ||
| ] | ||
| }, | ||
| "modelConfig": { | ||
| "bedrockEvaluatorModelConfig": { | ||
| "modelId": "us.anthropic.claude-sonnet-4-5-20250929-v1:0", | ||
| "inferenceConfig": { | ||
| "maxTokens": 512, | ||
| "temperature": 0 | ||
| } | ||
| } | ||
| } | ||
| } | ||
| }, | ||
| "level": "SESSION", | ||
| "status": "ACTIVE", | ||
| "createdAt": { | ||
| "$date": "2026-07-28T22:35:13.640Z" | ||
| }, | ||
| "updatedAt": { | ||
| "$date": "2026-07-28T22:35:16.477Z" | ||
| }, | ||
| "lockedForModification": false | ||
| } |
22 changes: 22 additions & 0 deletions
22
src/handlers/eval/evaluator/__fixtures__/GetEvaluatorCommand.6312984a1050d730.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| { | ||
| "evaluatorArn": "arn:aws:bedrock-agentcore:us-west-2:685197708687:evaluator/agentcore_cli_eval_fixture_code-KnZOVbDFFG", | ||
| "evaluatorId": "agentcore_cli_eval_fixture_code-KnZOVbDFFG", | ||
| "evaluatorName": "agentcore_cli_eval_fixture_code", | ||
| "evaluatorConfig": { | ||
| "codeBased": { | ||
| "lambdaConfig": { | ||
| "lambdaArn": "arn:aws:lambda:us-west-2:685197708687:function:agentcore-bugbash-echo-1774451937", | ||
| "lambdaTimeoutInSeconds": 45 | ||
| } | ||
| } | ||
| }, | ||
| "level": "SESSION", | ||
| "status": "ACTIVE", | ||
| "createdAt": { | ||
| "$date": "2026-07-28T22:35:10.771Z" | ||
| }, | ||
| "updatedAt": { | ||
| "$date": "2026-07-28T22:35:17.137Z" | ||
| }, | ||
| "lockedForModification": false | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.