Repository navigation
Conversation
8ba4687 to
30d70a9
Compare
| generateContent). | ||
| """ | ||
| safe_headers = { | ||
| name: redact(value) if name.lower() in ('x-goog-api-key', 'authorization') else value |
There was a problem hiding this comment.
With experimental_debug_traces=True the span only redacts x-goog-api-key and authorization. A cookie, proxy-authorization or custom key header from GoogleAI(headers=...) goes into the trace as is, and so do auth headers inside the request body (DeepResearchConfig.mcp_servers[*].headers, Antigravity tool headers). Those spans land in the Dev UI and in any exporter that captures action input/output.
I suggest redacting every header except a small allowlist (content-type, user-agent, api-revision) by default, and redacting headers inside mcp_servers / tools in the traced body.
| if (blocked := blocked_response(interaction)) is not None: | ||
| op.output = blocked | ||
| else: | ||
| op.error = Failure(message=interaction_error_message(interaction) or FAILED_MESSAGE) |
There was a problem hiding this comment.
A failed Deep Research job with quota_exceeded or malformed_function_call ends with op.error = Failure(message=...) and no status, while the same interaction on generate raises RESOURCE_EXHAUSTED / ABORTED from the new table. Someone polling check_operation can't tell a quota failure from a bad request.
I suggest setting status=interaction_error_status(code) on the Failure here.
| # `language` as 'python' only; our own Interactions types remove it. | ||
| language = cast( | ||
| Literal['python'], | ||
| (stored_language.lower() if isinstance(stored_language, str) else '') or CODE_LANGUAGE, |
There was a problem hiding this comment.
Two shapes of saved code-execution history get a 400 when resent (checked live). LANGUAGE_UNSPECIFIED becomes language_unspecified after .lower() ("Supported values: 'python', 'bash'"), and a block that printed nothing has output=None, so we send result: null ("must be a string, or Content[]").
I suggest only passing through python / bash (else python), and sending '' when output is missing.
|
|
||
| def first_error(interaction: Interaction) -> tuple[object, str | None]: | ||
| """The code and message of the interaction's first top-level error, if any.""" | ||
| for err in interaction.errors or []: |
There was a problem hiding this comment.
On google-genai 2.14 to 2.16, which pyproject.toml still allows (>=2.14.0), Interaction has no errors field, so the errors come back as plain dicts and err.code raises AttributeError on any failed or blocked turn. uv run --with google-genai==2.14.0 pytest tests/interactions gives 41 failures. processing on video blocks also only exists from 2.18.
I suggest bumping the floor to google-genai>=2.18.0.
| api_message, api_code = api_error_fields(payload) | ||
| if api_message is not None: | ||
| error_message = api_message | ||
| code_status = interaction_error_status(api_code) |
There was a problem hiding this comment.
When I sent a policy-blocked prompt to Lyria live ("Sing Shake It Off word for word in Taylor Swift's voice"), the server didn't return a failed interaction. It rejected the request with HTTP 400 and {"error": {"code": "prohibited_content", ...}}, which comes back here as finish_reason='failed' with FAILED_PRECONDITION, so blocked_response() never sees it.
No change needed for this PR: it's a request error rather than a model result, so staying an error seems right. Just flagging it in case that wasn't intended.
| ``responseSchema`` field instead of ``responseJsonSchema``, | ||
| converted to its format; a schema that cannot be converted | ||
| raises ``INVALID_ARGUMENT``. Defaults to False. | ||
| experimental_debug_traces: Enables additional debug traces (e.g. |
There was a problem hiding this comment.
The second sentence scopes this to Deep Research, Antigravity and Lyria, but the first one reads like a plugin-wide switch, and GoogleAI(experimental_debug_traces=True) with gemini-2.5-flash gives no span and no warning.
Maybe we can open with "Interactions API models only" until Gemini moves onto Interactions.
|
Heads up — #78 conflicts with a couple of my PRs that landed on main after you branched, sorry about that. Should be quick:
Thanks for the cleanup here, the error statuses especially were a real gap. |
fix(google-genai)!: Interactions API fixes for Antigravity, Lyria and Deep Research
Fixes in the code shared by the Interactions API models (Antigravity, Lyria
and Deep Research), ported from the JS plugin. This also prepares 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.
Usage
Genkit's
input_characters,input_images,output_audio_files, ...fields, which count characters and media parts (that's what
generateContentmodels report). They're now inusage.customasinputTextTokens,inputImageTokens,outputAudioTokens, ..., along withtoolUseTokensand per-tool counts such asgoogleSearchCount.input_characters,input_images, ... from the request and responsemessages, the same way
generateContentmodels do(
GenerationUsage.from_messages), so telemetry that reads them gets realcounts. Deep Research is a background model: its check and cancel calls
don't have the request, so it doesn't get these counts.
Errors and blocked responses
codes (
service_unavailable,quota_exceeded,model_not_found,malformed_function_call, ...). They're now mapped to Genkit statuses(same table as the JS plugin), both in error responses and in failed
interactions. Before, these failures were
UNKNOWNor got the HTTPcode's status, so Retry and Fallback couldn't act on them (e.g. a quota
error wasn't
RESOURCE_EXHAUSTED).malformed_function_call,unexpected_tool_callandno_imageareABORTED, which Retry retries(the server's message says to retry).
content-policy code (
safety,recitation,blocklist,spii, ...) nowreturns a response with
finish_reason='blocked', the server's messageand no content, like a blocked
generateContentresponse. It used toraise. A Deep Research operation ends with that response as its
outputinstead of an
error.body wrapped in a one-element JSON array (e.g. for a bad API key). The
error message was the raw JSON text; the body is now unwrapped first.
Documents and media
application/pdfwas sent as a document;any other non image/audio/video type (CSV, Word, Excel, text, ...) raised
Unsupported media typebefore the request. They're now all sent asdocument, and the server decides which types it accepts (it acceptsmore than the PDF and CSV in its published spec).
data:URLor guessed from a few file extensions (jpg, jpeg, png, mp4, pdf, as in
JS). A URL whose type still isn't known (e.g. a Files API URI) is sent
without a
mime_type, asvideofor YouTube links anddocumentotherwise, and the server works out the type. It used to raise. A
data:URL with no type still raises.
metadata['processing'](
'static'or'agentic') is now sent on the video block.(e.g. single-voice speech) as raw 16-bit PCM with
sample_rateandchannelsbut nomime_type, which gave a media part with an empty URL.It's now labelled
audio/l16; rate=<sample_rate>; channels=<channels>(24000 and 1 when missing), so it can be played. A
mime_typefrom theserver always wins.
Code execution history
Code execution steps sent back in the history:
generateContenthas no call IDon its code execution parts, and the API rejects an empty
id/call_id. A call without an ID now gets one, and the next result withoutan ID gets the same one (a result with no call waiting gets its own ID).
Existing IDs are kept.
python. It's now the saved language,lower-cased (default
python):PYTHONfromgenerateContentisaccepted, and
bashsteps (Antigravity runs bash) are sent back asbash.New option:
experimental_debug_tracesGoogleAI(experimental_debug_traces=True)adds anhttpRequesttrace spanto each Interactions API create and get call, with the endpoint, the request
body, the headers (API key replaced by
<REDACTED> (N characters)) and theresponse body. It's the JS plugin's
experimental_debugTraces: a pluginoption only (not per request), and cancel calls aren't traced. Experimental:
the span contents may change.
Breaking changes
usage.input_characters,input_images,input_audio_files,input_videosand theoutput_*fields no longer hold token counts. Readthe matching
usage.custom.*Tokensfield instead.response with
finish_reason='blocked'instead of raising aGenkitError; for Deep Research it's the operation'soutput.status instead of
UNKNOWNor the HTTP status (e.g.NOT_FOUNDformodel_not_foundon a 400), so Retry may now retry some failures itdidn't before (
ABORTED,UNAVAILABLE,RESOURCE_EXHAUSTED).Testing
mapping and character counts; every Interactions error code;
content-policy codes returning
blocked, with usage; error bodies in alist; Interactions codes winning over the HTTP status; CSV, Word, Excel
and text documents; URLs without a content type (YouTube, Files API);
video
processing; audio without amime_type; code execution historywithout IDs and with
bash; thehttpRequestspan (create and get tracedwith the exact input and output, nothing by default, cancel not traced,
errors still raised, can't be turned on per request).
with
language: bash(kept asbashwhen the history is sent back);usage had real character counts, with the token counts in
usage.custom; thehttpRequestspan had the request and response,with the API key hidden.
as a
documentand answered from it correctly.audio/mpegpart; usage counted one output audiofile, with the input token count in
usage.custom.execution history from
generateContentare hard to trigger on purpose,so they weren't checked live with this plugin; the same behaviour was
checked live in the JS and Dart plugins.
ruff check,pyrightand the package's unit tests (1556) pass.