runtime

package
v0.0.0-...-8c5cae0 Latest Latest
Warning

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

Go to latest
Published: Feb 13, 2026 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ContractVersionV1 is the first stable runtime event contract version.
	ContractVersionV1 = "v1"

	// MetaContractVersion marks runtime event contract version in event meta.
	MetaContractVersion = "contract_version"
	// MetaLifecycle is the payload key for lifecycle details.
	MetaLifecycle = "lifecycle"
)

Variables

This section is empty.

Functions

func IsSessionBusy

func IsSessionBusy(err error) bool

Types

type CompactRequest

type CompactRequest struct {
	AppName             string
	UserID              string
	SessionID           string
	Model               model.LLM
	Note                string
	ContextWindowTokens int
}

CompactRequest defines one manual compaction call.

type CompactionConfig

type CompactionConfig struct {
	Enabled                    bool
	WatermarkRatio             float64
	MinWatermarkRatio          float64
	MaxWatermarkRatio          float64
	DefaultContextWindowTokens int
	ReserveOutputTokens        int
	SafetyMarginTokens         int
	PreserveRecentTurns        int
	SummaryChunkTokens         int
	MaxModelSummaryRetries     int
	Strategy                   CompactionStrategy
}

CompactionConfig configures runtime history compaction behavior.

type CompactionStrategy

type CompactionStrategy interface {
	Summarize(context.Context, model.LLM, CompactionSummarizeInput) (CompactionSummarizeResult, error)
}

CompactionStrategy abstracts how runtime summarizes history chunks.

func DefaultCompactionStrategy

func DefaultCompactionStrategy() CompactionStrategy

DefaultCompactionStrategy returns kernel default compaction strategy.

type CompactionSummarizeInput

type CompactionSummarizeInput struct {
	Events                 []*session.Event
	InputBudget            int
	SummaryChunkTokens     int
	MaxModelSummaryRetries int
}

CompactionSummarizeInput describes compaction summarization input.

type CompactionSummarizeResult

type CompactionSummarizeResult struct {
	Text             string
	SummarizedEvents int
}

CompactionSummarizeResult is one compaction summary result.

type Config

type Config struct {
	Store      session.Store
	Compaction CompactionConfig
}

Config configures Runtime.

type ContextUsage

type ContextUsage struct {
	CurrentTokens int
	WindowTokens  int
	InputBudget   int
	Ratio         float64
	EventCount    int
}

ContextUsage is the estimated token usage snapshot for current session window.

type LifecycleInfo

type LifecycleInfo struct {
	Status    RunLifecycleStatus
	Phase     string
	Error     string
	ErrorCode toolexec.ErrorCode
}

LifecycleInfo is parsed lifecycle state from one lifecycle event.

func LifecycleFromEvent

func LifecycleFromEvent(ev *session.Event) (LifecycleInfo, bool)

LifecycleFromEvent extracts lifecycle info from one runtime lifecycle event.

type MapReduceCompactionStrategy

type MapReduceCompactionStrategy struct {
	// contains filtered or unexported fields
}

MapReduceCompactionStrategy is default token-budgeted compaction strategy.

func NewMapReduceCompactionStrategy

func NewMapReduceCompactionStrategy(cfg MapReduceCompactionStrategyConfig) *MapReduceCompactionStrategy

NewMapReduceCompactionStrategy builds one map-reduce compaction strategy.

func (*MapReduceCompactionStrategy) Summarize

type MapReduceCompactionStrategyConfig

type MapReduceCompactionStrategyConfig struct {
	SystemPrompt string
	UserPrefix   string
	MergePrefix  string
}

MapReduceCompactionStrategyConfig configures default map-reduce compaction.

type RunLifecycleStatus

type RunLifecycleStatus string

RunLifecycleStatus is a machine-readable runtime run status.

const (
	RunLifecycleStatusRunning         RunLifecycleStatus = "running"
	RunLifecycleStatusWaitingApproval RunLifecycleStatus = "waiting_approval"
	RunLifecycleStatusInterrupted     RunLifecycleStatus = "interrupted"
	RunLifecycleStatusFailed          RunLifecycleStatus = "failed"
	RunLifecycleStatusCompleted       RunLifecycleStatus = "completed"
)

type RunRequest

type RunRequest struct {
	AppName   string
	UserID    string
	SessionID string
	Input     string

	Agent                agent.Agent
	Model                model.LLM
	Tools                []tool.Tool
	CoreTools            tool.CoreToolsConfig
	Policies             []policy.Hook
	LSPBroker            *lspbroker.Broker
	LSPActivationTools   []string
	AutoActivateLSP      []string
	PersistPartialEvents bool
	ContextWindowTokens  int
}

RunRequest defines one invocation input.

type RunState

type RunState struct {
	HasLifecycle bool
	Status       RunLifecycleStatus
	Phase        string
	Error        string
	ErrorCode    toolexec.ErrorCode
	EventID      string
	UpdatedAt    time.Time
}

RunState is the latest lifecycle status snapshot for one session.

type RunStateRequest

type RunStateRequest struct {
	AppName   string
	UserID    string
	SessionID string
}

RunStateRequest defines one run-state query.

type Runtime

type Runtime struct {
	// contains filtered or unexported fields
}

Runtime orchestrates session lifecycle and agent execution.

func New

func New(cfg Config) (*Runtime, error)

func (*Runtime) Compact

func (r *Runtime) Compact(ctx context.Context, req CompactRequest) (*session.Event, error)

Compact triggers one manual compaction without sending user input to LLM.

func (*Runtime) ContextUsage

func (r *Runtime) ContextUsage(ctx context.Context, req UsageRequest) (ContextUsage, error)

ContextUsage returns current session context usage estimation.

func (*Runtime) Run

func (*Runtime) RunState

func (r *Runtime) RunState(ctx context.Context, req RunStateRequest) (RunState, error)

RunState returns latest lifecycle state from persisted session events.

type SessionBusyError

type SessionBusyError struct {
	AppName   string
	UserID    string
	SessionID string
}

SessionBusyError indicates one session already has an in-flight run.

func (*SessionBusyError) Code

func (*SessionBusyError) Error

func (e *SessionBusyError) Error() string

type UsageRequest

type UsageRequest struct {
	AppName             string
	UserID              string
	SessionID           string
	Model               model.LLM
	ContextWindowTokens int
}

UsageRequest defines one context usage inspection request.

Jump to

Keyboard shortcuts

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