Repository navigation
Conversation
… steps round-trip like JS
| return PlainValidator(lambda value: as_unknown(cls, key, value)) | ||
|
|
||
|
|
||
| def keep_unknown(cls: type[UnknownObject], key: str) -> WrapValidator: |
There was a problem hiding this comment.
The module docstring says one missing or off-shape field shouldn't fail a whole response, but a JSON null still does. I haven't seen the server send one, but if it does: a top-level or usage / errors null raises INTERNAL "Unable to parse Interaction response", and a null on a step demotes it to UnknownStep. For a pending function_call with signature: null, the turn ends stop with no tool request (ran it).
Maybe we can drop None values before validating, so null acts like a missing key.
| call_id: NotRequired[str] | ||
| is_error: NotRequired[bool] | ||
| # JS: text and image content only in the list. Any content is accepted. | ||
| result: NotRequired[dict[str, object] | str | list[Content]] |
There was a problem hiding this comment.
Is a sandbox function_result.result ever a JSON list (e.g. [{'path': 'a.py'}])? If so it doesn't match this union, the step becomes UnknownStep, and get_pending_function_call_ids reports the already-run sandbox call as pending, so Genkit would try to run it locally.
| 'arguments': call.get('arguments'), | ||
| } | ||
| signature = signature_of(metadata) | ||
| if (search := read_as(GOOGLE_SEARCH_CALL_PART, custom.get(GOOGLE_SEARCH_CALL))) is not None: |
There was a problem hiding this comment.
History saved by the current plugin can have None values in googleSearchCall.arguments, googleSearchResult.callId and executableCode.code. read_as rejects those, so the part falls through to "Unsupported part type" and is dropped: the resent history keeps the result but loses the call and its signature. without_none only runs on unknownStep parts.
I suggest running it before every read_as here.
| How the JS types map to Python: | ||
|
|
||
| - Each type is a TypedDict: the wire JSON itself. The plugin builds them as | ||
| dict literals and sends them as they are. ``extra_items=object`` keeps |
There was a problem hiding this comment.
TypedDict(..., extra_items=object) needs typing_extensions>=4.13 (import fails on 4.12) and pydantic>=2.12 (2.11 silently drops the unlisted fields like service_tier / environment / tools from raw), but pyproject.toml still says pydantic>=2.11 and typing_extensions>=4.2. It works today only because google-genai pulls in newer versions.
I suggest bumping the two floors to pydantic>=2.12 and typing_extensions>=4.14.1 (pydantic 2.12's own floor, which covers the 4.13 that extra_items needs).
| payload: dict[str, object] = { | ||
| 'name': step.get('name', ''), | ||
| 'result': step.get('result'), | ||
| 'call_id': step.get('call_id'), |
There was a problem hiding this comment.
serverFunctionResult is the one custom part still writing call_id / is_error; every other part next to it is callId / isError, and so is the JS plugin's serverFunctionResult. Once Gemini moves onto this path these are the keys everyone reads off part.custom.
I suggest writing the camelCase keys. The reader already takes both, so old history keeps working.
refactor(py/google-genai)!: own Interactions API types; built-in tool steps round-trip like JS
The Interactions API code (used by Antigravity, Lyria and Deep Research) now
uses the plugin's own wire types instead of the google-genai SDK's generated
google.genai.interactionstypes, like the JS and Dart plugins do. Thisprepares that code for Gemini models, which move to the Interactions API in
a follow-up PR. Gemini, Gemma, Imagen, Veo and embedder models are
unchanged, and so is the HTTP client (it was already the plugin's own).
Why
The SDK's generated types didn't fit how the plugin uses the API:
url_context_callstep with only anidcame back witharguments: {},an
mcp_server_tool_resultwithresult: {}, other steps withresult: None. Those fields were then saved in the message history andsent back to the server on the next turn.
languageof'python'only, while the API also takes'bash'; requiredfields the server itself leaves out), so the plugin needed casts and a
private SDK import to build valid requests.
The new types
_interactions/_types.pymirrors the JS plugin'sinteraction-types.ts(same type names, same order). Each type is a
TypedDictof the wire JSON:sent: nothing is filled in, and fields the types don't list are kept and
sent back unchanged.
typeis required. The server leaves out fields its spec marks asrequired at times, and one missing field shouldn't fail a whole response.
fields don't match its type) is kept as sent, as
UnknownStep,UnknownContent, ...come with the Gemini request mapping.
The stream event types are included too; they're used by the streaming
client in the follow-up PR.
Built-in tool steps
Steps for the server-side tools (URL context, file search, Google Maps, MCP
servers) and agentic video processing steps now come back as custom parts
with the JS plugin's names, and are sent back as the same steps (with their
signatures) when the history is resent:
urlContextCall/urlContextResult,fileSearchCall/fileSearchResult,googleMapsCall/googleMapsResult,mcpServerToolCall/mcpServerToolResult,processingCall/processingResult.step.
Before, these came back as
unknownStepparts, which held the SDK's filled-infields. History saved with
unknownStepparts is still sent back;Nonevalues in those parts (fields the SDK added) are dropped first.
Google Search parts now also keep the step's
search_type(assearchType)and
is_error(asisError), and leave outarguments/resultwhen theserver didn't send them, as in JS.
Two smaller fixes in the same spirit (steps go back as they came):
is_error: falseis now sent back as
false; onlytrueused to be sent.thought summary and the signature as separate steps. A step without a
signature no longer gets
metadata.thoughtSignature: Noneon its part.rawonlyResponses now carry the interaction in
rawonly, exactly as the serversent it. The response-level
customfield (deprecated by Genkit in favor ofraw) no longer holds a copy.Breaking changes
These only affect code that reads Interactions API responses at a low level:
server and processing steps are custom parts with their own key (see
above) instead of
custom['unknownStep'].response.custom: no longer holds the interaction; readresponse.raw.response.raw: holds the interaction as the server sent it, withoutthe fields the SDK used to fill in (
Nonevalues, emptyarguments).Testing
kept, unknown steps / content / annotations / stream deltas / events kept
as sent); ported from the JS plugin's tests with the same data: built-in
tool steps (Google Maps and URL context shapes seen live, file search and
MCP from the spec; converted to parts with their signatures, never tool
requests, sent back unchanged, ids-only steps round-trip, Google Search
steps without
arguments/result, an empty trailingmodel_outputstep) and agentic video processing steps; saved
unknownStepparts sentback without their
Nonevalues;rawis the interaction as received;function results resend
is_error: false; thought steps without asignature get no signature metadata.
The existing converter, client and model tests run against the new types.
url_contexttool.The response had four URL context call/result pairs (with signatures),
thought steps and sandbox function calls. The URL context steps came back
as
urlContextCall/urlContextResultparts (none asunknownStep),and converting the response back into history gave the server's steps
exactly as received: no empty
arguments, nonullfields.rawheldthe response as sent, including fields the types don't list
(
service_tier,environment,tools).ruff format --check,ruff check,pyright,ty,pyreflyand thepackage's unit tests (1582) pass.