agent

package
v0.32.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 15, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
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 CompactionSkippedMessage

func CompactionSkippedMessage(reason string) string

func CompactionSummaryContent

func CompactionSummaryContent(msg api.Message) (string, bool)

CompactionSummaryContent returns the user-visible summary from msg when it is a canonical compaction summary.

func CompactionSummaryMessages

func CompactionSummaryMessages(summary string, continueTask bool) []api.Message

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

func CompactionSummaryText(content string) string

CompactionSummaryText reverses CompactionSummaryMessages, returning the user-visible summary text with the prefix and any continuation instruction removed.

func IsCompactionSummary

func IsCompactionSummary(msg api.Message) bool

IsCompactionSummary reports whether msg uses the canonical compaction summary message representation.

func IsCompactionToolCall

func IsCompactionToolCall(msg api.Message) bool

IsCompactionToolCall reports whether msg is the synthetic assistant tool call paired with a compaction summary result.

func IsCompactionToolResult

func IsCompactionToolResult(msg api.Message) bool

IsCompactionToolResult reports whether msg is the synthetic tool result used to represent compaction in message history.

func ResolveCompactionThreshold

func ResolveCompactionThreshold(configured float64) float64

func ResolveContextWindowTokens

func ResolveContextWindowTokens(options map[string]any, configured int) int

func ToolRequiresApproval

func ToolRequiresApproval(tool Tool, args map[string]any) bool

Types

type Approval

type Approval struct {
	Allow       bool
	AllowAll    bool
	AllowScopes []string
	Reason      string
}

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 ApprovalRequired interface {
	RequiresApproval(map[string]any) bool
}

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 ApprovalToolCall struct {
	ToolCallID    string
	ToolName      string
	Args          map[string]any
	ApprovalScope string
}

type ChatClient

type ChatClient interface {
	Chat(context.Context, *api.ChatRequest, api.ChatResponseFunc) error
}

type CompactionOptions

type CompactionOptions struct {
	ContextWindowTokens int
	KeepUserTurns       int
	Threshold           float64
}

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 CompactionResult struct {
	Messages  []api.Message
	Compacted bool
	Due       bool
	Summary   string
	Reason    string
}

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 EventSink

type EventSink interface {
	Emit(Event) error
}

type EventSinkFunc

type EventSinkFunc func(Event) error

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)

func (*Registry) Get

func (r *Registry) Get(name string) (Tool, bool)

func (*Registry) Names

func (r *Registry) Names() []string

func (*Registry) Register

func (r *Registry) Register(tool Tool)

func (*Registry) Tools

func (r *Registry) Tools() api.Tools

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
}

func (*Session) Run

func (s *Session) Run(ctx context.Context, opts RunOptions) (*RunResult, error)

type SimpleCompactor

type SimpleCompactor struct {
	Client  ChatClient
	Options CompactionOptions
}

func (*SimpleCompactor) MaybeCompact

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
}

type ToolResult

type ToolResult struct {
	Content    string
	WorkingDir string
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL