package llm import "strings" // Role identifies the author of a message. type Role string const ( RoleSystem Role = "system" RoleUser Role = "user" RoleAssistant Role = "assistant" RoleTool Role = "tool" ) // Message is one turn in a conversation. // // Exactly which fields are populated depends on the role: user and system // messages carry Parts; assistant messages carry Parts and/or ToolCalls; // tool messages carry ToolResults. Providers translate this canonical shape // to and from their wire formats. type Message struct { Role Role // Parts is the message content (text, images, ...). Parts []Part // ToolCalls are tool invocations requested by the assistant // (meaningful only when Role == RoleAssistant). ToolCalls []ToolCall // ToolResults carry the outcomes of earlier ToolCalls // (meaningful only when Role == RoleTool). ToolResults []ToolResult } // Text returns the concatenation of all text parts in the message. func (m Message) Text() string { var b strings.Builder for _, p := range m.Parts { if t, ok := p.(TextPart); ok { b.WriteString(t.Text) } } return b.String() } // SystemText constructs a system message with one text part. func SystemText(s string) Message { return Message{Role: RoleSystem, Parts: []Part{Text(s)}} } // UserText constructs a user message with one text part. func UserText(s string) Message { return Message{Role: RoleUser, Parts: []Part{Text(s)}} } // UserParts constructs a user message from arbitrary content parts // (e.g. text plus images). func UserParts(parts ...Part) Message { return Message{Role: RoleUser, Parts: parts} } // AssistantText constructs an assistant message with one text part. func AssistantText(s string) Message { return Message{Role: RoleAssistant, Parts: []Part{Text(s)}} } // ToolResultsMessage constructs a tool message carrying one or more results. func ToolResultsMessage(results ...ToolResult) Message { return Message{Role: RoleTool, ToolResults: results} }