models

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: May 14, 2026 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	DefaultSessionTTL = 24 * time.Hour
	DefaultTaskTTL    = 1 * time.Hour
)

Time fields for tracking.

Functions

This section is empty.

Types

type AgentStatus

type AgentStatus string

AgentStatus represents agent running state.

const (
	AgentStatusStarting AgentStatus = "starting"
	AgentStatusReady    AgentStatus = "ready"
	AgentStatusBusy     AgentStatus = "busy"
	AgentStatusStopping AgentStatus = "stopping"
	AgentStatusOffline  AgentStatus = "offline"
)

type AgentType

type AgentType string

AgentType represents agent types.

const (
	AgentTypeLeader AgentType = "leader"
	AgentTypeTop    AgentType = "agent_top"
	AgentTypeBottom AgentType = "agent_bottom"

	// Travel agent types
	AgentTypeDestination AgentType = "destination"
	AgentTypeFood        AgentType = "food"
	AgentTypeHotel       AgentType = "hotel"
	AgentTypeItinerary   AgentType = "itinerary"
)

type Gender

type Gender string

Gender represents user gender.

const (
	GenderMale   Gender = "male"
	GenderFemale Gender = "female"
	GenderOther  Gender = "other"
)

type Occasion

type Occasion string

Occasion represents usage scenarios.

const (
	OccasionWork     Occasion = "work"
	OccasionSports   Occasion = "sports"
	OccasionFormal   Occasion = "formal"
	OccasionVacation Occasion = "vacation"
)

type PriceRange

type PriceRange struct {
	Min float64 `json:"min"`
	Max float64 `json:"max"`
}

PriceRange represents budget range.

func NewPriceRange

func NewPriceRange(min, max float64) *PriceRange

NewPriceRange creates a new PriceRange.

func (*PriceRange) Contains

func (p *PriceRange) Contains(price float64) bool

Contains checks if the price is within range.

func (*PriceRange) IsValid

func (p *PriceRange) IsValid() bool

IsValid checks if the price range is valid.

type RecommendItem

type RecommendItem struct {
	ItemID           string         `json:"item_id"`
	Category         string         `json:"category"`
	Name             string         `json:"name"`
	Brand            string         `json:"brand"`
	Price            float64        `json:"price"`
	URL              string         `json:"url"`
	ImageURL         string         `json:"image_url"`
	AgentPreferences []StyleTag     `json:"style"`
	Colors           []string       `json:"colors"`
	Description      string         `json:"description"`
	MatchReason      string         `json:"match_reason"`
	Content          string         `json:"content"` // add Content field saved by agI
	Metadata         map[string]any `json:"metadata"`
}

RecommendItem is a generic data item produced by an Agent. The Content field (a JSON string) and Metadata field (a key-value map) serve as universal data carriers for any scenario. Domain-specific fields such as Price, Brand, ImageURL, Category, Colors, and MatchReason are optional and should only be populated when the downstream consumer expects them.

type RecommendResult

type RecommendResult struct {
	SessionID  string           `json:"session_id"`
	UserID     string           `json:"user_id"`
	Items      []*RecommendItem `json:"items"`
	Reason     string           `json:"reason"`
	TotalPrice float64          `json:"total_price"`
	MatchScore float64          `json:"match_score"`
	Occasion   Occasion         `json:"occasion"`
	Season     string           `json:"season"`
	Feedback   *UserFeedback    `json:"feedback"`
	Metadata   map[string]any   `json:"metadata"`
	CreatedAt  time.Time        `json:"created_at"`
}

RecommendResult is a generic Agent output structure. In general-purpose scenarios, use the Content and Metadata fields as the primary data carriers. Fields such as TotalPrice, MatchScore, Occasion, and Season are optional and only meaningful in specific domains (e.g. e-commerce recommendations).

func NewRecommendResult

func NewRecommendResult(sessionID, userID string) *RecommendResult

NewRecommendResult creates a new RecommendResult.

func (*RecommendResult) AddItem

func (r *RecommendResult) AddItem(item *RecommendItem)

AddItem appends an item to the result. Only nil items are rejected; all other items are accepted regardless of whether domain-specific fields (e.g. Price) are populated.

func (*RecommendResult) CalculateScore

func (r *RecommendResult) CalculateScore() float64

CalculateScore returns a normalised score in [0, 1] based on item count. Uses 20 as the reference maximum (matching the default maxItems in the aggregator). Returns 0.0 when there are no items.

type Session

type Session struct {
	SessionID   string           `json:"session_id"`
	UserID      string           `json:"user_id"`
	UserProfile *UserProfile     `json:"user_profile"`
	Input       string           `json:"input"`
	Status      SessionStatus    `json:"status"`
	Tasks       []*Task          `json:"tasks"`
	Results     []*TaskResult    `json:"results"`
	FinalOutput *RecommendResult `json:"final_output"`
	Metadata    map[string]any   `json:"metadata"`
	CreatedAt   time.Time        `json:"created_at"`
	UpdatedAt   time.Time        `json:"updated_at"`
	ExpiredAt   time.Time        `json:"expired_at"`
}

Session represents a user conversation session.

func NewSession

func NewSession(sessionID, userID, input string) *Session

NewSession creates a new Session.

