auto

package
v0.35.0 Latest Latest
Warning

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

Go to latest
Published: Dec 29, 2025 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package auto 提供自动记忆捕获系统 自动从对话和事件中生成记忆,支持 tags 标签系统

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CaptureEvent

type CaptureEvent struct {
	// Type 事件类型
	Type EventType `json:"type"`

	// ProjectID 项目 ID(可选)
	ProjectID string `json:"project_id,omitempty"`

	// SessionID 会话 ID(可选)
	SessionID string `json:"session_id,omitempty"`

	// Data 事件数据
	Data map[string]any `json:"data"`

	// Timestamp 时间戳
	Timestamp time.Time `json:"timestamp"`
}

CaptureEvent 捕获事件

type Capturer

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

Capturer 自动记忆捕获器

func NewCapturer

func NewCapturer(store Store, config *CapturerConfig) *Capturer

NewCapturer 创建捕获器

func (*Capturer) CaptureFromDialog

func (c *Capturer) CaptureFromDialog(ctx context.Context, projectID, sessionID, role, message string) (*Memory, error)

CaptureFromDialog 从对话中捕获记忆

func (*Capturer) CaptureFromEvent

func (c *Capturer) CaptureFromEvent(ctx context.Context, event *CaptureEvent) (*Memory, error)

CaptureFromEvent 从事件中捕获记忆

func (*Capturer) RegisterTagExtractor

func (c *Capturer) RegisterTagExtractor(extractor TagExtractor)

RegisterTagExtractor 注册标签提取器

type CapturerConfig

type CapturerConfig struct {
	// MinConfidence 最低置信度阈值
	MinConfidence float64

	// MaxMemoriesPerProject 每个项目最大记忆数
	MaxMemoriesPerProject int

	// AutoTagging 是否自动添加标签
	AutoTagging bool

	// DeduplicateWindow 去重时间窗口
	DeduplicateWindow time.Duration
}

CapturerConfig 捕获器配置

func DefaultCapturerConfig

func DefaultCapturerConfig() *CapturerConfig

DefaultCapturerConfig 默认配置

type DefaultTagExtractor

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

DefaultTagExtractor 默认标签提取器

func NewDefaultTagExtractor

func NewDefaultTagExtractor() *DefaultTagExtractor

NewDefaultTagExtractor 创建默认标签提取器

func (*DefaultTagExtractor) Extract

func (e *DefaultTagExtractor) Extract(text string) []TagSuggestion

Extract 提取标签

type EventType

type EventType string

EventType 事件类型

const (
	// EventTaskCompleted 任务完成
	EventTaskCompleted EventType = "task_completed"
	// EventFeatureImplemented 功能实现
	EventFeatureImplemented EventType = "feature_implemented"
	// EventDecisionMade 做出决策
	EventDecisionMade EventType = "decision_made"
	// EventPreferenceExpressed 表达偏好
	EventPreferenceExpressed EventType = "preference_expressed"
	// EventErrorResolved 错误解决
	EventErrorResolved EventType = "error_resolved"
	// EventMilestoneReached 达到里程碑
	EventMilestoneReached EventType = "milestone_reached"
)

type InMemoryStore

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

InMemoryStore 内存存储实现

func NewInMemoryStore

func NewInMemoryStore(config *InMemoryStoreConfig) *InMemoryStore

NewInMemoryStore 创建内存存储

func (*InMemoryStore) Delete

func (s *InMemoryStore) Delete(ctx context.Context, id string) error

Delete 删除记忆

func (*InMemoryStore) GetStats

func (s *InMemoryStore) GetStats() map[string]any

GetStats 获取统计信息

func (*InMemoryStore) List

func (s *InMemoryStore) List(ctx context.Context, scope MemoryScope, projectID string, limit int) ([]*Memory, error)

List 列出记忆

func (*InMemoryStore) Load

func (s *InMemoryStore) Load(ctx context.Context, id string) (*Memory, error)

