Skip to content

feat(py)!: build data objects with their class; rename evaluator types before 1.0 - #6682

Merged
huangjeff5 merged 10 commits into
mainfrom
chore/py-1-0-renames
Oct 10, 2026
Merged

huangjeff5 merged 10 commits into
mainfrom
chore/py-1-0-renames

Conversation

@huangjeff5

@huangjeff5 huangjeff5 commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

A few public names change before 1.0 so the API reads the same way everywhere: if you're building a data object, you call its class.

  • Tools with media return MultipartToolResponse(...) directly. The response helper is removed. Build the class you already annotate, with content= for the parts.
  • new_middleware, embedder_ref, and evaluator_ref are removed. Use GenerateMiddleware(cls=..., name=...), EmbedderRef(name=...), and EvaluatorRef(name=...).
  • EvalStatusEnum is now ScoreStatus, and Details is now ScoreDetails. Serialized values don't change ("status": "PASS", "details": {"reasoning": ...}).
  • ActionKind.RETRIEVER, ActionKind.INDEXER, and ActionKind.RERANKER are removed.
  • Document.from_text and Document.from_media are classmethods, so a Document subclass gets its own type back.
  • An action key the Dev UI can't parse (for example /retriever/x) now returns 404 "Action not found" instead of a 500.
# before
from genkit import response
from genkit.evaluator import Details, EvalStatusEnum, Score, evaluator_ref
from genkit.plugin_api import new_middleware

return response({'ok': True}, parts=[png])
Score(status=EvalStatusEnum.PASS, details=Details(reasoning='...'))
evaluator_ref('my/judge', config={'threshold': 0.5})
new_middleware(Retry, name='retry')

# after
from genkit import MultipartToolResponse
from genkit.evaluator import EvaluatorRef, Score, ScoreDetails, ScoreStatus
from genkit.middleware import GenerateMiddleware

return MultipartToolResponse(output={'ok': True}, content=[png])
Score(status=ScoreStatus.PASS, details=ScoreDetails(reasoning='...'))
EvaluatorRef(name='my/judge', config={'threshold': 0.5})
GenerateMiddleware(cls=Retry, name='retry')

Writing tools

A tool returns its value, or a MultipartToolResponse when it also sends media:

# 1. Plain result
@ai.tool()
async def weather(input: WeatherInput) -> str:
    return 'Sunny, 22C'

# 2. Result plus media: the type you annotate is the type you build
@ai.tool()
async def screenshot(label: str) -> MultipartToolResponse[Shot]:
    return MultipartToolResponse(output=Shot(label=label), content=[png])

Answering an interrupt is unchanged: interrupt.respond(output) and interrupt.restart(resumed_metadata=...) build the reply from the interrupt you hold.

Decisions

  • Build data objects with their class; keep functions for real work.
    • If you're building something from scratch, call the class: MultipartToolResponse(...), Score(...), EvaluatorRef(...).
    • If you're converting an input, use a classmethod: Part.from_media(url, content_type=...).
    • If you're deriving a reply from an object you hold, use a method on it: interrupt.respond(...).
    • The removed helpers built an exported class under a second name, sometimes with different argument names (parts= vs content=). new_middleware also dropped metadata=.
  • MultipartToolResponse over a renamed helper. tool_response collided with Part.tool_response and ToolResponsePart(tool_response=...). It also read like it built a ToolResponse, so Part(tool_response=tool_response(...)) looked right but was the wrong type. The class name matches Go's MultipartToolResponse{Output, Content, Metadata} and the wire's output/content/metadata.
  • Bad arguments still fail where you write them. MultipartToolResponse rejects non-dict metadata and non-part content with the same INVALID_ARGUMENT status and reason the helper raised. The messages now name the class, for example MultipartToolResponse metadata must be a dict, got str. Parts with no payload, or with data that can't be serialized to JSON, fail when the tool returns, with an error that names the tool.
  • Score.status and Score.details read as one family: Score, ScoreStatus, ScoreDetails. EvalStatus read like the status of a whole eval run, and Details didn't say what it held. Go already uses ScoreStatus and a generated ScoreDetails. JS and the tools schema keep EvalStatusEnum on the wire-schema side.
  • Wire values are unchanged, so stored eval results and the Dev UI keep working. The Dev UI's schema view shows the new type names.
  • The Python SDK has no retriever, indexer, or reranker API, so those ActionKind values are gone. Adding enum values later is safe, but removing them after 1.0 isn't. If your plugin referenced ActionKind.RETRIEVER, drop it.

Also

  • The genkit-amazon-bedrock README now says rerank model IDs don't resolve on demand. The plugin already declines them.
  • genkit-evaluators, the google-genai Vertex evaluators, and the evaluators and multipart-tools samples use the new names.

@github-actions github-actions Bot added docs Improvements or additions to documentation python Python chore labels Oct 8, 2026

@gemini-code-assist gemini-code-assist 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.

Code Review

