Sarvam AI: add tool calling support#145
Open
alfredjimmy-redbus wants to merge 3 commits intoredbus-labs:mainfrom
Open
Sarvam AI: add tool calling support#145alfredjimmy-redbus wants to merge 3 commits intoredbus-labs:mainfrom
alfredjimmy-redbus wants to merge 3 commits intoredbus-labs:mainfrom
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Tool Calling Implementation – Sarvam AI Contrib
Overview
Tool calling allows Sarvam AI to work with the ADK’s function tools. The model receives tool definitions and can return tool calls; the runner executes tools and sends results back.
Files Edited
1.
ChatMessage.javaRole: Support tool calls and tool responses in messages.
tool_callsList<ChatToolCall>tool_call_idStringAdd getters/setters for both fields.
2.
ChatToolCall.javaRole: Map Sarvam’s tool call format (OpenAI-style).
Structure:
id,type="function",function: { name, arguments }(JSON string).3.
ChatRequest.javaRole: Convert ADK
LlmRequest→ Sarvam chat request, including tools and prior tool use.toolsfieldtool_choicefield"auto"when tools are presentfromLlmRequestPart.functionCall→ assistant message withtool_calls;Part.functionResponse→ tool message withtool_call_idbuildTools()FunctionDeclaration→{ type, function: { name, description, parameters } }schemaToMap()SchematoMapfor JSONschemaTypeToString()Typeenum → string ("string","number", etc.)getTools(),getToolChoice()Schema,Typefromcom.google.genai.types4.
SarvamAi.javaRole: Convert Sarvam responses → ADK
LlmResponse.toLlmResponse()effectiveMsg.getToolCalls()is non-empty → parse eachChatToolCall→ createFunctionCall.builder().id().name().args()→ buildPart.functionCall→ setContentparts → returnLlmResponsePart.fromText(content)as beforeChatToolCall,FunctionCall,ImmutableList,TypeReference,ArrayList,List,MapData Flow
LlmRequestwith tools and history →ChatRequest.fromLlmRequest()→ request JSON.message.content→toLlmResponse()→Part.fromText()→LlmResponse.message.tool_calls→toLlmResponse()→Part.functionCall()→LlmResponsefor the ADK runner.