Documentation
¶
Overview ¶
Package habit provides user habit learning and analysis for AI agents.
Package habit provides user habit learning and analysis for AI agents.
Package habit provides user habit learning and analysis for AI agents.
Package habit provides user habit learning and analysis for AI agents.
Index ¶
- type AnalysisConfig
- type HabitAnalyzer
- type HabitApplier
- func (a *HabitApplier) ApplyToScheduleCreate(ctx context.Context, userID int32, input *ScheduleInput) *ScheduleInput
- func (a *HabitApplier) EnhanceSearchQuery(ctx context.Context, userID int32, query string) []string
- func (a *HabitApplier) GetFrequentKeywords(ctx context.Context, userID int32) []string
- func (a *HabitApplier) GetSuggestedDuration(ctx context.Context, userID int32) int
- func (a *HabitApplier) GetSuggestedLocations(ctx context.Context, userID int32) []string
- func (a *HabitApplier) InferTime(ctx context.Context, userID int32, query string) time.Time
- type HabitLearner
- type ScheduleHabits
- type ScheduleInput
- type SearchHabits
- type TimeHabits
- type UserHabits
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AnalysisConfig ¶
type AnalysisConfig struct {
// LookbackDays is how many days of history to analyze
LookbackDays int `json:"lookback_days"`
// MinSamples is the minimum number of samples required for analysis
MinSamples int `json:"min_samples"`
// PeakMultiplier is the threshold for identifying peak hours (vs average)
PeakMultiplier float64 `json:"peak_multiplier"`
// MinKeywordFrequency is the minimum frequency for a keyword to be considered
MinKeywordFrequency int `json:"min_keyword_frequency"`
}
AnalysisConfig holds configuration for habit analysis.
func DefaultAnalysisConfig ¶
func DefaultAnalysisConfig() *AnalysisConfig
DefaultAnalysisConfig returns the default analysis configuration.
type HabitAnalyzer ¶
type HabitAnalyzer interface {
// Analyze analyzes user habits from historical data.
Analyze(ctx context.Context, userID int32) (*UserHabits, error)
}
HabitAnalyzer analyzes user interaction history to learn habits.
func NewHabitAnalyzer ¶
func NewHabitAnalyzer(memSvc memory.MemoryService, config *AnalysisConfig) HabitAnalyzer
NewHabitAnalyzer creates a new HabitAnalyzer instance.
type HabitApplier ¶
type HabitApplier struct {
// contains filtered or unexported fields
}
HabitApplier applies learned habits to enhance user experience.
func NewHabitApplier ¶
func NewHabitApplier(memSvc memory.MemoryService) *HabitApplier
NewHabitApplier creates a new HabitApplier.
func (*HabitApplier) ApplyToScheduleCreate ¶
func (a *HabitApplier) ApplyToScheduleCreate(ctx context.Context, userID int32, input *ScheduleInput) *ScheduleInput
ApplyToScheduleCreate enhances schedule creation input with learned habits.
func (*HabitApplier) EnhanceSearchQuery ¶
EnhanceSearchQuery suggests related keywords based on habits.
func (*HabitApplier) GetFrequentKeywords ¶
func (a *HabitApplier) GetFrequentKeywords(ctx context.Context, userID int32) []string
GetFrequentKeywords returns frequently used search keywords.
func (*HabitApplier) GetSuggestedDuration ¶
func (a *HabitApplier) GetSuggestedDuration(ctx context.Context, userID int32) int
GetSuggestedDuration returns the suggested duration for a schedule.
func (*HabitApplier) GetSuggestedLocations ¶
func (a *HabitApplier) GetSuggestedLocations(ctx context.Context, userID int32) []string
GetSuggestedLocations returns frequently used locations.
type HabitLearner ¶
type HabitLearner struct {
// contains filtered or unexported fields
}
HabitLearner runs periodic habit analysis for all users.
func NewHabitLearner ¶
func NewHabitLearner(analyzer HabitAnalyzer, memSvc memory.MemoryService, config *AnalysisConfig) *HabitLearner
NewHabitLearner creates a new HabitLearner.
func (*HabitLearner) RunOnce ¶
func (l *HabitLearner) RunOnce(ctx context.Context, userID int32) (*UserHabits, error)
RunOnce runs habit analysis for a specific user immediately. Useful for testing or manual triggers.
func (*HabitLearner) Start ¶
func (l *HabitLearner) Start(ctx context.Context) error
Start begins the periodic habit analysis.
func (*HabitLearner) WithRunHour ¶
func (l *HabitLearner) WithRunHour(hour int) *HabitLearner
WithRunHour sets the hour of day to run analysis.
type ScheduleHabits ¶
type ScheduleHabits struct {
PreferredSlots []string `json:"preferred_slots"`
FrequentLocations []string `json:"frequent_locations"`
TitlePatterns []string `json:"title_patterns"`
DefaultDuration int `json:"default_duration"`
}
ScheduleHabits represents learned schedule-related habits.
func DefaultScheduleHabits ¶
func DefaultScheduleHabits() *ScheduleHabits
DefaultScheduleHabits returns sensible defaults for schedule habits.
type ScheduleInput ¶
type ScheduleInput struct {
StartTime time.Time `json:"start_time"`
Title string `json:"title"`
Location string `json:"location"`
SuggestedTimes []string `json:"suggested_times,omitempty"`
SuggestedLocations []string `json:"suggested_locations,omitempty"`
Duration int `json:"duration"`
SuggestedDuration int `json:"suggested_duration,omitempty"`
}
ScheduleInput represents input for schedule creation.
type SearchHabits ¶
type SearchHabits struct {
SearchMode string `json:"search_mode"`
ResultPreference string `json:"result_preference"`
FrequentKeywords []string `json:"frequent_keywords"`
}
SearchHabits represents learned search-related habits.
func DefaultSearchHabits ¶
func DefaultSearchHabits() *SearchHabits
DefaultSearchHabits returns sensible defaults for search habits.
type TimeHabits ¶
type TimeHabits struct {
// ActiveHours are the most active hours of the day (0-23)
ActiveHours []int `json:"active_hours"`
// PreferredTimes are specific times the user prefers (e.g., "09:00", "14:00")
PreferredTimes []string `json:"preferred_times"`
// ReminderLeadMin is the preferred reminder lead time in minutes
ReminderLeadMin int `json:"reminder_lead_min"`
// WeekdayPattern indicates if user is primarily active on weekdays
WeekdayPattern bool `json:"weekday_pattern"`
}
TimeHabits represents learned time-related habits.
func DefaultTimeHabits ¶
func DefaultTimeHabits() *TimeHabits
DefaultTimeHabits returns sensible defaults for time habits.
type UserHabits ¶
type UserHabits struct {
UpdatedAt time.Time `json:"updated_at"`
Time *TimeHabits `json:"time"`
Schedule *ScheduleHabits `json:"schedule"`
Search *SearchHabits `json:"search"`
Version int `json:"version"`
UserID int32 `json:"user_id"`
}
UserHabits aggregates all learned habits for a user.
func DefaultUserHabits ¶
func DefaultUserHabits(userID int32) *UserHabits
DefaultUserHabits returns a UserHabits with all default values.