Documentation
¶
Overview ¶
Package reflex holds the agent's reflexes: standing rules that watch the conversation and the app, and act when their trigger fires.
A reflex is a trigger and an action. Triggers:
text {"pattern": "(?i)triage"} the owner's message matches a regular expression
predicate {...} a libs agent/core/reflexes predicate over the conversation
event {"topic": "notes.saved"} an event on the app's bus (prefix match)
focus {"view": "notes"} a window of that view comes in front
Actions:
remind {"body": "..."} told to the agent with the next message
halt {"message": "..."} the message is answered with this; the agent is not called
run_command {"command": "...", "args": {...}} an app command is run
call_tool {"tool": "...", "input": {...}} a tool is called (read and act levels only)
Reflexes live in the core database, so the owner and the Interaction Builder can add, change and switch them on without a restart. A reflex is on when Enabled is set, or while a layout whose Setup["reflexes"] lists its name is in use.
Index ¶
- Constants
- type Doer
- type Message
- type Outcome
- type Reflex
- type Set
- func (s *Set) Active(ctx context.Context, inLayout []string) []Reflex
- func (s *Set) Delete(ctx context.Context, name string) error
- func (s *Set) Get(ctx context.Context, name string) (Reflex, bool, error)
- func (s *Set) List(ctx context.Context) ([]Reflex, error)
- func (s *Set) OnEvent(ctx context.Context, ev module.Event, focusView string, inLayout []string)
- func (s *Set) OnMessage(ctx context.Context, m Message, inLayout []string) Outcome
- func (s *Set) Put(ctx context.Context, r Reflex) error
- func (s *Set) SetEnabled(ctx context.Context, name string, on bool) error
Constants ¶
const ( TriggerText = "text" TriggerPredicate = "predicate" TriggerEvent = "event" TriggerFocus = "focus" )
The trigger kinds.
const ( ActionRemind = "remind" ActionHalt = "halt" ActionRunCommand = "run_command" ActionCallTool = "call_tool" )
The action kinds.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Doer ¶
type Doer interface {
RunCommand(ctx context.Context, id string, args map[string]any) (any, error)
// CallTool calls a tool by name. It refuses tools above the act level: a reflex does
// not get to skip the owner's say on a change.
CallTool(ctx context.Context, name string, input json.RawMessage) (any, error)
}
Doer carries out the actions that reach into the app. The agent service supplies it.
type Message ¶
type Message struct {
Text string
// Prior is what came before, most recent first.
Prior []libreflex.MessageSignal
Sit module.Situation
}
Message is the owner's message and the conversation before it, for the triggers.
type Outcome ¶
type Outcome struct {
// Reminders are told to the agent with the message.
Reminders []string
// Halt, when set, answers the message instead of the agent.
Halt string
// Fired names the reflexes that fired.
Fired []string
}
Outcome is what the reflexes did to one message.
type Reflex ¶
type Reflex struct {
Name string `json:"name"`
About string `json:"about,omitempty"`
TriggerKind string `json:"trigger_kind"`
Trigger json.RawMessage `json:"trigger"`
ActionKind string `json:"action_kind"`
Action json.RawMessage `json:"action"`
// Cooldown is how long, in seconds, it stays quiet after firing. 0: no wait.
Cooldown int `json:"cooldown_seconds,omitempty"`
// Enabled turns it on everywhere. Off, it is on only in a layout that lists it.
Enabled bool `json:"enabled"`
LastFired string `json:"last_fired,omitempty"`
Fired int `json:"fired,omitempty"`
}
Reflex is one reflex.
type Set ¶
type Set struct {
// contains filtered or unexported fields
}
Set is the app's reflexes.
func Open ¶
func Open(ctx context.Context, db *sql.DB, doer Doer, log func(msg string, args ...any)) (*Set, error)
Open migrates the reflex table into db.
func (*Set) Active ¶
Active returns the reflexes that are on now: the enabled ones, and those the layout in use lists (inLayout).
func (*Set) OnEvent ¶
OnEvent puts an app event to the active event and focus reflexes. focusView is the view that came in front when the event is a focus change, else "".
func (*Set) OnMessage ¶
OnMessage puts a message to the active reflexes and carries out what fires. Reminders left by event and focus reflexes since the last message are given too.