FirebaseAILogic Framework Reference

Tool

@available(iOS 15.0, macOS 12.0, tvOS 15.0, watchOS 8.0, *)
public struct Tool : Sendable
extension Tool: Encodable

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

A Tool is a piece of code that enables the system to interact with external systems to perform an 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 it was trained (for example, the current date or weather conditions) or to allow it to interact with external systems (for example, making an API request or querying/updating a database). For more details and use cases, see Function calling using the Gemini API.

    Declaration

    Swift

    public static func functionDeclarations(_ functionDeclarations: [FunctionDeclaration]) -> Tool

    Parameters

    functionDeclarations

    A list of FunctionDeclarations available to the model that can be used for function calling. The model or system does not execute the function. Instead the defined function may be returned as a FunctionCallPart with arguments to the client side for execution. The model may decide to call none, some or all of the declared functions; this behavior may be configured by specifying a ToolConfig when instantiating the model. When a FunctionCallPart is received, the next conversation turn may contain a FunctionResponsePart in parts with a role 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 to access 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 API or Vertex AI Gemini API (see Service Terms section within the Service Specific Terms).

    Declaration

    Swift

    public static func googleSearch(_ googleSearch: GoogleSearch = GoogleSearch()) -> Tool

    Parameters

    googleSearch

    An empty GoogleSearch object. The presence of this object in the list of tools enables the model to use Google Search.

    Return Value

    A Tool configured for Google Search.

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

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

    Warning

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

    Declaration

    Swift

    public static func urlContext() -> Tool
  • Creates a tool that allows the model to execute code.

    For more details, see CodeExecution.

    Declaration

    Swift

    public static func codeExecution() -> Tool