fix(agent): Agent 运行 - 重复读取改为软收敛并保留可纠正的媒体失败原因

重复只读和同版本识图不再把运行标成失败,下一步暂时收起只读工具。媒体能力错误改为可纠正,准入失败保留安全原因。
This commit is contained in:
ddcat666
2026-10-10 20:19:32 +08:00
parent 37b44444f0
commit 1bbc95b996
15 changed files with 394 additions and 52 deletions

View File

@@ -248,6 +248,8 @@ func (s *Service) runCloudAgentModelStep(ctx context.Context, userID, runID stri
if historyErr != nil {
return nil, false, historyErr
}
softReadGuard := state.ReadLoopNudge && !compactionSummary
softReadToolName, softReadCount := state.ReadLoopToolName, state.ReadLoopCount
if len(canonical.Messages) == 0 {
return nil, false, fmt.Errorf("no canonical messages")
}
@@ -264,6 +266,10 @@ func (s *Service) runCloudAgentModelStep(ctx context.Context, userID, runID stri
// 纠偏上下文只用于这一次请求,不写回运行状态,避免下一步重复出现。
canonical.Messages = append(append([]map[string]any(nil), canonical.Messages...), correction...)
}
if softReadGuard {
// 只过滤本次请求,不回写长期工具目录;内部压缩不消耗纠偏机会。
cloudAgentApplyReadLoopNudge(&canonical, &state)
}
// 看图后的历史里有 resource: 图片占位,必须随请求带上获准图片清单,
// 否则预检以「模型协议引用了未获准的图片」拒绝(见 cloud_agent_pi_image_references.go)。
references, refErr := s.cloudAgentPiStepImageReferences(userID, state.Request, &canonical)
@@ -298,9 +304,21 @@ func (s *Service) runCloudAgentModelStep(ctx context.Context, userID, runID stri
LogicalModelID: state.Request.LogicalModelID,
Input: input,
}
if softReadGuard {
state.ReadLoopNudge = false
state.ReadLoopToolName = ""
state.ReadLoopCount = 0
}
err = s.enqueueCloudAgentTask(run, &state, req, nil)
if errors.Is(err, repository.ErrCreationConflict) {
state.ActiveTaskID = ""
if softReadGuard {
// The CAS lost before the checkpoint was written. Preserve the
// one-shot guard for the retry so a conflict cannot reopen the loop.
state.ReadLoopNudge = true
state.ReadLoopToolName = firstNonEmpty(softReadToolName, "只读工具")
state.ReadLoopCount = max(1, softReadCount)
}
time.Sleep(time.Duration(attempt+1) * 20 * time.Millisecond)
continue
}