NewAssistant constructs an assistant message with optional function tool calls.
(text string, calls []ToolCall)
| 54 | |
| 55 | // NewAssistant constructs an assistant message with optional function tool calls. |
| 56 | func NewAssistant[M adk.MessageType](text string, calls []ToolCall) M { |
| 57 | if KindOf[M]() == KindAgentic { |
| 58 | blocks := make([]*schema.ContentBlock, 0, len(calls)+1) |
| 59 | if text != "" { |
| 60 | blocks = append(blocks, normalizeAgenticContentBlock(schema.NewContentBlock(&schema.AssistantGenText{Text: text}))) |
| 61 | } |
| 62 | for _, call := range calls { |
| 63 | blocks = append(blocks, normalizeAgenticContentBlock(schema.NewContentBlock(&schema.FunctionToolCall{ |
| 64 | CallID: call.ID, |
| 65 | Name: call.Name, |
| 66 | Arguments: call.Args, |
| 67 | }))) |
| 68 | } |
| 69 | return any(&schema.AgenticMessage{ |
| 70 | Role: schema.AgenticRoleTypeAssistant, |
| 71 | ContentBlocks: blocks, |
| 72 | }).(M) |
| 73 | } |
| 74 | |
| 75 | schemaCalls := make([]schema.ToolCall, 0, len(calls)) |
| 76 | for _, call := range calls { |
| 77 | idx := call.Index |
| 78 | schemaCalls = append(schemaCalls, schema.ToolCall{ |
| 79 | ID: call.ID, |
| 80 | Index: &idx, |
| 81 | Function: schema.FunctionCall{Name: call.Name, Arguments: call.Args}, |
| 82 | }) |
| 83 | } |
| 84 | return any(schema.AssistantMessage(text, schemaCalls)).(M) |
| 85 | } |
| 86 | |
| 87 | // NewToolResult constructs a tool-result message for M. |
| 88 | func NewToolResult[M adk.MessageType](id, name, content string) M { |