schema

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jun 26, 2025 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (

	// CookStates contains all the states for the Cook machine.
	CookStates = ssC
	// CookGroups contains all the state groups for the Cook machine.
	CookGroups = sgC
)
View Source
var CookSchema = SchemaMerge(

	llm.LLMAgentSchema,
	am.Schema{

		ssC.ErrIngredients: {},
		ssC.ErrCooking:     {},

		ssC.DBStarting: {
			Require: S{ssC.Start},
			Remove:  S{ssC.DBReady},
		},
		ssC.DBReady: {
			Require: S{ssC.Start},
			Remove:  S{ssC.DBStarting},
		},

		ssC.IngredientsReady: {},
		ssC.RecipeReady:      {Require: S{ssC.IngredientsReady}},
		ssC.StepCompleted:    {Multi: true},

		ssC.StoryJoke:               {},
		ssC.StoryWakingUp:           {Tags: S{base.TagManual}},
		ssC.StoryIngredientsPicking: {Tags: S{base.TagPrompt}},
		ssC.StoryRecipePicking:      {Tags: S{base.TagPrompt}},
		ssC.StoryCookingStarted:     {Tags: S{base.TagPrompt}},
		ssC.StoryMealReady: {
			Tags:   S{base.TagPrompt, base.TagManual},
			Remove: S{ssC.InputPending},
		},
		ssC.StoryMemoryWipe: {Tags: S{base.TagPrompt}},
		ssC.StoryStartAgain: {Tags: S{base.TagPrompt}},

		ssC.CheckStories: {
			Multi:   true,
			Require: S{ssC.Start},
		},
		ssC.StoryChanged: {
			Multi: true,
			After: S{ssC.CheckStories},
		},

		ssC.RestoreCharacter: {
			Auto:    true,
			Require: S{ssC.DBReady},
			Remove:  sgC.Character,
		},
		ssC.GenCharacter: {
			Require: S{ssC.DBReady},
			Remove:  sgC.Character,
			Tags:    S{base.TagPrompt, base.TagTrigger},
		},
		ssC.CharacterReady: {Remove: sgC.Character},

		ssC.RestoreJokes: {
			Auto:    true,
			Require: S{ssC.DBReady, ssC.CharacterReady},
			Remove:  sgC.Jokes,
		},
		ssC.GenJokes: {
			Require: S{ssC.CharacterReady, ssC.DBReady},
			Remove:  sgC.Jokes,
			Tags:    S{base.TagPrompt},
		},
		ssC.JokesReady: {Remove: sgC.Jokes},

		ssC.RestoreResources: {
			Auto:    true,
			Require: S{ssC.CharacterReady, ssC.DBReady},
			Remove:  sgC.Resources,
		},
		ssC.GenResources: {
			Require: S{ssC.CharacterReady, ssC.DBReady},
			Remove:  sgC.Resources,
			Tags:    S{base.TagPrompt, base.TagTrigger},
		},
		ssC.ResourcesReady: {Remove: sgC.Resources},

		ssC.GenSteps: {
			Auto:    true,
			Require: S{ssC.StoryCookingStarted},
			Remove:  S{ssC.StepsReady},
			Tags:    S{base.TagPrompt},
		},
		ssC.StepsReady: {
			Require: S{ssC.RecipeReady},
			Remove:  S{ssC.GenSteps},
		},

		ssC.GenStepComments: {
			Auto:    true,
			Require: S{ssC.StoryCookingStarted},
			Remove:  S{ssC.StepCommentsReady},
			Tags:    S{base.TagPrompt},
		},
		ssC.StepCommentsReady: {Remove: S{ssC.GenStepComments}},

		ssC.Orienting: {
			Multi: true,
			Tags:  S{base.TagPrompt},
		},
		ssC.OrientingMove: {},

		ssC.Start: StateAdd(saLLM[ssLLM.Start], State{
			Add: S{ssC.CheckStories, ssC.DBStarting},
		}),
		ssC.Ready: StateAdd(saLLM[ssLLM.Ready], State{
			Auto:    true,
			Require: S{ssC.CharacterReady, ssC.ResourcesReady},
		}),
		ssC.Interrupted: StateAdd(saLLM[ssLLM.Interrupted], State{

			Remove: sgC.Interruptable,
		}),
		ssC.Prompt: StateAdd(saLLM[ssLLM.Prompt], State{}),
	})

CookSchema represents all relations and properties of CookStates.

View Source
var Exception = am.Exception

Exception is a type alias for the exception state.

