mind

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2026 License: MIT Imports: 30 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package mind runs the cognitive cycle: take a percept, decide, act, record.

System 1 (fast, typed answers) reads every text message and System 2 (slow reasoning) replies as the agent itself. Pronouns are resolved to names before System 1 reads anything, so "your church" and "my church" are never confused. A second loop on the clock's ticks lets the agent speak first (initiative.go) and live a day of its own (life.go).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Asker

type Asker interface {
	// Ask returns where it sent the request, for Settle.
	Ask(ctx context.Context, p perception.Percept, text, id string) (json.RawMessage, error)
	Settle(ctx context.Context, where json.RawMessage, text string) error
}

type Calls

type Calls struct {
	On         bool
	AsksPerDay int // after-calls asked on Telegram a day; the rest wait for the console
	// ReplyWindow is how long after a different pick (or "something else")
	// the owner's next message is taken as their reason (or answer).
	ReplyWindow time.Duration
}

type CheckIns

type CheckIns struct {
	// Times of day, from midnight in its time zone. Empty: it never checks in unprompted.
	Times []time.Duration
	Quiet time.Duration
}

type Chooser

type Chooser interface {
	// Choose adds a button for something else, and returns where it was sent.
	Choose(ctx context.Context, p perception.Percept, text, id string, n, pick int) (json.RawMessage, error)
}

type Config

type Config struct {
	Life character.Character
	// Judgment is seeded for the owner to review; only what they approve is used.
	Judgment character.Judgment
	Percepts <-chan perception.Percept
	Store    Store
	Replier  Replier
	System1  system1.DecisionModel
	System2  system2.Reasoner
	Incoming questions.Set
	FollowUp questions.Set // zero value: never checked
	// LifeArea zero value: nothing is labelled and every reply searches memory.
	LifeArea     questions.Set
	PersonCircle questions.Set
	// FactRelevance is a one-question template, asked once per fact ({fact});
	// zero value: no recall.
	FactRelevance questions.Set
	// OpenThreads replaces FactRelevance for small talk; zero value: small talk
	// recalls like any other message.
	OpenThreads      questions.Set
	RecallCandidates int // facts considered per reply: same life area first, then newest
	ReplyPrompt      Prompt
	Working          WorkingMemory
	// Ticks is the clock, about once a minute; nil: the agent never speaks first.
	Ticks <-chan time.Time
	// Zone is for reminders and check-in times; nil: UTC.
	Zone      *time.Location
	CheckIns  CheckIns
	Day       Day
	Abilities *ability.Set
	// SkillLevel zero value: works aren't scored, and skills only move with feedback.
	SkillLevel questions.Set
	// StageCheck checks that a piece of work meets a learning stage before
	// the stage moves on (one predicate); zero value: its own word is enough.
	StageCheck questions.Set
	// Autonomy is what it may do on its own; the zero value allows everything.
	Autonomy action.Policy
	// Asker nil: requests to the owner wait unsent and expire.
	Asker Asker
	// Filer nil: everything it sends is a message.
	Filer Filer
	// Formats is the files it can send things as; nil: none.
	Formats *render.Set
	// Doers are tools that change things; ActionsPerDay caps how many it
	// proposes a day.
	Doers         []Doer
	ActionsPerDay int
	// Watchers are tools looked at on a schedule; what's new is perceived.
	Watchers []Watcher
	// Skills are know-how its owner gave it (agent_skills).
	Skills []agentskill.Skill
	Calls  Calls
	// Embedder nil: it takes the owner's newest decision of the right type instead.
	Embedder embed.Embedder
	Log      *slog.Logger
}

type Day

type Day struct {
	PlanAt        time.Duration // when it plans its day, from midnight in its time zone
	JournalAt     time.Duration
	MaxActivities int     // things it plans a round (a day at pace 1), besides the journal
	BudgetUSD     float64 // most its own day may cost; past it, the rest waits for tomorrow
	// Pace is how much faster than a person it works: its waking day runs in
	// this many rounds, each planned when it starts. 0 or 1: one plan a day.
	Pace           int
	PlanPrompt     Prompt // zero: no day of its own
	ActivityPrompt Prompt
	ReviewDay      time.Weekday
	ReviewAt       time.Duration // from midnight in its time zone
	ReviewPrompt   Prompt        // zero: no review
	LearnPrompt    Prompt        // zero: no learning plans
	DataPrompt     Prompt        // zero: what was made before its kind carried data never gets it
	ObservePrompt  Prompt        // zero: what it watches is only recorded
}

type Doer

type Doer interface {
	Name() string
	Describe() string
	Class() action.Class
	// Destructive tools always ask, even when their class is auto.
	Destructive() bool
	Check(args string) error
	Do(ctx context.Context, args string, at time.Time) (string, error)
}

Doer is a tool that changes things (tools.Action).

type Filer

type Filer interface {
	SendFile(ctx context.Context, p perception.Percept, name string, data []byte, caption string) error
}

type Mind

