Documentation
¶
Index ¶
- Constants
- func EstimateTokens(messages []provider.Message) int
- type Agent
- func (a *Agent) HandleMessage(ctx context.Context, msg bus.InboundMessage) string
- func (a *Agent) HandleWebChat(ctx context.Context, text string) string
- func (a *Agent) InjectGroupMessage(ctx context.Context, msg bus.InboundMessage)
- func (a *Agent) Name() string
- func (a *Agent) SetGroupContext(gc *GroupContext)
- type CompactResult
- type ContextBuilder
- type GroupContext
- type Heartbeat
- type HeartbeatConfig
- type HookContext
- type HookFunc
- type HookPoint
- type HookRegistry
- type Manager
- type Memory
- type Skill
- type SkillsLoader
Constants ¶
const ( // DefaultTokenThreshold is the default threshold at which compaction triggers (80K tokens). DefaultTokenThreshold = 80000 // PruneTurnAge is the number of recent turns to keep intact; older messages get pruned. PruneTurnAge = 20 )
const ( // DefaultHeartbeatInterval is the default interval between heartbeat checks. DefaultHeartbeatInterval = 30 * time.Minute )
Variables ¶
This section is empty.
Functions ¶
func EstimateTokens ¶
EstimateTokens provides a rough token estimate: chars/4.
Types ¶
type Agent ¶
type Agent struct {
// contains filtered or unexported fields
}
Agent is the ReAct agent loop.
func NewAgent ¶
func NewAgent(rc config.ResolvedAgent, prov provider.Provider, mb *bus.MessageBus, homeDir string) *Agent
NewAgent creates a new Agent from a resolved config.
func (*Agent) HandleMessage ¶
HandleMessage processes an inbound message through the ReAct loop.
func (*Agent) HandleWebChat ¶ added in v0.3.0
HandleWebChat handles a chat message from the web UI.
func (*Agent) InjectGroupMessage ¶
func (a *Agent) InjectGroupMessage(ctx context.Context, msg bus.InboundMessage)
InjectGroupMessage appends a message from another bot into the session history without triggering an LLM call. This gives the agent awareness of what other bots said in the group chat.
func (*Agent) SetGroupContext ¶
func (a *Agent) SetGroupContext(gc *GroupContext)
SetGroupContext configures group chat awareness for this agent's system prompt.
type CompactResult ¶
CompactResult holds the result of a compaction operation.
func CompactMessages ¶
func CompactMessages(messages []provider.Message, workspace string, prov provider.Provider, model string) (*CompactResult, error)
CompactMessages prunes and optionally compresses the message history when it exceeds the token threshold. Step 1 (Pruning): For messages older than PruneTurnAge, strip tool result content. Step 2 (Compression): If still over threshold after pruning, summarize older messages using the LLM and write full history to a log file.
type ContextBuilder ¶
type ContextBuilder struct {
// contains filtered or unexported fields
}
ContextBuilder assembles the system prompt and runtime context.
func NewContextBuilder ¶
func NewContextBuilder(workspace string, memory *Memory, skillsSummary string) *ContextBuilder
NewContextBuilder creates a new context builder.
func (*ContextBuilder) BuildRuntimeContext ¶
func (cb *ContextBuilder) BuildRuntimeContext(channel, chatID string) string
BuildRuntimeContext returns the runtime context to inject before the user message.
func (*ContextBuilder) BuildSystemPrompt ¶
func (cb *ContextBuilder) BuildSystemPrompt() string
BuildSystemPrompt assembles the system prompt from identity, bootstrap files, memory, and skills.
func (*ContextBuilder) SetGroupContext ¶
func (cb *ContextBuilder) SetGroupContext(gc *GroupContext)
SetGroupContext sets the group chat context for system prompt generation.
type GroupContext ¶
type GroupContext struct {
BotUsername string // this agent's bot username
Teammates []string // other agent names in the group
}
GroupContext holds information about the group chat environment for system prompt injection.
type Heartbeat ¶
type Heartbeat struct {
// contains filtered or unexported fields
}
Heartbeat runs periodic checks and triggers agent actions.
func NewHeartbeat ¶
NewHeartbeat creates a new heartbeat for the given agent.
type HeartbeatConfig ¶
HeartbeatConfig holds heartbeat configuration.
type HookContext ¶
type HookContext struct {
AgentName string
Point HookPoint
Messages []provider.Message
ToolName string // for tool-related hooks
ToolArgs string // for BeforeToolCall
ToolResult string // for AfterToolCall
Response *provider.Response
Error error
StartTime time.Time // set at BeforeModelCall/BeforeToolCall for timing
}
HookContext carries data available to hooks at each hook point.
type HookFunc ¶
type HookFunc func(ctx context.Context, hc *HookContext)
HookFunc is a function that runs at a hook point. It can inspect and modify the HookContext.
func LoggingHook ¶
func LoggingHook() HookFunc
LoggingHook returns a hook function that logs timing information.
type HookRegistry ¶
type HookRegistry struct {
// contains filtered or unexported fields
}
HookRegistry stores registered hooks per hook point.
func NewHookRegistry ¶
func NewHookRegistry() *HookRegistry
NewHookRegistry creates a new hook registry.
func (*HookRegistry) Register ¶
func (hr *HookRegistry) Register(point HookPoint, fn HookFunc)
Register adds a hook function for the given hook point.
func (*HookRegistry) Run ¶
func (hr *HookRegistry) Run(ctx context.Context, hc *HookContext)
Run executes all hooks registered at the given point.
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager loads and manages all agent instances.
func NewManager ¶
func NewManager(resolved []config.ResolvedAgent, prov provider.Provider, mb *bus.MessageBus) (*Manager, error)
NewManager creates agents from resolved configs.
func (*Manager) DefaultAgent ¶
DefaultAgent returns the default agent (set when only one agent exists).
type Memory ¶
type Memory struct {
// contains filtered or unexported fields
}
Memory manages the dual-layer memory system (MEMORY.md + HISTORY.md).
func (*Memory) AppendHistory ¶
AppendHistory adds an entry to the history log.
func (*Memory) LoadHistory ¶
LoadHistory reads the history log.
func (*Memory) LoadMemory ¶
LoadMemory reads the long-term memory file.
func (*Memory) ReviewAndUpdateMemory ¶
ReviewAndUpdateMemory scans recent history entries and appends new key facts to MEMORY.md. This is called by the heartbeat to keep long-term memory fresh.
func (*Memory) SaveMemory ¶
SaveMemory overwrites the long-term memory file.
type Skill ¶
type Skill struct {
Name string // directory name
Layer string // "global", "team", or "agent"
Content string // contents of SKILL.md
}
Skill represents a discovered skill.
type SkillsLoader ¶
type SkillsLoader struct {
// contains filtered or unexported fields
}
SkillsLoader discovers and merges skills from three layers: global > team > agent. Agent-level skills win on conflict.
func NewSkillsLoader ¶
func NewSkillsLoader(homeDir, agentDir, teamDir string, skillsCfg config.SkillsConfig) *SkillsLoader
NewSkillsLoader creates a new skills loader.
func (*SkillsLoader) BuildSkillsSummary ¶
func (sl *SkillsLoader) BuildSkillsSummary(skills []Skill) string
BuildSkillsSummary returns an XML summary of all skills for the system prompt. Always-load skills get their full content injected.
func (*SkillsLoader) LoadSkills ¶
func (sl *SkillsLoader) LoadSkills() []Skill
LoadSkills discovers skills from all layers and returns them merged (agent wins on conflict).