View Source
var LLMResources = ParamsGenResources{
	Phrases: map[string]string{
		"NoCookingNoJokes":      "No jokes without cooking.",
		"IngredientsPicking":    "Tell me what cooking ingredients do you have at hand, we need at least %d to continue.",
		"IngredientsPickingEnd": "OK, I have the ingredients I need.",
		"RecipePicking":         "Ok, let me check my books for what we could make...",
		"ResumeNeeded":          "You have to Resume for me to do anything.",
		"WokenUp":               "OK I'm ready to start",
		"CookingStarted":        "You chose %s as the recipe which we will cook, got it. I will plan all the cooking steps nicely for us. Just press those buttons on the right, once I'm done.",
		"CharacterReady": sp(`
			Welcome to Cook - your AI-powered cooking assistant! It will help you pick a meal from the ingredients you have, and then you can cook it together (wink wink).
	`),
		ssC.StoryMealReady: "We made it, the meal is ready! You can enjoy it now. I hope you had fun cooking with us.",
		"ReqLimitReached":  "You have reached the limit of %d requests per session. Please come back later.",
	},
}
View Source
var MatchIngredients = regexp.MustCompile("^Ingredient")
View Source
var MatchSteps = regexp.MustCompile(`^Step`)
View Source
var MemMealReady = "StepMealReady"

TODO schema, define the base memory in baseschema

View Source
var SAdd = am.SAdd

SAdd is a func alias for merging lists of states.

View Source
var SchemaMerge = am.SchemaMerge

SchemaMerge is a func alias for extending an existing state schema.

View Source
var StateAdd = am.StateAdd

StateAdd is a func alias for adding to an existing state definition.

View Source
var StateSet = am.StateSet

StateSet is a func alias for replacing parts of an existing state definition.

View Source
var StoryCookingStarted = &Story{
	Story: shared.Story[Story]{
		StoryInfo: shared.StoryInfo{
			State: ssC.StoryCookingStarted,
			Title: "Cooking Started",
			Desc:  "The main story, the bot translates the recipe into actionable steps, then acts on them.",
		},
	},
	Cook: shared.StoryActor{
		Trigger: amhelp.Cond{
			Is: S{ssC.Ready, ssC.RecipeReady},
		},
	},
	Memory: shared.StoryActor{
		Trigger: amhelp.Cond{
			Not: S{MemMealReady},
		},
	},
}
View Source
var StoryIngredientsPicking = &Story{
	Story: shared.Story[Story]{
		StoryInfo: shared.StoryInfo{
			State: ssC.StoryIngredientsPicking,
			Title: "Ingredients Picking",
			Desc:  "The bot asks the user what ingredients they have at hand.",
		},
	},
	Cook: shared.StoryActor{
		Trigger: amhelp.Cond{
			Is:  S{ssC.Ready},
			Not: S{ssC.IngredientsReady, ssC.StoryWakingUp},
		},
	},
}
View Source
var StoryJoke = &Story{
	Story: shared.Story[Story]{
		StoryInfo: shared.StoryInfo{
			State: ssC.StoryJoke,
			Title: "Joke",
			Desc:  "In this story the bot tells a joke when asked to, based on the character.",
		},

		CanActivate: func(s *Story) bool {
			mem := s.Memory.Mach
			stepStates := mem.StateNamesMatch(MatchSteps)
			stepsNow := mem.TimeSum(stepStates) + s.Epoch
			freq := 1.5

			return s.Tick == 0 || float64(stepsNow)*freq >= float64(s.Tick)
		},
	},
}
View Source
var StoryMealReady = &Story{
	Story: shared.Story[Story]{
		StoryInfo: shared.StoryInfo{
			State: ssC.StoryMealReady,
			Title: "Meal Ready",
			Desc:  "This story is the end of the flow, the recipe should have been materialized by now.",
		},
	},
	Memory: shared.StoryActor{
		Trigger: amhelp.Cond{
			Is: S{MemMealReady},
		},
	},
}
View Source
var StoryMemoryWipe = &Story{
	Story: shared.Story[Story]{
		StoryInfo: shared.StoryInfo{
			State: ssC.StoryMemoryWipe,
			Title: "Memory Wipe",
			Desc:  "The bot will clean both short term and long term memory.",
		},
	},
}
View Source
var StoryRecipePicking = &Story{
	Story: shared.Story[Story]{
		StoryInfo: shared.StoryInfo{
			State: ssC.StoryRecipePicking,
			Title: "Recipe Picking",
			Desc:  "The bot offers some recipes, based on the ingredients.",
		},
	},
	Cook: shared.StoryActor{
		Trigger: amhelp.Cond{
			Is:  S{ssC.Ready, ssC.IngredientsReady},
			Not: S{ssC.RecipeReady},
		},
	},
}
View Source
var StoryStartAgain = &Story{
	Story: shared.Story[Story]{
		StoryInfo: shared.StoryInfo{
			State: ssC.StoryStartAgain,
			Title: "Start Again",
			Desc:  "The session will re-start, keeping the bot's memory.",
		},
	},
}
View Source
var StoryWakingUp = &Story{
	Story: shared.Story[Story]{
		StoryInfo: shared.StoryInfo{
			State: ssC.StoryWakingUp,
			Title: "Waking Up",
			Desc:  "The waking up story is the bot starting on either cold or warm boot.",
		},
	},
	Cook: shared.StoryActor{
		Trigger: amhelp.Cond{
			Not: S{ssC.Ready},
		},
	},
}