type Mind struct {
	Config
	// contains filtered or unexported fields
}

func New

func New(c Config) *Mind

func (*Mind) EnsurePlans

func (m *Mind) EnsurePlans(ctx context.Context, now time.Time)

EnsurePlans drafts a plan for each active skill goal that has none.

func (*Mind) Review

func (m *Mind) Review(ctx context.Context, now time.Time) error

Review looks back at the week, now: it is what the weekly review does, and `tinio review` runs it on demand.

func (*Mind) Run

func (m *Mind) Run(ctx context.Context) error

Run runs two loops until ctx is done or the percepts end: one talks, the other lives its day on the clock's ticks, so a slow plan, activity or review never keeps a reply waiting.

type Prompt

type Prompt struct {
	Ref  string
	Text string
}

Prompt's Ref versions Text and is recorded on every System 2 decision.

type Replier

type Replier interface {
	Reply(ctx context.Context, p perception.Percept, text string) error
}

type Store

type Store interface {
	SavePercept(ctx context.Context, p perception.Percept) (isNew bool, err error)
	SaveDecision(ctx context.Context, d decision.Decision) error
	RecentExchanges(ctx context.Context, source, thread string, since time.Time,
		exclude ulid.ULID, limit int) ([]memory.Exchange, error)
	SaveFact(ctx context.Context, f memory.Fact) error
	RecallCandidates(ctx context.Context, subjects, areas []string, limit int) ([]memory.Fact, error)
	UnlabelledFacts(ctx context.Context, limit int) ([]memory.Fact, error)
	SetFactAreas(ctx context.Context, id ulid.ULID, areas []string) error
	Person(ctx context.Context, key string) (memory.Person, bool, error)
	KnownPeople(ctx context.Context, limit int) ([]memory.Person, error)
	SavePerson(ctx context.Context, p memory.Person) error
	AddPersonIfNew(ctx context.Context, p memory.Person) (bool, error)
	SaveIntention(ctx context.Context, i memory.Intention) error
	DueIntentions(ctx context.Context, now time.Time, limit int) ([]memory.Intention, error)
	IntentionsDue(ctx context.Context, from, to time.Time) ([]memory.Intention, error)
	FinishIntention(ctx context.Context, id ulid.ULID, status, result string, at time.Time) error
	PostponeIntention(ctx context.Context, id ulid.ULID, due time.Time) error
	OpenIntentions(ctx context.Context, subject, kind string) ([]memory.Intention, error)
	AwaitIntention(ctx context.Context, id ulid.ULID) error
	ResumeIntention(ctx context.Context, id ulid.ULID, notBefore time.Time) error
	SaveApproval(ctx context.Context, a memory.Approval) error
	Approval(ctx context.Context, id ulid.ULID) (memory.Approval, bool, error)
	UnsentApprovals(ctx context.Context, limit int) ([]memory.Approval, error)
	MarkApprovalSent(ctx context.Context, id ulid.ULID, message []byte, at time.Time) error
	DecideApproval(ctx context.Context, id ulid.ULID, status string, at time.Time) (bool, error)
	StaleApprovals(ctx context.Context, before time.Time, limit int) ([]memory.Approval, error)
	SetWorkPublic(ctx context.Context, id ulid.ULID, public bool, by string) (bool, error)
	SaveAutonomyRule(ctx context.Context, class, verdict, by string, percept ulid.ULID, at time.Time) error
	AutonomyRules(ctx context.Context) (map[string]string, error)
	DeleteFact(ctx context.Context, id ulid.ULID) (bool, error)
	SaveLabel(ctx context.Context, l memory.Label) error
	LastRead(ctx context.Context, setID, source, thread string, before time.Time) (ulid.ULID, bool, error)
	SaveDream(ctx context.Context, d memory.Dream) error
	Dreams(ctx context.Context, activeOnly bool) ([]memory.Dream, error)
	SaveGoal(ctx context.Context, g memory.Goal) error
	Goals(ctx context.Context, activeOnly bool) ([]memory.Goal, error)
	AddSkill(ctx context.Context, sk memory.Skill) error
	Skills(ctx context.Context) ([]memory.Skill, error)
	SetSkillLevel(ctx context.Context, name string, level float64, at time.Time) error
	SaveEvidence(ctx context.Context, e memory.Evidence) error
	RecentEvidence(ctx context.Context, skill string, limit int) ([]memory.Evidence, error)
	SaveLesson(ctx context.Context, l memory.Lesson) error
	Lessons(ctx context.Context, skill string, limit int) ([]memory.Lesson, error)
	RetireLesson(ctx context.Context, id ulid.ULID, at time.Time) error
	MarkReviewAsked(ctx context.Context, work ulid.ULID, at time.Time) error
	AskedForReview(ctx context.Context, since time.Time) (memory.Work, bool, error)
	SavePlan(ctx context.Context, p memory.LearningPlan) error
	Plans(ctx context.Context, activeOnly bool) ([]memory.LearningPlan, error)
	AdvancePlan(ctx context.Context, plan ulid.ULID, at time.Time) error
	EndPlan(ctx context.Context, plan ulid.ULID, status string, at time.Time) error
	SaveResource(ctx context.Context, r memory.Resource) error
	Resources(ctx context.Context, plan ulid.ULID) ([]memory.Resource, error)
	FinishResource(ctx context.Context, id, work ulid.ULID, title string, at time.Time) error
	RecentFound(ctx context.Context, limit int) ([]search.Result, error)
	SeedJudgment(ctx context.Context, cases []memory.JudgmentCase, principles []memory.Principle) (int, int, error)
	Principles(ctx context.Context, status string) ([]memory.Principle, error)
	JudgmentCases(ctx context.Context, status string, types []string) ([]memory.JudgmentCase, error)
	SavePrinciple(ctx context.Context, p memory.Principle) error
	SaveCaseEmbedding(ctx context.Context, id ulid.ULID, v []float32, model string) error
	SaveTaste(ctx context.Context, t memory.Taste) error
	Tastes(ctx context.Context, limit int) ([]memory.Taste, error)
	SaveCall(ctx context.Context, c memory.Call) error
	Call(ctx context.Context, id ulid.ULID) (memory.Call, bool, error)
	RecentCalls(ctx context.Context, status string, limit int) ([]memory.Call, error)
	CallsAskedSince(ctx context.Context, mode string, since time.Time) (int, error)
	MarkCallAsked(ctx context.Context, id ulid.ULID, where json.RawMessage, at time.Time) error
	StaleCalls(ctx context.Context, before time.Time, limit int) ([]memory.Call, error)
	ExpireCall(ctx context.Context, id ulid.ULID) (bool, error)
	WaitForOwner(ctx context.Context, id ulid.ULID, waiting string, at time.Time) error
	WaitingCall(ctx context.Context, since time.Time) (memory.Call, bool, error)
	AnswerCall(ctx context.Context, c memory.Call, asCase bool) (bool, error)
	GiveCallReason(ctx context.Context, id ulid.ULID, reason string, at time.Time) error
	CallsToLookBack(ctx context.Context, types []string, from, to time.Time, limit int) ([]memory.Call, error)
	SetOutcome(ctx context.Context, id ulid.ULID, outcome, verdict, note, by string, at time.Time) (bool, error)
	IntentionWork(ctx context.Context, intention ulid.ULID) (memory.Work, bool, error)
	Work(ctx context.Context, id ulid.ULID) (memory.Work, bool, error)
	SaveAction(ctx context.Context, a memory.Action) error
	SeenFrom(ctx context.Context, source string) (bool, error)
	LastFrom(ctx context.Context, source string) (string, bool, error)
	SetAction(ctx context.Context, id ulid.ULID, from []string, status, result string, at time.Time) (bool, error)
	Actions(ctx context.Context, statuses []string, limit int) ([]memory.Action, error)
	ActionsSince(ctx context.Context, since time.Time) (int, error)
	SetWorkData(ctx context.Context, id ulid.ULID, kind string, data json.RawMessage) error
	WorksMissingData(ctx context.Context, kinds []string, limit int) ([]memory.Work, error)
	Intention(ctx context.Context, id ulid.ULID) (memory.Intention, bool, error)
	WorksFor(ctx context.Context, person string, limit int) ([]memory.Work, error)
	SaveWorkEmbedding(ctx context.Context, id ulid.ULID, v []float32, model string) error
	SaveProject(ctx context.Context, p memory.Project) error
	Project(ctx context.Context, id ulid.ULID) (memory.Project, bool, error)
	ActiveProjects(ctx context.Context, limit int) ([]memory.Project, error)
	SaveWork(ctx context.Context, w memory.Work) error
	WorksBetween(ctx context.Context, from, to time.Time) ([]memory.Work, error)
	ProjectWorks(ctx context.Context, project ulid.ULID, limit int) ([]memory.Work, error)
	LatestWork(ctx context.Context, kind string) (memory.Work, bool, error)
	CostSince(ctx context.Context, since time.Time, actions []string) (float64, error)
	Conversations(ctx context.Context) ([]memory.Conversation, error)
	LastSpokeFirst(ctx context.Context, person, kind string) (time.Time, bool, error)
	UnaskedFacts(ctx context.Context, person string, since time.Time, limit int) ([]memory.Fact, error)
	MarkFactsAsked(ctx context.Context, ids []ulid.ULID, at time.Time) error
}

type Watcher

type Watcher interface {
	Name() string
	Every() time.Duration
	Look(ctx context.Context, at time.Time) ([]memory.Watched, error)
}

Watcher is a tool looked at on a schedule (tools.Watcher).

type WorkingMemory

type WorkingMemory struct {
	Turns  int
	Window time.Duration
}

WorkingMemory bounds how much of the current conversation the mind keeps in view: at most Turns earlier exchanges, none older than Window.

Jump to

Keyboard shortcuts

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