MCPcopy
hub / github.com/google/ax / protoToContents

Function protoToContents

examples/docker_agent/main.go:165–239  ·  view source on GitHub ↗

protoToContents converts history to Gemini conversation format.

(inputs []*proto.Message)

Source from the content-addressed store, hash-verified

163}
164// protoToContents converts history to Gemini conversation format.
165func protoToContents(inputs []*proto.Message) []*genai.Content {
166 var contents []*genai.Content
167 for _, msg := range inputs {
168 if msg.GetInternalOnly() {
169 continue
170 }
171 role := msg.Role
172 if role != "user" {
173 role = "model"
174 }
175
176 content := msg.GetContent()
177 if content == nil {
178 continue
179 }
180
181 switch m := content.Type.(type) {
182 case *proto.Content_Text:
183 contents = append(contents, &genai.Content{
184 Role: role,
185 Parts: []*genai.Part{
186 {
187 Text: m.Text.Text,
188 },
189 },
190 })
191 case *proto.Content_Confirmation:
192 // shouldn't be sent to Gemini
193 switch m.Confirmation.Decision.(type) {
194 case *proto.ConfirmationContent_Decline:
195 // shouldn't be sent to Gemini
196 case *proto.ConfirmationContent_Approval:
197 // shouldn't be sent to Gemini
198 }
199 case *proto.Content_ToolCall:
200 tc := m.ToolCall
201 if fc := tc.GetFunctionCall(); fc != nil {
202 contents = append(contents, &genai.Content{
203 Role: "model",
204 Parts: []*genai.Part{
205 {
206 ThoughtSignature: tc.Signature,
207 FunctionCall: &genai.FunctionCall{
208 ID: tc.Id,
209 Name: fc.Name,
210 Args: fc.Arguments.AsMap(),
211 },
212 },
213 },
214 })
215 }
216 case *proto.Content_ToolResult:
217 tr := m.ToolResult
218 if fr := tr.GetFunctionResult(); fr != nil {
219 var respMap map[string]any
220 if fr.GetResponse() != nil {
221 respMap = fr.GetResponse().AsMap()
222 }

Callers 1

ConnectMethod · 0.70

Calls 5

GetInternalOnlyMethod · 0.80
GetContentMethod · 0.80
GetFunctionCallMethod · 0.80
GetFunctionResultMethod · 0.80
GetResponseMethod · 0.80

Tested by

no test coverage detected