Documentation
¶
Index ¶
- Constants
- Variables
- func AddErrAI(event *am.Event, mach *am.Machine, err error, args ...am.A) am.Result
- func AddErrDB(event *am.Event, mach *am.Machine, err error, args ...am.A) am.Result
- func BinaryPath(absolute bool) string
- func GenerateAtomFeed(items []FeedItem, title string) string
- func GetSQLiteSchema(db *sql.DB) (string, error)
- func GetVersion() string
- func IsStory(state string) bool
- func KdlFormat(input []byte, cfg any) string
- func MachTelemetry(mach *am.Machine, logArgs am.LogArgsMapperFn)
- func Map[A, B any](vals []A, f func(A) B) []B
- func NullString(s string) sql.NullString
- func NumRef(text string) int
- func OpenURL(url string) error
- func OptArgs(args []am.A) am.A
- func P(txt string, args ...any)
- func PascalCase(in string) string
- 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
- func TextCut(txt string, maxLen int) string
- type ABaseDBSaving
- type ACheckingMenuRefs
- type AConfigUpdate
- type AIClient
- type AInterrupted
- type APrompt
- type ARequestingAI
- type ARequestingTool
- type ASSHConn
- type ASSHDisconn
- type ASSHReady
- type AStoryAction
- type AStoryChanged
- type AUIMsg
- type AUIRenderClock
- type AUIRenderStories
- type Action
- type ActionInfo
- type AgentAPI
- type AgentBaseAPI
- type AgentInit
- type AgentQueries
- type AgentStore
- type Args
- type Config
- type ConfigAI
- type ConfigAICommon
- type ConfigAIGemini
- type ConfigAIOpenAI
- type ConfigAgent
- type ConfigAgentHistory
- type ConfigAgentLog
- type ConfigDebug
- type ConfigSearXNG
- type ConfigTUI
- type ConfigTools
- type ConfigWeb
- func (c *ConfigWeb) AddrAgent() string
- func (c *ConfigWeb) AddrListen() string
- func (c *ConfigWeb) AgentURL() string
- func (c *ConfigWeb) ConfigWebLogAddr() string
- func (c *ConfigWeb) DBAddrs() (base, agent, mach string)
- func (c *ConfigWeb) DBAddrsListen() (base, agent, mach string)
- func (c *ConfigWeb) DashURL() string
- func (c *ConfigWeb) REPLAddrAgentUI() string
- func (c *ConfigWeb) REPLAddrDash() string
- type Document
- type FeedItem
- type From
- type GeminiClient
- type HasPromptUsage
- type MCPCallToolParams
- type MCPCallToolRequest
- type Msg
- type OfferRef
- type OpenAIClient
- type Prompt
- func (p *Prompt[P, R]) AddDoc(doc *Document)
- func (p *Prompt[P, R]) AddGodoc(godoc map[string]string) *Prompt[P, R]
- func (p *Prompt[P, R]) AddTool(tool ToolApi)
- func (p *Prompt[P, R]) Concurrency() int
- func (p *Prompt[P, R]) Conversation() (*core.Conversation, string)
- func (p *Prompt[P, R]) Exec(e *am.Event, params P, cachedParams []*P, opts ...PromptOpts) (res *R, usage *PromptUsage, err error)
- func (p *Prompt[P, R]) ExecMulti(e *am.Event, times int, params P, cachedParams []*P, opts ...PromptOpts) ([]*R, []*PromptUsage, error)
- func (p *Prompt[P, R]) GenSysPrompt() string
- func (p *Prompt[P, R]) HistClean()
- func (p *Prompt[P, R]) QueryProviders(opts ...PromptOpts) []*AIClient
- func (p *Prompt[P, R]) SetGodoc(godoc map[string]string) *Prompt[P, R]
- type PromptApi
- type PromptConfig
- type PromptMsg
- type PromptOpts
- type PromptRaw
- func (p *PromptRaw) AddDoc(doc *Document)
- func (p *PromptRaw) AddTool(tool ToolApi)
- func (p *PromptRaw) Concurrency() int
- func (p *PromptRaw) Conversation() (*core.Conversation, string)
- func (p *PromptRaw) Exec(e *am.Event, params string, opts ...PromptOpts) (res []byte, usage *PromptUsage, err error)
- func (p *PromptRaw) ExecInto(e *am.Event, params string, result any, opts ...PromptOpts) (*PromptUsage, error)
- func (p *PromptRaw) ExecMulti(e *am.Event, times int, params string) ([][]byte, []*PromptUsage, error)
- func (p *PromptRaw) GenSysPrompt() string
- func (p *PromptRaw) HistClean()
- type PromptRawMsg
- type PromptRawRole
- type PromptSchemaless
- type PromptUsage
- type RawAIClient
- type RawGeminiClient
- type RawOpenAIClient
- type SlogWriter
- type Story
- type StoryActionsByIdx
- type StoryActor
- type StoryInfo
- type ToolApi
- type ValEnc
- type ValFileEnc
Constants ¶
const APrefix = "secai"
const (
EnvNoDotEnv = "SECAI_NO_DOTENV"
)
Variables ¶
var ( FromAssistant = From{"assistant"} FromSystem = From{"system"} FromUser = From{"user"} FromNarrator = From{"narrator"} FromEnum = enum.New(FromAssistant, FromSystem, FromUser) )
var ( ValEncJson = ValEnc{"json"} ValEncYaml = ValEnc{"yaml"} ValEncDump = ValEnc{"dump"} ValEncTxt = ValEnc{"txt"} ValEncEnum = enum.New(ValEncJson, ValEncYaml, ValEncDump, ValEncTxt) ValEncs = ValEncEnum )
var ( ValFileEncJson = ValEncJson ValFileEncYaml = ValEncYaml ValFileEncDump = ValEncDump ValFileEncTxt = ValEncTxt ValFileEncEnum = ValEncEnum ValFileEncs = ValEncs )
var ArgsRPC = []am.ArgsApi{AStoryAction{}, AUIRenderStories{}, AUIMsg{}, APrompt{}, AInterrupted{}, AConfigUpdate{}, AUIRenderClock{}}
var ErrAI = errors.New("AI error")
ErrAI is for states.AgentBaseStatesDef.ErrAI.
var ErrDB = errors.New("DB error")
ErrDB is for states.AgentBaseStatesDef.ErrDB.
var (
ErrHistNil = errors.New("history is nil")
)
var Fmt = message.NewPrinter(language.English)
Functions ¶
func BinaryPath ¶ added in v0.5.0
func GenerateAtomFeed ¶ added in v0.6.0
func GetSQLiteSchema ¶ added in v0.5.0
TODO format "github.com/maxrichie5/go-sqlfmt/sqlfmt" config := sqlfmt.NewDefaultConfig() formatted := sqlfmt.Format(rawSQL, config)
func GetVersion ¶ added in v0.6.0
func GetVersion() string
func KdlFormat ¶ added in v0.6.0
KdlFormat parses a raw KDL string and returns it formatted with proper newlines, inherited indentation, and names resolved from the Config struct.
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 NullString ¶ added in v0.8.0
func NullString(s string) sql.NullString
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 ABaseDBSaving ¶ added in v0.6.0
type ABaseDBSaving struct {
Args
// DBQuery is a function that executes a query on the database.
DBQuery func(ctx context.Context) error
}
func (ABaseDBSaving) ArgsState ¶ added in v0.6.0
func (ABaseDBSaving) ArgsState() string
type ACheckingMenuRefs ¶ added in v0.6.0
type ACheckingMenuRefs struct {
Args
// RetStr returns dereferenced user prompts based on the list of offer.
RetOfferRef chan<- *OfferRef
// Perform additional checks via LLM
CheckLLM bool `log:"check_llm"`
// Prompt is a prompt to be checked.
Prompt string `log:"prompt"`
// List of choices (optional)
Choices []string
}
func (ACheckingMenuRefs) ArgsState ¶ added in v0.6.0
func (ACheckingMenuRefs) ArgsState() string
type AConfigUpdate ¶ added in v0.6.0
func (AConfigUpdate) ArgsState ¶ added in v0.6.0
func (AConfigUpdate) ArgsState() string
type AIClient ¶ added in v0.6.0
type AIClient struct {
OpenAI *OpenAIClient
Gemini *GeminiClient
}
AIClient is the picked AI client from the pool (from either provider).
func (*AIClient) Cfg ¶ added in v0.6.0
func (c *AIClient) Cfg() *ConfigAICommon
type AInterrupted ¶ added in v0.6.0
func (AInterrupted) ArgsState ¶ added in v0.6.0
func (AInterrupted) ArgsState() string
type ARequestingAI ¶ added in v0.8.0
func (ARequestingAI) State ¶ added in v0.8.0
func (ARequestingAI) State() string
type ARequestingTool ¶ added in v0.8.0
type ARequestingTool struct {
Args
Name string `log:"name"`
Source string `log:"source"`
Target string `log:"target"`
}
func (ARequestingTool) State ¶ added in v0.8.0
func (ARequestingTool) State() string
type ASSHConn ¶ added in v0.6.0
type ASSHDisconn ¶ added in v0.6.0
type ASSHDisconn struct {
Args
Addr string `log:"addr"`
// Id of the disconnected TUI.
Id string `log:"id"`
}
func (ASSHDisconn) ArgsState ¶ added in v0.6.0
func (ASSHDisconn) ArgsState() string
type AStoryAction ¶ added in v0.6.0
func (AStoryAction) ArgsState ¶ added in v0.6.0
func (AStoryAction) ArgsState() string
type AStoryChanged ¶ added in v0.6.0
type AStoryChanged struct {
Args
StatesList []string `log:"states_list"`
ActivateList []bool `log:"activate_list"`
}
func (AStoryChanged) ArgsState ¶ added in v0.6.0
func (AStoryChanged) ArgsState() string
type AUIMsg ¶ added in v0.6.0
type AUIRenderClock ¶ added in v0.6.0
func (AUIRenderClock) ArgsState ¶ added in v0.6.0
func (AUIRenderClock) ArgsState() string
type AUIRenderStories ¶ added in v0.6.0
type AUIRenderStories struct {
Args
Actions []ActionInfo `log:"actions"`
Stories []StoryInfo `log:"stories"`
}
func (AUIRenderStories) ArgsState ¶ added in v0.6.0
func (AUIRenderStories) ArgsState() string
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)
SetConfigBase(*Config) error
ConfigBase() *Config
AIs() []*AIClient
Start() am.Result
Stop(disposeCtx context.Context)
Log(msg string, args ...any)
LogTrace(msg string, args ...any)
LogDebug(msg string, args ...any)
LogWarn(msg string, err error, args ...any)
LogErr(msg string, err error, args ...any)
LogCtx(ctx context.Context, txt string, args ...any)
LogCtxDebug(ctx context.Context, txt string, args ...any)
LogCtxTrace(ctx context.Context, txt string, args ...any)
LogCtxWarn(ctx context.Context, txt string, err error, args ...any)
LogCtxErr(ctx context.Context, msg string, err error, args ...any)
LogEv(e *am.Event, txt string, args ...any)
LogEvDebug(e *am.Event, txt string, args ...any)
LogEvTrace(e *am.Event, txt string, args ...any)
LogEvWarn(e *am.Event, txt string, err error, args ...any)
LogEvErr(e *am.Event, 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 []am.ArgsApi,
) 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 Args ¶ added in v0.6.0
func (Args) ArgsPrefix ¶ added in v0.6.0
type Config ¶ added in v0.4.0
type Config struct {
AI ConfigAI
Agent ConfigAgent
Web ConfigWeb
TUI ConfigTUI
Tools ConfigTools
Debug ConfigDebug
// File is the path to the loaded config file.
File string `kdl:"-"`
ProdBuild bool `kdl:"-"`
// ServerMode doesnt autorun the GUI and listens on 0.0.0.0
ServerMode bool `kdl:"-"`
DockerMode bool `kdl:"-"`
// random instance ID
SessionID string `kdl:"-"`
}
func ConfigDefault ¶ added in v0.4.0
func ConfigDefault() Config
ConfigDefault produces a default config with ports in the range 12800-12900.
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 ConfigAICommon ¶ added in v0.6.0
type ConfigAICommon struct {
Model string
Key string
Disabled bool
Name string `kdl:",omitempty"`
// Def: 3
Retries int `kdl:",omitempty"`
Tags []string `kdl:",omitempty"`
Priority int `kdl:",omitempty"`
// For how long blacklist this provider on error (def 1h).
FallbackTimeout time.Duration `kdl:",omitempty"`
// Number of concurrent req for this provider TODO
Concurrency int `kdl:",omitempty"`
URL string `kdl:",omitempty"`
// temporarily disabled (eg offline)
DisabledUntil time.Time `kdl:"-"`
// provider name
API string `kdl:"-"`
// num of times this backend was called without errs
Calls int `kdl:"-"`
}
ConfigAICommon are shared fields across all AI providers.
func (*ConfigAICommon) IsEnabled ¶ added in v0.6.0
func (c *ConfigAICommon) IsEnabled() bool
type ConfigAIGemini ¶ added in v0.4.0
type ConfigAIGemini struct {
ConfigAICommon
// NoEnforceSchema skips `instr.WithMode(instr.ModeJSONSchema)` for local models
NoEnforceSchema bool
}
func ConfigDefaultAIGemini ¶ added in v0.6.0
func ConfigDefaultAIGemini() ConfigAIGemini
type ConfigAIOpenAI ¶ added in v0.4.0
type ConfigAIOpenAI struct {
ConfigAICommon
// NoEnforceSchema skips `instr.WithMode(instr.ModeJSONSchema)` for local models
NoEnforceSchema bool
}
func ConfigDefaultAIOpenAI ¶ added in v0.6.0
func ConfigDefaultAIOpenAI() 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
}
func (*ConfigAgent) DirPath ¶ added in v0.6.0
func (c *ConfigAgent) DirPath() string
DirPath returns an absolute path to the agent's data directory.
func (*ConfigAgent) LogPath ¶ added in v0.6.0
func (c *ConfigAgent) LogPath(absolute bool) string
type ConfigAgentHistory ¶ added in v0.4.0
type ConfigAgentLog ¶ added in v0.4.0
type ConfigAgentLog struct {
// path to the log file
File string
// log prompts as log level debug
Prompts bool
// mark log errs as ErrLog multi state
FwdErrState bool
// mark log warning as WarnLog multi state
FwdWarnState bool
// mach log level 0-5
MachLevel am.LogLevel
// print machine log
MachPrint bool
// agent log level
Level slog.Level
// enable instructor-go logging for AI requests
AI bool
}
type ConfigDebug ¶ added in v0.4.0
type ConfigDebug struct {
Root *Config `kdl:"-" json:"-"`
// 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 (am-relay, browser RPC, TRACE logs)
Verbose bool
// Enable SQL query logging
VerboseSQL 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:{DBGAddr}
DBGEmbed bool
// Expose the embedded debugger on http://localhost:{DBGEmbedWeb}
DBGEmbedWeb int
// Start a web REPL on http://localhost:{REPLWeb}
REPLWeb int
}
func (*ConfigDebug) DbgAddrListen ¶ added in v0.8.0
func (c *ConfigDebug) DbgAddrListen() (dbgAddr string, err error)
func (*ConfigDebug) DbgAddrs ¶ added in v0.6.0
func (c *ConfigDebug) DbgAddrs() (dbgAddr, httpAddr, sshAddr string, err error)
TODO keep in sync with debugger.Params
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 {
Root *Config `kdl:"-" json:"-"`
// 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)
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) AddrListen ¶ added in v0.8.0
func (*ConfigWeb) ConfigWebLogAddr ¶ added in v0.6.0
func (*ConfigWeb) DBAddrsListen ¶ added in v0.8.0
func (*ConfigWeb) REPLAddrAgentUI ¶ added in v0.5.0
func (*ConfigWeb) REPLAddrDash ¶ added in v0.5.0
type Document ¶ added in v0.6.0
type Document struct {
// contains filtered or unexported fields
}
func NewDocument ¶ added in v0.6.0
func (*Document) AddToPrompts ¶ added in v0.6.0
type GeminiClient ¶ added in v0.5.0
type GeminiClient struct {
Cfg *ConfigAIGemini
C *instructor.InstructorGoogle
}
type HasPromptUsage ¶ added in v0.8.0
type HasPromptUsage interface {
GetPromptUsage() *PromptUsage
}
type MCPCallToolParams ¶ added in v0.8.0
type MCPCallToolParams struct {
Name string `json:"name" jsonschema:"description=The name of the target MCP tool"`
Arguments json.RawMessage `json:"arguments" jsonschema:"description=JSON object of arguments matching the tool schema"`
}
MCPCallToolParams represents the inner parameters of a tools/call request
type MCPCallToolRequest ¶ added in v0.8.0
type MCPCallToolRequest struct {
JSONRPC string `json:"jsonrpc" jsonschema:"const=2.0"`
ID int `json:"id" jsonschema:"description=Request identifier"`
Method string `json:"method" jsonschema:"const=tools/call"`
Params MCPCallToolParams `json:"params"`
}
MCPCallToolRequest enforces the exact JSON-RPC 2.0 MCP request structure
type OpenAIClient ¶ added in v0.5.0
type OpenAIClient struct {
Cfg *ConfigAIOpenAI
C *instructor.InstructorOpenAI
}
type Prompt ¶ added in v0.6.0
type Prompt[P any, R any] struct { Conditions string Steps string Result string State string A AgentBaseAPI // number of previous messages to include (excluding system msg) HistoryMsgLen int // Msg holds msgs for this prompt and is used to build the Conversation instance (on-demand) Msgs []*PromptMsg Thread string Reasoning string LastModel string Godoc map[string]string // contains filtered or unexported fields }
func NewPrompt ¶ added in v0.6.0
func NewPrompt[P any, R any](agent AgentBaseAPI, state, condition, steps, results string) *Prompt[P, R]
func (*Prompt[P, R]) AddGodoc ¶ added in v0.8.0
AddGodoc adds entries to the godoc comment map for the prompt schema.
func (*Prompt[P, R]) AddTool ¶ added in v0.6.0
AddTool registers a SECAI TOOL which then exports it's documents into the system prompt. This is different from an AI tool.
func (*Prompt[P, R]) Concurrency ¶ added in v0.6.0
Concurrency returns the number of concurrent requests possible for this prompt, based on configured providers.
func (*Prompt[P, R]) Conversation ¶ added in v0.6.0
func (p *Prompt[P, R]) Conversation() (*core.Conversation, string)
Conversation will create a conversation with history and system prompt, return sys prompt on the side.
func (*Prompt[P, R]) Exec ¶ added in v0.6.0
func (p *Prompt[P, R]) Exec(e *am.Event, params P, cachedParams []*P, opts ...PromptOpts) (res *R, usage *PromptUsage, err error)
Exec sends the AI prompt to the AI provider and returns unmarshalled output. [cachedParams] are useful for caching common data between similar prompts. Unlike historical messages, cache prompts never triggered an AI response.
func (*Prompt[P, R]) ExecMulti ¶ added in v0.6.0
func (p *Prompt[P, R]) ExecMulti( e *am.Event, times int, params P, cachedParams []*P, opts ...PromptOpts, ) ([]*R, []*PromptUsage, error)
ExecMulti executes Prompt.Exec multiple times and returns all the results. Useful for scoring content.
func (*Prompt[P, R]) GenSysPrompt ¶ added in v0.6.0
GenSysPrompt generates a system prompt.
func (*Prompt[P, R]) QueryProviders ¶ added in v0.8.0
func (p *Prompt[P, R]) QueryProviders(opts ...PromptOpts) []*AIClient
type PromptApi ¶ added in v0.6.0
type PromptApi interface {
AddTool(tool ToolApi)
AddDoc(doc *Document)
GenSysPrompt() string
Conversation() (*core.Conversation, string)
HistClean()
}
TODO incomplete?
type PromptConfig ¶ added in v0.8.0
type PromptOpts ¶ added in v0.6.0
type PromptRaw ¶ added in v0.8.0
type PromptRaw struct {
Conditions string
Steps string
Result string
// TODO use better schema pkg
ResultSchema *oaischema.Definition
State string
A AgentBaseAPI
// number of previous messages to include
HistoryMsgLen int
Msgs []*PromptRawMsg
// contains filtered or unexported fields
}
PromptRaw is a prompt that uses stock clients (openai.Client, genai.Client) instead of instructor-go for structured output parsing. Params are a raw string (typically JSON), and ResultSchema defines the expected JSON Schema for structured output enforcement. The raw JSON response is returned via Exec / ExecInto.
func NewPromptRaw ¶ added in v0.8.0
func NewPromptRaw(agent AgentBaseAPI, state, condition, steps, result string, resultEmpty any) (*PromptRaw, error)
func (*PromptRaw) AddTool ¶ added in v0.8.0
AddTool registers a SECAI TOOL which then exports its documents into the system prompt.
func (*PromptRaw) Concurrency ¶ added in v0.8.0
Concurrency returns the number of concurrent requests possible for this prompt.
func (*PromptRaw) Conversation ¶ added in v0.8.0
func (p *PromptRaw) Conversation() (*core.Conversation, string)
Conversation will create a conversation with history and system prompt, return sys prompt on the side.
func (*PromptRaw) Exec ¶ added in v0.8.0
func (p *PromptRaw) Exec(e *am.Event, params string, opts ...PromptOpts) (res []byte, usage *PromptUsage, err error)
Exec sends params as a user message and returns the raw JSON response bytes.
func (*PromptRaw) ExecInto ¶ added in v0.8.0
func (p *PromptRaw) ExecInto(e *am.Event, params string, result any, opts ...PromptOpts) (*PromptUsage, error)
ExecInto calls Exec and unmarshals the raw JSON response into result.
func (*PromptRaw) ExecMulti ¶ added in v0.8.0
func (p *PromptRaw) ExecMulti(e *am.Event, times int, params string) ([][]byte, []*PromptUsage, error)
ExecMulti calls Exec multiple times and collects results as JSON byte slices.
func (*PromptRaw) GenSysPrompt ¶ added in v0.8.0
GenSysPrompt generates a system prompt.
type PromptRawMsg ¶ added in v0.8.0
type PromptRawMsg struct {
Role PromptRawRole
Content string
}
PromptRawMsg is a message in a PromptRaw conversation.
type PromptRawRole ¶ added in v0.8.0
type PromptRawRole string
PromptRawRole is a simple role type, replacing core.Role from instructor-go.
const ( PromptRawRoleSystem PromptRawRole = "system" PromptRawRoleUser PromptRawRole = "user" PromptRawRoleAssistant PromptRawRole = "assistant" )
type PromptSchemaless ¶ added in v0.6.0
type PromptUsage ¶ added in v0.8.0
type PromptUsage struct {
Model string
API string
URL string
PromptTokens int
PromptTokensCached int
CompletionTokens int
TotalTokens int
PromptChars int
HistoryChars int
Provider string
}
func (*PromptUsage) Compute ¶ added in v0.8.0
func (p *PromptUsage) Compute()
type RawAIClient ¶ added in v0.8.0
type RawAIClient struct {
OpenAI *RawOpenAIClient
Gemini *RawGeminiClient
}
RawAIClient is the picked AI client from the pool for PromptRaw (stock clients).
func (*RawAIClient) Cfg ¶ added in v0.8.0
func (c *RawAIClient) Cfg() *ConfigAICommon
type RawGeminiClient ¶ added in v0.8.0
type RawGeminiClient struct {
Cfg *ConfigAIGemini
C *genai.Client
}
RawGeminiClient wraps the stock Google GenAI client.
type RawOpenAIClient ¶ added in v0.8.0
type RawOpenAIClient struct {
Cfg *ConfigAIOpenAI
C *openai.Client
}
RawOpenAIClient wraps the stock OpenAI client.
type SlogWriter ¶ added in v0.6.0
type SlogWriter struct {
// contains filtered or unexported fields
}
SlogWriter adapts an slog.Logger to the io.Writer interface.
func NewSlogWriter ¶ added in v0.6.0
func NewSlogWriter(logger *slog.Logger, level slog.Level) *SlogWriter
NewSlogWriter creates a new io.Writer that writes to the provided slog.Logger at the specified log level.
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.
type ValFileEnc ¶ added in v0.8.0
type ValFileEnc = ValEnc