fix: agent context doubled up — conversation history duplicated in prompt (archie)
Implements #65
This commit is contained in:
1 parent
368221b285
commit
b164bcbb14
2 files changed
+22
-42
No files matched your search
@@ -26,14 +26,14 @@ func (c *captureRunner) Run(_ context.Context, _ string, req Request) (Result, e
|
||||
}, nil
|
||||
}
|
||||
|
||||
// ── regression: Agent doesn't load its own skills ───────────────────
|
||||
// ── regression: HandleMessage must not duplicate skill body ─────────
|
||||
|
||||
func TestHandleMessageLoadsSkillsFromWorktree(t *testing.T) {
|
||||
// PRD section 1: archie-agent owns skill loading — reads
|
||||
// .agents/skills/archie-wf-* from the worktree.
|
||||
//
|
||||
// Currently the daemon loads skills and injects the body into
|
||||
// the Mission string. HandleMessage never touches .agents/skills/.
|
||||
func TestHandleMessageDoesNotDuplicateSkillBody(t *testing.T) {
|
||||
// Regression for issue #65: the daemon already prepends the skill
|
||||
// body to every mission via missionWithSkill() before the Request
|
||||
// reaches HandleMessage. HandleMessage must pass the mission
|
||||
// through unchanged — a second prepend here would duplicate the
|
||||
// skill body in the agent's context window.
|
||||
|
||||
dir := t.TempDir()
|
||||
skillsDir := filepath.Join(dir, ".agents", "skills", "archie-wf-tdd")
|
||||
@@ -53,6 +53,12 @@ Analyse the bug. Write repro tests. Fix.
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
// Mission already includes the daemon-side prepend (as produced by
|
||||
// missionWithSkill in internal/workflow/agent.go).
|
||||
alreadyPrepended := "Follow these project-specific guidelines:\n\n" +
|
||||
"Analyse the bug. Write repro tests. Fix.\n\n---\n\n" +
|
||||
"Analyse this bug"
|
||||
|
||||
var capturedMission string
|
||||
captureFactory := func(providers map[string]Provider, log *slog.Logger) Runner {
|
||||
return &captureRunner{callback: func(req Request) {
|
||||
@@ -69,7 +75,7 @@ Analyse the bug. Write repro tests. Fix.
|
||||
Request: Request{
|
||||
Version: ProtocolVersion, TaskID: 1, Attempt: 1,
|
||||
Stage: "analyse", Model: "test/model",
|
||||
Mission: "Analyse this bug",
|
||||
Mission: alreadyPrepended,
|
||||
Budget: Budget{MaxSteps: 1, MaxTokens: 10},
|
||||
},
|
||||
Providers: map[string]Provider{"test": {Class: "openai", APIKeyEnv: "FAKE"}},
|
||||
@@ -81,14 +87,13 @@ Analyse the bug. Write repro tests. Fix.
|
||||
}
|
||||
_ = resp
|
||||
|
||||
// The agent must load the skill body from its workspace. If the
|
||||
// agent loaded the skill, the Mission sent to the runner would
|
||||
// include the skill body prepended.
|
||||
if capturedMission == "Analyse this bug" {
|
||||
t.Error("Gap: HandleMessage does not load skills from the worktree. " +
|
||||
"The Mission sent to the runner is the bare mission string — " +
|
||||
"no skill content was loaded from " + skillsDir + ". " +
|
||||
"HandleMessage must load .agents/skills/<workflow>/SKILL.md " +
|
||||
"from the workspace when processing a task. PRD section 1.")
|
||||
// The mission must be passed through unchanged. Any modification
|
||||
// would indicate a double-prepend bug (issue #65).
|
||||
if capturedMission != alreadyPrepended {
|
||||
t.Errorf("HandleMessage modified the mission:\n got: %q\n want: %q\n\n"+
|
||||
"The daemon already prepends the skill body via missionWithSkill(). "+
|
||||
"HandleMessage must not prepend it again — doing so duplicates content "+
|
||||
"in the agent's context window (issue #65).",
|
||||
capturedMission, alreadyPrepended)
|
||||
}
|
||||
}
|
||||
@@ -8,8 +8,6 @@ import (
|
||||
"io"
|
||||
"log/slog"
|
||||
"strings"
|
||||
|
||||
"github.com/samcharles93/archie-core/internal/skill"
|
||||
)
|
||||
|
||||
const maxProtocolBytes = 8 << 20
|
||||
@@ -70,18 +68,6 @@ func HandleMessage(ctx context.Context, msg AgentRequestMessage, log *slog.Logge
|
||||
channel = "response"
|
||||
}
|
||||
|
||||
// Load the skill body from the worktree — the agent owns skill
|
||||
// loading per PRD section 1. Mirrors daemon-side loadSkillBody().
|
||||
if msg.Workflow != "" && msg.Workspace != "" {
|
||||
body := skill.LoadBody(msg.Workspace, skillDirForWorkflow(msg.Workspace, msg.Workflow))
|
||||
if body != "" {
|
||||
msg.Request.Mission = "Follow these project-specific guidelines:\n\n" + body + "\n\n---\n\n" + msg.Request.Mission
|
||||
for i := range msg.Stages {
|
||||
msg.Stages[i].Mission = "Follow these project-specific guidelines:\n\n" + body + "\n\n---\n\n" + msg.Stages[i].Mission
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Per-task mode: run all stages for this workflow as a batch.
|
||||
if msg.Workflow != "" && len(msg.Stages) > 0 {
|
||||
return runStages(ctx, runner, msg, channel, log)
|
||||
@@ -151,17 +137,6 @@ func runStages(ctx context.Context, runner Runner, msg AgentRequestMessage, chan
|
||||
}, nil
|
||||
}
|
||||
|
||||
// skillDirForWorkflow finds the skill directory for a workflow from the
|
||||
// workspace catalog. Skills declare their workflow in metadata.archie.workflow.
|
||||
func skillDirForWorkflow(workspace, workflow string) string {
|
||||
catalog, _ := skill.Catalog(workspace)
|
||||
entry := skill.SkillForWorkflow(catalog, workflow)
|
||||
if entry == nil {
|
||||
return ""
|
||||
}
|
||||
return entry.Dir
|
||||
}
|
||||
|
||||
func decodeOne(r io.Reader, value any) error {
|
||||
data, err := io.ReadAll(io.LimitReader(r, maxProtocolBytes+1))
|
||||
if err != nil {
|
||||
|
||||
Reference in new issue
Block a user