Repository navigation
feat(effect-ai): GoogleLanguageModel over /google/v1 generateContent (phase 5) - #97
Conversation
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
This stack of pull requests is managed by Graphite. Learn more about stacking. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: b617b0b8c7
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
b617b0b to
bdce8de
Compare
…ic JSON and local IDs, map in-band errors
bdce8de to
b85bb41
Compare
Merge activity
|

Summary
Phase 5 of
packages/foundry-effect-ai/docs/PLAN.md:GoogleLanguageModelover Foundry's/google/v1/models/{rid}:generateContentand:streamGenerateContent?alt=sse, withinternal/google-gemini/(schema, request, response, stream) andinternal/models/google.ts.FoundryClient; the model RID goes in the path. Aliases resolve through the Gemini model list, and any other target passes through.configtakesthinkingConfig, thegenerationConfigfield of the same name, sent as given. Foundry accepts upper-casethinkingLevelvalues only;lowreturns 422.foundry-googleon the part that carried them, including signature-only fragments with or without atextfield, and go back on that part when replayed. In streams, a signature closes its text or reasoning block. Gemini rejects a replayed function call without its signature (400), so thetoolscells exercise replay for real.id(Foundry always sent one). A call without one gets a local ID fromIdGenerator, markedlocalId, which replay leaves off thefunctionCalland itsfunctionResponse. Arguments arrive as objects and pass through to Toolkit unchanged.responseJsonSchemafromLanguageModel.defaultCodecTransformer. A live check accepted the default schema (additionalProperties,anyOf, integer bounds,enum,$defs/$ref) and the output conformed.constis accepted but ignored, and Effect never emits it, so no Gemini subset rewrite is needed. Keywords outside Gemini's subset and types with no JSON form pass through unchecked; the codec still validates the answer. PLAN.md says so.responseJsonSchemaand tools in one request,gemini-3.1-flash-litecalled the tool again after every result (16 of 16 tries). In that case the schema is sent as a syntheticjsonfunction underANYmode, as@ai-sdk/googledoes for forced tool choice. Its call comes back as the only answer text (other text in that mode is dropped) and replays as the original signedfunctionCall. Thejsoncall answered 3 of 3 tries, and a live third turn replaying it succeeded.STOP→stoportool-calls,MAX_TOKENSandCONTINUATION→length, safety reasons and a confirmed prompt block →content-filter,MALFORMED_FUNCTION_CALL→error. Gemini streams have no terminal event, so the finish is emitted at end of stream, and only after a finish reason (not empty orFINISH_REASON_UNSPECIFIED) or prompt block arrived; otherwise the stream fails withInvalidResponseError.tool-callparts, and content after them, are held and emitted in one array with the finish. Core then skips handlers on alengthorcontent-filterturn, and a truncated stream never starts one.{error}(JSON body or SSE event) is classified by numeric code or RPC status: 400/404/409 →InvalidRequestError, 401/403 →AuthenticationError, 429 →RateLimitError, 5xx or none →InternalProviderError.promptTokenCount + toolUsePromptTokenCount, output is candidates plus thoughts. A missing snapshot (Gemini sends{}until the last chunk) leaves usage undefined; inside a snapshot, missing counts are zero because proto3 JSON omits zeros.// Adapted from @ai-sdk/google (Apache-2.0), 4.0.122.andNOTICEcredits Vercel. PLAN.md's upstream-code row says so.Matrix
The
GoogleLanguageModelrow has no todos:text,stream,json,tools,stream-tools,json-tools,image,reasoning,stream-truncated,stream-error.gemini-3.1-flash-lite. Reasoning cells sendthinkingConfig: { includeThoughts: true, thinkingLevel: 'HIGH' }: without a level flash-lite returns no thoughts, and atLOWstreamed summaries were unreliable.toolsandstream-toolsfirst turns carry a thought and a signed function call, and the second request replays both. The target's replay check asserts the signature on the call.stream-truncatedkeeps only the first chunk of the recorded stream, before the finish reason.stream-errorfollows it with a Gemini{"error":{"code":500,"status":"INTERNAL"}}event.Checks
pnpm run verifypasses.-t GoogleLanguageModel): all 8 cells pass ongemini-3.1-flash-lite, after the review fixes and the rebase onto phases 3 and 7. I didn't run the other rows.Deferred
modelOutputwith files) fail withInvalidUserInputError; Foundry's support forfunctionResponse.partsis unverified. Text model output is sent ascontent.fileData, unverified on Foundry. Base64 data URLs becomeinlineData.partialArgsstreaming,cachedContent,VALIDATEDmode, safety settings andCONTINUATIONresubmission aren't implemented: no cell needs them.InvalidUserInputError, as in the AI SDK adapter.