refactor(agent): relocate reminder to tail and update completion prompt
Replace append-only reminder injection with delete-and-reappend so the reminder always sits at the tail of the messages slice, maximising LLM attention. Also change "respond with your summary" to "move on" to avoid premature stops on sub-task completion. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
5bb050cc41
commit
9974c5b1d2
2 changed files with 11 additions and 4 deletions
|
|
@ -462,12 +462,12 @@ func buildTaskReminder(userMessage string, lastBlocker string) providers.Message
|
||||||
if lastBlocker != "" {
|
if lastBlocker != "" {
|
||||||
truncatedBlocker := utils.Truncate(lastBlocker, blockerMaxChars)
|
truncatedBlocker := utils.Truncate(lastBlocker, blockerMaxChars)
|
||||||
content = fmt.Sprintf(
|
content = fmt.Sprintf(
|
||||||
"[TASK REMINDER]\nOriginal task:\n---\n%s\n---\nLast blocker:\n---\n%s\n---\nDecide: fix the blocker if it's essential, or find an alternative approach to complete the original task.",
|
"[TASK REMINDER]\nOriginal task:\n---\n%s\n---\nLast blocker:\n---\n%s\n---\nFix the blocker if essential, or find an alternative. If all steps are complete, move on.",
|
||||||
truncatedTask, truncatedBlocker,
|
truncatedTask, truncatedBlocker,
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
content = fmt.Sprintf(
|
content = fmt.Sprintf(
|
||||||
"[TASK REMINDER]\nOriginal task:\n---\n%s\n---\nContinue with the next step toward completing this task.",
|
"[TASK REMINDER]\nOriginal task:\n---\n%s\n---\nIf all steps of the original task are complete, move on. Otherwise, continue with the next step.",
|
||||||
truncatedTask,
|
truncatedTask,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
@ -482,6 +482,7 @@ func buildTaskReminder(userMessage string, lastBlocker string) providers.Message
|
||||||
func (al *AgentLoop) runLLMIteration(ctx context.Context, agent *AgentInstance, messages []providers.Message, opts processOptions) (string, int, error) {
|
func (al *AgentLoop) runLLMIteration(ctx context.Context, agent *AgentInstance, messages []providers.Message, opts processOptions) (string, int, error) {
|
||||||
iteration := 0
|
iteration := 0
|
||||||
var finalContent string
|
var finalContent string
|
||||||
|
lastReminderIdx := -1
|
||||||
|
|
||||||
for iteration < agent.MaxIterations {
|
for iteration < agent.MaxIterations {
|
||||||
iteration++
|
iteration++
|
||||||
|
|
@ -711,9 +712,15 @@ func (al *AgentLoop) runLLMIteration(ctx context.Context, agent *AgentInstance,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Inject ephemeral task reminder to prevent focus drift.
|
// Inject ephemeral task reminder to prevent focus drift.
|
||||||
|
// Remove previous reminder and re-append at the tail so it stays
|
||||||
|
// close to the LLM's attention window.
|
||||||
if shouldInjectReminder(iteration, agent.TaskReminderInterval) && !opts.NoHistory {
|
if shouldInjectReminder(iteration, agent.TaskReminderInterval) && !opts.NoHistory {
|
||||||
|
if lastReminderIdx >= 0 && lastReminderIdx < len(messages) {
|
||||||
|
messages = append(messages[:lastReminderIdx], messages[lastReminderIdx+1:]...)
|
||||||
|
}
|
||||||
reminderMsg := buildTaskReminder(opts.UserMessage, lastBlocker)
|
reminderMsg := buildTaskReminder(opts.UserMessage, lastBlocker)
|
||||||
messages = append(messages, reminderMsg)
|
messages = append(messages, reminderMsg)
|
||||||
|
lastReminderIdx = len(messages) - 1
|
||||||
logger.DebugCF("agent", "Injected task reminder",
|
logger.DebugCF("agent", "Injected task reminder",
|
||||||
map[string]interface{}{
|
map[string]interface{}{
|
||||||
"agent_id": agent.ID,
|
"agent_id": agent.ID,
|
||||||
|
|
|
||||||
|
|
@ -669,8 +669,8 @@ func TestBuildTaskReminder_WithoutBlocker(t *testing.T) {
|
||||||
if strings.Contains(msg.Content, "blocker") {
|
if strings.Contains(msg.Content, "blocker") {
|
||||||
t.Error("expected content NOT to contain 'blocker' when no blocker provided")
|
t.Error("expected content NOT to contain 'blocker' when no blocker provided")
|
||||||
}
|
}
|
||||||
if !strings.Contains(msg.Content, "Continue with the next step") {
|
if !strings.Contains(msg.Content, "move on") {
|
||||||
t.Error("expected content to contain continuation prompt")
|
t.Error("expected content to contain completion prompt")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue