Files
archie/internal/agentexec/modelloop/history.go
T
sam 44237b448b
deploy / plan (push) Successful in 6s
deploy / archied-image (push) Canceled after 0s
deploy / agent-image (push) Canceled after 0s
deploy / dist-zip (push) Canceled after 0s
ci/woodpecker/push/deploy Pipeline was canceled
deploy / gate (push) Canceled after 2m58s
refactor(prompts): every model prompt is a file in internal/prompts
2026-11-11 00:01:43 +11:00

46 lines
1.4 KiB
Go

package modelloop
import (
"fmt"
"strings"
"github.com/samcharles93/archie-core/internal/domain/agentrun"
"github.com/samcharles93/archie-core/internal/prompts"
)
// 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>\n" + prompts.ResumeRun() + "\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
}