Repository navigation
feat(py): genkit.evaluator exports Evaluator and BatchEvaluator for plugin authors - #6689
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
Code Review
This pull request introduces a new evaluator function to build evaluator actions without registering them immediately, allowing plugin authors to defer registration or resolve them dynamically. It also updates evaluator_action_metadata to require display names, definitions, and billing flags for the Dev UI. The Google GenAI plugin is refactored to adopt these new APIs, and corresponding tests are added. Feedback suggests validating that the provided evaluator function (fn) is an asynchronous coroutine function when building the evaluator action to prevent runtime errors.
huangjeff5
marked this pull request as draft
October 9, 2026 03:35
huangjeff5
marked this pull request as ready for review
October 9, 2026 03:42
…stering it Plugins can now return evaluators from init()/resolve() the same way they return models and embedders. evaluator_action_metadata takes the display name, definition and billed flag so a listed evaluator shows the same card in the Dev UI as the built one. The Vertex plugin uses both, so starting it no longer constructs a throwaway Genkit app (and an extra Dev UI reflection server), and its evaluator listing carries real names and billed=true.
huangjeff5
force-pushed
the
feat/py-evaluator-builder
branch
from
October 9, 2026 03:59
7d7b35d to
7837b84
Compare
apascal07
approved these changes
Oct 9, 2026
…lder # Conflicts: # py/packages/genkit-google-genai/src/genkit_google_genai/_evaluators/_evaluation.py # py/packages/genkit-google-genai/src/genkit_google_genai/_google.py # py/packages/genkit/src/genkit/_ai/_evaluator.py
… METRIC_CONFIGS directly define_batch_evaluator uses _evaluator_metadata again instead of the pre-#6669 block that wrote into the caller's nested evaluator dict, and the builder keeps main's private name and config_schema type. Vertex builds one evaluator per metric with no None path, and the duplicate listing test folds its enum check into the existing one.
…ithout registering it define_batch_evaluator is now batch_evaluator(...) plus register, the same split as evaluator / define_evaluator, so a plugin can return a batch evaluator from init() or resolve() without a registry.
…nd batch_evaluator()
…a-key' into feat/py-evaluator-builder # Conflicts: # py/packages/genkit-ollama/src/genkit_ollama/plugin_api.py # py/packages/genkit/src/genkit/_ai/_evaluator.py # py/scripts/schema_to_typing.py
huangjeff5
added a commit
that referenced
this pull request
Oct 12, 2026
Main's #6689 turned define_evaluator / define_batch_evaluator into the Evaluator and BatchEvaluator classes. Port this PR's typed options onto them: the options class from the per-row fn's annotation, config_schema on the action, Dev UI customOptions, and an EvaluatorRequest for an unannotated batch fn. EvalRequest[Cfg] is now EvaluatorRequest[Cfg] and EvalFnResponse is EvaluatorResponse, following main.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
genkit.evaluatornow exportsEvaluatorandBatchEvaluator(Actionsubclasses) so plugins can construct evaluator actions once and return them directly acrossinit(),resolve(), andlist_actions()without spinning up a hiddenGenkit()instance.Main Changes
EvaluatorandBatchEvaluatorsubclassAction: Previously, plugins could only build evaluators throughai.define_evaluator(), forcing the Vertex AI plugin to instantiate a privateGenkit()app on import (which launched a second reflection server in dev mode). Furthermore, exporting a lowercasefrom genkit.evaluator import evaluatorfunction in Python shadows both thegenkit.evaluatorsubmodule and the localevaluatorvariable in caller code. We madeEvaluatorandBatchEvaluatorPascalCase subclasses ofAction[EvaluatorRequest, EvaluatorResponse, Never]whose__init__wires up dataset iteration, per-datapoint spans, and Dev UI metadata, so plugins can return them directly fromPlugin.init(),Plugin.resolve(), andPlugin.list_actions().EvaluatorRequestandEvaluatorResponsenaming: RenamedEvalRequest→EvaluatorRequestandEvalFnResponse→EvaluatorResponseacross all packages and tests to establish consistent type naming with Go and Dart.Plugin.list_actions()acceptsAction(Evaluator/BatchEvaluator) directly: Previously, advertising an evaluator inPlugin.list_actions()required a separate metadata builder that duplicated the display name, definition, billing flag, and config schema already passed toEvaluator(...).Registry.list_actions()now convertsActioninstances viaAction._action_metadata(), soPlugin.list_actions()can returnEvaluator(...)andBatchEvaluator(...)instances directly without a public.action_metadata()step.input_schemaandoutput_schemafield onActionMetadata: Previously,ActionMetadataexposed bothinput_schema/output_schemaandinput_json_schema/output_json_schema, and plugins settinginput_json_schemahad their schemas silently dropped when serialized to the Dev UI asinputSchema/outputSchema.ActionMetadatanow defines onlyinput_schema: dict[str, Any] | Noneandoutput_schema: dict[str, Any] | None, rejecting the retired*_json_schemafields and unserialized class objects at construction time.ai.define_evaluatoris unchanged: Previously,define_evaluatoranddefine_batch_evaluatorbuilt rawActioninstances inline. They now instantiateEvaluator(...)andBatchEvaluator(...)and register them onai.registry, returning the typedEvaluator/BatchEvaluatorinstance while keeping the exact same call signature for application code.deffunction to an evaluator succeeded at registration time and only failed whenawait fn(...)raised aTypeErroron every dataset row during an eval run. BothEvaluatorandBatchEvaluatornow checkinspect.iscoroutinefunction(fn)in__init__and raiseTypeErrorimmediately when defined.