fork

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Aug 18, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SplitNonPrefixWindows added in v0.2.0

func SplitNonPrefixWindows(turns []llm.Message, userStep, maxWindows int) [][]llm.Message

SplitNonPrefixWindows slices turns into fixed user-turn groups (every userStep user turns), non-overlapping (unlike prefix windows). Each window covers a distinct transcript segment; the last window carries the trailing turns after the final step boundary.

func SplitPrefixWindows

func SplitPrefixWindows(turns []llm.Message, userStep, maxWindows int) [][]llm.Message

SplitPrefixWindows slices turns into growing prefix windows, stepping one boundary per userStep user turns. Rationale: the rendered prompt of window k is a strict string prefix of window k+1, so LLM providers with prompt prefix caching (DeepSeek / SiliconFlow context caching) hit the shared prefix and cut token cost. When the transcript has fewer than userStep user turns it returns a single full window (no split — straight into the extraction/verification flow).

maxWindows>0 caps the result by keeping the longest windows (they remain a prefix chain and the longest covers the full transcript).

func SplitWindows

func SplitWindows(turns []llm.Message, windowTurns int) [][]llm.Message

SplitWindows slices turns into fixed-turn windows. Empty or non-positive windowTurns falls back to 10. Kept for compatibility; production uses SplitPrefixWindows.

Types

type Analyzer

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

Analyzer extracts candidate interest points from transcript windows using a side LLM call per window (pipeline step 1). Windows are analyzed concurrently (bounded by maxConcurrency); results are deduplicated across the overlapping prefix windows.

func NewAnalyzer

func NewAnalyzer(client LLM, cfg config.ForkConfig, selective bool) *Analyzer

NewAnalyzer builds an Analyzer from fork config.

func (*Analyzer) Analyze

func (a *Analyzer) Analyze(ctx context.Context, agentID string, windows [][]llm.Message) ([]Candidate, error)

Analyze extracts candidates per route strategy:

  • "prefix" prefix-window split, full render (incl. tool output)
  • "non_prefix" non-overlapping user-turn windows, compressed render
  • "full" single full-context window, compressed render, one pass
  • "full2" single full-context window, compressed render, two passes (append)

Windows are re-split internally from the last (full-transcript) window, so the service layer passes the same split output regardless of route.

type Candidate

type Candidate struct {
	Topic      string   `json:"topic"`
	Reason     string   `json:"reason"`
	Confidence float64  `json:"confidence"`
	Tags       []string `json:"tags"`
	TurnRange  [2]int   `json:"turn_range"` // [start_turn, end_turn] 1-indexed
	Subjective bool     `json:"subjective"` // subjective preference/opinion (exempt from verify's web fact-check)
	// WikiWorthy is the LLM's verdict (selective mode) on whether this topic
	// deserves its own wiki page. nil = not judged (treated as worthy).
	WikiWorthy *bool `json:"wiki_worthy,omitempty"`
	// EventTime is the session event time, set by the service layer after
	// extraction (LLM never sees this field).
	EventTime time.Time `json:"-"`
}

Candidate is one interest point extracted from a conversation window. Aligned with my-agent-core's InterestPoint shape (topic/reason/confidence/ tags/turn_range).

type ForkAnalyzer

type ForkAnalyzer interface {
	Analyze(ctx context.Context, agentID string, windows [][]llm.Message) ([]Candidate, error)
}

ForkAnalyzer is the domain interface. The service layer depends on this, not on the concrete Analyzer.

type LLM

type LLM interface {
	ChatJSON(ctx context.Context, messages []llm.Message, out any) error
}

LLM is the chat surface fork needs (implemented by *llm.Client). Kept as a narrow interface so tests can inject a fake.

Jump to

Keyboard shortcuts

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