Functions

func NewCook

func NewCook(ctx context.Context) *am.Machine

NewCook will create the most basic Cook state machine.

Types

type CookGroupsDef

type CookGroupsDef struct {
	// Group with all stories.
	Stories S
	// Group with all the start states which call LLMs.
	BootGen S
	// Group with ready states for BootGen.
	BootGenReady S
	// All the states which should be stopped on Interrupt
	Interruptable S

	// All the states for the character generation.
	Character S
	// All the states for jokes generation.
	Jokes S
	// All the states for resource generation.
	Resources S
	// List of main flow states.
	MainFlow S
}

CookGroupsDef contains all the state groups Cook state machine.

type CookStatesDef

type CookStatesDef struct {
	*am.StatesBase

	ErrIngredients string
	ErrCooking     string

	DBStarting string
	DBReady    string

	// Ready is when the agent has CharacterReady, JokesReady, and ResourcesReady.
	Ready string
	// IngredientsReady is the first step of the flow, the bot has a list of ingredients.
	IngredientsReady string
	// RecipeReady is when the user and the bot agree on the recipe.
	RecipeReady string
	// One of the cooking steps have been completed.
	StepCompleted string

	// StoryJoke indicates that the joke story is currently happening.
	StoryJoke string
	// StoryWakingUp indicates that the waking-up story is currently happening.
	// This will boot up the bot from the prev session (SQL) or construct a new one (LLM).
	StoryWakingUp string
	// StoryIngredientsPicking indicates that the ingredients story is currently happening.
	StoryIngredientsPicking string
	StoryRecipePicking      string
	StoryCookingStarted     string
	StoryMealReady          string
	StoryMemoryWipe         string
	StoryStartAgain         string

	// Check the status of all the stories.
	CheckStories string
	// At least one of the stories has changed its status (active / inactive).
	StoryChanged string

	RestoreCharacter string
	GenCharacter     string
	CharacterReady   string

	RestoreJokes string
	GenJokes     string
	JokesReady   string

	RestoreResources string
	GenResources     string
	ResourcesReady   string

	GenSteps string
	// StepsReady implies the steps have been translated into actionable memory.
	StepsReady string

	GenStepComments   string
	StepCommentsReady string

	// The LLM is given possible moves and checks if the user wants to make any. Orienting usually runs in parallel with other prompts. After de-activation, it leaves results in handler struct `h.oriented`.
	Orienting string
	// OrientingMove performs a move decided upon by Orienting.
	OrientingMove string

	// inherit from LLM Agent
	*llm.LLMAgentStatesDef
}

CookStatesDef contains all the states of the Cook state machine.

type Ingredient

type Ingredient struct {
	Name   string
	Amount int
	Unit   string
}

type ParamsCookingStarted

type ParamsCookingStarted struct {
	Recipe         Recipe
	ExtractedSteps []string
}

type ParamsGenCharacter

type ParamsGenCharacter struct {
	CharacterProfession string
	CharacterYear       int
}

type ParamsGenJokes

type ParamsGenJokes struct {
	// The number of jokes to generate.
	Amount int
}

type ParamsGenResources

type ParamsGenResources struct {
	Phrases map[string]string
}

type ParamsGenStepComments

type ParamsGenStepComments struct {
	Steps  []string
	Recipe Recipe
}

type ParamsGenSteps

type ParamsGenSteps struct {
	Recipe Recipe
}

type ParamsIngredientsPicking

type ParamsIngredientsPicking struct {
	// The minimum number of ingredients needed.
	MinIngredients int
	// Text to extract ingredients from.
	Prompt string
	// List of ingredients extracted from prompts till now.
	Ingredients []Ingredient
}

