diff --git a/cmd/olliesrv/internal/agent/history.go b/cmd/olliesrv/internal/agent/history.go index 6f0308e..ae7e14d 100644 --- a/cmd/olliesrv/internal/agent/history.go +++ b/cmd/olliesrv/internal/agent/history.go @@ -104,7 +104,8 @@ func toolMessageID(m backend.Message) string { const coldSummaryCacheVersion = "v2" func toolSummaryHash(m backend.Message) string { - h := sha256.Sum256([]byte(normalizeSummaryCacheContent(m.Content))) + input := coldSummaryCacheVersion + "\x00" + m.ToolName + "\x00" + normalizeSummaryCacheContent(m.Content) + h := sha256.Sum256([]byte(input)) return "cold-summary:" + coldSummaryCacheVersion + ":" + hex.EncodeToString(h[:]) } @@ -185,6 +186,7 @@ func (s *History) update(assistant backend.Message, results []toolResult) { Content: r.Content, ContentBlocks: r.ContentBlocks, ToolCallID: r.ToolCallID, + ToolName: r.Name, } if r.ToolCallID != "" { m.ID = toolMessageID(m) diff --git a/cmd/olliesrv/internal/agent/summary_cache_test.go b/cmd/olliesrv/internal/agent/summary_cache_test.go index d7be978..d3873be 100644 --- a/cmd/olliesrv/internal/agent/summary_cache_test.go +++ b/cmd/olliesrv/internal/agent/summary_cache_test.go @@ -11,6 +11,14 @@ func messageWithContent(callID, content string) backend.Message { return backend.Message{Role: "tool", ToolCallID: callID, Content: content} } +func TestToolSummaryHashSeparatesToolNames(t *testing.T) { + first := toolSummaryHash(backend.Message{Role: "tool", ToolName: "shell", Content: "same result"}) + second := toolSummaryHash(backend.Message{Role: "tool", ToolName: "file_read", Content: "same result"}) + if first == second { + t.Fatal("different tool names produced the same hash") + } +} + func TestNormalizeSummaryCacheContentPlainText(t *testing.T) { got := normalizeSummaryCacheContent(" first line \r\n\r\n\nsecond line \t\n\n") if got != "first line\n\nsecond line" { diff --git a/cmd/olliesrv/internal/backend/backend.go b/cmd/olliesrv/internal/backend/backend.go index 48a70db..b307799 100644 --- a/cmd/olliesrv/internal/backend/backend.go +++ b/cmd/olliesrv/internal/backend/backend.go @@ -39,6 +39,7 @@ type Message struct { ContentBlocks []ContentBlock `json:"content_blocks,omitempty"` // when set, overrides Content ToolCalls []ToolCall `json:"tool_calls,omitempty"` // set by assistant when calling tools ToolCallID string `json:"tool_call_id,omitempty"` // set on role=tool replies (required by OpenAI) + ToolName string `json:"tool_name,omitempty"` // local tool identity for history/cache semantics SummaryApplied bool `json:"summary_applied,omitempty"` // local history state }