hooks

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Mar 22, 2026 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ReadRerankCache added in v0.4.0

func ReadRerankCache(homeDir, sessionID string) []models.RecallResult

ReadRerankCache reads pre-ranked results if the cache is fresh (< 5 min). Returns nil if missing, expired, or corrupt.

func WriteRerankCache added in v0.4.0

func WriteRerankCache(homeDir, sessionID string, results []models.RecallResult)

WriteRerankCache writes pre-ranked results for a session to disk.

Types

type PostTurnHook

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

PostTurnHook captures memories from a completed agent turn.

func NewPostTurnHook

func NewPostTurnHook(cap capture.Capturer, cls classifier.Classifier, emb embedder.Embedder, st store.Store, logger *slog.Logger, dedupThreshold float64, concurrency int) *PostTurnHook

NewPostTurnHook creates a post-turn hook handler. dedupThreshold is the cosine similarity threshold above which a memory is considered a duplicate. A value of 0.95 is recommended. concurrency controls the number of memories processed simultaneously in Execute; 0 falls back to the default of 4; values above 16 are clamped to 16.

func (*PostTurnHook) Execute

func (h *PostTurnHook) Execute(ctx context.Context, input PostTurnInput) error

Execute runs the post-turn hook: extract → classify → embed → reinforce/dedup → store.

func (*PostTurnHook) WithConflictDetector added in v0.4.0

func (h *PostTurnHook) WithConflictDetector(cd *capture.ConflictDetector) *PostTurnHook

WithConflictDetector configures an optional ConflictDetector. Must be called before the hook is used concurrently. When set, each new memory is checked against similar existing memories for contradictions before being stored. On any detector error the memory is stored as-is (graceful degradation).

func (*PostTurnHook) WithReinforcement added in v0.4.0

func (h *PostTurnHook) WithReinforcement(threshold, boost float64) *PostTurnHook

WithReinforcement configures confidence reinforcement for near-duplicate memories. threshold is the cosine similarity above which a near-duplicate triggers reinforcement. boost is added to the existing memory's confidence (capped at 1.0). Set threshold to 0 to disable reinforcement.

type PostTurnInput

type PostTurnInput struct {
	UserMessage      string                     `json:"user_message"`
	AssistantMessage string                     `json:"assistant_message"`
	SessionID        string                     `json:"session_id"`
	Project          string                     `json:"project"`
	PriorTurns       []capture.ConversationTurn `json:"prior_turns,omitempty"`
}

PostTurnInput contains the conversation turn data.

type PreTurnHook

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

PreTurnHook retrieves relevant memories before an agent turn.

func NewPreTurnHook

func NewPreTurnHook(emb embedder.Embedder, st store.Store, recaller *recall.Recaller, logger *slog.Logger) *PreTurnHook

NewPreTurnHook creates a pre-turn hook handler.

func (*PreTurnHook) Execute

func (h *PreTurnHook) Execute(ctx context.Context, input PreTurnInput) (*PreTurnOutput, error)

Execute runs the pre-turn hook.

func (*PreTurnHook) WithReasoner added in v0.4.0

func (h *PreTurnHook) WithReasoner(r *recall.Reasoner, cfg RerankConfig) *PreTurnHook

WithReasoner attaches an optional Reasoner for threshold-gated re-ranking. Must be called before the hook is used concurrently.

type PreTurnInput

type PreTurnInput struct {
	Message     string `json:"message"`
	Project     string `json:"project"`
	TokenBudget int    `json:"token_budget"`
	SessionID   string `json:"session_id"`
}

PreTurnInput contains the context for a pre-turn hook.

type PreTurnOutput

type PreTurnOutput struct {
	Memories    []models.RecallResult `json:"memories"`
	TokensUsed  int                   `json:"tokens_used"`
	MemoryCount int                   `json:"memory_count"`
	Context     string                `json:"context"`
}

PreTurnOutput contains the memories to inject into context.

type RerankCacheEntry added in v0.4.0

type RerankCacheEntry struct {
	SessionID string                `json:"session_id"`
	RankedAt  time.Time             `json:"ranked_at"`
	Results   []models.RecallResult `json:"results"`
}

RerankCacheEntry holds pre-ranked results for a session.

type RerankConfig added in v0.4.0

type RerankConfig struct {
	ScoreSpreadThreshold float64
	LatencyBudgetMs      int
}

RerankConfig holds re-ranking thresholds and latency budget for the hook.

Jump to

Keyboard shortcuts

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