diff --git a/internal/agentexec/helpers.go b/internal/agentexec/helpers.go index 3d20661f3..7967f4b35 100644 --- a/internal/agentexec/helpers.go +++ b/internal/agentexec/helpers.go @@ -30,14 +30,6 @@ func ClipToolCallDetail(s string) string { return s[:cut] + "…" } -func ProjectScopedRules(workspace, extra string) string { - rule := "Confine discovery to " + workspace + ". Do not inspect home directories, dependency/module caches, or unrelated projects unless the mission explicitly requests that external path." - if strings.TrimSpace(extra) == "" { - return rule - } - return rule + "\n" + extra -} - func ProtectionMatcher(p agentrun.Protection, readOnly bool) func(string) bool { if readOnly || len(p.Suffixes)+len(p.Globs) == 0 { return nil diff --git a/internal/agentexec/modelloop/loop_runner.go b/internal/agentexec/modelloop/loop_runner.go index 42916a58c..e163d7d88 100644 --- a/internal/agentexec/modelloop/loop_runner.go +++ b/internal/agentexec/modelloop/loop_runner.go @@ -17,6 +17,7 @@ import ( "github.com/samcharles93/archie-core/internal/agentexec" "github.com/samcharles93/archie-core/internal/domain/agentrun" + "github.com/samcharles93/archie-core/internal/prompts" "github.com/samcharles93/archie-core/internal/taskstate" "github.com/samcharles93/archie-core/internal/tools" ) @@ -91,7 +92,7 @@ func (r *LoopRunner) Run(ctx context.Context, workspace string, req agentrun.Req MaxParallelToolCalls: MaxParallelToolCalls, Mission: missionWithHistory(req), - ExtraRules: agentexec.ProjectScopedRules(workspace, req.ExtraRules), + ExtraRules: prompts.ProjectScopedRules(workspace, req.ExtraRules), Notes: notes, Gate: toAgentGate(req.Gate), Preflight: toAgentCommands(req.Preflight), diff --git a/internal/domain/workflow/prreview_stages_verify.go b/internal/domain/workflow/prreview_stages_verify.go index 9ae316ff7..d1eec4cd7 100644 --- a/internal/domain/workflow/prreview_stages_verify.go +++ b/internal/domain/workflow/prreview_stages_verify.go @@ -11,6 +11,7 @@ import ( "github.com/samcharles93/archie-core/internal/domain/agentrun" "github.com/samcharles93/archie-core/internal/domain/workflow/prreview" "github.com/samcharles93/archie-core/internal/domain/workflow/task" + "github.com/samcharles93/archie-core/internal/prompts" ) func stagePRVerification() Stage { @@ -355,15 +356,7 @@ func runAdversary(ctx context.Context, tc *TaskContext, findings []prreview.Find return findings, nil } - mission := fmt.Sprintf( - "You are the adversary reviewing this pull request's findings. For each finding "+ - "below, confirm it (you agree it is a real defect) or challenge it (you believe "+ - "it is wrong or not actually a problem). Read the snapshot yourself to check. "+ - "%s Also look for any defect every reviewer missed and report it as a new "+ - "finding.\n\n%s\n"+ - "Call adversary_verdicts exactly once with one verdict per finding index. If you "+ - "found anything new, call report_findings once too (skip it if you found "+ - "nothing new). Then call finish with status \"passed\".", + mission := prompts.PRReviewAdversary( adversarySkepticism(tc.prReview.aiGenerated), findingsListing(findings), ) res, err := runPRReviewAgentRecorded(ctx, tc, tc.prReview.snapshotDir, "adversary", mission, 25, []agentrun.CaptureTool{ diff --git a/internal/platform/prompts/model-probe.md b/internal/platform/prompts/model-probe.md new file mode 100644 index 000000000..05fea2233 --- /dev/null +++ b/internal/platform/prompts/model-probe.md @@ -0,0 +1 @@ +Reply with the single word OK. diff --git a/internal/platform/prompts/prompts.go b/internal/platform/prompts/prompts.go index 806e4e989..efe589961 100644 --- a/internal/platform/prompts/prompts.go +++ b/internal/platform/prompts/prompts.go @@ -18,6 +18,9 @@ var followThrough string //go:embed record_cause.md var recordCause string +//go:embed model-probe.md +var modelProbe string + // FollowThrough is added to an agent's prompt when it described an action it // didn't call. func FollowThrough() string { return followThrough } @@ -30,6 +33,10 @@ func Agent() string { return agent } // cause in Archie's memory. func RecordCause() string { return recordCause } +// ModelProbe is the one question a saved model is tested with, so the operator +// learns the endpoint, model and key work before relying on them. +func ModelProbe() string { return modelProbe } + //go:embed chat_system.tmpl var chatSystem string diff --git a/internal/prompts/pr-review-adversary.tmpl b/internal/prompts/pr-review-adversary.tmpl new file mode 100644 index 000000000..c602e0dc2 --- /dev/null +++ b/internal/prompts/pr-review-adversary.tmpl @@ -0,0 +1,4 @@ +You are the adversary reviewing this pull request's findings. For each finding below, confirm it (you agree it is a real defect) or challenge it (you believe it is wrong or not actually a problem). Read the snapshot yourself to check. {{.Skepticism}} Also look for any defect every reviewer missed and report it as a new finding. + +{{.Findings}} +Call adversary_verdicts exactly once with one verdict per finding index. If you found anything new, call report_findings once too (skip it if you found nothing new). Then call finish with status "passed". diff --git a/internal/prompts/project-scoped-rules.tmpl b/internal/prompts/project-scoped-rules.tmpl new file mode 100644 index 000000000..2b1eef2f0 --- /dev/null +++ b/internal/prompts/project-scoped-rules.tmpl @@ -0,0 +1,4 @@ +Confine discovery to {{.Workspace}}. Do not inspect home directories, dependency/module caches, or unrelated projects unless the mission explicitly requests that external path. +{{- if .Extra}} +{{.Extra}} +{{- end}} diff --git a/internal/prompts/prompts.go b/internal/prompts/prompts.go index cce8c7a28..93b143179 100644 --- a/internal/prompts/prompts.go +++ b/internal/prompts/prompts.go @@ -133,6 +133,21 @@ func PRReviewLens(lens Lens, title, body, diff, instructions string) string { }{lens.Name, lens.Angle, title, body, diff, instructions}) } +// ProjectScopedRules confines a task agent's discovery to its workspace, with +// any extra rules the task adds on their own line. +func ProjectScopedRules(workspace, extra string) string { + if strings.TrimSpace(extra) == "" { + extra = "" + } + return render("project-scoped-rules.tmpl", struct{ Workspace, Extra string }{workspace, extra}) +} + +// PRReviewAdversary has the adversary confirm or challenge each finding, with +// the listing it references by index. +func PRReviewAdversary(skepticism, findings string) string { + return render("pr-review-adversary.tmpl", struct{ Skepticism, Findings string }{skepticism, findings}) +} + // PRReviewReviewer asks a reviewer to report findings for one dimension. func PRReviewReviewer(dimension, targetFiles, instructions string) string { return render("pr-review-reviewer.tmpl", struct{ Dimension, TargetFiles, Instructions string }{dimension, targetFiles, instructions}) diff --git a/modules/governance/governance.go b/modules/governance/governance.go index 23cf1c887..45d900a59 100644 --- a/modules/governance/governance.go +++ b/modules/governance/governance.go @@ -24,6 +24,7 @@ import ( "github.com/samcharles93/ai-sdk/runtime" "github.com/samcharles93/archie-core/internal/platform/httpapi" + "github.com/samcharles93/archie-core/internal/platform/prompts" "github.com/samcharles93/archie-core/modules/governance/internal/store" ) @@ -631,7 +632,7 @@ func (m *Module) testAgentModel(ctx context.Context, in *struct{ Body Model }) ( defer cancel() resp, err := provider.Chat(ctx, chat.Request{ Model: model.Model, - Messages: []chat.Message{{Role: chat.RoleUser, Content: "Reply with the single word OK."}}, + Messages: []chat.Message{{Role: chat.RoleUser, Content: prompts.ModelProbe()}}, MaxTokens: 32, }) if err != nil {