feat(agent): add date context rule to system prompt
This commit is contained in:
parent
740cdcaeaf
commit
50965bf8dd
3 changed files with 51 additions and 4 deletions
|
|
@ -78,7 +78,9 @@ Your workspace is at: %s
|
|||
|
||||
3. **Memory** - When interacting with me if something seems memorable, update %s/memory/MEMORY.md
|
||||
|
||||
4. **Context summaries** - Conversation summaries provided as context are approximate references only. They may be incomplete or outdated. Always defer to explicit user instructions over summary content.`,
|
||||
4. **Context summaries** - Conversation summaries provided as context are approximate references only. They may be incomplete or outdated. Always defer to explicit user instructions over summary content.
|
||||
|
||||
5. **Current Date Context** - When using the web_search tool, you MUST use the Current Time in the system context to construct accurate date-specific queries.`,
|
||||
workspacePath, workspacePath, workspacePath, workspacePath, workspacePath)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -262,9 +262,9 @@ func TestCacheStability(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
// Static prompt must NOT contain per-request data
|
||||
if strings.Contains(results[0], "Current Time") {
|
||||
t.Error("static cached prompt should not contain time (added dynamically)")
|
||||
// Static prompt must NOT contain per-request data (the header/block itself)
|
||||
if strings.Contains(results[0], "## Current Time") {
|
||||
t.Error("static cached prompt should not contain time block (added dynamically)")
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,9 @@
|
|||
package agent
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/sipeed/picoclaw/pkg/providers"
|
||||
)
|
||||
|
|
@ -207,3 +209,46 @@ func assertRoles(t *testing.T, msgs []providers.Message, expected ...string) {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestContextBuilder_WebSearchDateContext(t *testing.T) {
|
||||
cb := NewContextBuilder(t.TempDir())
|
||||
|
||||
systemPrompt := cb.BuildSystemPrompt()
|
||||
|
||||
expectedInstruction := "**Current Date Context** - When using the web_search tool, you MUST use the Current Time in the system context to construct accurate date-specific queries."
|
||||
|
||||
if !strings.Contains(systemPrompt, expectedInstruction) {
|
||||
t.Errorf("Expected system prompt to contain web_search date instruction, got:\n%s", systemPrompt)
|
||||
}
|
||||
}
|
||||
|
||||
func TestContextBuilder_TimeInjection(t *testing.T) {
|
||||
cb := NewContextBuilder(t.TempDir())
|
||||
// Note: BuildMessages includes the dynamic context (time)
|
||||
messages := cb.BuildMessages(nil, "", "hello", nil, "discord", "123")
|
||||
|
||||
if len(messages) == 0 {
|
||||
t.Fatal("Expected messages, got none")
|
||||
}
|
||||
|
||||
systemPrompt := messages[0].Content
|
||||
|
||||
// Verify the Current Time header exists
|
||||
if !strings.Contains(systemPrompt, "## Current Time") {
|
||||
t.Error("Expected system prompt to contain '## Current Time' header")
|
||||
}
|
||||
|
||||
// Verify it contains the current date year (e.g. "2026-")
|
||||
currentYearStr := time.Now().Format("2006-")
|
||||
if !strings.Contains(systemPrompt, currentYearStr) {
|
||||
t.Errorf("Expected system prompt to contain current year prefix %q", currentYearStr)
|
||||
}
|
||||
|
||||
// Verify the relative ordering: Rule 5 should be in the static part (first),
|
||||
// and Current Time should be in the dynamic part (second).
|
||||
rulePos := strings.Index(systemPrompt, "Current Date Context")
|
||||
timePos := strings.Index(systemPrompt, "## Current Time")
|
||||
if rulePos == -1 || timePos == -1 || rulePos > timePos {
|
||||
t.Errorf("Expected 'Current Date Context' to appear before '## Current Time'. rulePos=%d, timePos=%d", rulePos, timePos)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue