Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func MarshalParts ¶
func MarshalParts(parts []ContentPart) ([]byte, error)
MarshalParts serializes a slice of ContentPart to JSON using type-tagged wrappers. Each part becomes {"type":"...", "data":{...}}.
Types ¶
type ContentPart ¶
type ContentPart interface {
// contains filtered or unexported methods
}
ContentPart is the marker interface for all message content block types. A message contains a heterogeneous slice of ContentPart values, enabling rich structured messages that carry text, reasoning, tool calls, tool results, and finish markers in a single message.
func UnmarshalParts ¶
func UnmarshalParts(data []byte) ([]ContentPart, error)
UnmarshalParts deserializes type-tagged JSON back into a slice of ContentPart.
type Finish ¶
type Finish struct {
Reason string `json:"reason"` // "end_turn", "tool_use", "max_tokens", etc.
}
Finish marks the end of an assistant turn, carrying the stop reason.
type ImageContent ¶ added in v0.7.0
ImageContent holds image data within a message. The data is stored as raw bytes (not base64-encoded); serialization handles encoding. MediaType is a MIME type such as "image/png" or "image/jpeg".
type Message ¶
type Message struct {
ID string `json:"id"`
Role MessageRole `json:"role"`
Parts []ContentPart `json:"parts"`
Model string `json:"model,omitempty"`
Provider string `json:"provider,omitempty"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
Message is a single conversation message containing a heterogeneous slice of ContentPart blocks. This design enables a single assistant message to carry text, reasoning, and multiple tool calls as discrete, typed blocks rather than flattening everything into strings.
func FromLLMMessage ¶ added in v0.30.0
FromLLMMessage converts an LLM message into our Message type, extracting all content parts into the appropriate block types.
func (*Message) Images ¶ added in v0.7.0
func (m *Message) Images() []ImageContent
Images returns all ImageContent parts from this message.
func (*Message) Reasoning ¶
func (m *Message) Reasoning() ReasoningContent
Reasoning returns the ReasoningContent if present, or a zero value.
func (*Message) ToLLMMessages ¶ added in v0.30.0
ToLLMMessages converts a Message to one or more LLM message values. An assistant message with tool calls produces a single message with mixed TextPart and ToolCallPart content. Tool-role messages produce ToolResultPart entries.
func (*Message) ToolResults ¶
func (m *Message) ToolResults() []ToolResult
ToolResults returns all ToolResult parts from this message.
type MessageRole ¶
type MessageRole string
MessageRole identifies the sender of a message.
const ( RoleUser MessageRole = "user" RoleAssistant MessageRole = "assistant" RoleTool MessageRole = "tool" RoleSystem MessageRole = "system" )
type ReasoningContent ¶
type ReasoningContent struct {
Thinking string `json:"thinking"`
Signature string `json:"signature,omitempty"` // Anthropic
}
ReasoningContent holds extended thinking / reasoning output from the LLM. Provider-specific metadata (signatures, etc.) is preserved for round-trip fidelity when the conversation is sent back to the provider.
type TextContent ¶
type TextContent struct {
Text string `json:"text"`
}
TextContent holds plain text content within a message.
type ToolCall ¶
type ToolCall struct {
ID string `json:"id"`
Name string `json:"name"`
Input string `json:"input"` // JSON string of arguments
Finished bool `json:"finished"`
}
ToolCall represents a tool invocation initiated by the LLM. It is stored as a content part within an assistant message, not as a separate message.
type ToolResult ¶
type ToolResult struct {
ToolCallID string `json:"tool_call_id"`
Name string `json:"name"`
Content string `json:"content"`
IsError bool `json:"is_error"`
// MediaData holds the base64 payload of a media tool result, such as an
// image returned by the read tool. It is empty for a text result. The
// value is base64 so that a resumed session rebuilds the same message
// the provider saw before.
MediaData string `json:"media_data,omitempty"`
// MediaType is the MIME type of MediaData, such as "image/png".
MediaType string `json:"media_type,omitempty"`
}
ToolResult represents the result of executing a tool. It is stored as a content part within a tool-role message, linked to a ToolCall by ID.