Gemini.Tools (GeminiEx v0.2.1)
View SourceHigh-level facade for tool registration and execution in the Gemini client.
This module provides a convenient interface for developers to register tool implementations and execute function calls returned by the Gemini API. It integrates with the ALTAR LATER runtime for robust tool execution.
Usage
# Register a tool
{:ok, declaration} = Altar.ADM.new_function_declaration(%{
name: "get_weather",
description: "Gets weather for a location",
parameters: %{}
})
:ok = Gemini.Tools.register(declaration, &MyApp.Tools.get_weather/1)
# Execute function calls from API response
function_calls = [%Altar.ADM.FunctionCall{...}]
{:ok, results} = Gemini.Tools.execute_calls(function_calls)
Summary
Functions
Execute a list of function calls in parallel using the LATER executor.
Register a tool implementation with the LATER registry.
Functions
@spec execute_calls([Altar.ADM.FunctionCall.t()]) :: {:ok, [Altar.ADM.ToolResult.t()]}
Execute a list of function calls in parallel using the LATER executor.
Takes a list of %Altar.ADM.FunctionCall{}
structs (typically from a
GenerateContentResponse) and executes them concurrently, returning a list
of %Altar.ADM.ToolResult{}
structs.
Returns {:ok, [ToolResult.t()]}
on success. Individual tool failures
are captured in the ToolResult's is_error
field rather than causing
the entire operation to fail.
@spec register(Altar.ADM.FunctionDeclaration.t(), (map() -> any())) :: :ok | {:error, term()}
Register a tool implementation with the LATER registry.
declaration
is a validated%Altar.ADM.FunctionDeclaration{}
fun
is an arity-1 function that accepts a map of arguments
Returns :ok
on success or {:error, reason}
if registration fails.