core

package
v0.56.0 Latest Latest
Warning

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

Go to latest
Published: Sep 13, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultContextWindowTokenCount = 200000

Variables

This section is empty.

Functions

func ContextFitsBudget

func ContextFitsBudget(contextWindowTokenCount int, currentInputTokenCount int) bool

func ContextInputBudget

func ContextInputBudget(contextWindowTokenCount int) int

func EstimateContextTokenCount

func EstimateContextTokenCount(text string) int

func EstimateJSONTokenCount

func EstimateJSONTokenCount(v any) int

func ShouldAutoCompact

func ShouldAutoCompact(estimatedInputTokenCount, effectiveBudget int) bool

Types

type AutoCompactionEvent

type AutoCompactionEvent struct {
	Cancel      func()
	Replacement []Message
	Usage       *TokenUsage
	Error       error
}

type ContextBreakdown

type ContextBreakdown struct {
	SystemPromptTokens  int
	ToolDefinitionCount int
	ToolDefTokens       int
	UserMessageTokens   int
	AssistantTokens     int
	ToolResultTokens    int
	TotalEstimated      int
}

func EstimateContextBreakdown

func EstimateContextBreakdown(systemPrompt string, toolDefs []ContextToolDef, messages []ContextMessage) ContextBreakdown

type ContextMessage

type ContextMessage struct {
	Role         Role
	Content      string
	ToolActivity []HistoricalToolActivity
}

type ContextToolDef

type ContextToolDef struct {
	Name        string
	Description string
	InputSchema map[string]any
}

type HistoricalToolActivity

type HistoricalToolActivity struct {
	TextOffset     int            `json:"text_offset"`
	Tool           string         `json:"tool"`
	Input          map[string]any `json:"input,omitempty"`
	Status         string         `json:"status"`
	ExitCode       *int           `json:"exit_code,omitempty"`
	HasRawOutput   bool           `json:"-"`
	RawOutput      any            `json:"-"`
	RetainedOutput any            `json:"retained_output,omitempty"`
}

type Message

type Message struct {
	Role       Role
	Content    string
	TurnMemory *TurnMemory
}

func CloneMessage

func CloneMessage(message Message) Message

func CloneMessages

func CloneMessages(messages []Message) []Message

type Role

type Role string
const (
	RoleSystem    Role = "system"
	RoleUser      Role = "user"
	RoleAssistant Role = "assistant"
)

type StreamEvent

type StreamEvent struct {
	Type           StreamEventType
	Content        string
	Error          error
	ToolCall       *ToolCall
	Usage          *TokenUsage
	Attempt        int
	AutoCompaction *AutoCompactionEvent
}

type StreamEventType

type StreamEventType string
const (
	StreamEventTypeChunk                   StreamEventType = "chunk"
	StreamEventTypeReasoningChunk          StreamEventType = "reasoning_chunk"
	StreamEventTypeDone                    StreamEventType = "done"
	StreamEventTypeError                   StreamEventType = "error"
	StreamEventTypeToolStart               StreamEventType = "tool_start"
	StreamEventTypeToolEnd                 StreamEventType = "tool_end"
	StreamEventTypeUsage                   StreamEventType = "usage"
	StreamEventTypeRetry                   StreamEventType = "retry"
	StreamEventTypeIncomplete              StreamEventType = "incomplete"
	StreamEventTypeAutoCompactionStarted   StreamEventType = "auto_compaction_started"
	StreamEventTypeAutoCompactionApplied   StreamEventType = "auto_compaction_applied"
	StreamEventTypeAutoCompactionCancelled StreamEventType = "auto_compaction_cancelled"
	StreamEventTypeAutoCompactionFailed    StreamEventType = "auto_compaction_failed"
)

type StreamOptions

type StreamOptions struct {
	SessionID             string
	OneShot               bool
	DisableAutoCompaction bool
	DisableToolCalls      bool
}

type TokenUsage

type TokenUsage struct {
	InputTokens     int
	OutputTokens    int
	TotalTokens     int
	ReasoningTokens int
	CachedTokens    int
}

type ToolCall

type ToolCall struct {
	Name     string
	Input    map[string]any
	Output   any
	Error    string
	Duration time.Duration
}

type TurnMemory

type TurnMemory struct {
	ToolActivity []HistoricalToolActivity `json:"tool_activity,omitempty"`
}

func CloneTurnMemory

func CloneTurnMemory(memory *TurnMemory) *TurnMemory

func (*TurnMemory) IsEmpty

func (m *TurnMemory) IsEmpty() bool

Jump to

Keyboard shortcuts

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