Skip to main content
This page describes how GPROXY makes a Gemini upstream deliver its reply in the argument of a function call and turns that call back into ordinary text for the client. A client turns the feature on with magic strings embedded in the prompt and neither declares nor handles the function call itself. The feature applies to generateContent and streamGenerateContent in the Gemini protocol. A client request in OpenAI or Claude format that is routed to one of these providers is converted to Gemini first, so it works there too, and the client still receives a response in its own format.

Magic strings

Embed these strings in any text of the prompt:
The strings are part of the protocol between the client and GPROXY and do not change between versions.

Enabling

Enable it in the provider config:
The channels that have this switch are aistudio, vertex, vertexexpress, geminicli, antigravity and playground. The console shows it as “Enable Gemini magic tool delivery”. These channels remove the strings from a request whether the switch is on or off. With the switch off, only the strings are removed and nothing else changes. A body without a string is forwarded byte for byte; it is neither parsed nor serialized again.

Tool delivery

When the first string appears in a request, GPROXY removes it and adds one function declaration and a configuration that forces the call:
The position of the string makes no difference. The text around it stays where it is. In the response, a call of narrative is replaced by a text part that holds the text argument. The other fields of that part, thoughtSignature included, are kept, and thought parts are unchanged:
The client sends this text back as history on the next turn, so the history never contains a function call. When the model writes the reply directly instead of calling the function, the response is returned as it is.

Context wrapping

The text between the second and third strings is moved out of systemInstruction and contents into the function’s description. Each message becomes one section, in request order, with the system instruction first:
The rules:
  • The text is cut at the exact position of the strings. When a string falls inside a message, the part outside the range stays in that message and the part inside the range moves into the description.
  • A start without an end extends the range to the end of the request.
  • Non-text parts in the range, such as images, stay where they are. Thought parts in the range are dropped.
  • A part or a message left without text is removed.
  • When no user message is left outside the range, GPROXY appends one user message: Read the narrative tool's description, then call it with your reply.
The first string is not needed when wrapping is used. A wrapped request has no cacheable prefix, because the function declaration precedes every message and changes on each turn.

Limits

  • When the client declares tools of its own, built-in tools such as googleSearch included, the feature is not applied and only the strings are removed.
  • Gemini sends the arguments of a function call as a whole. With the feature on, the text of a streamed response arrives at once after the model has finished writing it, not incrementally.
  • The protocol of the playground channel has no place for the calling mode, so the function is declared but not forced. For a reliable call, state in the prompt that the whole reply must be delivered through the narrative function.
  • GPROXY adds no instruction to the prompt, apart from the appended user message described above.