diff --git a/R/content.R b/R/content.R index 025926184..4db2adab1 100644 --- a/R/content.R +++ b/R/content.R @@ -202,6 +202,8 @@ show_image <- function(x) { #' @param arguments Named list of arguments to call the function with. #' @param tool ellmer automatically matches a tool request to the tools defined #' for the chatbot. If `NULL`, the request did not match a defined tool. +#' @param extra Provider-specific metadata associated with the tool request. +#' Automatically managed by \pkg{ellmer}. ContentToolRequest <- new_class( "ContentToolRequest", parent = Content, @@ -209,7 +211,8 @@ ContentToolRequest <- new_class( id = prop_string(), name = prop_string(), arguments = class_list, - tool = NULL | ToolDef + tool = NULL | ToolDef, + extra = class_list ) ) method(format, ContentToolRequest) <- function( diff --git a/R/provider-google.R b/R/provider-google.R index 65110504a..db8eef6e5 100644 --- a/R/provider-google.R +++ b/R/provider-google.R @@ -327,10 +327,14 @@ method(value_turn, ProviderGoogleGemini) <- function( ContentText(content$text) } } else if (has_name(content, "functionCall")) { + extra <- compact(list( + thoughtSignature = content$thoughtSignature + )) ContentToolRequest( content$functionCall$name, content$functionCall$name, - content$functionCall$args + content$functionCall$args, + extra = extra ) } else if (has_name(content, "inlineData")) { ContentImageInline( @@ -456,12 +460,13 @@ method(as_json, list(ProviderGoogleGemini, ContentToolRequest)) <- function( x, ... ) { - list( + compact(list( functionCall = list( name = x@id, args = x@arguments - ) - ) + ), + thoughtSignature = x@extra$thoughtSignature + )) } # https://ai.google.dev/api/caching#FunctionResponse diff --git a/man/Content.Rd b/man/Content.Rd index 598e3992c..b13bed733 100644 --- a/man/Content.Rd +++ b/man/Content.Rd @@ -26,7 +26,8 @@ ContentToolRequest( id = stop("Required"), name = stop("Required"), arguments = list(), - tool = NULL + tool = NULL, + extra = list() ) ContentToolResult(value = NULL, error = NULL, extra = list(), request = NULL) @@ -60,14 +61,14 @@ Automatically managed by \pkg{ellmer}.} \item{tool}{ellmer automatically matches a tool request to the tools defined for the chatbot. If \code{NULL}, the request did not match a defined tool.} +\item{extra}{Additional data.} + \item{value}{The results of calling the tool function, if it succeeded.} \item{error}{The error message, as a string, or the error condition thrown as a result of a failure when calling the tool function. Must be \code{NULL} when the tool call is successful.} -\item{extra}{Additional data.} - \item{request}{The \link{ContentToolRequest} associated with the tool result, automatically added by \pkg{ellmer} when evaluating the tool call.}