MCPcopy
hub / github.com/kagent-dev/kagent / extractTextFromTask

Function extractTextFromTask

go/adk/pkg/tools/remote_a2a_tool.go:493–516  ·  view source on GitHub ↗

extractTextFromTask extracts the text result from a completed Task.

(task *a2atype.Task)

Source from the content-addressed store, hash-verified

491
492// extractTextFromTask extracts the text result from a completed Task.
493func extractTextFromTask(task *a2atype.Task) string {
494 if task == nil {
495 return ""
496 }
497 // Prefer artifacts (canonical result).
498 if len(task.Artifacts) > 0 {
499 var texts []string
500 for _, artifact := range task.Artifacts {
501 for _, part := range artifact.Parts {
502 if tp, ok := part.(a2atype.TextPart); ok && tp.Text != "" {
503 texts = append(texts, tp.Text)
504 }
505 }
506 }
507 if len(texts) > 0 {
508 return strings.Join(texts, "\n")
509 }
510 }
511 // Fall back to status message.
512 if task.Status.Message != nil {
513 return extractTextFromMessage(task.Status.Message)
514 }
515 return ""
516}
517
518// extractTextFromMessage extracts text from a direct A2A Message response.
519func extractTextFromMessage(message *a2atype.Message) string {

Callers 1

processResultMethod · 0.85

Calls 2

extractTextFromMessageFunction · 0.85
JoinMethod · 0.45

Tested by

no test coverage detected