Documentation
¶
Index ¶
- Constants
- func CompactionSkippedMessage(reason string) string
- func CompactionSummaryContent(msg api.Message) (string, bool)
- func CompactionSummaryMessages(summary string, continueTask bool) []api.Message
- func CompactionSummaryText(content string) string
- func IsCompactionSummary(msg api.Message) bool
- func IsCompactionToolCall(msg api.Message) bool
- func IsCompactionToolResult(msg api.Message) bool
- func ResolveCompactionThreshold(configured float64) float64
- func ResolveContextWindowTokens(options map[string]any, configured int) int
- func ToolRequiresApproval(tool Tool, args map[string]any) bool
- type Approval
- type ApprovalPrompter
- type ApprovalRequest
- type ApprovalRequired
- type ApprovalState
- func (s *ApprovalState) AllowAll() bool
- func (s *ApprovalState) AllowScopes(scopes []string)
- func (s *ApprovalState) Allows(scope string) bool
- func (s *ApprovalState) Apply(result *Approval)
- func (s *ApprovalState) Set(allowAll bool, scopes map[string]bool)
- func (s *ApprovalState) SetAllowAll(allowAll bool)
- type ApprovalToolCall
- type ChatClient
- type CompactionOptions
- type CompactionProgress
- type CompactionRequest
- type CompactionResult
- type Compactor
- type Event
- type EventSink
- type EventSinkFunc
- type EventType
- type Registry
- type RunOptions
- type RunResult
- type Session
- type SimpleCompactor
- type Tool
- type ToolContext
- type ToolResult
Constants ¶
const ( CompactionSummaryMessagePrefix = "Conversation summary:\n" CompactionToolName = "summary" CompactionToolCallID = "ollama_compaction" CompactionContinueInstruction = "continue the task in progress. the history has been compacted, do not mention compaction to the user" )
Compaction wire-format. These constants and helpers are the single canonical definition of how a compacted turn is represented in message history.
Variables ¶
This section is empty.
Functions ¶
func CompactionSummaryContent ¶
CompactionSummaryContent returns the user-visible summary from msg when it is a canonical compaction summary.
func CompactionSummaryMessages ¶
CompactionSummaryMessages renders a compaction summary as the assistant tool-call plus tool-result pair that represents a compacted turn in the message history.
func CompactionSummaryText ¶
CompactionSummaryText reverses CompactionSummaryMessages, returning the user-visible summary text with the prefix and any continuation instruction removed.
func IsCompactionSummary ¶
IsCompactionSummary reports whether msg uses the canonical compaction summary message representation.
func IsCompactionToolCall ¶
IsCompactionToolCall reports whether msg is the synthetic assistant tool call paired with a compaction summary result.
func IsCompactionToolResult ¶
IsCompactionToolResult reports whether msg is the synthetic tool result used to represent compaction in message history.
Types ¶
type ApprovalPrompter ¶
type ApprovalPrompter interface {
PromptApproval(context.Context, ApprovalRequest) (Approval, error)
}
type ApprovalRequest ¶
type ApprovalRequest struct {
WorkingDir string
Calls []ApprovalToolCall
}
func (*ApprovalRequest) AddToolCall ¶ added in v0.32.0
func (r *ApprovalRequest) AddToolCall(id, name string, args map[string]any)
type ApprovalRequired ¶
type ApprovalState ¶ added in v0.32.0
type ApprovalState struct {
// contains filtered or unexported fields
}
func (*ApprovalState) AllowAll ¶ added in v0.32.0
func (s *ApprovalState) AllowAll() bool
func (*ApprovalState) AllowScopes ¶ added in v0.32.0
func (s *ApprovalState) AllowScopes(scopes []string)
func (*ApprovalState) Allows ¶ added in v0.32.0
func (s *ApprovalState) Allows(scope string) bool
func (*ApprovalState) Apply ¶ added in v0.32.0
func (s *ApprovalState) Apply(result *Approval)
func (*ApprovalState) Set ¶ added in v0.32.0
func (s *ApprovalState) Set(allowAll bool, scopes map[string]bool)
func (*ApprovalState) SetAllowAll ¶ added in v0.32.0
func (s *ApprovalState) SetAllowAll(allowAll bool)
type ApprovalToolCall ¶
type ChatClient ¶
type ChatClient interface {
Chat(context.Context, *api.ChatRequest, api.ChatResponseFunc) error
}
type CompactionOptions ¶
type CompactionProgress ¶
type CompactionProgress struct {
Tokens int
}
type CompactionRequest ¶
type CompactionRequest struct {
ChatID string
Model string
SystemPrompt string
Messages []api.Message
Tools api.Tools
Format string
Latest api.ChatResponse
Options map[string]any
KeepAlive *api.Duration
Think *api.ThinkValue
Force bool
ContinueTask bool
KeepUserTurns *int
Progress func(CompactionProgress)
}
type CompactionResult ¶
type Compactor ¶
type Compactor interface {
MaybeCompact(context.Context, CompactionRequest) (CompactionResult, error)
}
type Event ¶
type Event struct {
Type EventType `json:"type"`
RunID string `json:"runId,omitempty"`
ChatID string `json:"chatId,omitempty"`
Model string `json:"model,omitempty"`
Status string `json:"status,omitempty"`
ToolCallID string `json:"toolCallId,omitempty"`
ToolName string `json:"toolName,omitempty"`
WorkingDir string `json:"workingDir,omitempty"`
Content string `json:"content,omitempty"`
Thinking string `json:"thinking,omitempty"`
ToolCalls []api.ToolCall `json:"toolCalls,omitempty"`
Messages []api.Message `json:"messages,omitempty"`
Args map[string]any `json:"args,omitempty"`
Tokens int `json:"tokens,omitempty"`
Error string `json:"error,omitempty"`
}
type EventSinkFunc ¶
func (EventSinkFunc) Emit ¶
func (fn EventSinkFunc) Emit(event Event) error
type EventType ¶
type EventType string
const ( EventMessageDelta EventType = "message_delta" EventThinkingDelta EventType = "thinking_delta" EventToolCallDetected EventType = "tool_call_detected" EventToolStarted EventType = "tool_started" EventToolFinished EventType = "tool_finished" EventCompactionStarted EventType = "compaction_started" EventCompactionProgress EventType = "compaction_progress" EventCompacted EventType = "compacted" EventCompactionSkipped EventType = "compaction_skipped" EventRunFinished EventType = "run_finished" EventError EventType = "error" )
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
func (*Registry) Execute ¶
func (r *Registry) Execute(ctx context.Context, toolCtx ToolContext, call api.ToolCall) (ToolResult, error)
type RunOptions ¶
type RunOptions struct {
ChatID string
Model string
SystemPrompt string
Messages []api.Message
NewMessages []api.Message
Format string
Options map[string]any
Think *api.ThinkValue
KeepAlive *api.Duration
// MaxToolRounds limits consecutive model/tool cycles.
// Zero uses the default guard; negative disables the guard for tests or
// special callers.
MaxToolRounds int
}
type RunResult ¶
type RunResult struct {
Messages []api.Message
Latest api.ChatResponse
WorkingDir string
}
type Session ¶
type Session struct {
Client ChatClient
EventSinks []EventSink
Tools *Registry
DisableTools bool
ApprovalPrompter ApprovalPrompter
ApprovalState *ApprovalState
WorkingDir string
Compactor Compactor
}
type SimpleCompactor ¶
type SimpleCompactor struct {
Client ChatClient
Options CompactionOptions
}
func (*SimpleCompactor) MaybeCompact ¶
func (c *SimpleCompactor) MaybeCompact(ctx context.Context, req CompactionRequest) (CompactionResult, error)
type Tool ¶
type Tool interface {
Name() string
Description() string
Schema() api.ToolFunction
Execute(context.Context, ToolContext, map[string]any) (ToolResult, error)
}
type ToolContext ¶
type ToolContext struct {
WorkingDir string
}