trait

package
v1.10.3 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2026 License: MIT Imports: 5 Imported by: 3

Documentation

Overview

Package trait defines the Trait entity — who an agent is.

Traits are personality dimensions that influence HOW an agent works. They are declarative, not imperative — you don't tell the agent what to do, you tell it who it is.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Category

type Category string

Category groups related traits.

const (
	CategoryPersonality   Category = "personality"
	CategoryWorkstyle     Category = "workstyle"
	CategoryCommunication Category = "communication"
	CategoryRisk          Category = "risk"
)

type Dimension

type Dimension struct {
	Name      string  `json:"name"`
	LowLabel  string  `json:"low_label"`
	HighLabel string  `json:"high_label"`
	Value     float64 `json:"value"`
}

Dimension represents a bipolar personality axis. Value ranges from 0.0 to 1.0 where each extreme has a label.

type Influence

type Influence struct {
	Target    InfluenceTarget `json:"target"`
	Value     any             `json:"value"`
	Condition string          `json:"condition,omitempty"`
	Weight    float64         `json:"weight,omitempty"`
}

Influence describes a runtime modification applied by a trait.

type InfluenceTarget

type InfluenceTarget string

InfluenceTarget is what a trait influence modifies at runtime.

const (
	TargetPromptInjection InfluenceTarget = "prompt_injection"
	TargetTemperature     InfluenceTarget = "temperature"
	TargetMaxSteps        InfluenceTarget = "max_steps"
	TargetToolSelection   InfluenceTarget = "tool_selection"
	TargetResponseStyle   InfluenceTarget = "response_style"
)

type ListFilter

type ListFilter struct {
	Exact    bool
	Category Category
	Search   string
	Limit    int
	Offset   int
}

ListFilter controls pagination and matching for trait listing. Scope arrives on the context; Exact narrows to rows stored at precisely that depth instead of everything beneath it.

type Store

type Store interface {
	CreateTrait(ctx context.Context, trait *Trait) error
	GetTrait(ctx context.Context, traitID id.TraitID) (*Trait, error)
	GetTraitByName(ctx context.Context, name string) (*Trait, error)
	UpdateTrait(ctx context.Context, trait *Trait) error
	DeleteTrait(ctx context.Context, traitID id.TraitID) error
	ListTraits(ctx context.Context, filter *ListFilter) ([]*Trait, error)
	CountTraits(ctx context.Context, filter *ListFilter) (int64, error)
}

Store defines persistence for traits.

type Trait

type Trait struct {
	cortex.Entity
	ID          id.TraitID     `json:"id"`
	Name        string         `json:"name"`
	Description string         `json:"description,omitempty"`
	Scope       cortex.Scope   `json:"scope"`
	Dimensions  []Dimension    `json:"dimensions,omitempty"`
	Influences  []Influence    `json:"influences,omitempty"`
	Category    Category       `json:"category,omitempty"`
	Metadata    map[string]any `json:"metadata,omitempty"`
}

Trait represents a personality dimension that influences agent behavior.

func (*Trait) Sections

func (t *Trait) Sections(order int) []prompt.Section

Sections returns the trait's contribution to an agent's system prompt: one section per prompt-injection influence, in the order the influences are declared. A trait with no prompt injections returns nothing, which is the common case for traits that only move temperature or tool selection.

order is where the trait's first section sits in the assembled prompt, and further sections take consecutive orders from there. A caller walking an agent's trait list starts at prompt.OrderTrait and advances by the number of sections each trait returned, since assembly falls back to sorting by ID when two sections share an order and that would reorder the traits alphabetically.

The heading stays inside Body rather than moving to Title so the assembled text is byte-identical to the prompt this injection has always produced. Title is for sections a host authors.

The first injection is addressed as "trait:<name>". A trait with more than one gets "trait:<name>:2" onwards, so the ordinary single injection keeps the ID an overlay author would guess.

Jump to

Keyboard shortcuts

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