cook

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Jul 15, 2025 License: MIT Imports: 27 Imported by: 0

Documentation

Overview

Package cook is a recipe-choosing and cooking agent with a gen-ai character.

Index

Constants

View Source
const APrefix = "cook"

Variables

View Source
var PassAA = shared.Pass
View Source
var SAdd = am.SAdd
View Source
var WelcomeMessage = "Please wait while loading..."

Functions

func LogArgs

func LogArgs(args am.A) map[string]string

LogArgs is an args logger for A and secai.A.

func Pass

func Pass(args *A) am.A

Pass prepares am.A from A to be passed to further mutations (encoder).

func PassRpc

func PassRpc(args *A) am.A

PassRpc is a network-safe version of Pass. Use it when mutating aRPC workers.

Types

type A

type A struct {
	// base args of the framework
	*shared.A

	// agent's args
	Move *schema.ResultOrienting `log:"move"`
}

A is a struct for node arguments. It's a typesafe alternative to am.A.

func ParseArgs

func ParseArgs(args am.A) *A

ParseArgs extracts A from am.Event.ArgsAPrefix (decoder).

type AA

type AA = shared.A

type AARpc

type AARpc = shared.ARpc

type ARpc

type ARpc struct {
	// base args of the framework
	*shared.A

	// agent's args
	Move *schema.ResultOrienting `log:"move"`
}

ARpc is a subset of am.A, that can be passed over RPC (eg no channels, instances, etc)

type Agent

type Agent struct {
	// inherit from LLM Agent
	*llmagent.Agent

	Config      Config
	StoriesList []string
	Stories     map[string]*StoryUI
	TUIs        []shared.UI
	Msgs        []*shared.Msg
	MemCutoff   atomic.Uint64
	// contains filtered or unexported fields
}

func New

func New(
	ctx context.Context, id string, states am.S, machSchema am.Schema,
) *Agent

New returns a custom instance of Agent.

func NewCook

func NewCook(ctx context.Context, config Config) (*Agent, error)

NewCook returns a preconfigured instance of Agent.

func (*Agent) AnyState

func (a *Agent) AnyState(e *am.Event)

func (*Agent) CharacterReadyEnd

func (a *Agent) CharacterReadyEnd(e *am.Event)

func (*Agent) CharacterReadyEnter

func (a *Agent) CharacterReadyEnter(e *am.Event) bool

func (*Agent) CharacterReadyState

func (a *Agent) CharacterReadyState(e *am.Event)

func (*Agent) CheckStoriesState

func (a *Agent) CheckStoriesState(e *am.Event)

func (*Agent) DBStartingState

func (a *Agent) DBStartingState(e *am.Event)

func (*Agent) DisposedState

func (a *Agent) DisposedState(e *am.Event)

func (*Agent) ExceptionState

func (a *Agent) ExceptionState(e *am.Event)

func (*Agent) GenCharacterEnd

func (a *Agent) GenCharacterEnd(e *am.Event)

func (*Agent) GenCharacterState

func (a *Agent) GenCharacterState(e *am.Event)

func (*Agent) GenJokesEnd

func (a *Agent) GenJokesEnd(e *am.Event)

func (*Agent) GenJokesEnter

func (a *Agent) GenJokesEnter(e *am.Event) bool

func (*Agent) GenJokesState

func (a *Agent) GenJokesState(e *am.Event)

func (*Agent) GenResourcesEnd

func (a *Agent) GenResourcesEnd(e *am.Event)

func (*Agent) GenResourcesEnter

func (a *Agent) GenResourcesEnter(e *am.Event) bool

func (*Agent) GenResourcesState

func (a *Agent) GenResourcesState(e *am.Event)

func (*Agent) GenStepCommentsEnd

func (a *Agent) GenStepCommentsEnd(e *am.Event)

func (*Agent) GenStepCommentsState

func (a *Agent) GenStepCommentsState(e *am.Event)

func (*Agent) GenStepsEnd

func (a *Agent) GenStepsEnd(e *am.Event)

func (*Agent) GenStepsState

func (a *Agent) GenStepsState(e *am.Event)

func (*Agent) HeartbeatState

func (a *Agent) HeartbeatState(e *am.Event)

func (*Agent) IngredientsReadyEnd

func (a *Agent) IngredientsReadyEnd(e *am.Event)

func (*Agent) Init

