Documentation
¶
Index ¶
- Constants
- Variables
- func BinaryPath(cfg *Config) string
- func ConfigDbgAddrs(cfg ConfigDebug) (dbgAddr, httpAddr, sshAddr string, err error)
- func ConfigLogPath(cfg ConfigAgent) string
- func ConfigWebDBAddrs(cfg ConfigWeb) (base, agent, mach string)
- func ConfigWebLogAddr(cfg ConfigWeb) string
- func GetSQLiteSchema(db *sql.DB) (string, error)
- func LogArgs(args am.A) map[string]string
- func MachTelemetry(mach *am.Machine, logArgs am.LogArgsMapperFn)
- func Map[A, B any](vals []A, f func(A) B) []B
- func NumRef(text string) int
- func OpenURL(url string) error
- func OptArgs(args []am.A) am.A
- func P(txt string, args ...any)
- func ParseRpc(args am.A) am.A
- func PascalCase(in string) string
- func Pass(args *A) am.A
- func PassRPC(args *A) am.A
- func RemoveStyling(str string) string
- func RevertPascalCase(in string) string
- func Sj(parts ...string) string
- func Sl(txt string, args ...any) string
- func SlicesWithout[S ~[]E, E comparable](coll S, el E) S
- func Sp(txt string, args ...any) string
- type A
- type ARPC
- type Action
- type ActionInfo
- type AgentAPI
- type AgentBaseAPI
- type AgentInit
- type AgentQueries
- type AgentStore
- type Config
- type ConfigAI
- type ConfigAIGemini
- type ConfigAIOpenAI
- type ConfigAgent
- type ConfigAgentHistory
- type ConfigAgentLog
- type ConfigDebug
- type ConfigSearXNG
- type ConfigTUI
- type ConfigTools
- type ConfigWeb
- type From
- type GeminiClient
- type Msg
- type OfferRef
- type OpenAIClient
- type Story
- type StoryActionsByIdx
- type StoryActor
- type StoryInfo
Constants ¶
const ( // EnvConfig config location EnvConfig = "SECAI_CONFIG" EnvNoDotEnv = "SECAI_NO_DOTENV" )
const APrefix = "secai"
Variables ¶
var ( FromAssistant = From{"assistant"} FromSystem = From{"system"} FromUser = From{"user"} FromNarrator = From{"narrator"} FromEnum = enum.New(FromAssistant, FromSystem, FromUser) )
Functions ¶
func ConfigDbgAddrs ¶ added in v0.5.0
func ConfigDbgAddrs(cfg ConfigDebug) (dbgAddr, httpAddr, sshAddr string, err error)
TODO config method
func ConfigWebDBAddrs ¶ added in v0.5.0
TODO config method
func ConfigWebLogAddr ¶ added in v0.5.0
TODO config method
func GetSQLiteSchema ¶ added in v0.5.0
TODO format "github.com/maxrichie5/go-sqlfmt/sqlfmt" config := sqlfmt.NewDefaultConfig() formatted := sqlfmt.Format(rawSQL, config)
func MachTelemetry ¶
func MachTelemetry(mach *am.Machine, logArgs am.LogArgsMapperFn)
func Map ¶
func Map[A, B any](vals []A, f func(A) B) []B
Map maps vals through f and returns a list of returned values from f.
func NumRef ¶ added in v0.2.0
NumRef returns a number reference from the passed text, or -1 if none found.
func OpenURL ¶ added in v0.5.0
OpenURL opens the specified URL in the default browser of the user. https://gist.github.com/sevkin/9798d67b2cb9d07cb05f89f14ba682f8
func P ¶
P formats and prints the given string after de-denting and trimming it, and returns the number of bytes written and any error.
func PascalCase ¶ added in v0.2.0
PascalCase converts the input string to pascal case, matching the naming convention of state names.
func RemoveStyling ¶ added in v0.2.0
func RevertPascalCase ¶ added in v0.2.0
func SlicesWithout ¶ added in v0.2.0
func SlicesWithout[S ~[]E, E comparable](coll S, el E) S
Types ¶
type A ¶ added in v0.2.0
type A struct {
// ID is a general string ID param.
ID string `log:"id"`
// Addr is a network address.
Addr string `log:"addr"`
// Timeout is a generic timeout.
Timeout time.Duration `log:"timeout"`
// Prompt is a prompt to be sent to LLM.
Prompt string `log:"prompt"`
// IntByTimeout means the interruption was caused by timeout.
IntByTimeout bool `log:"int_by_timeout"`
// Msg is a single message with an author and text.
Msg *Msg `log:"msg"`
// Perform additional checks via LLM
CheckLLM bool `log:"check_llm"`
// List of choices
Choices []string
// Actions are a list of buttons to be displayed in the UI.
Actions []ActionInfo `log:"actions"`
Stories []StoryInfo `log:"stories"`
StatesList []string `log:"states_list"`
// ActivateList is a list of booleans for StatesList, indicating an active state at the given index.
ActivateList []bool `log:"activate_list"`
ConfigAI *ConfigAI
ClockDiff [][]int
// Result is a buffered channel to be closed by the receiver
ResultCh chan<- am.Result
// DBQuery is a function that executes a query on the database.
DBQuery func(ctx context.Context) error
// RetStr returns dereferenced user prompts based on the list of offer.
RetOfferRef chan<- *OfferRef
SSHServer *ssh.Server
SSHSess ssh.Session
// Done is a buffered channel to be closed by the receiver
Done chan<- struct{}
}
A is a struct for node arguments. It's a typesafe alternative to am.A.
type ARPC ¶ added in v0.5.0
type ARPC struct {
// ID is a general string ID param.
ID string `log:"id"`
// Addr is a network address.
Addr string `log:"addr"`
// Timeout is a generic timeout.
Timeout time.Duration `log:"timeout"`
// Prompt is a prompt to be sent to LLM.
Prompt string `log:"prompt"`
// IntByTimeout means the interruption was caused by timeout.
IntByTimeout bool `log:"int_by_timeout"`
// Msg is a single message with an author and text.
Msg *Msg `log:"msg"`
// Perform additional checks via LLM
CheckLLM bool `log:"check_llm"`
// List of choices
Choices []string
// Actions are a list of buttons to be displayed in the UI.
Actions []ActionInfo `log:"actions"`
Stories []StoryInfo `log:"stories"`
StatesList []string `log:"states_list"`
ActivateList []bool `log:"activate_list"`
Result am.Result
ConfigAI *ConfigAI
ClockDiff [][]int
}
ARPC is a subset of am.A that can be passed over RPC.
type Action ¶ added in v0.5.0
type Action struct {
// random ID
ID string
// Current value.
Value func() int
// Maximum value.
ValueEnd func() int
Label string
Desc string
Action func()
StateAdd string
StateRemove string
VisibleAgent amhelp.Cond
VisibleMem amhelp.Cond
IsDisabled func() bool
LabelEnd string
Pos int
PosInferred bool
}
type ActionInfo ¶ added in v0.5.0
type ActionInfo struct {
// random ID
ID string
// Current value.
Value int
// Maximum value.
ValueEnd int
Label string
Desc string
Action bool
StateAdd string
StateRemove string
VisibleAgent bool
VisibleMem bool
IsDisabled bool
LabelEnd string
Pos int
PosInferred bool
}
ActionInfo is a static model for Action.
type AgentAPI ¶ added in v0.5.0
type AgentAPI interface {
AgentBaseAPI
Msgs() []*Msg
Splash() string
MachSchema() (am.Schema, am.S)
Actions() []ActionInfo
Stories() []StoryInfo
Story(state string) *Story
DBAgent() *sql.DB
MachMem() *am.Machine
// Moves return a list of moves and their descriptions for orienting.
OrientingMoves() map[string]string
// HistoryStates returns a list of states to track in the history.
HistoryStates() am.S
}
AgentAPI is the top-level API to be implemented by the final agent.
type AgentBaseAPI ¶ added in v0.5.0
type AgentBaseAPI interface {
// AgentImpl returns the top-level agent implementation.
AgentImpl() AgentAPI
// Output outputs text to the user.
Output(txt string, from From) am.Result
Mach() *am.Machine
DBG() *debugger.Debugger
Hist() (history.MemoryApi, error)
ConfigBase() *Config
OpenAI() []*OpenAIClient
Gemini() []*GeminiClient
Start() am.Result
Stop(disposeCtx context.Context) am.Result
Log(msg string, args ...any)
LogErr(msg string, err error, args ...any)
Logger() *slog.Logger
Store() *AgentStore
QueriesBase() *sqlc.Queries
DBBase() *sql.DB
DBHistory() *sql.DB
}
AgentBaseAPI is the base agent API implemented by the framework.
type AgentInit ¶ added in v0.5.0
type AgentInit interface {
Init(
agentImpl AgentAPI, cfg *Config, logArgs am.LogArgsMapperFn, groups any, states am.States, args any,
) error
}
AgentInit is an init func for embeddable agent structs (non-top level ones).
type AgentQueries ¶ added in v0.5.0
type AgentQueries[TQueries any] interface { Queries() *TQueries }
AgentQueries is a generic SQL API.
type AgentStore ¶ added in v0.5.0
type Config ¶ added in v0.4.0
type Config struct {
// File is the path to the loaded config file.
File string `kdl:"-"`
AI ConfigAI
Agent ConfigAgent
Web ConfigWeb
TUI ConfigTUI
Tools ConfigTools
Debug ConfigDebug
}
func ConfigDefault ¶ added in v0.4.0
func ConfigDefault() Config
type ConfigAI ¶ added in v0.4.0
type ConfigAI struct {
OpenAI []ConfigAIOpenAI `kdl:"OpenAI,multiple"`
Gemini []ConfigAIGemini `kdl:"Gemini,multiple"`
// Max LLM requests per session.
ReqLimit int
}
type ConfigAIGemini ¶ added in v0.4.0
func ConfigDefaultGemini ¶ added in v0.4.0
func ConfigDefaultGemini() ConfigAIGemini
type ConfigAIOpenAI ¶ added in v0.4.0
type ConfigAIOpenAI struct {
Key string
Disabled bool
URL string
Model string
Tags []string
Retries int `kdl:",omitempty"`
}
func ConfigDefaultOpenAI ¶ added in v0.4.0
func ConfigDefaultOpenAI() ConfigAIOpenAI
type ConfigAgent ¶ added in v0.4.0
type ConfigAgent struct {
// bot ID
ID string
Label string
// // dir for tmp files, defaults to CWD
Dir string
Intro string
IntroDash string
Log ConfigAgentLog
History ConfigAgentHistory
}
type ConfigAgentHistory ¶ added in v0.4.0
type ConfigAgentLog ¶ added in v0.4.0
type ConfigDebug ¶ added in v0.4.0
type ConfigDebug struct {
// Display extra info about these stories in the machine log
Story []string
// Run the mock scenario
Mock bool
// Start pprof on addr
ProfilerAddr string
// Enable misc debugging modes (SQL history, am-relay, browser RPC)
// TODO extract SQL
Verbose bool
// Create value files for inspection
ValFiles bool
// Enable REPL for agent, mem, and tools
REPL bool
// Connect and send dbg info to am-dbg
DBGAddr string
// Start an embedded debugger on localhost:{DBGEmbed}
DBGEmbed bool
// Expose the embedded debugger on http://localhost:{DBGEmbedWeb}
DBGEmbedWeb int
// Start a web REPL on http://localhost:{REPLWeb}
REPLWeb int
}
type ConfigSearXNG ¶ added in v0.4.0
type ConfigTools ¶ added in v0.4.0
type ConfigTools struct {
SearXNG ConfigSearXNG
}
type ConfigWeb ¶ added in v0.5.0
type ConfigWeb struct {
// Base address for HTTP services:
// - main HTTP server
// - +1 WebSocket addr of the agent's RPC server (dashboard)
// - +2 WebSocket addr of the agent's RPC server (agent UI)
// - +3 TCP addr of the dashboard REPL server (WS tunnel)
// - +4 TCP addr of the agent UI REPL server (WS tunnel)
Addr string
// Start a DBPort web UI on http://localhost:{DBPort[0-2]}
DBPort int
// Start a log web UI on http://localhost:{LogPort}
LogPort int
}
func (*ConfigWeb) AgentWSAddrDash ¶ added in v0.5.0
func (*ConfigWeb) AgentWSAddrRemoteUI ¶ added in v0.5.0
TODO remove when dialing via relay lands
func (*ConfigWeb) REPLAddrAgentUI ¶ added in v0.5.0
func (*ConfigWeb) REPLAddrDash ¶ added in v0.5.0
type GeminiClient ¶ added in v0.5.0
type GeminiClient struct {
Cfg *ConfigAIGemini
C *instructor.InstructorGoogle
}
type OpenAIClient ¶ added in v0.5.0
type OpenAIClient struct {
Cfg *ConfigAIOpenAI
C *instructor.InstructorOpenAI
}
type Story ¶ added in v0.2.0
type Story struct {
StoryInfo
Agent StoryActor
Memory StoryActor
// If is an optional function used to confirm that this story can activate. It has access to the whole story struct,
// so all the involved state machines and their historical snapshots (relative to activation and deactivation of
// this story).
CanActivate func(instance *Story) bool
Actions []Action
}
Story is the basis for all stories.
type StoryActionsByIdx ¶ added in v0.4.0
type StoryActionsByIdx []Action
func (StoryActionsByIdx) Len ¶ added in v0.4.0
func (s StoryActionsByIdx) Len() int
func (StoryActionsByIdx) Less ¶ added in v0.4.0
func (s StoryActionsByIdx) Less(i, j int) bool
func (StoryActionsByIdx) Swap ¶ added in v0.4.0
func (s StoryActionsByIdx) Swap(i, j int)
type StoryActor ¶ added in v0.2.0
type StoryActor struct {
Mach *am.Machine
// actor's time when the story activated
TimeActivated am.Time
TimeDeactivated am.Time
// When these conditions are met, the story will activate itself.
Trigger amhelp.Cond
}
StoryActor is a binding between a Story and an actor (state machine).
type StoryInfo ¶ added in v0.2.0
type StoryInfo struct {
// Name of the bound state (eg StoryFoo).
State string
// Tick is the current tick of the bound state.
Tick uint64
// Epoch is the sum of all previous memories, before a replacement.
Epoch uint64
// Title of this story.
Title string
// Description of this story.
Desc string
// The story was last deactivated at this human time.
DeactivatedAt time.Time
// The story was last active for this many ticks of the AgentLLM machine.
LastActiveTicks uint64
}
StoryInfo is a static model for Story.