type ParamsOrienting

type ParamsOrienting struct {
	Prompt string
	// List of possible cooking choices to take.
	MovesCooking []string
	// List of possible stories to switch to and their descriptions.
	MovesStories map[string]string
}

type ParamsRecipePicking

type ParamsRecipePicking struct {
	// List of available ingredients.
	Ingredients []Ingredient
	// The number of recipes needed.
	Amount int
}

type PromptCookingStarted

type PromptCookingStarted = secai.Prompt[ParamsCookingStarted, ResultCookingStarted]

func NewPromptCookingStarted

func NewPromptCookingStarted(agent secai.AgentAPI) *PromptCookingStarted

type PromptGenCharacter

type PromptGenCharacter = secai.Prompt[ParamsGenCharacter, ResultGenCharacter]

func NewPromptGenCharacter

func NewPromptGenCharacter(agent secai.AgentAPI) *PromptGenCharacter

type PromptGenJokes

type PromptGenJokes = secai.Prompt[ParamsGenJokes, ResultGenJokes]

func NewPromptGenJokes

func NewPromptGenJokes(agent secai.AgentAPI) *PromptGenJokes

type PromptGenResources

type PromptGenResources = secai.Prompt[ParamsGenResources, ResultGenResources]

func NewPromptGenResources

func NewPromptGenResources(agent secai.AgentAPI) *PromptGenResources

type PromptGenStepComments

type PromptGenStepComments = secai.Prompt[ParamsGenStepComments, ResultGenStepComments]

func NewPromptGenStepComments

func NewPromptGenStepComments(agent secai.AgentAPI) *PromptGenStepComments

type PromptGenSteps

type PromptGenSteps = secai.Prompt[ParamsGenSteps, ResultGenSteps]

func NewPromptGenSteps

func NewPromptGenSteps(agent secai.AgentAPI) *PromptGenSteps

type PromptOrienting

type PromptOrienting = secai.Prompt[ParamsOrienting, ResultOrienting]

func NewPromptOrienting

func NewPromptOrienting(agent secai.AgentAPI) *PromptOrienting

type PromptRecipePicking

type PromptRecipePicking = secai.Prompt[ParamsRecipePicking, ResultRecipePicking]

func NewPromptRecipePicking

func NewPromptRecipePicking(agent secai.AgentAPI) *PromptRecipePicking

type Recipe

type Recipe struct {
	Name  string
	Desc  string
	Steps string
}

type ResultCookingStarted

type ResultCookingStarted struct {
	// Max 2 sentences, min 3 words.
	Answer string
}

type ResultGenCharacter

type ResultGenCharacter struct {
	// 3 sentences describing the character's personality and background.
	Description string
	Profession  string
	Year        int
	Name        string
}

type ResultGenJokes

type ResultGenJokes struct {
	// List of jokes, max 2 sentences each.
	Jokes []string
	IDs   []int64
}

type ResultGenResources

type ResultGenResources struct {
	Phrases map[string][]string
}

type ResultGenStepComments

type ResultGenStepComments struct {
	// Comments for each step.
	Comments []string
}

type ResultGenSteps

type ResultGenSteps struct {
	Schema am.Schema
}

type ResultIngredientsPicking

type ResultIngredientsPicking struct {
	Ingredients []Ingredient
	// A message to be shown to the user if the results are not valid.
	RedoMsg string
}

type ResultOrienting

type ResultOrienting struct {
	// Users choice
	Move string
	// TODO debug
	Reasoning string
	// Certainty is the probability that the next move is correct.
	Certainty float64
}

TODO add Removing

func (ResultOrienting) String

func (r ResultOrienting) String() string

type ResultRecipePicking

type ResultRecipePicking struct {
	// List of proposed recipes
	Recipes []Recipe
	// Extra recipe with unavailable ingredients.
	ExtraRecipe Recipe
	// Message to the user, summarizing the recipes. Max 3 sentences.
	Summary string
}

type S

type S = am.S

S is a type alias for a list of state names.

type State

type State = am.State

State is a type alias for a state definition. See am.State.

type StepsStatesDef

type StepsStatesDef struct {
}

type Story

type Story struct {
	shared.Story[Story]

	Cook   shared.StoryActor
	Memory shared.StoryActor
}

Story is the basis for all stories.

func (*Story) Clone

func (s *Story) Clone() *Story

Clone returns a copy of the story.

Jump to

Keyboard shortcuts

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