Documentation
¶
Index ¶
- func ExtractText(parts []ContentPart) string
- func ExtractThinking(parts []ContentPart) string
- type Agent
- type ChatCompletionProvider
- type Chunk
- type ChunkKind
- type ContentPart
- type ContentPartType
- type Event
- type EventType
- type Items
- type Message
- type MessageBuilder
- type MessageMeta
- type MessageRole
- type Model
- type PermissionMode
- type Provider
- type ReasoningEffort
- type RequestParameters
- type TokenCounter
- type ToolCall
- type ToolConfirmation
- type ToolEnvelope
- type ToolImpl
- type ToolInfo
- type ToolParameter
- type ToolPermission
- type ToolPermissionCheck
- type ToolResult
- type ToolSpec
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ExtractText ¶
func ExtractText(parts []ContentPart) string
ExtractText returns the concatenated text of all text-type parts.
func ExtractThinking ¶
func ExtractThinking(parts []ContentPart) string
ExtractThinking returns the concatenated text of all thinking-type parts.
Types ¶
type Agent ¶
Agent represents a configured agent with its properties.
func (*Agent) HasFileSystemTool ¶ added in v0.7.0
HasFileSystemTool returns true if the agent's toolbox includes at least one filesystem tool (Read, Write, Edit, Grep, or Glob).
type ChatCompletionProvider ¶
type ChatCompletionProvider interface {
// CreateChatCompletion generates a chat completion response to the
// provided messages.
CreateChatCompletion(
ctx context.Context,
params RequestParameters,
messages []Message,
) (*Message, error)
// CreateChatCompletionStream streams the response via the output callback.
CreateChatCompletionStream(
ctx context.Context,
params RequestParameters,
messages []Message,
output func(Chunk),
) (*Message, error)
}
ChatCompletionProvider is the interface for LLM chat completion backends.
type ChunkKind ¶ added in v0.6.2
type ChunkKind int
ChunkKind identifies the variant of a streaming response chunk.
type ContentPart ¶
type ContentPart struct {
Type ContentPartType `json:"type"`
Text string `json:"text,omitempty"` // text and thinking parts
MIMEType string `json:"mimeType,omitempty"` // image parts (e.g. "image/png")
Data []byte `json:"data,omitempty"` // raw bytes - base64 encoded when serialized
}
ContentPart represents a single part of a message's content. Messages are composed of one or more content parts — text, thinking (reasoning), or image data. This mirrors the multi-part content model used by Anthropic and OpenAI APIs.
func BuildContentParts ¶
func BuildContentParts(content, reasoning string) []ContentPart
BuildContentParts builds a Parts slice from legacy Content and ReasoningContent strings.
func NewImagePart ¶
func NewImagePart(mimeType string, data []byte) ContentPart
NewImagePart returns an image content part with the given MIME type and raw image bytes.
func NewTextPart ¶
func NewTextPart(text string) ContentPart
NewTextPart returns a text content part.
func NewThinkingPart ¶
func NewThinkingPart(text string) ContentPart
NewThinkingPart returns a thinking/reasoning content part.
type ContentPartType ¶
type ContentPartType string
ContentPartType identifies the kind of a single content part within a message.
const ( ContentPartText ContentPartType = "text" ContentPartThinking ContentPartType = "thinking" ContentPartImage ContentPartType = "image" )
type Event ¶
type Event struct {
Type EventType
Chunk Chunk // EventChunk
Message *Message // EventResponseComplete
Error error // EventError
}
Event represents a single event emitted during a completion step. Only the fields relevant to the EventType are populated; the rest are zero-valued. Message is a pointer so that chunk events (the most frequent) carry no weight from it.
type EventType ¶
type EventType int
EventType identifies the kind of event emitted during a completion step.
type Items ¶
type Items struct {
Type string `json:"type"` // e.g. "string"
}
Items describes the element type for array tool parameters.
type Message ¶
type Message struct {
Role MessageRole
Parts []ContentPart
ToolCalls []ToolCall
ToolResults []ToolResult
Metadata MessageMeta
}
func NewMessageWithAssistant ¶
func NewMessageWithToolCalls ¶
func (*Message) HasContent ¶ added in v0.7.0
func (*Message) TextContent ¶
TextContent returns the concatenated text of all text-type parts.
func (*Message) ThinkingContent ¶
ThinkingContent returns the concatenated text of all thinking-type parts.
type MessageBuilder ¶
type MessageBuilder struct {
// contains filtered or unexported fields
}
MessageBuilder accumulates streaming content for a message The accumulated content is presented as []ContentPart via Parts().
func NewMessageBuilder ¶
func NewMessageBuilder(role MessageRole) *MessageBuilder
NewMessageBuilder creates a builder for a message with the given role.
func (*MessageBuilder) AppendContent ¶
func (b *MessageBuilder) AppendContent(chunk string)
AppendContent appends a streaming text chunk.
func (*MessageBuilder) AppendReasoning ¶
func (b *MessageBuilder) AppendReasoning(chunk string)
AppendReasoning appends a streaming reasoning/thinking chunk.
func (*MessageBuilder) Build ¶
func (b *MessageBuilder) Build() *Message
Build finalizes the builder into a Message.
func (*MessageBuilder) InitFromParts ¶
func (b *MessageBuilder) InitFromParts(parts []ContentPart)
InitFromParts seeds the builder with existing content parts. Used when continuing to stream into an existing assistant message (prefill).
func (*MessageBuilder) Parts ¶
func (b *MessageBuilder) Parts() []ContentPart
Parts returns the accumulated content as a parts slice. The slice is constructed fresh on each call (from the internal string builders), so callers can use it directly without copying.
type MessageMeta ¶
type MessageMeta struct {
GenerationProvider *string `json:"generation_provider,omitempty"`
GenerationModel *string `json:"generation_model,omitempty"`
TimeToFirstToken *time.Duration `json:"time_to_first_token,omitempty"`
TotalDuration *time.Duration `json:"total_duration,omitempty"`
Tokens int `json:"completion_tokens,omitzero"`
ThinkingSignature *string `json:"thinking_signature,omitempty"`
ReasoningDetails json.RawMessage `json:"reasoning_details,omitempty"` // preserved reasoning_detail blocks (OpenRouter)
}
MessageMeta contains metadata about a message's generation.
func (*MessageMeta) Scan ¶
func (m *MessageMeta) Scan(value any) error
Scan implements sql.Scanner for MessageMeta.
type MessageRole ¶
type MessageRole string
const ( MessageRoleSystem MessageRole = "system" MessageRoleUser MessageRole = "user" MessageRoleAssistant MessageRole = "assistant" MessageRoleToolCall MessageRole = "tool_call" MessageRoleToolResult MessageRole = "tool_result" )
func (MessageRole) FriendlyRole ¶
func (m MessageRole) FriendlyRole() string
FriendlyRole returns a human friendly signifier for the message's role.
func (MessageRole) IsAssistant ¶
func (m MessageRole) IsAssistant() bool
func (MessageRole) IsSystem ¶
func (m MessageRole) IsSystem() bool
func (MessageRole) IsUser ¶
func (m MessageRole) IsUser() bool
type Model ¶
Model represents a resolved model ready for making completion requests. It references its Provider for the client connection.
type PermissionMode ¶ added in v0.7.0
type PermissionMode int
PermissionMode controls which tools are allowed to run without user confirmation.
const ( PermNone PermissionMode = 0 // prompt for every tool call PermRead PermissionMode = 1 // auto-approve read tools (r--) PermWrite PermissionMode = 2 // auto-approve read + write tools (rw-) PermExec PermissionMode = 3 // auto-approve all tools (rwx) )
func ParsePermissionMode ¶ added in v0.7.0
func ParsePermissionMode(s string) (PermissionMode, error)
ParsePermissionMode parses a permission mode string ("none", "r", "w", "x").
func (PermissionMode) String ¶ added in v0.7.0
func (m PermissionMode) String() string
String returns the short rwx string for a permission mode.
type Provider ¶
type Provider struct {
Name string
Display string
Client ChatCompletionProvider
Models []Model
}
Provider holds a fully initialized provider backend with its resolved models.
type ReasoningEffort ¶
type ReasoningEffort string
ReasoningEffort controls how much reasoning the model should perform.
const ( XHigh ReasoningEffort = "xhigh" High ReasoningEffort = "high" Medium ReasoningEffort = "medium" Low ReasoningEffort = "low" Minimal ReasoningEffort = "minimal" None ReasoningEffort = "none" )
type RequestParameters ¶
type RequestParameters struct {
Model *Model
Agent *Agent
Effort ReasoningEffort
Temperature float32
MaxTokens int
}
RequestParameters contains everything needed for a single completion request.
func NewRequestParameters ¶
func NewRequestParameters(model *Model, agent *Agent, effort ReasoningEffort, temperature float32, maxTokens int) RequestParameters
NewRequestParameters builds RequestParameters for a completion request.
type TokenCounter ¶ added in v0.7.0
type TokenCounter interface {
// CountTokens counts the input tokens for the given messages and
// configuration, without generating a completion.
CountTokens(ctx context.Context, params RequestParameters, messages []Message) (int, error)
}
TokenCounter is an interface to provide token counting for prompts.
type ToolConfirmation ¶
ToolConfirmation represents the user's decision for a single tool call. Approved must be set for every tool call (the slice length must match). When Approved is false, Reason is optionally included in the rejection message sent back to the model, giving the user a way to steer the agent.
type ToolEnvelope ¶ added in v0.7.0
ToolEnvelope is the JSON structure sent on stdin to every out-of-process tool invocation (both built-in via lmcli tool and custom executables).
type ToolImpl ¶ added in v0.7.0
ToolImpl is the signature for a tool's in-process implementation. ctx provides cancellation; tool is the spec for the tool being called; args are the parsed tool call parameters.
type ToolInfo ¶ added in v0.7.0
type ToolInfo struct {
Name string `json:"name"`
Description string `json:"description,omitempty"`
Config map[string]any `json:"config,omitempty"`
Environment map[string]string `json:"environment,omitempty"`
}
ToolInfo describes the static tool definition part of the envelope.
type ToolParameter ¶
type ToolParameter struct {
Name string `json:"name" yaml:"name"`
Type string `json:"type" yaml:"type"` // "string", "integer", "boolean", "array"
Required bool `json:"required" yaml:"required"`
Description string `json:"description" yaml:"description"`
Enum []string `json:"enum,omitempty" yaml:"enum"`
Items *Items `json:"items,omitempty" yaml:"items"` // for array types
}
type ToolPermission ¶
type ToolPermission string
ToolPermission classifies the kind of access a tool performs.
const ( ToolPermRead ToolPermission = "read" // read-only (Read, Grep, Glob) ToolPermWrite ToolPermission = "write" // write (Write, Edit) ToolPermExec ToolPermission = "exec" // execute (Bash) )
func ParseToolPermission ¶ added in v0.7.0
func ParseToolPermission(s string) ToolPermission
ParseToolPermission parses a permission string into a ToolPermission. Accepts "read", "write", "exec". Defaults to ToolPermExec on invalid input.
type ToolPermissionCheck ¶ added in v0.7.0
ToolPermissionCheck records whether a specific tool call needs user confirmation under the caller's permission mode.
func CheckToolPermissions ¶ added in v0.7.0
func CheckToolPermissions(toolCalls []ToolCall, toolbox []ToolSpec, mode PermissionMode) []ToolPermissionCheck
CheckToolPermissions evaluates each tool call against the permission mode and returns a per-tool status slice. When toolbox is nil or empty, unknown tool calls are treated as requiring confirmation.
type ToolResult ¶
type ToolSpec ¶
type ToolSpec struct {
Name string
Description string
Permission ToolPermission
Parameters []ToolParameter
InProcess bool // execute Impl directly instead of shelling out
Config any // tool-specific configuration from lmcli config
Impl ToolImpl
ExecPath string // custom executable path; empty for built-in tools
Environment []string // env vars for out-of-process execution ("KEY=val")
}