feat: add memory tool enabled/disabled flag

Allow disabling the memory tool via config (tools.memory.enabled).
When disabled, the system prompt switches to file-path-based memory
instructions instead of tool-based ones.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Kohei 2026-02-22 11:54:19 +09:00
parent 5343398a34
commit fc02b81caa
3 changed files with 48 additions and 17 deletions

View file

@ -15,13 +15,14 @@ import (
)
type ContextBuilder struct {
workspace string
dataDir string
skillsLoader *skills.SkillsLoader
memory *MemoryStore
tools *tools.ToolRegistry // Direct reference to tool registry
mcpManager *mcp.Manager // MCP server manager
enabledChannels []string // Active communication channels
workspace string
dataDir string
skillsLoader *skills.SkillsLoader
memory *MemoryStore
tools *tools.ToolRegistry // Direct reference to tool registry
mcpManager *mcp.Manager // MCP server manager
enabledChannels []string // Active communication channels
memoryToolEnabled bool // Whether memory tool is registered
}
func getGlobalConfigDir() string {
@ -72,12 +73,35 @@ func (cb *ContextBuilder) SetEnabledChannels(channels []string) {
cb.enabledChannels = channels
}
// SetMemoryToolEnabled sets whether the memory tool is registered.
// When disabled, the system prompt switches to file-path-based memory instructions.
func (cb *ContextBuilder) SetMemoryToolEnabled(enabled bool) {
cb.memoryToolEnabled = enabled
}
func (cb *ContextBuilder) getIdentity() string {
now := time.Now().Format("2006-01-02 15:04 (Monday)")
workspacePath, _ := filepath.Abs(filepath.Join(cb.workspace))
// Build tools section dynamically
toolsSection := cb.buildToolsSection()
// Build memory instruction based on whether memory tool is enabled
var memoryInstruction string
if cb.memoryToolEnabled {
memoryInstruction = `3. **Memory** - Use the memory tool to store and retrieve information.
- write_long_term: Save important, date-independent facts (user preferences, project info, permanent notes)
- append_daily: Record today's events and memos (diary-like daily entries)
- read_long_term: Read long-term memory
- read_daily: Read today's daily notes`
} else {
dataDirAbs, _ := filepath.Abs(cb.dataDir)
memoryInstruction = fmt.Sprintf(`3. **Memory** - When interacting with me if something seems memorable, update %s/memory/MEMORY.md
- Long-term memory: %s/memory/MEMORY.md
- Daily notes: %s/memory/YYYYMM/YYYYMMDD.md (e.g. %s/memory/%s/%s.md)`,
dataDirAbs, dataDirAbs, dataDirAbs, dataDirAbs,
time.Now().Format("200601"), time.Now().Format("20060102"))
}
return fmt.Sprintf(`## Current Time
%s
@ -95,12 +119,8 @@ Your workspace is at: %s
2. **Be helpful and accurate** - When using tools, briefly explain what you're doing.
3. **Memory** - Use the memory tool to store and retrieve information.
- write_long_term: Save important, date-independent facts (user preferences, project info, permanent notes)
- append_daily: Record today's events and memos (diary-like daily entries)
- read_long_term: Read long-term memory
- read_daily: Read today's daily notes`,
now, workspacePath, toolsSection)
%s`,
now, workspacePath, toolsSection, memoryInstruction)
}
func (cb *ContextBuilder) buildChannelsSection() string {

View file

@ -186,10 +186,13 @@ func NewAgentLoop(cfg *config.Config, msgBus *bus.MessageBus, provider providers
contextBuilder := NewContextBuilder(workspace, dataDir)
contextBuilder.SetToolsRegistry(toolsRegistry)
// Register memory and skill tools (controlled access to dataDir)
memoryTool := tools.NewMemoryTool(contextBuilder.GetMemory())
toolsRegistry.Register(memoryTool)
subagentTools.Register(memoryTool)
// Register memory tool (conditionally based on config)
contextBuilder.SetMemoryToolEnabled(cfg.Tools.Memory.Enabled)
if cfg.Tools.Memory.Enabled {
memoryTool := tools.NewMemoryTool(contextBuilder.GetMemory())
toolsRegistry.Register(memoryTool)
subagentTools.Register(memoryTool)
}
skillTool := tools.NewSkillTool(contextBuilder.GetSkillsLoader())
toolsRegistry.Register(skillTool)

View file

@ -257,12 +257,17 @@ type AndroidToolsConfig struct {
Enabled bool `json:"enabled" env:"PICOCLAW_TOOLS_ANDROID_ENABLED"`
}
type MemoryToolsConfig struct {
Enabled bool `json:"enabled" env:"PICOCLAW_TOOLS_MEMORY_ENABLED"`
}
type ToolsConfig struct {
Web WebToolsConfig `json:"web"`
Exec ExecToolsConfig `json:"exec"`
I2C I2CToolsConfig `json:"i2c"`
SPI SPIToolsConfig `json:"spi"`
Android AndroidToolsConfig `json:"android"`
Memory MemoryToolsConfig `json:"memory"`
MCP map[string]MCPServerConfig `json:"mcp,omitempty"`
}
@ -382,6 +387,9 @@ func DefaultConfig() *Config {
Android: AndroidToolsConfig{
Enabled: true,
},
Memory: MemoryToolsConfig{
Enabled: true,
},
Web: WebToolsConfig{
Brave: BraveConfig{
Enabled: false,