Skip to content

feat(ai): add GeminiLanguageModel tool calling - #16620

Open
andrewheard wants to merge 3 commits into
ah/ai-glm-guided-generationfrom
ah/ai-glm-tool-calling
Open

feat(ai): add GeminiLanguageModel tool calling#16620
andrewheard wants to merge 3 commits into
ah/ai-glm-guided-generationfrom
ah/ai-glm-tool-calling

Conversation

@andrewheard

Copy link
Copy Markdown
Contributor

Add function calling (tool calling) support to GeminiLanguageModel conforming to Apple's FoundationModels framework.

  • Added the .toolCalling capability to GeminiLanguageModel.
  • Translates the Foundation Models ToolDefinition into a Gemini Tool and FunctionDeclaration using parametersJsonSchema.
  • Maps GenerationOptions.ToolCallingMode (.allowed, .required,
    .disallowed) to Gemini FunctionCallingConfig.Mode.
  • Streams function calls in GeminiLanguageModelExecutor, forwarding JSON-encoded arguments or empty fallback "{}" (omitted by the backend on empty arguments) into channel actions.
  • Translates Transcript tool calls and tool outputs into Gemini Contentparts, preserving thought signatures from reasoning models and flushing buffered reasoning thoughts cleanly.
  • Unpacks structured tool responses and wrap scalar text tool outputs under the result field (since Foundation Models supports primitives as tool outputs).
  • Support parameterless (void) tools with empty arguments across request schema translation, model response handling, and transcript history.
  • Add unit tests across GeminiLanguageModel, GeminiRequestTranslator, and GeminiTranscriptTranslator.
  • Add end-to-end integration tests covering single-turn, sequential, parallel, disallowed, parameterless, and reasoning tool calling across all supported backends.

#no-changelog

@gemini-code-assist

Copy link
Copy Markdown
Contributor
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize the Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counterproductive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

@andrewheard
andrewheard force-pushed the ah/ai-glm-tool-calling branch from d330410 to cd30fb2 Compare September 6, 2026 02:54
@andrewheard
andrewheard force-pushed the ah/ai-glm-tool-calling branch from 1086768 to 3658758 Compare September 6, 2026 03:38
@andrewheard
andrewheard force-pushed the ah/ai-glm-tool-calling branch 2 times, most recently from 0170896 to 5672bfb Compare September 7, 2026 04:13
@andrewheard
andrewheard marked this pull request as ready for review September 7, 2026 05:13
@andrewheard
andrewheard force-pushed the ah/ai-glm-tool-calling branch from 9685c3a to d6109de Compare September 7, 2026 16:50
Add function calling (tool calling) support to GeminiLanguageModel
conforming to Apple's FoundationModels framework.

* Add .toolCalling capability to GeminiLanguageModel.
* Translate FoundationModels ToolDefinition into Gemini Tool and
  FunctionDeclaration using OpenAPI parametersJsonSchema.
* Map GenerationOptions.ToolCallingMode (.allowed, .required,
  .disallowed) to Gemini FunctionCallingConfig.Mode.
* Stream function calls in GeminiLanguageModelExecutor, forwarding
  JSON-encoded arguments or empty fallback "{}" into channel actions.
* Translate Transcript tool calls and tool outputs into Gemini Content
  parts, preserving thought signatures from reasoning models and
  flushing buffered reasoning thoughts cleanly.
* Unpack structured tool responses and wrap scalar text tool outputs
  under the result field.
* Support parameterless tools with empty arguments across request
  schema translation, model response handling, and transcript history.
* Add unit tests across GeminiLanguageModel, GeminiRequestTranslator,
  and GeminiTranscriptTranslator.
* Add end-to-end integration tests covering single-turn, sequential,
  parallel, disallowed, parameterless, and reasoning tool calling
  across all supported backends.
Update documentation across GeminiLanguageModel test directories to
cover tool calling (function calling) test suites and workflows.

* Streamline Quick Start to use 'swift test --filter IntegrationTests',
  relying on .requireIntegrationTestingBackend for automatic execution
  or clean skipping.
* Add 'swift test --filter ToolCallingIntegrationTests' and
  'swift test --skip Integration' across test and test-server guides.
* Update the test suites summary table to reflect tool calling in
  unit and integration test suites.
* Add ToolCallingIntegrationTests.swift to the integration test file
  catalog.
* Fix broken relative link to test_server documentation in
  IntegrationTests/README.md.
* Format prose and remove extraneous blank lines.
Add integration tests for GeminiLanguageModel tool calling in FirebaseAI
and streamline suite tagging.

* Add testToolCalling and testToolCallingDisallowed integration tests
  for FirebaseAI.geminiLanguageModel in FirebaseAITestApp.
* Define GetTemperature tool conforming to FoundationModels.Tool with
  @generable arguments and return types.
* Move .tags(.integration) to the @suite declaration in
  ToolCallingIntegrationTests.swift.
@andrewheard
andrewheard force-pushed the ah/ai-glm-tool-calling branch from d6109de to e74e166 Compare September 7, 2026 22:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant