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

Method HandleExecute

internal/gemini/gemini.go:407–541  ·  view source on GitHub ↗
(ctx context.Context, fc *genai.FunctionCall, approved bool, o agent.OutputHandler)

Source from the content-addressed store, hash-verified

405}
406
407func (t *SkillsTool) HandleExecute(ctx context.Context, fc *genai.FunctionCall, approved bool, o agent.OutputHandler) error {
408 if fc.Name == "activate_skill" {
409 var output string
410 result, err := t.executor.HandleCall(ctx, fc)
411 if err != nil {
412 output = "Error: " + err.Error()
413 } else {
414 var parts []string
415 if result.Stdout != "" {
416 parts = append(parts, result.Stdout)
417 }
418 if result.Stderr != "" {
419 parts = append(parts, "Stderr: "+result.Stderr)
420 }
421 output = strings.Join(parts, "\n")
422 }
423
424 respStruct, err := structpb.NewStruct(map[string]any{"result": output})
425 if err != nil {
426 return fmt.Errorf("failed to convert function response to structpb: %w", err)
427 }
428
429 return o(&proto.AgentOutputs{
430 Messages: []*proto.Message{
431 {
432 Role: "model",
433 Content: &proto.Content{
434 Type: &proto.Content_ToolResult{
435 ToolResult: &proto.ToolResultContent{
436 CallId: fc.ID,
437 Type: &proto.ToolResultContent_FunctionResult{
438 FunctionResult: &proto.FunctionResultContent{
439 Name: fc.Name,
440 Result: &proto.FunctionResultContent_Response{
441 Response: respStruct,
442 },
443 },
444 },
445 },
446 },
447 },
448 },
449 },
450 })
451 }
452
453 if !approved {
454 // Declined, nothing to do in terms of executing any commands.
455 // But we still have to finish with a function response,
456 // not to keep the previously log function call hanging forever.
457 return o(&proto.AgentOutputs{
458 Messages: []*proto.Message{
459 {
460 Role: "model",
461 Content: &proto.Content{
462 Type: &proto.Content_ToolResult{
463 ToolResult: &proto.ToolResultContent{
464 CallId: fc.ID,

Callers 1

HandleCallMethod · 0.95

Calls 1

HandleCallMethod · 0.65

Tested by

no test coverage detected