FirebaseAILogic Framework Reference

Tool

@available(iOS15.0,macOS12.0,tvOS15.0,watchOS8.0,*)publicstructTool:Sendable
extensionTool:Encodable

A helper tool that the model may use when generating responses.

ATool is a piece of code that enables the system to interact with external systems to performan action, or set of actions, outside of knowledge and scope of the model.

  • Creates a tool that allows the model to perform function calling.

    Function calling can be used to provide data to the model that was not known at the time itwas trained (for example, the current date or weather conditions) or to allow it to interactwith external systems (for example, making an API request or querying/updating a database).For more details and use cases, seeFunction calling using the GeminiAPI.

    Declaration

    Swift

    publicstaticfuncfunctionDeclarations(_functionDeclarations:[FunctionDeclaration])->Tool

    Parameters

    functionDeclarations

    A list ofFunctionDeclarations available to the model that can beused for function calling.The model or system does not execute the function. Instead the defined function may bereturned as aFunctionCallPart with arguments to the client side for execution. Themodel may decide to call none, some or all of the declared functions; this behavior may beconfigured by specifying aToolConfig when instantiating the model. When aFunctionCallPart is received, the next conversation turn may contain aFunctionResponsePart inparts with arole of"function"; this response contains the result of executing the function on the client,providing generation context for the model’s next turn.

  • Creates a tool that allows the model to use Grounding with Google Search.

    Grounding with Google Search can be used to allow the model to connect to Google Search toaccess and incorporate up-to-date information from the web into it’s responses.

    Important

    When using this feature, you are required to comply with the“Grounding with Google Search” usage requirements for your chosen API provider:Gemini Developer APIor Vertex AI Gemini API (seeService Termssection within the Service Specific Terms).

    Declaration

    Swift

    publicstaticfuncgoogleSearch(_googleSearch:GoogleSearch=GoogleSearch())->Tool

    Parameters

    googleSearch

    An emptyGoogleSearch object. The presence of this object in the listof tools enables the model to use Google Search.

    Return Value

    ATool configured for Google Search.

  • Creates a tool that allows you to provide additional context to the models in the form ofpublic web URLs.

    By including URLs in your request, the Gemini model will access the content from those pagesto inform and enhance its response.

    Warning

    URL context is aPublic Preview feature, which means that it is not subject toany SLA or deprecation policy and could change in backwards-incompatible ways.

    Declaration

    Swift

    publicstaticfuncurlContext()->Tool
  • Creates a tool that allows the model to execute code.

    For more details, seeCodeExecution.

    Declaration

    Swift

    publicstaticfunccodeExecution()->Tool

Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2025-10-28 UTC.