func (a *Agent) Init(agent secai.AgentAPI) error

func (*Agent) InputPendingState

func (a *Agent) InputPendingState(e *am.Event)

InputPendingState is a test mocking handler.

func (*Agent) InterruptedState

func (a *Agent) InterruptedState(e *am.Event)

func (*Agent) JokesReadyEnd

func (a *Agent) JokesReadyEnd(e *am.Event)

func (*Agent) LoopEnter

func (a *Agent) LoopEnter(e *am.Event) bool

func (*Agent) LoopState

func (a *Agent) LoopState(e *am.Event)

func (*Agent) MockEnter

func (a *Agent) MockEnter(e *am.Event) bool

func (*Agent) MockState

func (a *Agent) MockState(e *am.Event)

func (*Agent) MsgState

func (a *Agent) MsgState(e *am.Event)

func (*Agent) OrientingMoveEnter

func (a *Agent) OrientingMoveEnter(e *am.Event) bool

func (*Agent) OrientingMoveState

func (a *Agent) OrientingMoveState(e *am.Event)

func (*Agent) OrientingState

func (a *Agent) OrientingState(e *am.Event)

func (*Agent) OutputPhrase

func (a *Agent) OutputPhrase(key string, args ...any) error

OutputPhrase is sugar for Phrase followed by Output FromAssistant.

func (*Agent) Phrase

func (a *Agent) Phrase(key string, args ...any) string

Phrase returns a random phrase from resources under [key], or an empty string. TODO move to base agent

func (*Agent) PromptEnter

func (a *Agent) PromptEnter(e *am.Event) bool

func (*Agent) PromptState

func (a *Agent) PromptState(e *am.Event)

func (*Agent) Queries

func (a *Agent) Queries() *db.Queries

func (*Agent) ReadyEnter

func (a *Agent) ReadyEnter(e *am.Event) bool

func (*Agent) ReadyState

func (a *Agent) ReadyState(e *am.Event)

ReadyState is a test mocking handler.

func (*Agent) ResourcesReadyEnd

func (a *Agent) ResourcesReadyEnd(e *am.Event)

func (*Agent) RestoreCharacterState

func (a *Agent) RestoreCharacterState(e *am.Event)

func (*Agent) RestoreJokesState

func (a *Agent) RestoreJokesState(e *am.Event)

func (*Agent) RestoreResourcesState

func (a *Agent) RestoreResourcesState(e *am.Event)

func (*Agent) StartState

func (a *Agent) StartState(e *am.Event)

func (*Agent) StepCommentsReadyEnd

func (a *Agent) StepCommentsReadyEnd(e *am.Event)

func (*Agent) StepCompletedState

func (a *Agent) StepCompletedState(e *am.Event)

func (*Agent) StepsReadyEnd

func (a *Agent) StepsReadyEnd(e *am.Event)

func (*Agent) StepsReadyState

func (a *Agent) StepsReadyState(e *am.Event)

func (*Agent) StoryActivate

func (a *Agent) StoryActivate(e *am.Event, story string) am.Result

TODO move to base agent

func (*Agent) StoryChangedState

func (a *Agent) StoryChangedState(e *am.Event)

func (*Agent) StoryCookingStartedEnd

func (a *Agent) StoryCookingStartedEnd(e *am.Event)

func (*Agent) StoryCookingStartedEnter

func (a *Agent) StoryCookingStartedEnter(e *am.Event) bool

func (*Agent) StoryCookingStartedState

func (a *Agent) StoryCookingStartedState(e *am.Event)

func (*Agent) StoryDeactivate

func (a *Agent) StoryDeactivate(e *am.Event, story string) am.Result

TODO move to base agent

func (*Agent) StoryIngredientsPickingEnd

func (a *Agent) StoryIngredientsPickingEnd(e *am.Event)

func (*Agent) StoryIngredientsPickingState

func (a *Agent) StoryIngredientsPickingState(e *am.Event)

func (*Agent) StoryJokeEnter

func (a *Agent) StoryJokeEnter(e *am.Event) bool

func (*Agent) StoryJokeState

func (a *Agent) StoryJokeState(e *am.Event)

func (*Agent) StoryMealReadyState

func (a *Agent) StoryMealReadyState(e *am.Event)

func (*Agent) StoryMemoryWipeState

func (a *Agent) StoryMemoryWipeState(e *am.Event)

func (*Agent) StoryRecipePickingEnd

func (a *Agent) StoryRecipePickingEnd(e *am.Event)

func (*Agent) StoryRecipePickingEnter

func (a *Agent) StoryRecipePickingEnter(e *am.Event) bool

func (*Agent) StoryRecipePickingState

func (a *Agent) StoryRecipePickingState(e *am.Event)

func (*Agent) StoryStartAgainState

func (a *Agent) StoryStartAgainState(e *am.Event)

func (*Agent) StoryWakingUpEnd

func (a *Agent) StoryWakingUpEnd(e *am.Event)

func (*Agent) StoryWakingUpState

func (a *Agent) StoryWakingUpState(e *am.Event)

func (*Agent) UIModeEnd

func (a *Agent) UIModeEnd(e *am.Event)

func (*Agent) UIModeState

func (a *Agent) UIModeState(e *am.Event)

func (*Agent) UIReadyEnter

func (a *Agent) UIReadyEnter(e *am.Event) bool

func (*Agent) UISessConnState

func (a *Agent) UISessConnState(e *am.Event)

func (*Agent) UISessDisconnState

func (a *Agent) UISessDisconnState(e *am.Event)

func (*Agent) UISrvListeningState

func (a *Agent) UISrvListeningState(e *am.Event)

type Config

type Config struct {
	MinIngredients int           `arg:"env:COOK_MIN_INGREDIENTS" help:"Number of ingredients to collect." default:"3"`
	GenJokesAmount int           `arg:"env:COOK_GEN_JOKES_AMOUNT" help:"Number of jokes to generate." default:"3"`
	SessionTimeout time.Duration `arg:"env:COOK_SESSION_TIMEOUT" help:"Session timeout." default:"1h"`
	// Number of recipes to generate.
	GenRecipes   int `arg:"env:COOK_GEN_RECIPES" help:"Number of recipes to generate." default:"3"`
	MinPromptLen int `arg:"env:COOK_MIN_PROMPT_LEN" help:"Minimum prompt length." default:"2"`
	// Lower number = higher frequency of step comments. 2=50%, 3=33%.
	StepCommentFreq int           `arg:"env:COOK_STEP_COMMENT_FREQ" help:"Step comment frequency." default:"2"`
	HeartbeatFreq   time.Duration `arg:"env:COOK_HEARTBEAT_FREQ" help:"Heartbeat frequency." default:"1h"`
	// Certainty above which the orienting move should be accepted.
	OrientingMoveThreshold float64 `arg:"env:COOK_ORIENTING_MOVE_THRESHOLD" help:"Certainty above which the orienting move should be accepted." default:"0.5"`

	OpenAIAPIKey   string `arg:"env:OPENAI_API_KEY" help:"OpenAI API key."`
	DeepseekAPIKey string `arg:"env:DEEPSEEK_API_KEY" help:"DeepSeek API key."`
	TUIPort        int    `arg:"env:SECAI_TUI_PORT" help:"SSH port for the TUI." default:"7854"`
	TUIHost        string `arg:"env:SECAI_TUI_HOST" help:"SSH host for the TUI." default:"localhost"`
	Mock           bool   `arg:"env:SECAI_MOCK" help:"Enable scenario mocking."`
	ReqLimit       int    `arg:"env:SECAI_REQ_LIMIT" help:"Max LLM requests per session." default:"1000"`
}

type Mock

type Mock struct {
	// Global mock switch, also requires AM_MOCK=1.
	Active bool

	FlowPromptIngredients string
	FlowPromptRecipe      string
	FlowPromptCooking     string

	Recipe                    string
	GenStepsRes               string
	GenStepCommentsRes        string
	StoryCookingStartedInput  string
	StoryCookingStartedInput3 string
}

type S

type S = am.S

type StepsByReqFinal

type StepsByReqFinal struct {
	Name   string
	Schema am.Schema
}

type StepsByReqFinalList

type StepsByReqFinalList []StepsByReqFinal

func (StepsByReqFinalList) Len

func (s StepsByReqFinalList) Len() int

func (StepsByReqFinalList) Less

func (s StepsByReqFinalList) Less(n1, n2 int) bool

func (StepsByReqFinalList) Swap

func (s StepsByReqFinalList) Swap(i, j int)

type StoryUI

type StoryUI struct {
	*schema.Story

	Buttons []shared.StoryButton
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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