dcd004289f
Phase 1 of the majordomo build: - llm/ canonical contract (messages, parts, tools, capabilities, streaming, Model/Provider, error classification) - health/ clock-injected tracker (threshold bench, exponential capped cooldown, reset-on-success) - root Registry + Parse (verbatim model ids, inline recursive alias expansion with cycle detection, chain dedup), LLM_* env-DSN providers (go-llm parity: lazy fallback + eager LoadEnv), health-aware chain executor behind the Model interface - provider/fake scriptable test provider; hermetic test suite incl. the trailing-thinking chain and foreman:// env loading - ADRs 0001-0008, CLAUDE.md, README (honest matrix), CI workflow, docs/phase-1-design.md Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
72 lines
2.0 KiB
Go
72 lines
2.0 KiB
Go
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}
|
|
}
|