This pull request renames several core concepts and types in Genkit Python, including changing 'response' to 'tool_response', 'EvalStatusEnum' to 'EvalStatus', and 'Details' to 'ScoreDetails'. It also moves 'BaseDataPoint' to the 'genkit.evaluator' module and removes unsupported action kinds ('reranker', 'indexer', 'retriever'), updating key parsing and reflection endpoints to return a 404 error instead of a server error for invalid keys. Feedback on the changes suggests restoring a deleted test for metadata validation using the new 'tool_response' function to preserve test coverage.

I am having trouble creating individual review comments. Click here to see my feedback.

py/packages/genkit/tests/genkit/ai/tool_multipart_test.py (110-116)

medium

The test test_response_rejects_non_dict_metadata was removed, but the validation logic in _tools.py remains. This test should be updated to use tool_response instead of being removed to maintain test coverage.

def test_tool_response_rejects_non_dict_metadata() -> None:
    with pytest.raises(GenkitError) as ei:
        tool_response(1, metadata='nope')  # type: ignore[arg-type]
    assert ei.value.status == 'INVALID_ARGUMENT'
    assert ei.value.reason is RuntimeErrorReason.INVALID_INPUT
    assert 'metadata' in ei.value.original_message
    assert 'INVALID_INPUT' not in ei.value.original_message

- Tools return `tool_response(output, parts=..., metadata=...)` instead of
  `response(...)`; error messages now say `tool_response()`.
- `BaseDataPoint` is imported from `genkit.evaluator` instead of `genkit`.
- Evaluators build `Score(status=EvalStatus.PASS, details=ScoreDetails(...))`
  instead of `EvalStatusEnum` / `Details`. The JSON is the same ('PASS',
  details.reasoning).
- `ActionKind` no longer has `RETRIEVER`, `INDEXER`, or `RERANKER`.
- Running an action key the Dev UI can't parse (for example '/retriever/x' or
  '/tool/x') returns 404 "Action not found" instead of a 500, and the
  JSON-RPC runAction returns its usual not-found error.
@huangjeff5
huangjeff5 force-pushed the chore/py-1-0-renames branch from a9ba105 to f880a9c Compare October 8, 2026 20:06
@huangjeff5

Copy link
Copy Markdown
Contributor Author

Re gemini's metadata test note: valid, that one got dropped in the rename by accident. Restored as test_tool_response_rejects_non_dict_metadata in d51985f.

Score.status, Score.details now read as one family: Score, ScoreStatus,
ScoreDetails. EvalStatus read like the status of a whole eval run.
Wire values (PASS/FAIL/UNKNOWN) are unchanged. Matches Go's ScoreStatus.
@huangjeff5
huangjeff5 requested a review from apascal07 October 8, 2026 21:13
Genkit Python has no reranker primitive, so Bedrock.rerank() was a one-off
plugin method with its own request/response types. Drop it, its exported
types, the rerank-model resolve guard, tests, and docs before the plugin's
first release. It can come back as a registered reranker action once core
has one.
Rerank models have no Converse path and the plugin registers no reranker
action, so bedrock/cohere.rerank-* declines at resolve instead of failing
on the first call. is_rerank_model moves to model_info as pure ID routing.
# Conflicts:
#	py/docs/index.md
#	py/docs/types.md
#	py/packages/genkit-google-genai/src/genkit_google_genai/_evaluators/_evaluation.py
#	py/packages/genkit/src/genkit/__init__.py
#	py/packages/genkit/src/genkit/evaluator/__init__.py
#	py/packages/genkit/tests/genkit/veneer/veneer_test.py
#	py/samples/evaluators/src/main.py
# Conflicts:
#	py/packages/genkit-amazon-bedrock/CHANGELOG.md
#	py/packages/genkit-amazon-bedrock/README.md
#	py/packages/genkit-amazon-bedrock/src/genkit_amazon_bedrock/__init__.py
#	py/packages/genkit-amazon-bedrock/src/genkit_amazon_bedrock/_plugin.py
#	py/packages/genkit-amazon-bedrock/tests/live_test.py
#	py/packages/genkit-amazon-bedrock/tests/plugin_test.py
#	py/packages/genkit-google-genai/src/genkit_google_genai/_evaluators/__init__.py
# Conflicts:
#	py/packages/genkit-google-genai/src/genkit_google_genai/_evaluators/_evaluation.py
…r functions

- Remove tool_response(); construct MultipartToolResponse(output=, content=,
  metadata=). Its argument checks move onto the class.
- Remove new_middleware, embedder_ref, and evaluator_ref in favor of
  GenerateMiddleware, EmbedderRef, and EvaluatorRef.
- Document.from_text/from_media are classmethods.
- Share the reflection run-key guard as resolve_runnable_key.
- Bedrock README: rerank IDs don't resolve on demand.
@huangjeff5 huangjeff5 changed the title feat(py)!: rename tool and evaluator helpers before 1.0 feat(py)!: build data objects with their class; rename evaluator types before 1.0 Oct 10, 2026
@huangjeff5
huangjeff5 enabled auto-merge (squash) October 10, 2026 04:17
@huangjeff5
huangjeff5 merged commit 8ef8746 into main Oct 10, 2026
28 checks passed
@huangjeff5
huangjeff5 deleted the chore/py-1-0-renames branch October 10, 2026 04:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

chore docs Improvements or additions to documentation python Python

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants