Skip to content

feat(project): add project add evaluator code-based - #2144

Open
jariy17 wants to merge 7 commits into
refactorfrom
feat/project-add-evaluator-code-based
Open

feat(project): add project add evaluator code-based#2144
jariy17 wants to merge 7 commits into
refactorfrom
feat/project-add-evaluator-code-based

Conversation

@jariy17

@jariy17 jariy17 commented Aug 28, 2026

Copy link
Copy Markdown
Contributor

Command structure

agentcore project add evaluator          add a custom evaluator to the current project
├── llm-as-a-judge                       existing — LLM prompted to score a session
└── code-based                           NEW — a Lambda that scores a session
agentcore project remove evaluator --name <name>   NEW — enabled via the generic remove

agentcore project add evaluator code-based --help:

Usage: agentcore project add evaluator code-based [options]

add a code-based evaluator — a Lambda that scores a session. Pass a 3P metric,
an existing Lambda, or neither to scaffold an empty evaluator you fill in

Options:
  --name <name>                        the name of the evaluator
  --level <level>                      what to score: SESSION, TRACE, or TOOL_CALL
  --metric <metric>                    3P metric to scaffold as <library.Metric>,
                                       e.g. deepeval.FaithfulnessMetric or autoevals.Factuality
  --model <model>                      judge model for the 3P metric,
                                       e.g. bedrock/anthropic.claude-3-5-sonnet-20240620-v1:0
  --lambda-arn <lambda-arn>            ARN of an existing Lambda that scores a session
  --timeout-seconds <timeout-seconds>  Lambda timeout in seconds (1-300)
  --description <description>          a description of what this evaluator measures
  --kms-key-arn <kms-key-arn>          customer-managed KMS key ARN to encrypt the evaluator
  --tags <tags>                        tags to apply (JSON object of key/value strings)
  -h, --help                           display help for command

Commits

  1. c4430c03 feat — the command + 3 scaffold templates + remove evaluator
  2. baec1630 fix — guard app/<name> collisions (up-front, no partial writes)
  3. e7bc3675 fix — validate --metric class + require a Bedrock --model
  4. 9bd79980 fix — echo the inferred mode + caveats at add time
  5. 32a10ef9 refactor — share toPythonPackageName via fsUtils; DEFAULT_TIMEOUT const
  6. 853dcf86 refactor — move template knowledge into templates/evaluator.ts (runtime layering)

Testing

  • bun run build OK · bun test src/handlers/project src/core/project597 pass / 0 fail.
  • Cloud bug bash (5 parallel agents; 2 deployed to a non-prod account, us-west-2, then tore down): all 5 flows + a 13-case error matrix pass at the CLI/scaffold/synth layer. The managed evaluator synthesizes correctly into AWS::BedrockAgentCore::Evaluator + Lambda + role + permissions, and generated Python ast.parses for deepeval + autoevals (bedrock + openai branches). Full report shared separately.

@github-actions github-actions Bot added the size/xl PR size: XL label Aug 28, 2026
@agentcore-devx-automation agentcore-devx-automation Bot added agentcore-harness-reviewing AgentCore Harness review in progress claude-security-reviewing Claude Code /security-review in progress labels Aug 28, 2026

@agentcore-devx-automation agentcore-devx-automation Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AgentCore Harness Review

Verdict: Looks good

Small, focused fix that surfaces two real footguns of the code-based evaluator scaffold:

  • Empty stub silently returns Pass for every session (verified against src/assets/evaluators/python-lambda/lambda_function.py, which returns label="Pass").
  • Managed code-based evaluators aren't yet provisioned by project deploy.

Logic in index.ts (lines 158–166) matches the commit message: the "returns Pass" note is gated on !hasLambda && !hasMetric, and the "not yet provisioned" note is gated on !hasLambda, so --lambda-arn (external) correctly prints neither.

Tests in index.test.ts use real temp directories via mkdtemp and drive the handler through the router — no excessive mocking — and cover both the stub and external paths. Telemetry isn't warranted here since this only adds informational stderr output, not a new feature.

Nothing blocking.