Load 加载记忆

func (*InMemoryStore) Save

func (s *InMemoryStore) Save(ctx context.Context, memory *Memory) error

Save 保存记忆

func (*InMemoryStore) Search

func (s *InMemoryStore) Search(ctx context.Context, query string, tags []string, limit int) ([]*Memory, error)

Search 搜索记忆

type InMemoryStoreConfig

type InMemoryStoreConfig struct {
	// MaxMemories 最大记忆数
	MaxMemories int
}

InMemoryStoreConfig 配置

type Memory

type Memory struct {
	// ID 记忆 ID
	ID string `json:"id"`

	// Scope 作用域
	Scope MemoryScope `json:"scope"`

	// ProjectID 项目 ID(当 Scope 为 project 时)
	ProjectID string `json:"project_id,omitempty"`

	// SessionID 会话 ID(当 Scope 为 session 时)
	SessionID string `json:"session_id,omitempty"`

	// Title 标题(简短描述)
	Title string `json:"title"`

	// Content 详细内容
	Content string `json:"content"`

	// Tags 标签列表
	Tags []string `json:"tags"`

	// Source 来源
	Source MemorySource `json:"source"`

	// Confidence 置信度 (0.0-1.0)
	Confidence float64 `json:"confidence"`

	// AccessCount 访问次数
	AccessCount int `json:"access_count"`

	// LastAccessed 最后访问时间
	LastAccessed time.Time `json:"last_accessed"`

	// Metadata 元数据
	Metadata map[string]any `json:"metadata,omitempty"`

	// CreatedAt 创建时间
	CreatedAt time.Time `json:"created_at"`

	// UpdatedAt 更新时间
	UpdatedAt time.Time `json:"updated_at"`
}

Memory 自动捕获的记忆

func NewMemory

func NewMemory(scope MemoryScope, title, content string, tags []string) *Memory

NewMemory 创建新记忆

func (*Memory) AddTag

func (m *Memory) AddTag(tag string)

AddTag 添加标签

func (*Memory) HasTag

func (m *Memory) HasTag(tag string) bool

HasTag 检查是否有指定标签

func (*Memory) MarkAccessed

func (m *Memory) MarkAccessed()

MarkAccessed 标记访问

type MemoryScope

type MemoryScope string

MemoryScope 记忆作用域

const (
	// ScopeGlobal 全局记忆(用户级)
	ScopeGlobal MemoryScope = "global"
	// ScopeProject 项目记忆
	ScopeProject MemoryScope = "project"
	// ScopeSession 会话记忆
	ScopeSession MemoryScope = "session"
)

type MemorySource

type MemorySource string

MemorySource 记忆来源

const (
	// SourceDialog 来自对话
	SourceDialog MemorySource = "dialog"
	// SourceTool 来自工具调用
	SourceTool MemorySource = "tool"
	// SourceSystem 来自系统
	SourceSystem MemorySource = "system"
	// SourceUser 来自用户显式操作
	SourceUser MemorySource = "user"
)

type Store

type Store interface {
	Save(ctx context.Context, memory *Memory) error
	Load(ctx context.Context, id string) (*Memory, error)
	List(ctx context.Context, scope MemoryScope, projectID string, limit int) ([]*Memory, error)
	Search(ctx context.Context, query string, tags []string, limit int) ([]*Memory, error)
	Delete(ctx context.Context, id string) error
}

Store 记忆存储接口

type TagExtractor

type TagExtractor interface {
	Extract(text string) []TagSuggestion
}

TagExtractor 标签提取器接口

type TagSuggestion

type TagSuggestion struct {
	// Tag 标签
	Tag string `json:"tag"`
	// Confidence 置信度
	Confidence float64 `json:"confidence"`
	// Reason 原因
	Reason string `json:"reason"`
}

TagSuggestion 标签建议

Jump to

Keyboard shortcuts

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