func (*Session) AddResult

func (s *Session) AddResult(result *TaskResult)

AddResult adds a task result to the session.

func (*Session) AddTask

func (s *Session) AddTask(task *Task)

AddTask adds a task to the session.

func (*Session) IsCompleted

func (s *Session) IsCompleted() bool

IsCompleted checks if the session is completed.

func (*Session) IsExpired

func (s *Session) IsExpired() bool

IsExpired checks if the session has expired.

func (*Session) Progress

func (s *Session) Progress() float64

Progress returns the completion progress (0.0 - 1.0).

func (*Session) SetStatus

func (s *Session) SetStatus(status SessionStatus)

SetStatus updates the session status.

type SessionStatus

type SessionStatus string

SessionStatus represents session state.

const (
	SessionStatusPending    SessionStatus = "pending"
	SessionStatusProcessing SessionStatus = "processing"
	SessionStatusCompleted  SessionStatus = "completed"
	SessionStatusFailed     SessionStatus = "failed"
	SessionStatusExpired    SessionStatus = "expired"
)

type StyleTag

type StyleTag string

StyleTag represents user preference style tags.

const (
	Sporty          StyleTag = "sporty"
	StyleMinimalist StyleTag = "minimalist"
	StyleVintage    StyleTag = "vintage"
	StyleBohemian   StyleTag = "bohemian"
)

type Task

type Task struct {
	TaskID      string         `json:"task_id"`
	TaskType    AgentType      `json:"task_type"`
	AgentType   AgentType      `json:"agent_type"`
	UserProfile *UserProfile   `json:"user_profile"`
	Context     *TaskContext   `json:"context"`
	Payload     map[string]any `json:"payload"`
	Priority    int            `json:"priority"`
	Deadline    time.Time      `json:"deadline"`
	CreatedAt   time.Time      `json:"created_at"`
}

Task represents a recommendation task.

func NewTask

func NewTask(taskID string, agentType AgentType, profile *UserProfile) *Task

NewTask creates a new Task.

func (*Task) IsExpired

func (t *Task) IsExpired() bool

IsExpired checks if the task has expired.

type TaskContext

type TaskContext struct {
	Dependencies []string               `json:"dependencies"`
	DepResults   map[string]*TaskResult `json:"dep_results"`
	Coordination map[string]any         `json:"coordination"`
}

TaskContext contains task dependencies and coordination data.

type TaskResult

type TaskResult struct {
	TaskID    string           `json:"task_id"`
	AgentType AgentType        `json:"agent_type"`
	Success   bool             `json:"success"`
	Items     []*RecommendItem `json:"items"`
	Reason    string           `json:"reason"`
	Metadata  map[string]any   `json:"metadata"`
	Error     string           `json:"error"`
	Duration  time.Duration    `json:"duration"`
	CreatedAt time.Time        `json:"created_at"`
}

TaskResult represents the result of a task execution. The Items field retains []*RecommendItem for backward compatibility, but in general-purpose scenarios prefer using the Metadata field (or a dedicated Content field if added) as the primary data carrier. Items is only relevant when the task produces domain-specific structured results.

func NewTaskResult

func NewTaskResult(taskID string, agentType AgentType) *TaskResult

NewTaskResult creates a new TaskResult.

func (*TaskResult) SetError

func (r *TaskResult) SetError(errMsg string)

SetError marks the task as failed.

func (*TaskResult) SetSuccess

func (r *TaskResult) SetSuccess(items []*RecommendItem, reason string)

SetSuccess marks the task as successful.

type UserFeedback

type UserFeedback struct {
	Liked   bool   `json:"liked"`
	Comment string `json:"comment"`
	Rating  int    `json:"rating"`
}

UserFeedback represents user feedback on recommendations.

func (*UserFeedback) IsValid

func (f *UserFeedback) IsValid() bool

IsValid checks if the rating is valid.

func (*UserFeedback) SetRating

func (f *UserFeedback) SetRating(rating int) bool

SetRating sets the rating with validation.

type UserProfile

type UserProfile struct {
	UserID      string         `json:"user_id"`
	Name        string         `json:"name"`
	Gender      Gender         `json:"gender"`
	Age         int            `json:"age"`
	Occupation  string         `json:"occupation"`
	Style       []StyleTag     `json:"style"`
	Budget      *PriceRange    `json:"budget"`
	Colors      []string       `json:"colors"`
	Occasions   []Occasion     `json:"occasions"`
	BodyType    string         `json:"body_type"`
	Preferences map[string]any `json:"preferences"`
	CreatedAt   time.Time      `json:"created_at"`
	UpdatedAt   time.Time      `json:"updated_at"`
}

UserProfile represents user profile information.

func NewUserProfile

func NewUserProfile(userID, name string) *UserProfile

NewUserProfile creates a new UserProfile.

func (*UserProfile) HasOccasion

func (p *UserProfile) HasOccasion(occ Occasion) bool

HasOccasion checks if user has the specified occasion.

func (*UserProfile) HasStyle

func (p *UserProfile) HasStyle(tag StyleTag) bool

HasStyle checks if user has the specified style tag.

func (*UserProfile) Validate

func (p *UserProfile) Validate() error

Validate validates the user profile.

Jump to

Keyboard shortcuts

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