diff --git a/contrib/sarvam-ai/pom.xml b/contrib/sarvam-ai/pom.xml
index 12eb49ac0..636289044 100644
--- a/contrib/sarvam-ai/pom.xml
+++ b/contrib/sarvam-ai/pom.xml
@@ -20,7 +20,7 @@
com.google.adk
google-adk-parent
- 1.2.0
+ 0.9.1-SNAPSHOT
../../pom.xml
diff --git a/contrib/sarvam-ai/src/main/java/com/google/adk/models/sarvamai/SarvamAi.java b/contrib/sarvam-ai/src/main/java/com/google/adk/models/sarvamai/SarvamAi.java
index 4ced7f6c9..02b16c5c1 100644
--- a/contrib/sarvam-ai/src/main/java/com/google/adk/models/sarvamai/SarvamAi.java
+++ b/contrib/sarvam-ai/src/main/java/com/google/adk/models/sarvamai/SarvamAi.java
@@ -16,6 +16,7 @@
package com.google.adk.models.sarvamai;
+import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.adk.models.BaseLlm;
@@ -24,13 +25,19 @@
import com.google.adk.models.LlmResponse;
import com.google.adk.models.sarvamai.chat.ChatRequest;
import com.google.adk.models.sarvamai.chat.ChatResponse;
+import com.google.adk.models.sarvamai.chat.ChatToolCall;
+import com.google.common.collect.ImmutableList;
import com.google.errorprone.annotations.CanIgnoreReturnValue;
import com.google.genai.types.Content;
+import com.google.genai.types.FunctionCall;
import com.google.genai.types.Part;
import io.reactivex.rxjava3.core.BackpressureStrategy;
import io.reactivex.rxjava3.core.Flowable;
import java.io.BufferedReader;
import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
import java.util.Objects;
import java.util.concurrent.TimeUnit;
import okhttp3.MediaType;
@@ -233,12 +240,48 @@ private LlmResponse toLlmResponse(ChatResponse chatResponse) {
}
var choice = chatResponse.getChoices().get(0);
var effectiveMsg = choice.effectiveMessage();
- if (effectiveMsg == null || effectiveMsg.getContent() == null) {
- throw new SarvamAiException("No content in response choice");
+ if (effectiveMsg == null) {
+ throw new SarvamAiException("No message in response choice");
}
- Content content =
- Content.builder().role("model").parts(Part.fromText(effectiveMsg.getContent())).build();
+ // Handle tool_calls in response (model requesting function execution)
+ if (effectiveMsg.getToolCalls() != null && !effectiveMsg.getToolCalls().isEmpty()) {
+ List parts = new ArrayList<>();
+ for (ChatToolCall tc : effectiveMsg.getToolCalls()) {
+ if (tc.getFunction() == null || tc.getFunction().getName() == null) {
+ continue;
+ }
+ String argsStr = tc.getFunction().getArguments();
+ if (argsStr == null) {
+ argsStr = "{}";
+ }
+ Map args;
+ try {
+ args = objectMapper.readValue(argsStr, new TypeReference