Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/api/orchestration.md
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ curl -u "$AGENTFLOW_USER:$AGENTFLOW_PASS" -X POST \

### `GET /api/runs/{runId}/eval/stream`

SSE:`thought` / `done` / `error`。
SSE 的 `thought` 事件报告平台阶段,`stage` 依次为 `queued`、`collecting`、`evaluating`、`validating`,`text` 为阶段说明。评测完成后发送 `done`,失败时发送 `error`。

### `POST /api/runs/{runId}/eval/apply`

Expand Down
24 changes: 13 additions & 11 deletions internal/httpapi/run_eval.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,9 @@ func (h *runsHandlers) streamRunEval(c *gin.Context) {
c.Status(http.StatusOK)
for _, ev := range replay {
writeSSE(c, ev.Type, ev.Payload)
if ev.Type == "done" || ev.Type == "error" {
return
}
}
notify := c.Request.Context().Done()
for {
Expand Down Expand Up @@ -439,6 +442,8 @@ func (h *runsHandlers) runEvalJob(ctx context.Context, job *runEvalJob, rec doma
hub.mu.Unlock()
}()
hub := h.evalHub()
emit := func(event string, payload any) { job.publish(event, payload) }
emitRunEvalStage(emit, "queued", "评测已提交,正在等待执行")
select {
case hub.tokens <- struct{}{}:
defer func() { <-hub.tokens }()
Expand All @@ -447,8 +452,7 @@ func (h *runsHandlers) runEvalJob(ctx context.Context, job *runEvalJob, rec doma
job.publish("error", map[string]string{"error": "评测排队超时"})
return
}
emit := func(event string, payload any) { job.publish(event, payload) }
emit("thought", map[string]string{"kind": "thinking", "text": "正在整理本次 SOP 轨迹…"})
emitRunEvalStage(emit, "collecting", "正在整理本次 SOP 轨迹")
exec := currentRunEvalExec()
if exec == nil {
exec = h.executeRunEval
Expand Down Expand Up @@ -482,26 +486,24 @@ func (h *runsHandlers) executeRunEval(ctx context.Context, rec domain.RunEvalRec
facts := runeval.BuildFacts(run, catalog)
rec.Facts = facts
_ = h.repo.PutRunEval(rec)
emit("thought", map[string]string{"kind": "thinking", "text": "正在用 " + rec.Model + " 评测…"})
system, prompt := runeval.BuildPrompt(rec.Policy, facts)
raw, _, err := runAssistantCLI(ctx, assistantCLIRequest{Prompt: prompt, Model: rec.Model, SystemPrompt: system, UserID: user.ID, ReviewOnly: true}, user, func(ev assistantStreamEvent) {
if emit == nil {
return
}
if text := strings.TrimSpace(ev.Text); text != "" {
emit("thought", map[string]string{"kind": ev.Kind, "text": text})
}
})
emitRunEvalStage(emit, "evaluating", "正在用 "+rec.Model+" 分析并评分")
raw, _, err := runAssistantCLI(ctx, assistantCLIRequest{Prompt: prompt, Model: rec.Model, SystemPrompt: system, UserID: user.ID, ReviewOnly: true}, user, nil)
if err != nil {
return domain.RunEvalResult{}, err
}
emitRunEvalStage(emit, "validating", "正在校验评分并保存报告")
result, err := runeval.ParseModelResult(raw, rec.Policy)
if err != nil {
return domain.RunEvalResult{}, err
}
return result, nil
}

func emitRunEvalStage(emit func(string, any), stage, text string) {
emit("thought", map[string]string{"kind": "thinking", "stage": stage, "text": text})
}

func (h *runsHandlers) failRunEval(rec domain.RunEvalRecord, message string) {
rec.Status = domain.RunEvalFailed
rec.Error = message
Expand Down
7 changes: 6 additions & 1 deletion internal/httpapi/run_eval_cases_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"errors"
"net/http"
"net/http/httptest"
"strings"
"testing"
"time"

Expand Down Expand Up @@ -328,7 +329,7 @@ func TestRunEvalLiveStreamAndPersistenceErrors(t *testing.T) {
}
h := &runsHandlers{deps: &deps{repo: f.s}, evalJobs: newRunEvalHub()}
job := &runEvalJob{runID: run.ID, evalID: "eval", subs: map[chan runEvalJobEvent]struct{}{}, done: make(chan struct{})}
job.publish("thought", map[string]string{"text": "replay"})
emitRunEvalStage(job.publish, "collecting", "正在整理本次 SOP 轨迹")
h.evalJobs.jobs[run.ID] = job
router := gin.New()
router.GET("/api/runs/:id/eval/stream", h.streamRunEval)
Expand All @@ -354,6 +355,10 @@ func TestRunEvalLiveStreamAndPersistenceErrors(t *testing.T) {
if rec.Code != http.StatusOK {
t.Fatalf("live eval stream = %d: %s", rec.Code, rec.Body.String())
}
body := rec.Body.String()
if !strings.Contains(body, `"stage":"collecting"`) || !strings.Contains(body, "event: done") {
t.Fatalf("missing eval stage or completion: %s", body)
}
case <-time.After(time.Second):
t.Fatal("live eval stream did not finish")
}
Expand Down
10 changes: 6 additions & 4 deletions internal/runeval/prompt.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,12 @@ func BuildPrompt(policy domain.RunEvalPolicy, facts domain.RunEvalFacts) (system
b.WriteString("规则:\n")
b.WriteString(fmt.Sprintf("- 准入线 %d 分。dimensions 每维填写 0-100 的整数,必须覆盖全部维度。总分由服务端按权重计算。\n", policy.Threshold))
b.WriteString("- findings 用中文,指向具体 nodeId 和 digest seq / event。severity 只能是 info/warn/error。\n")
b.WriteString("- summary 必须包含这次 run 的质量结论,以及如果没有可应用补丁时应该怎么改。\n")
b.WriteString("- recommendations 可为空。可应用时 action 只能是:update_node、upsert_gate、remove_gate、append_task_prompt(追加到角色 prompt)。\n")
b.WriteString("- target 为 workflow 或 agent。改节点重试用 update_node + set.maxAttempts/maxReworks/onFailure/retryStrategy。\n")
b.WriteString("- 门禁只属于角色;改门禁用 target=agent + upsert_gate/remove_gate,并给 gate.id 和 targetId。\n")
b.WriteString("- summary 用简洁中文,先给本次运行的质量结论,再说明最影响结果的问题或后续动作。不要重复罗列所有分数。\n")
b.WriteString("- recommendations 可为空。每条包含中文 title(用一句话说清改什么)和 rationale(说明依据及原因)。title 不要用操作代码。\n")
b.WriteString("- 可回写建议必须给出真实 targetId 和完整修改内容。targetId 和 nodeId 从 facts 取值。缺少可执行修改时,只给 title、rationale 和相关 nodeId。\n")
b.WriteString("- 调整节点策略:target=workflow、action=update_node、nodeId、set,set 中只放要更新的 maxAttempts/maxReworks/onFailure/retryStrategy。\n")
b.WriteString("- 追加角色任务说明:target=agent、action=append_task_prompt、text,text 填写实际要追加的完整正文。\n")
b.WriteString("- 修改角色门禁:target=agent、action=upsert_gate、gate,gate 包含 id/name/mode/required 及适用的 stage/commands/executionScope/onFailure。移除门禁用 action=remove_gate 并给出 gate.id。\n")
b.WriteString("- 不要整份重写 SOP 或角色,不要改边或删节点。\n")
b.WriteString("评分维度:\n")
for _, dim := range policy.Dimensions {
Expand Down
Loading
Loading