Repository navigation
Add TGeminiProvider so the gemini catalog row goes from placeholder to live - #48
Conversation
…o live
New unit src/pkg/providers/PasClaw.Providers.Gemini.pas implements
Google's generateContent REST API directly — different enough from
OpenAI Chat Completions that it doesn't fit TOpenAIProvider:
Endpoint: POST <base>/v1beta/models/<model>:generateContent
Auth: x-goog-api-key: <key>
Three wire-shape differences from the OpenAI / Anthropic providers
that the implementation handles explicitly:
1. Roles are "user" and "model" (not "assistant"). System prompts
don't live in the messages array — they go in a top-level
`systemInstruction` field. Multiple TMessage system entries +
Options.SystemPrompt are joined with line breaks before being
placed there.
2. Tool calls live inside `parts[].functionCall`, and tool results
come back via `parts[].functionResponse` (sent with role:"user").
functionResponse is keyed by tool NAME, not by id, so the
request builder pre-scans assistant turns to build an id->name
map before emitting the contents[] array.
3. Tools are declared at the top level as
`tools: [{functionDeclarations: [{name, description, parameters}]}]`
— one wrapper array containing a single object with an inner
functionDeclarations array. The provider also defends against a
missing parameters schema by emitting `parameters: {}`.
generationConfig handles `maxOutputTokens` + `temperature` from
TChatOptions. The response parser pulls text and functionCall parts
out of every candidate, normalizes Gemini's STOP / MAX_TOKENS finish
reasons to the canonical OpenAI-style stop / length / tool_calls so
the rest of PasClaw doesn't need special-casing, and lifts
promptTokenCount / candidatesTokenCount into the usage record.
Scope kept tight (~340 LOC):
In - text, tool calls, tool results, system instruction,
generationConfig, usage parsing
Out - streaming (ChatStream delegates to Chat and emits a single
text chunk like TOpenAIProvider does for its non-streaming
providers), thinkingConfig, image / media attachments, proxy
/ extraBody knobs
Wiring changes:
Catalog adds a `pfGemini` value to TProtocolFamily and flips the
existing gemini row from pfPlaceholder to pfGemini with auth
scheme asHeader/x-goog-api-key. Header comment updated to describe
the three live families + what pfPlaceholder is still reserved for.
Factory's case dispatch gets a `pfGemini -> TGeminiProvider.Create`
branch and a uses-clause entry. No call site needs to know whether
the kind is Gemini or OpenAI — onboard, status, and tool loop all
go through NewProviderFromConfig.
PasClaw.dproj picks up the new unit between OpenAI and Factory in
DCCReference order. FPC Makefile UNIT_DIRS already covers
src/pkg/providers.
README's Gemini row drops the "implementation pending" note and
documents the auth scheme.
Side note: Nanobot (nanobot-ai/nanobot and HKUDS/nanobot) is NOT
being added as a provider. It's a peer agent framework that itself
consumes the same Anthropic / OpenAI / Gemini APIs PasClaw does, not
a proxy in front of them. The actual proxies in the catalog —
LiteLLM (`kind: litellm`) and OpenRouter (`kind: openrouter`) — are
already there and cover the "fan out to many providers behind one
endpoint" use case.
https://claude.ai/code/session_01TBcLtmpj7dqA5tyFbGnQon
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 08958d18e2
ℹ️ 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".
| FuncCall := Part.ChildObject('functionCall'); | ||
| if FuncCall <> nil then | ||
| try | ||
| TC.Id := FuncCall.GetStr('id', ''); |
There was a problem hiding this comment.
Synthesize ids for Gemini tool calls
When Gemini returns a functionCall, the response has name/args but no OpenAI-style id, so this assigns '' to every Gemini tool call. In the next loop iteration the tool loop stores that empty id on the mrTool result (PasClaw.Tools.ToolLoop.pas lines 278-282), while this provider's request builder only records non-empty ids before resolving functionResponse.name; any Gemini tool call therefore gets sent back as a function response with an empty name and cannot be associated with the requested tool. Please synthesize a stable local id (for example from the function name and part index) when Gemini omits one.
Useful? React with 👍 / 👎.
Summary
Implements
TGeminiProviderfor Google'sgenerateContentREST API. Thegeminirow in the catalog flips frompfPlaceholderto a real protocol family (pfGemini) and an end-to-endpasclaw agentcall against a Gemini config now actually round-trips.Why a new provider class (not a TOpenAIProvider tweak)
Three wire-shape differences make it not fit OpenAI Chat Completions:
Roles are
user/model(notassistant). System prompts don't live in the messages array — they go in a top-levelsystemInstructionfield. The request builder joins everymrSystementry +Options.SystemPromptwith line breaks before placing it there.Tool calls live in
parts[].functionCall; tool results come back viaparts[].functionResponse(sent with roleuser, per Google's spec).functionResponseis keyed by tool name, not id, so the builder pre-scans assistant turns to build anid → namemap before emittingcontents[].Tools are wrapped:
tools: [{functionDeclarations: [{name, description, parameters}]}]— one outer array, one object, an innerfunctionDeclarationsarray. A missingparametersschema emitsparameters: {}so Gemini doesn't 400 on tools without input shape.generationConfighandlesmaxOutputTokens+temperaturefromTChatOptions. The response parser normalizes Gemini'sSTOP/MAX_TOKENSfinish reasons to the canonicalstop/length/tool_callsstrings so the tool loop doesn't need any special-casing, and liftspromptTokenCount/candidatesTokenCountinto the usage record.Scope kept tight (~340 LOC)
ChatStreamfalls back toChat, like our other non-streaming providers)systemInstructionaggregationthinkingConfiggenerationConfig(max_tokens, temperature)usageMetadataparsingWiring changes
pfGeminitoTProtocolFamily, flips thegeminirow frompfPlaceholdertopfGeminiwithasHeader / x-goog-api-key. Header comment refreshed to describe the three live families + whatpfPlaceholderis still reserved for (Bedrock / Azure / Copilot / Antigravity).case Spec.Family ofgets apfGemini → TGeminiProvider.Create(APIKey, Base, Model)branch + a uses-clause entry. No call site (onboard / status / tool loop) needs to know whether the kind is Gemini or OpenAI — they all go throughNewProviderFromConfig.DCCReferenceorder betweenOpenAIandFactory. FPC MakefileUNIT_DIRSalready coverssrc/pkg/providers.On Nanobot
Skipping — nanobot (nanobot-ai/nanobot and HKUDS/nanobot) isn't a proxy in front of LLMs. It's a peer agent framework that itself consumes the same Anthropic / OpenAI / Gemini APIs PasClaw does. The actual "one endpoint, many providers behind it" proxies in the catalog are LiteLLM (
kind: litellm) and OpenRouter (kind: openrouter) — already there.Test plan
pasclaw onboard→ pick Gemini → key prompt appears (it'sasHeader, notasNone) → config written withkind: gemini,api_base: https://generativelanguage.googleapis.com, default modelgemini-1.5-flashpasclaw agent "hi"against the Gemini config — returns text, no errorspasclaw agent "list this directory"— model issuesfs_list_dirtool call, tool result loops back, model produces final text. Specifically verify the tool result message is sent asrole: "user" + parts[].functionResponse{name, response{result}}and Gemini accepts itid → namelookup correctly resolves to the tool name infunctionResponsemake) + Delphi.dprojbuild cleanlyhttps://claude.ai/code/session_01TBcLtmpj7dqA5tyFbGnQon
Generated by Claude Code