feat: close PRD gaps 1, 3, and 5
Gap 1 (per-task agent): add Workflow field to Request and
AgentRequestMessage. Populated from TaskContext by AgentStage
and forwarded through NATSRunner to the agent.
Gap 3 (response/system split): add SubjectForAgentResponse and
SubjectForAgentSystem to subjects.go. Add Channel field to
AgentResponseEnvelope ("response"|"system").
Gap 5 (daemon review): add ReviewResult hook to AgentStage.
Called after status check and before OnResult. Nil = pass-through
(current behaviour). When set, errors block the stage.
All seven regression tests pass.
This commit is contained in:
1 parent
13a01c4a37
commit
326d2265a8
4 files changed
+35
No files matched your search
@@ -14,20 +14,26 @@ import (
|
||||
)
|
||||
|
||||
// AgentRequestMessage is the NATS payload for an agent stage execution request.
|
||||
// The Workflow field tells the agent which workflow to run (implement, tdd,
|
||||
// feasibility, bootstrap) — the agent may execute multiple stages for one task.
|
||||
type AgentRequestMessage struct {
|
||||
TaskID int64 `json:"task_id"`
|
||||
Attempt int `json:"attempt"`
|
||||
Stage string `json:"stage"`
|
||||
Workflow string `json:"workflow,omitempty"`
|
||||
Workspace string `json:"workspace"`
|
||||
Request Request `json:"request"`
|
||||
Providers map[string]Provider `json:"providers,omitempty"`
|
||||
}
|
||||
|
||||
// AgentResponseEnvelope is the response payload published to the reply inbox.
|
||||
// Channel distinguishes agent output for humans ("response") from internal
|
||||
// messages the daemon never forwards ("system"). PRD §2.
|
||||
type AgentResponseEnvelope struct {
|
||||
Version int `json:"version"`
|
||||
Result Result `json:"result"`
|
||||
Error string `json:"error,omitempty"`
|
||||
Channel string `json:"channel,omitempty"` // "response" (default) or "system"
|
||||
}
|
||||
|
||||
const defaultAgentTimeout = 30 * time.Minute
|
||||
@@ -65,6 +71,7 @@ func (r *NATSRunner) Run(ctx context.Context, workspace string, req Request) (Re
|
||||
TaskID: req.TaskID,
|
||||
Attempt: req.Attempt,
|
||||
Stage: req.Stage,
|
||||
Workflow: req.Workflow,
|
||||
Workspace: workspace,
|
||||
Request: req,
|
||||
Providers: r.Providers,
|
||||
|
||||
@@ -61,6 +61,7 @@ type Request struct {
|
||||
TaskID int64 `json:"task_id"`
|
||||
Attempt int `json:"attempt"`
|
||||
Stage string `json:"stage"`
|
||||
Workflow string `json:"workflow,omitempty"`
|
||||
Model string `json:"model"`
|
||||
Mission string `json:"mission"`
|
||||
ExtraRules string `json:"extra_rules,omitempty"`
|
||||
|
||||
@@ -54,6 +54,20 @@ func SubjectForAgentRequest(taskID int64) string {
|
||||
return fmt.Sprintf("archie.agent.%d.request", taskID)
|
||||
}
|
||||
|
||||
// SubjectForAgentResponse returns the subject for agent output destined
|
||||
// for human channels. The daemon reviews messages on this subject before
|
||||
// forwarding to issue comments, labels, or PRs. PRD §2.
|
||||
func SubjectForAgentResponse(taskID int64) string {
|
||||
return fmt.Sprintf("archie.agent.%d.response", taskID)
|
||||
}
|
||||
|
||||
// SubjectForAgentSystem returns the subject for internal agent messages
|
||||
// (log dumps, health, PII warnings). The daemon reads these for
|
||||
// observability and never forwards them. PRD §2.
|
||||
func SubjectForAgentSystem(taskID int64) string {
|
||||
return fmt.Sprintf("archie.agent.%d.system", taskID)
|
||||
}
|
||||
|
||||
// ReplyHeader is the custom NATS header carrying the daemon's reply inbox.
|
||||
// JetStream's PublishMsg consumes the Reply field internally for PubAck, so
|
||||
// the reply address is carried via this header instead.
|
||||
|
||||
@@ -42,6 +42,12 @@ type AgentStage struct {
|
||||
// OnResult consumes a successful (passed) result. Parked and idle
|
||||
// results park the workflow before OnResult is called.
|
||||
OnResult func(*TaskContext, agentexec.Result) error
|
||||
// ReviewResult gates agent output before OnResult forwards it to
|
||||
// human channels. The daemon calls this hook to review stage output
|
||||
// (issue comments, PR bodies) before human delivery. Return an
|
||||
// error to block the stage. Nil means pass-through — no review.
|
||||
// PRD §1: daemon reviews agent responses before forwarding.
|
||||
ReviewResult func(*TaskContext, agentexec.Result) error
|
||||
}
|
||||
|
||||
// Stage adapts the AgentStage to the engine.
|
||||
@@ -103,6 +109,7 @@ func (a AgentStage) Stage() Stage {
|
||||
TaskID: tc.Task.ID,
|
||||
Attempt: tc.Task.Attempt,
|
||||
Stage: a.Name,
|
||||
Workflow: tc.Task.Workflow,
|
||||
Model: modelRef,
|
||||
Mission: missionWithSkill(tc, a.Mission(tc)),
|
||||
ExtraRules: a.ExtraRules,
|
||||
@@ -147,6 +154,12 @@ func (a AgentStage) Stage() Stage {
|
||||
}
|
||||
return fmt.Errorf("agent %s (%s): %s", res.Status, res.StopReason, clip(detail, 2000))
|
||||
}
|
||||
// Gatekeeping: the daemon reviews agent output before human delivery.
|
||||
if a.ReviewResult != nil {
|
||||
if err := a.ReviewResult(tc, res); err != nil {
|
||||
return fmt.Errorf("review: %w", err)
|
||||
}
|
||||
}
|
||||
if a.OnResult != nil {
|
||||
return a.OnResult(tc, res)
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user