@@ -3,10 +3,35 @@ package tools
33import (
44 "context"
55 "fmt"
6+ "strings"
67
78 "github.com/local/picobot/internal/agent/memory"
89)
910
11+ // heartbeatPhrases contains lowercase substrings that identify heartbeat-status
12+ // log entries. Any write_memory or edit_memory call whose content matches one
13+ // of these is rejected — the heartbeat loop must never pollute memory files.
14+ var heartbeatPhrases = []string {
15+ "heartbeat check" ,
16+ "heartbeat.md" ,
17+ "heartbeat log" ,
18+ "system status: healthy" ,
19+ "no pending tasks" ,
20+ "no actions required" ,
21+ "periodic tasks" ,
22+ }
23+
24+ // isHeartbeatContent returns true if content looks like a heartbeat status log.
25+ func isHeartbeatContent (content string ) bool {
26+ l := strings .ToLower (content )
27+ for _ , phrase := range heartbeatPhrases {
28+ if strings .Contains (l , phrase ) {
29+ return true
30+ }
31+ }
32+ return false
33+ }
34+
1035// WriteMemoryTool writes to the agent's memory (today's note or long-term MEMORY.md)
1136type WriteMemoryTool struct {
1237 mem * memory.MemoryStore
@@ -18,7 +43,7 @@ func NewWriteMemoryTool(mem *memory.MemoryStore) *WriteMemoryTool {
1843
1944func (w * WriteMemoryTool ) Name () string { return "write_memory" }
2045func (w * WriteMemoryTool ) Description () string {
21- return "Write or append to memory (today's note or long-term MEMORY.md)"
46+ return "Write or append to memory (today's note or long-term MEMORY.md). NEVER store heartbeat status, health checks, or 'no pending tasks' results. "
2247}
2348
2449func (w * WriteMemoryTool ) Parameters () map [string ]interface {} {
@@ -63,6 +88,9 @@ func (w *WriteMemoryTool) Execute(ctx context.Context, args map[string]interface
6388 if ! ok {
6489 return "" , fmt .Errorf ("write_memory: 'content' must be a string" )
6590 }
91+ if isHeartbeatContent (content ) {
92+ return "" , fmt .Errorf ("write_memory: heartbeat status logs must not be stored in memory — skip this write" )
93+ }
6694 appendFlag := true
6795 if a , ok := args ["append" ]; ok {
6896 if b , ok := a .(bool ); ok {
@@ -96,3 +124,4 @@ func (w *WriteMemoryTool) Execute(ctx context.Context, args map[string]interface
96124 return "" , fmt .Errorf ("write_memory: unknown target '%s'" , target )
97125 }
98126}
127+
0 commit comments