-
Notifications
You must be signed in to change notification settings - Fork 66
feat: add --model-provider flag for keyless Bedrock LLM judge evaluators #1828
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
jariy17
merged 25 commits into
aws:main
from
stone-coding:feature/bedrock-model-templates
Jul 31, 2026
Merged
Changes from all commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
6fba5c8
Add deepeval CLI integration: flags, templates, warnings, memory, uni…
haomiao037 d44430a
Refactor CLI to registry-driven third-party evaluator framework (Deep…
haomiao037 485000e
fix: Update 3P evaluator templates and add --param/--parameters-file …
haomiao037 0bff7a8
feat: Add 3P evaluator E2E test + fix autoevals template
haomiao037 9153b3c
fix: Rename AutoevalsAdapter → AutoEvalsAdapter in template (match SD…
haomiao037 7b5348c
fix: Reject --3p-library with --type llm-as-a-judge
haomiao037 56158e3
feat: Add --model-provider flag for keyless Bedrock evaluators
haomiao037 1a860d9
fix: Require --model with --model-provider bedrock, remove env var de…
haomiao037 591760a
fix: Address Copilot review comments
haomiao037 a100276
fix: Update E2E test to use --model-provider bedrock (keyless)
haomiao037 f92635c
fix: Default --model-provider to bedrock, add OpenAI warning
haomiao037 27ba5a2
fix: Use hasOwnProperty for library validation (Copilot review)
haomiao037 f1cf617
fix: Allow --model without explicit --model-provider (bedrock is defa…
haomiao037 1aa9152
fix: Parse Python-style True/False/None in --param values
haomiao037 11537a1
fix: Autoevals dangling comma + clarify inference profile in --model …
haomiao037 e9cb8f6
fix: Remove --memory flag (to be handled via GitHub issue)
haomiao037 565eeda
feat: Add --3p-template-json and --3p-template-json-file flags
haomiao037 978a29c
fix: Remove individual 3P flags, use --3p-template-json only
haomiao037 73376a3
fix: Remove dead parseParamFlags code + update E2E tests to use --3p-…
haomiao037 de7768b
fix: Add OpenAI warning + pass model to metric in OpenAI path
haomiao037 315fa1d
fix: Make model optional for deterministic metrics in --3p-template-json
haomiao037 802a95f
fix: Pin deepeval and autoevals with upper version bounds
haomiao037 e740815
fix: Remove memorySizeMb, fix lint errors per TJ review
haomiao037 59aa8b8
fix: Resolve typecheck errors (TS2454, TS2353)
haomiao037 ec5c264
fix: Apply prettier formatting to test file
haomiao037 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,214 @@ | ||
| import { parseJsonOutput, retry } from '../src/test-utils/index.js'; | ||
| import { | ||
| baseCanRun, | ||
| hasAws, | ||
| installCdkTarball, | ||
| runAgentCoreCLI, | ||
| teardownE2EProject, | ||
| writeAwsTargets, | ||
| } from './e2e-helper.js'; | ||
| import { randomUUID } from 'node:crypto'; | ||
| import { mkdir, rm } from 'node:fs/promises'; | ||
| import { tmpdir } from 'node:os'; | ||
| import { join } from 'node:path'; | ||
| import { afterAll, beforeAll, describe, expect, it } from 'vitest'; | ||
|
|
||
| const canRun = baseCanRun && hasAws; | ||
|
|
||
| describe.sequential('e2e: third-party evaluator lifecycle (DeepEval + Autoevals)', () => { | ||
| let testDir: string; | ||
| let projectPath: string; | ||
| const agentName = `E2e3pEval${String(Date.now()).slice(-8)}`; | ||
| const deepevalEvalName = 'answer_relevancy'; | ||
| const autoevalsEvalName = 'exact_match'; | ||
|
|
||
| beforeAll(async () => { | ||
| if (!canRun) return; | ||
|
|
||
| testDir = join(tmpdir(), `agentcore-e2e-3p-eval-${randomUUID()}`); | ||
| await mkdir(testDir, { recursive: true }); | ||
|
|
||
| const result = await runAgentCoreCLI( | ||
| [ | ||
| 'create', | ||
| '--name', | ||
| agentName, | ||
| '--language', | ||
| 'Python', | ||
| '--framework', | ||
| 'Strands', | ||
| '--model-provider', | ||
| 'Bedrock', | ||
| '--memory', | ||
| 'none', | ||
| '--json', | ||
| ], | ||
| testDir | ||
| ); | ||
| expect(result.exitCode, `Create failed: ${result.stderr}`).toBe(0); | ||
| projectPath = (parseJsonOutput(result.stdout) as { projectPath: string }).projectPath; | ||
|
|
||
| await writeAwsTargets(projectPath); | ||
| installCdkTarball(projectPath); | ||
| }, 300000); | ||
|
|
||
| afterAll(async () => { | ||
| if (projectPath && hasAws) { | ||
| await teardownE2EProject(projectPath, agentName, 'Bedrock'); | ||
| } | ||
| if (testDir) await rm(testDir, { recursive: true, force: true, maxRetries: 3, retryDelay: 1000 }); | ||
| }, 600000); | ||
|
|
||
| const run = (args: string[]) => runAgentCoreCLI(args, projectPath); | ||
|
|
||
| it.skipIf(!canRun)( | ||
| 'adds a DeepEval 3P evaluator with --3p-template-json', | ||
| async () => { | ||
| const templateJson = JSON.stringify({ | ||
| library: 'deepeval', | ||
| metric: 'AnswerRelevancyMetric', | ||
| modelProvider: 'bedrock', | ||
| model: 'us.anthropic.claude-sonnet-4-20250514-v1:0', | ||
| params: { threshold: 0.5 }, | ||
| }); | ||
| const result = await run([ | ||
| 'add', | ||
| 'evaluator', | ||
| '--name', | ||
| deepevalEvalName, | ||
| '--level', | ||
| 'TRACE', | ||
| '--type', | ||
| 'code-based', | ||
| '--3p-template-json', | ||
| templateJson, | ||
| '--json', | ||
| ]); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please update all the tests |
||
| expect(result.exitCode, `Add DeepEval evaluator failed: ${result.stdout}`).toBe(0); | ||
| const json = parseJsonOutput(result.stdout) as { success: boolean; evaluatorName: string; codePath: string }; | ||
| expect(json.success).toBe(true); | ||
| expect(json.evaluatorName).toBe(deepevalEvalName); | ||
| expect(json.codePath).toContain(deepevalEvalName); | ||
| }, | ||
| 60000 | ||
| ); | ||
|
|
||
| it.skipIf(!canRun)( | ||
| 'adds an Autoevals 3P evaluator with --3p-template-json', | ||
| async () => { | ||
| const templateJson = JSON.stringify({ | ||
| library: 'autoevals', | ||
| metric: 'ExactMatch', | ||
| modelProvider: 'bedrock', | ||
| model: 'us.anthropic.claude-sonnet-4-20250514-v1:0', | ||
| }); | ||
| const result = await run([ | ||
| 'add', | ||
| 'evaluator', | ||
| '--name', | ||
| autoevalsEvalName, | ||
| '--level', | ||
| 'TRACE', | ||
| '--type', | ||
| 'code-based', | ||
| '--3p-template-json', | ||
| templateJson, | ||
| '--json', | ||
| ]); | ||
| expect(result.exitCode, `Add Autoevals evaluator failed: ${result.stdout}`).toBe(0); | ||
| const json = parseJsonOutput(result.stdout) as { success: boolean; evaluatorName: string; codePath: string }; | ||
| expect(json.success).toBe(true); | ||
| expect(json.evaluatorName).toBe(autoevalsEvalName); | ||
| expect(json.codePath).toContain(autoevalsEvalName); | ||
| }, | ||
| 60000 | ||
| ); | ||
|
|
||
| it.skipIf(!canRun)( | ||
| 'deploys agent with 3P evaluators', | ||
| async () => { | ||
| const result = await run(['deploy', '--yes', '--json']); | ||
| if (result.exitCode !== 0) { | ||
| console.log('Deploy stdout:', result.stdout); | ||
| console.log('Deploy stderr:', result.stderr); | ||
| } | ||
| expect(result.exitCode, 'Deploy failed').toBe(0); | ||
| const json = parseJsonOutput(result.stdout) as { success: boolean }; | ||
| expect(json.success).toBe(true); | ||
| }, | ||
| 600000 | ||
| ); | ||
|
|
||
| it.skipIf(!canRun)( | ||
| 'invokes the deployed agent to generate traces', | ||
| async () => { | ||
| await retry( | ||
| async () => { | ||
| const result = await run(['invoke', '--prompt', 'What is 2+2?', '--runtime', agentName, '--json']); | ||
| expect(result.exitCode, `Invoke failed: ${result.stderr}`).toBe(0); | ||
| const json = parseJsonOutput(result.stdout) as { success: boolean }; | ||
| expect(json.success).toBe(true); | ||
| }, | ||
| 3, | ||
| 15000 | ||
| ); | ||
| }, | ||
| 180000 | ||
| ); | ||
|
|
||
| it.skipIf(!canRun)( | ||
| 'runs on-demand evaluation with DeepEval 3P evaluator', | ||
| async () => { | ||
| await retry( | ||
| async () => { | ||
| const result = await run([ | ||
| 'run', | ||
| 'eval', | ||
| '--runtime', | ||
| agentName, | ||
| '--evaluator', | ||
| deepevalEvalName, | ||
| '--days', | ||
| '1', | ||
| '--json', | ||
| ]); | ||
| expect(result.exitCode, `Run eval failed (stdout: ${result.stdout}, stderr: ${result.stderr})`).toBe(0); | ||
| const json = parseJsonOutput(result.stdout) as Record<string, unknown>; | ||
| expect(json).toHaveProperty('success', true); | ||
| expect(json).toHaveProperty('run'); | ||
| }, | ||
| 18, | ||
| 10000 | ||
| ); | ||
| }, | ||
| 300000 | ||
| ); | ||
|
|
||
| it.skipIf(!canRun)( | ||
| 'runs on-demand evaluation with Autoevals 3P evaluator', | ||
| async () => { | ||
| await retry( | ||
| async () => { | ||
| const result = await run([ | ||
| 'run', | ||
| 'eval', | ||
| '--runtime', | ||
| agentName, | ||
| '--evaluator', | ||
| autoevalsEvalName, | ||
| '--days', | ||
| '1', | ||
| '--json', | ||
| ]); | ||
| expect(result.exitCode, `Run eval failed (stdout: ${result.stdout}, stderr: ${result.stderr})`).toBe(0); | ||
| const json = parseJsonOutput(result.stdout) as Record<string, unknown>; | ||
| expect(json).toHaveProperty('success', true); | ||
| expect(json).toHaveProperty('run'); | ||
| }, | ||
| 18, | ||
| 10000 | ||
| ); | ||
| }, | ||
| 300000 | ||
| ); | ||
| }); | ||
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
15 changes: 15 additions & 0 deletions
15
src/assets/evaluators/autoevals-lambda/execution-role-policy.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,15 @@ | ||
| { | ||
| "Version": "2012-10-17", | ||
| "Statement": [ | ||
| { | ||
| "Effect": "Allow", | ||
| "Action": ["logs:CreateLogGroup", "logs:CreateLogStream", "logs:PutLogEvents"], | ||
| "Resource": "arn:*:logs:*:*:log-group:/aws/lambda/*" | ||
| }, | ||
| { | ||
| "Effect": "Allow", | ||
| "Action": ["bedrock:InvokeModel"], | ||
| "Resource": "*" | ||
| } | ||
| ] | ||
| } |
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,37 @@ | ||
| {{#if ModelProviderBedrock}} | ||
| import os | ||
|
|
||
| # litellm's Bedrock provider reads AWS_REGION_NAME; Lambda only sets AWS_REGION/AWS_DEFAULT_REGION. | ||
| os.environ.setdefault("AWS_REGION_NAME", os.environ.get("AWS_REGION", "us-west-2")) | ||
|
|
||
| from autoevals import {{ EvaluatorClass }}, init | ||
| from autoevals.litellm import LiteLLMClient | ||
|
|
||
| from bedrock_agentcore.evaluation.custom_code_based_evaluators import ( | ||
| EvaluatorInput, | ||
| EvaluatorOutput, | ||
| custom_code_based_evaluator, | ||
| ) | ||
| from bedrock_agentcore.evaluation.custom_code_based_evaluators.third_party.autoevals import AutoEvalsAdapter | ||
|
|
||
| client = LiteLLMClient() | ||
| init(client=client, default_model="{{ Model }}") | ||
|
|
||
| adapter = AutoEvalsAdapter(metric={{ EvaluatorClass }}(client=client, model="{{ Model }}"){{#if EvaluatorParams}}, {{{ EvaluatorParams }}}{{/if}}) | ||
| {{else}} | ||
| from autoevals import {{ EvaluatorClass }} | ||
|
|
||
| from bedrock_agentcore.evaluation.custom_code_based_evaluators import ( | ||
| EvaluatorInput, | ||
| EvaluatorOutput, | ||
| custom_code_based_evaluator, | ||
| ) | ||
| from bedrock_agentcore.evaluation.custom_code_based_evaluators.third_party.autoevals import AutoEvalsAdapter | ||
|
|
||
| adapter = AutoEvalsAdapter(metric={{ EvaluatorClass }}({{#if Model}}model="{{ Model }}"{{/if}}){{#if EvaluatorParams}}, {{{ EvaluatorParams }}}{{/if}}) | ||
| {{/if}} | ||
|
|
||
|
|
||
| @custom_code_based_evaluator() | ||
| def handler(evaluator_input: EvaluatorInput, context) -> EvaluatorOutput: | ||
| return adapter(evaluator_input, context) |
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 @@ | ||
| [build-system] | ||
| requires = ["hatchling"] | ||
| build-backend = "hatchling.build" | ||
|
|
||
| [project] | ||
| name = "{{ Name }}" | ||
| version = "0.1.0" | ||
| description = "AgentCore Code-Based Evaluator (Autoevals)" | ||
| requires-python = ">=3.10" | ||
| dependencies = [ | ||
| "bedrock-agentcore[autoevals]", | ||
| "autoevals>=0.0.80,<1.0.0", | ||
| {{#if ModelProviderBedrock}} | ||
| # autoevals grades via LiteLLMClient -> Bedrock (Converse); litellm replaces the openai judge | ||
| "litellm>=1.60,<1.85", | ||
| {{else}} | ||
| "openai>=1.0.0", | ||
| {{/if}} | ||
| ] | ||
|
|
||
| [tool.hatch.build.targets.wheel] | ||
| packages = ["."] |
15 changes: 15 additions & 0 deletions
15
src/assets/evaluators/deepeval-lambda/execution-role-policy.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,15 @@ | ||
| { | ||
| "Version": "2012-10-17", | ||
| "Statement": [ | ||
| { | ||
| "Effect": "Allow", | ||
| "Action": ["logs:CreateLogGroup", "logs:CreateLogStream", "logs:PutLogEvents"], | ||
| "Resource": "arn:*:logs:*:*:log-group:/aws/lambda/*" | ||
| }, | ||
| { | ||
| "Effect": "Allow", | ||
| "Action": ["bedrock:InvokeModel"], | ||
| "Resource": "*" | ||
| } | ||
| ] | ||
| } |
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,29 @@ | ||
| import os | ||
|
|
||
| os.environ.setdefault("DEEPEVAL_RESULTS_FOLDER", "/tmp/.deepeval") | ||
| os.environ.setdefault("DEEPEVAL_TELEMETRY_OPT_OUT", "YES") | ||
| os.chdir("/tmp") | ||
|
|
||
| {{#if ModelProviderBedrock}} | ||
| from deepeval.models import AmazonBedrockModel | ||
| {{/if}} | ||
| from deepeval.metrics import {{ EvaluatorClass }} | ||
|
|
||
| from bedrock_agentcore.evaluation.custom_code_based_evaluators import ( | ||
| EvaluatorInput, | ||
| EvaluatorOutput, | ||
| custom_code_based_evaluator, | ||
| ) | ||
| from bedrock_agentcore.evaluation.custom_code_based_evaluators.third_party.deepeval import DeepEvalAdapter | ||
|
|
||
| {{#if ModelProviderBedrock}} | ||
| model = AmazonBedrockModel(model="{{ Model }}", region=os.environ.get("AWS_REGION", "us-west-2")) | ||
| adapter = DeepEvalAdapter(metric={{ EvaluatorClass }}(model=model{{#if EvaluatorParams}}, {{{ EvaluatorParams }}}{{/if}})) | ||
| {{else}} | ||
| adapter = DeepEvalAdapter(metric={{ EvaluatorClass }}({{{ EvaluatorParams }}})) | ||
| {{/if}} | ||
|
|
||
|
|
||
| @custom_code_based_evaluator() | ||
| def handler(evaluator_input: EvaluatorInput, context) -> EvaluatorOutput: | ||
| return adapter(evaluator_input, context) |
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,19 @@ | ||
| [build-system] | ||
| requires = ["hatchling"] | ||
| build-backend = "hatchling.build" | ||
|
|
||
| [project] | ||
| name = "{{ Name }}" | ||
| version = "0.1.0" | ||
| description = "AgentCore Code-Based Evaluator (DeepEval)" | ||
| requires-python = ">=3.10" | ||
| dependencies = [ | ||
| "bedrock-agentcore[deepeval]", | ||
| "deepeval>=2.0.0,<3.0.0", | ||
| {{#if ModelProviderBedrock}} | ||
| "aiobotocore>=2.13.0", | ||
| {{/if}} | ||
| ] | ||
|
|
||
| [tool.hatch.build.targets.wheel] | ||
| packages = ["."] |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please run typecheck, linter, and prettier on this PR.