ci / vet-and-test (pull_request) Successful in 52s
Why: The bounded A01 model call produced a five-finding malformed payload and an abbreviated quote that strict validation correctly rejected. Evidence: Full Backend suite passed; original paid failure and rejected source citations remain unchanged. Impact: Advertise one to three findings per publication and continuous literal quotes, bumping material recipe identity to v7; Core authority and budget remain unchanged. Refs: U2/U3 failed A01 assessment and proposed bounded follow-up
68 lines
4.0 KiB
Go
68 lines
4.0 KiB
Go
package runtime
|
|
|
|
import (
|
|
agentllm "agent-native/runtime/llm"
|
|
agenttools "agent-native/runtime/tools"
|
|
core "agent-system-core"
|
|
"bytes"
|
|
"encoding/json"
|
|
"fmt"
|
|
"io"
|
|
)
|
|
|
|
const workCheckpointTool = "publish_work_checkpoint"
|
|
|
|
type WorkCheckpointSink interface {
|
|
PublishWorkCheckpoint(core.WorkCheckpointCandidate) error
|
|
}
|
|
|
|
func checkpointEnabled(rc RunCtx) bool {
|
|
if capability, ok := rc.(interface{ WorkCheckpointAvailable() bool }); ok && !capability.WorkCheckpointAvailable() {
|
|
return false
|
|
}
|
|
src, ok := rc.(interface{ SubagentID() string })
|
|
if !ok || src.SubagentID() != materialSubagentID {
|
|
return false
|
|
}
|
|
if _, ok = rc.(WorkCheckpointSink); !ok {
|
|
return false
|
|
}
|
|
if !rc.Profile().Tools.ToolAllowed(workCheckpointTool) || rc.Profile().Tools.NeedsConfirm(workCheckpointTool) {
|
|
return false
|
|
}
|
|
for _, tool := range rc.Tools() {
|
|
if tool.Name == workCheckpointTool {
|
|
return false
|
|
}
|
|
}
|
|
return true
|
|
}
|
|
func checkpointDecl() agentllm.ToolDecl {
|
|
return agentllm.ToolDecl{Name: workCheckpointTool, Description: "将本次材料整理中已形成的有用发现及时保存到同一任务卡。只引用已提供的 sourceId/blockIndex 和原文片段;material_record由宿主展示经核验的原文引用,不采用模型转述或影响判断;归纳、推算或判断用analysis/provisional并写明assumptions。长材料在形成阶段结果时发布,不额外调用摘要模型;不要为了进度凑发现。普通发布最多6次,每次只提交1至3条新增发现;原文quote必须是同一段落连续出现的短句,不能拼接或用省略号。需要更正以前发现时用 corrects 填其 findingKey。此工具不创建确认按钮,也不表示暂停执行。", Parameters: json.RawMessage(`{"type":"object","additionalProperties":false,"required":["checkpointId","phaseId","findings"],"properties":{"checkpointId":{"type":"string"},"phaseId":{"type":"string","enum":["reading","crosscheck","summarizing","draft-ready"]},"focus":{"type":"string"},"remaining":{"type":"string"},"nextStep":{"type":"string"},"findings":{"type":"array","minItems":1,"maxItems":3,"items":{"type":"object","additionalProperties":false,"required":["findingKey","text","kind","sources"],"properties":{"findingKey":{"type":"string"},"text":{"type":"string"},"impact":{"type":"string"},"kind":{"type":"string","enum":["material_record","analysis","provisional","needs_user"]},"assumptions":{"type":"string"},"corrects":{"type":"string"},"sources":{"type":"array","minItems":1,"items":{"type":"object","additionalProperties":false,"required":["sourceId","blockIndex","quote"],"properties":{"sourceId":{"type":"string"},"blockIndex":{"type":"integer","minimum":0},"quote":{"type":"string","description":"原文连续短句,勿拼接或用省略号"}}}}}}}}}`)}
|
|
}
|
|
func publishCheckpoint(rc RunCtx, args string) agenttools.Result {
|
|
if !checkpointEnabled(rc) {
|
|
return agenttools.Result{IsError: true, Content: "检查点发布不适用于当前任务或工具策略不允许"}
|
|
}
|
|
if len(args) > 16*1024 {
|
|
return agenttools.Result{IsError: true, Content: "检查点超过16KiB;已有成果保留"}
|
|
}
|
|
var candidate core.WorkCheckpointCandidate
|
|
d := json.NewDecoder(bytes.NewBufferString(args))
|
|
d.DisallowUnknownFields()
|
|
if err := d.Decode(&candidate); err != nil {
|
|
return agenttools.Result{IsError: true, Content: err.Error()}
|
|
}
|
|
var extra any
|
|
if err := d.Decode(&extra); err != io.EOF {
|
|
return agenttools.Result{IsError: true, Content: "检查点只接受一个JSON对象"}
|
|
}
|
|
if err := core.ValidateWorkCheckpoint(candidate); err != nil {
|
|
return agenttools.Result{IsError: true, Content: err.Error()}
|
|
}
|
|
if err := rc.(WorkCheckpointSink).PublishWorkCheckpoint(candidate); err != nil {
|
|
return agenttools.Result{IsError: true, Content: fmt.Sprintf("阶段发现未发布,已有成果保留:%v", err)}
|
|
}
|
|
return agenttools.Result{Content: "阶段发现已保存到当前任务卡。继续处理剩余工作;发布成功只表示来源片段和归属通过校验,不表示分析结论已独立核实。"}
|
|
}
|