Documentation
¶
Index ¶
- type Binding
- type ConversationInfo
- type Dispatcher
- func (d *Dispatcher) Agent(name string) *Engine
- func (d *Dispatcher) Agents() []string
- func (d *Dispatcher) Dispatch(ctx context.Context, agentName string, msg adapter.IncomingMessage) error
- func (d *Dispatcher) Run(ctx context.Context) error
- func (d *Dispatcher) SendFor(adapterName string) SendFunc
- func (d *Dispatcher) SendVia(ctx context.Context, adapterName string, msg adapter.OutgoingMessage) error
- type Engine
- func (e *Engine) AppendSkill(s skill.Skill)
- func (e *Engine) Chat(ctx context.Context, msg adapter.IncomingMessage) (string, error)
- func (e *Engine) HandleMessage(ctx context.Context, msg adapter.IncomingMessage) error
- func (e *Engine) HasTools() bool
- func (e *Engine) ModelName() string
- func (e *Engine) Name() string
- func (e *Engine) PermissionTier() string
- func (e *Engine) PersonaDir() string
- func (e *Engine) PersonaSections() map[string]bool
- func (e *Engine) SetScheduler(sched *scheduler.Scheduler)
- func (e *Engine) SetSkillDirs(agentSkillsDir, globalSkillsDir string)
- func (e *Engine) Skills() []skill.Skill
- func (e *Engine) ToolNames() []string
- type MemoryStore
- type SQLiteMemoryStore
- func (s *SQLiteMemoryStore) AddMessage(ctx context.Context, convID string, msg StoredMessage) error
- func (s *SQLiteMemoryStore) Close() error
- func (s *SQLiteMemoryStore) ConversationCost(ctx context.Context, convID string) (float64, error)
- func (s *SQLiteMemoryStore) CountConversationsBefore(ctx context.Context, before time.Time) (int, error)
- func (s *SQLiteMemoryStore) DeleteConversation(ctx context.Context, convID string) error
- func (s *SQLiteMemoryStore) GetMessages(ctx context.Context, convID string, limit int) ([]StoredMessage, error)
- func (s *SQLiteMemoryStore) GetOrCreateConversation(ctx context.Context, adapterName, externalID string) (string, error)
- func (s *SQLiteMemoryStore) GetOrCreateConversationByID(ctx context.Context, convID string) error
- func (s *SQLiteMemoryStore) ListConversations(ctx context.Context) ([]ConversationInfo, error)
- func (s *SQLiteMemoryStore) PruneConversations(ctx context.Context, before time.Time) (int, error)
- type SendFunc
- type StoredMessage
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Binding ¶
Binding maps an adapter pattern to an agent name. Pattern is either a wildcard ("telegram") or specific ("telegram:12345").
type ConversationInfo ¶
type ConversationInfo struct {
ID string `db:"id" json:"id"`
Adapter string `db:"adapter" json:"adapter"`
ExternalID string `db:"external_id" json:"external_id"`
CreatedAt time.Time `db:"created_at" json:"created_at"`
MessageCount int `db:"message_count" json:"message_count"`
}
ConversationInfo provides metadata about a conversation.
type Dispatcher ¶
type Dispatcher struct {
// contains filtered or unexported fields
}
Dispatcher routes incoming messages to the correct agent Engine based on adapter bindings. It owns the adapter lifecycle and the shared incoming channel.
func NewDispatcher ¶
func NewDispatcher( agents map[string]*Engine, bindings []Binding, adapters []adapter.Adapter, logger *slog.Logger, ) *Dispatcher
NewDispatcher creates a Dispatcher from a set of named engines, bindings, and adapters. Bindings are processed in order; specific bindings ("telegram:12345") take priority over wildcard bindings ("telegram").
func (*Dispatcher) Agent ¶
func (d *Dispatcher) Agent(name string) *Engine
Agent returns the Engine for the named agent, or nil if not found.
func (*Dispatcher) Agents ¶
func (d *Dispatcher) Agents() []string
Agents returns the names of all registered agents.
func (*Dispatcher) Dispatch ¶
func (d *Dispatcher) Dispatch(ctx context.Context, agentName string, msg adapter.IncomingMessage) error
Dispatch sends a message to a specific agent by name. Used by the scheduler.
func (*Dispatcher) Run ¶
func (d *Dispatcher) Run(ctx context.Context) error
Run starts all adapters and processes incoming messages until ctx is cancelled.
func (*Dispatcher) SendFor ¶
func (d *Dispatcher) SendFor(adapterName string) SendFunc
SendFor returns a SendFunc that routes outgoing messages through the adapter matching the incoming message's adapter name.
func (*Dispatcher) SendVia ¶
func (d *Dispatcher) SendVia(ctx context.Context, adapterName string, msg adapter.OutgoingMessage) error
SendVia sends a message through the adapter registered under adapterName. Returns an error if no adapter with that name is registered.
type Engine ¶
type Engine struct {
// contains filtered or unexported fields
}
Engine is the core agent orchestrator. Each named agent gets its own Engine instance with its own persona, skills, permissions, and LLM router.
func (*Engine) AppendSkill ¶
AppendSkill appends a new skill to the engine's in-memory skill list.
func (*Engine) Chat ¶
Chat processes a single incoming message through the full pipeline and returns the response text. It does not call the sendFunc — use this when the caller wants to receive the reply directly (e.g. the REST API). Any pending approval request is accessible via GET /api/v1/approvals.
func (*Engine) HandleMessage ¶
HandleMessage processes a single incoming message and sends the response back via the adapter's SendFunc. It delegates the full pipeline to chatWithApproval so it can attach inline keyboard buttons when an approval was created during this call.
func (*Engine) PermissionTier ¶
PermissionTier returns the agent's default permission tier.
func (*Engine) PersonaDir ¶
PersonaDir returns the directory the agent's persona was loaded from. Returns an empty string if no persona is configured.
func (*Engine) PersonaSections ¶
PersonaSections returns which persona sections are loaded (soul/user/memory). Returns nil if no persona is configured.
func (*Engine) SetScheduler ¶
SetScheduler provides a Scheduler reference so the engine can register new schedules at runtime via SCHEDULE_ADD directives. Call this after the Scheduler is initialized.
func (*Engine) SetSkillDirs ¶
SetSkillDirs configures the directories used for skill creation and hot-reload. agentSkillsDir is where new skill files are written; globalSkillsDir is the shared skills directory merged on top of agent-specific skills. Call this after NewEngine, before the engine starts handling messages.
type MemoryStore ¶
type MemoryStore interface {
GetOrCreateConversation(ctx context.Context, adapter, externalID string) (string, error)
// GetOrCreateConversationByID ensures a conversation row exists for the given
// convID without requiring a real adapter/externalID pair. Used by the
// scheduler for isolated sessions that are not tied to a chat channel.
GetOrCreateConversationByID(ctx context.Context, convID string) error
AddMessage(ctx context.Context, convID string, msg StoredMessage) error
GetMessages(ctx context.Context, convID string, limit int) ([]StoredMessage, error)
ListConversations(ctx context.Context) ([]ConversationInfo, error)
// DeleteConversation removes a conversation and all its messages by ID.
// Returns nil if the conversation does not exist (idempotent).
DeleteConversation(ctx context.Context, convID string) error
Close() error
}
MemoryStore defines the interface for conversation persistence.
type SQLiteMemoryStore ¶
type SQLiteMemoryStore struct {
// contains filtered or unexported fields
}
SQLiteMemoryStore implements MemoryStore using SQLite.
func NewInMemoryStore ¶
func NewInMemoryStore() (*SQLiteMemoryStore, error)
NewInMemoryStore creates an in-memory SQLite store (for testing).
func NewSQLiteMemoryStore ¶
func NewSQLiteMemoryStore(dbPath string) (*SQLiteMemoryStore, error)
NewSQLiteMemoryStore opens or creates a SQLite database at the given path.
func (*SQLiteMemoryStore) AddMessage ¶
func (s *SQLiteMemoryStore) AddMessage(ctx context.Context, convID string, msg StoredMessage) error
func (*SQLiteMemoryStore) Close ¶
func (s *SQLiteMemoryStore) Close() error
func (*SQLiteMemoryStore) ConversationCost ¶ added in v0.7.0
ConversationCost returns the total cost of all messages in a conversation.
func (*SQLiteMemoryStore) CountConversationsBefore ¶ added in v0.7.0
func (s *SQLiteMemoryStore) CountConversationsBefore(ctx context.Context, before time.Time) (int, error)
CountConversationsBefore returns the number of conversations created before the given time.
func (*SQLiteMemoryStore) DeleteConversation ¶
func (s *SQLiteMemoryStore) DeleteConversation(ctx context.Context, convID string) error
func (*SQLiteMemoryStore) GetMessages ¶
func (s *SQLiteMemoryStore) GetMessages(ctx context.Context, convID string, limit int) ([]StoredMessage, error)
func (*SQLiteMemoryStore) GetOrCreateConversation ¶
func (*SQLiteMemoryStore) GetOrCreateConversationByID ¶
func (s *SQLiteMemoryStore) GetOrCreateConversationByID(ctx context.Context, convID string) error
func (*SQLiteMemoryStore) ListConversations ¶
func (s *SQLiteMemoryStore) ListConversations(ctx context.Context) ([]ConversationInfo, error)
func (*SQLiteMemoryStore) PruneConversations ¶ added in v0.7.0
PruneConversations deletes all conversations (and their messages) created before the given time. Returns the number of conversations deleted.
type SendFunc ¶
type SendFunc func(ctx context.Context, msg adapter.OutgoingMessage) error
SendFunc is a callback for sending a response back to the originating adapter. The Dispatcher sets this when constructing each Engine.
type StoredMessage ¶
type StoredMessage struct {
ID int64 `db:"id"`
ConversationID string `db:"conversation_id"`
Role string `db:"role"`
Content string `db:"content"`
TokensUsed int `db:"tokens_used"`
Cost float64 `db:"cost"`
CreatedAt time.Time `db:"created_at"`
}
StoredMessage represents a message persisted in the memory store.