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

Method handleSubagentCall

internal/gemini/gemini_planner.go:306–456  ·  view source on GitHub ↗
(ctx context.Context, conversationID string, fc *genai.FunctionCall, signature []byte, history []*proto.Message, e agent.Executor, handler agent.OutputHandler)

Source from the content-addressed store, hash-verified

304}
305
306func (p *geminiPlannerAgent) handleSubagentCall(ctx context.Context, conversationID string, fc *genai.FunctionCall, signature []byte, history []*proto.Message, e agent.Executor, handler agent.OutputHandler) error {
307
308 prompt, ok := fc.Args["prompt"].(string)
309 if !ok {
310 return fmt.Errorf("missing or invalid 'prompt' argument")
311 }
312
313 // Record the function call in the history.
314 argsStruct, err := structpb.NewStruct(fc.Args)
315 if err != nil {
316 return err
317 }
318 if err := handler(&proto.AgentOutputs{
319 Messages: []*proto.Message{
320 {
321 Role: "model",
322 Content: &proto.Content{
323 Type: &proto.Content_ToolCall{
324 ToolCall: &proto.ToolCallContent{
325 Id: fc.ID,
326 Signature: signature,
327 Type: &proto.ToolCallContent_FunctionCall{
328 FunctionCall: &proto.FunctionCallContent{
329 Name: fc.Name,
330 Arguments: argsStruct,
331 },
332 },
333 },
334 },
335 },
336 },
337 },
338 }); err != nil {
339 return err
340 }
341
342 mappedName := strings.ReplaceAll(fc.Name, "_", "-")
343 var historyStr strings.Builder
344 for _, msg := range history {
345 historyStr.WriteString(fmt.Sprintf("%s: ", msg.Role))
346 if msg.Content != nil {
347 if txt := msg.Content.GetText(); txt != nil {
348 historyStr.WriteString(txt.Text)
349 }
350 }
351 historyStr.WriteString("\n")
352 }
353
354 subagentStart := &proto.AgentStart{
355 AgentId: mappedName,
356 Messages: []*proto.Message{
357 {
358 Role: "user",
359 Content: &proto.Content{
360 Type: &proto.Content_Text{
361 Text: &proto.TextContent{Text: fmt.Sprintf("History Summary:\n%s\n\nPrompt:\n%s", historyStr.String(), prompt)},
362 },
363 },

Callers 5

processMethod · 0.95

Calls 3

ExecMethod · 0.65
GetTextMethod · 0.45
StringMethod · 0.45