From fc02b81caaa88d562c49a20bd6421a1ceb9069e2 Mon Sep 17 00:00:00 2001 From: Kohei Date: Sun, 22 Feb 2026 11:54:19 +0900 Subject: [PATCH] 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 --- pkg/agent/context.go | 46 +++++++++++++++++++++++++++++++------------- pkg/agent/loop.go | 11 +++++++---- pkg/config/config.go | 8 ++++++++ 3 files changed, 48 insertions(+), 17 deletions(-) diff --git a/pkg/agent/context.go b/pkg/agent/context.go index 9ae6bf282..a65803ca5 100644 --- a/pkg/agent/context.go +++ b/pkg/agent/context.go @@ -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 { diff --git a/pkg/agent/loop.go b/pkg/agent/loop.go index 62e46a40c..9555c765b 100644 --- a/pkg/agent/loop.go +++ b/pkg/agent/loop.go @@ -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) diff --git a/pkg/config/config.go b/pkg/config/config.go index 6565949cf..2267f3334 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -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,