Files
archie/internal/agentexec/modelloop/history.go
T
sam dc2c3b983f
deploy / plan (push) Successful in 7s
deploy / gate (push) Successful in 8m12s
deploy / agent-image (push) Successful in 28s
deploy / dist-zip (push) Skipped
deploy / archied-image (push) Successful in 2m11s
feat(workflow): a budget continuation resumes at the stopped step with its conversation (#1832)
2026-11-09 12:44:01 +11:00

46 lines
1.5 KiB
Go

package modelloop
import (
"fmt"
"strings"
"github.com/samcharles93/archie-core/internal/domain/agentrun"
)
// missionWithHistory puts the conversation of an earlier run of the stage
// ahead of the mission, cut to fit the model's context window. agentloop has no
// field for prior messages, so the conversation goes in the first user message
// as text.
func missionWithHistory(req agentrun.Request) string {
entries := agentrun.BoundHistory(req.History, agentrun.HistoryBytes(req.ContextWindow))
if len(entries) == 0 {
return req.Mission
}
var b strings.Builder
b.WriteString("<previous_run>\nAn earlier run of this stage stopped at its step budget and was approved to continue. " +
"Its conversation follows and its edits are already in the worktree. Continue from where it stopped; do not start over.\n\n")
for _, e := range entries {
switch e.Kind {
case agentrun.TranscriptModel:
if e.Text != "" {
fmt.Fprintf(&b, "[you] %s\n", e.Text)
}
for _, call := range e.ToolCalls {
fmt.Fprintf(&b, "[you called %s] %s\n", call.Name, call.Args)
}
case agentrun.TranscriptTool:
if e.Error != "" {
fmt.Fprintf(&b, "[%s failed] %s\n", e.Tool, e.Error)
} else {
fmt.Fprintf(&b, "[%s returned] %s\n", e.Tool, e.Output)
}
case agentrun.TranscriptUser:
fmt.Fprintf(&b, "[feedback] %s\n", e.Text)
case agentrun.TranscriptCompaction:
fmt.Fprintf(&b, "[summary of earlier steps] %s\n", e.Text)
}
}
b.WriteString("</previous_run>\n\n")
return b.String() + req.Mission
}