@agentcore-devx-automation agentcore-devx-automation Bot removed the agentcore-harness-reviewing AgentCore Harness review in progress label Aug 28, 2026
@codecov-commenter

codecov-commenter commented Aug 28, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.24%. Comparing base (d304147) to head (ef9f5ca).

Additional details and impacted files
@@             Coverage Diff              @@
##           refactor    #2144      +/-   ##
============================================
+ Coverage     97.22%   97.24%   +0.01%     
============================================
  Files           507      509       +2     
  Lines         33809    34009     +200     
============================================
+ Hits          32872    33073     +201     
+ Misses          937      936       -1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@agentcore-devx-automation

Copy link
Copy Markdown
Contributor

Claude Security Review: no high-confidence findings. (run)

@agentcore-devx-automation agentcore-devx-automation Bot removed the claude-security-reviewing Claude Code /security-review in progress label Aug 28, 2026
@jariy17
jariy17 force-pushed the feat/project-add-evaluator-code-based branch from 303c8db to 9bd7998 Compare August 31, 2026 14:51
@github-actions github-actions Bot added size/l PR size: L and removed size/xl PR size: XL labels Aug 31, 2026
@agentcore-devx-automation agentcore-devx-automation Bot added the claude-security-reviewing Claude Code /security-review in progress label Aug 31, 2026
@agentcore-devx-automation

Copy link
Copy Markdown
Contributor

Claude Security Review: no high-confidence findings. (run)

@agentcore-devx-automation agentcore-devx-automation Bot removed the claude-security-reviewing Claude Code /security-review in progress label Aug 31, 2026
const context: Record<string, unknown> = { Name: toPythonPackageName(flags["name"]) };

if (hasMetric) {
const raw = flags["metric"]!;

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we use make this helper function and use zod here.

@github-actions github-actions Bot added size/l PR size: L and removed size/l PR size: L labels Aug 31, 2026
@agentcore-devx-automation agentcore-devx-automation Bot added the claude-security-reviewing Claude Code /security-review in progress label Aug 31, 2026
@agentcore-devx-automation

Copy link
Copy Markdown
Contributor

Claude Security Review: no high-confidence findings. (run)

@agentcore-devx-automation agentcore-devx-automation Bot removed the claude-security-reviewing Claude Code /security-review in progress label Aug 31, 2026
@github-actions github-actions Bot added size/l PR size: L and removed size/l PR size: L labels Aug 31, 2026
@agentcore-devx-automation agentcore-devx-automation Bot added the claude-security-reviewing Claude Code /security-review in progress label Aug 31, 2026
@agentcore-devx-automation

Copy link
Copy Markdown
Contributor

Claude Security Review: no high-confidence findings. (run)

@agentcore-devx-automation agentcore-devx-automation Bot removed the claude-security-reviewing Claude Code /security-review in progress label Aug 31, 2026
@jariy17
jariy17 force-pushed the feat/project-add-evaluator-code-based branch from e78e9bc to 32a10ef Compare August 31, 2026 17:33
@github-actions github-actions Bot added size/l PR size: L and removed size/l PR size: L labels Aug 31, 2026
@agentcore-devx-automation agentcore-devx-automation Bot added the claude-security-reviewing Claude Code /security-review in progress label Aug 31, 2026
@agentcore-devx-automation

Copy link
Copy Markdown
Contributor

Claude Security Review: no high-confidence findings. (run)

@github-actions github-actions Bot added size/l PR size: L and removed size/l PR size: L labels Aug 31, 2026
@@ -0,0 +1,15 @@
{

@jariy17 jariy17 Aug 31, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't want add an abstraction to generate common assets like this one due time constraints. We can look for this in the future.

@github-actions github-actions Bot added size/l PR size: L and removed size/l PR size: L labels Aug 31, 2026
@agentcore-devx-automation agentcore-devx-automation Bot added the claude-security-reviewing Claude Code /security-review in progress label Aug 31, 2026
@agentcore-devx-automation

Copy link
Copy Markdown
Contributor

Claude Security Review: no high-confidence findings. (run)

@agentcore-devx-automation agentcore-devx-automation Bot removed the claude-security-reviewing Claude Code /security-review in progress label Aug 31, 2026
@jariy17
jariy17 force-pushed the feat/project-add-evaluator-code-based branch from e440cb5 to 7215450 Compare August 31, 2026 19:41
@github-actions github-actions Bot added size/l PR size: L and removed size/l PR size: L labels Aug 31, 2026
@agentcore-devx-automation agentcore-devx-automation Bot added the claude-security-reviewing Claude Code /security-review in progress label Aug 31, 2026
@agentcore-devx-automation

Copy link
Copy Markdown
Contributor

Claude Security Review: no high-confidence findings. (run)

@agentcore-devx-automation agentcore-devx-automation Bot removed the claude-security-reviewing Claude Code /security-review in progress label Aug 31, 2026
@github-actions github-actions Bot added size/l PR size: L and removed size/l PR size: L labels Sep 1, 2026
jariy17 added 7 commits September 1, 2026 00:07
Declarative code-based evaluators via projects. Mode is inferred from flags
(mirrors CodeBasedConfigSchema managed XOR external):
  --lambda-arn  -> external (BYO Lambda)
  --metric <library.Metric> -> managed 3P (deepeval/autoevals), scaffolded
  neither       -> managed empty stub you fill in

Scaffolds app/<name>/ from ported evaluator templates (python/deepeval/autoevals
lambda), hardcodes codeLocation, and auto-wires additionalPolicies=
[execution-role-policy.json]. Also enables `project remove evaluator`.
…aluators

Runtimes, harnesses, and evaluators all scaffold into app/<name>, but the
duplicate-name guard is per-resource-type and the tree write happens outside
the rollback try/catch. An evaluator whose name matches an existing runtime/
harness dir (or a leftover from a removed evaluator) threw a raw 'File already
exists' mid-write and orphaned partial files. Fail up front with a clear
InputValidationError when app/<name> already exists.
…or code-based evaluators

- Reject a namespaced/multi-dot metric class (e.g. deepeval.metrics.Faithfulness)
  that would render invalid Python; require a single class identifier.
- --model is Bedrock-only: accept a bare model id / inference-profile-or-
  foundation-model ARN, optionally prefixed with bedrock/, validated via
  isValidBedrockModelId (same forms the llm-as-a-judge handler accepts).
  Non-Bedrock or slashless values now error instead of being silently dropped
  (deepeval) or passed to the wrong client (autoevals).
- autoevals template prefixes bedrock/ for litellm routing now that Model is the
  bare id.
Print notes after add: the empty stub returns Pass for every session until
implemented, and managed evaluators are scaffolded but not yet provisioned by
'project deploy' (no CDK/L3 support). External (--lambda-arn) prints neither.
…templates layer

Mirror the runtime layering: the handler now just parses/validates flags and
passes a ManagedEvaluatorScaffoldInput; templates/evaluator.ts owns the library
registry, per-library timeouts, render context, and buildManagedEvaluatorSpec
(parallels buildRuntimeSpec). Also adds "evaluator" to RemoveResourceInput.
…aluators

The L3 (@aws/agentcore-cdk) does provision spec.evaluators — synth emits
AWS::BedrockAgentCore::Evaluator + Lambda — so the note was inaccurate. Keep the
empty-stub 'returns Pass until implemented' note, which is still true.
@jariy17
jariy17 force-pushed the feat/project-add-evaluator-code-based branch from 7215450 to ef9f5ca Compare September 1, 2026 00:09
@github-actions github-actions Bot added size/l PR size: L and removed size/l PR size: L labels Sep 1, 2026
@agentcore-devx-automation agentcore-devx-automation Bot added the claude-security-reviewing Claude Code /security-review in progress label Sep 1, 2026
@agentcore-devx-automation

Copy link
Copy Markdown
Contributor

Claude Security Review: no high-confidence findings. (run)

@agentcore-devx-automation agentcore-devx-automation Bot removed the claude-security-reviewing Claude Code /security-review in progress label Sep 1, 2026
@jariy17
jariy17 marked this pull request as ready for review September 1, 2026 00:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/l PR size: L

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants