diff --git a/README.md b/README.md
index b8a108a..0f44376 100644
--- a/README.md
+++ b/README.md
@@ -65,3 +65,5 @@ dotnet run --project tests/TensorPreprocessing.Smoke
```
界面检查使用假相机,覆盖新设置入口、手部触发、区域取图和实际送检图保存。D3 的工位误判率及间歇请求延迟仍需现场验证,当前不承诺每次请求都低于 200ms。
+
+Agent 助手的“生成步骤”和“回测并修订”独立运行:生成只产出草稿,普通对话只修改草稿,不自动回测;草稿可直接编辑或添加到配方。点击“回测并修订”后才启用标准视频验证与按证据修订,显式回测未通过或已验证草稿发生变化时需重新回测才能应用。旧设置中的 autoVerify 字段不再生效。
diff --git a/src/SopHelper.Avalonia/VVMs/RecipeEditor/RecipeEditor.axaml b/src/SopHelper.Avalonia/VVMs/RecipeEditor/RecipeEditor.axaml
index 3d16e8a..12b7433 100644
--- a/src/SopHelper.Avalonia/VVMs/RecipeEditor/RecipeEditor.axaml
+++ b/src/SopHelper.Avalonia/VVMs/RecipeEditor/RecipeEditor.axaml
@@ -510,14 +510,12 @@
-
-
+
+
-
-
-
+
diff --git a/src/SopHelper.Avalonia/VVMs/RecipeEditor/SopAgentVerificationViewModel.cs b/src/SopHelper.Avalonia/VVMs/RecipeEditor/SopAgentVerificationViewModel.cs
index 4ebe37a..3b08401 100644
--- a/src/SopHelper.Avalonia/VVMs/RecipeEditor/SopAgentVerificationViewModel.cs
+++ b/src/SopHelper.Avalonia/VVMs/RecipeEditor/SopAgentVerificationViewModel.cs
@@ -9,7 +9,7 @@ namespace SopHelper.VVMs.RecipeEditor;
public partial class RecipeEditorViewModel
{
public ISopDraftVideoVerifier DraftVerifier { get; set; } = new SopDraftVideoVerifier();
- private bool _agentAutoVerify = true;
+ private bool _agentVerificationRequired;
private string? _agentVerifiedFingerprint;
private Task? _agentVerificationTask;
private readonly List _agentRegionAdjustments = [];
@@ -17,14 +17,9 @@ public partial class RecipeEditorViewModel
public string AgentVerificationSummary { get => _agentVerificationSummary; private set => SetProperty(ref _agentVerificationSummary, value); }
public string AgentRegionAdjustmentsSummary => string.Join("\n", _agentRegionAdjustments.Select(r =>
$"区域校正草稿:{r.Key} [{r.X1},{r.Y1}]–[{r.X2},{r.Y2}] · {r.Note}"));
- public bool AgentAutoVerify
- {
- get => _agentAutoVerify;
- set { if (SetProperty(ref _agentAutoVerify, value)) { SaveAgentSettings(); ApplyAgentDraftCommand?.RaiseCanExecuteChanged(); } }
- }
public DelegateCommand VerifyAgentDraftCommand { get; private set; } = null!;
private bool CanApplyAgentDraft() => !IsAgentBusy && !_draftApplied && AgentDraftSteps.Count > 0
- && (!AgentAutoVerify || _agentVerifiedFingerprint is not null);
+ && (!_agentVerificationRequired || _agentVerifiedFingerprint is not null);
private async Task VerifyAgentDraftAsync(SopVideoDraft draft, SopVideoSample video, SopConfig template,
IProgress progress, CancellationToken token)
diff --git a/src/SopHelper.Avalonia/VVMs/RecipeEditor/SopVideoAgentViewModel.cs b/src/SopHelper.Avalonia/VVMs/RecipeEditor/SopVideoAgentViewModel.cs
index 24ef925..85b3472 100644
--- a/src/SopHelper.Avalonia/VVMs/RecipeEditor/SopVideoAgentViewModel.cs
+++ b/src/SopHelper.Avalonia/VVMs/RecipeEditor/SopVideoAgentViewModel.cs
@@ -94,7 +94,7 @@ public partial class RecipeEditorViewModel
FetchAgentModelsCommand = new DelegateCommand(() => ScheduleModelDiscovery(immediate: true));
CancelAgentCommand = new DelegateCommand(() => _agentCancellation?.Cancel(), () => IsAgentBusy);
ApplyAgentDraftCommand = new DelegateCommand(ApplyAgentDraft, CanApplyAgentDraft);
- VerifyAgentDraftCommand = new DelegateCommand(() => _agentTask = AnalyzeVideoAsync("请保留当前工艺要求,返回当前完整草稿,并用标准视频自动回测、按实际失败证据修订;不要只回复讨论文字。"),
+ VerifyAgentDraftCommand = new DelegateCommand(() => _agentTask = AnalyzeVideoAsync("请基于当前草稿保留工艺要求,用标准视频回测,并仅按实际失败证据修订,返回完整草稿;不要重新从头生成,不要只回复讨论文字。", verifyDraft: true),
() => !IsAgentBusy && !IsCapturing && AgentDraftSteps.Count > 0);
BrowseAgentVideoCommand = new DelegateCommand(async () =>
{
@@ -121,7 +121,6 @@ public partial class RecipeEditorViewModel
if (root.TryGetProperty("temperature", out var temperature)) AgentTemperature = temperature.GetDouble();
if (root.TryGetProperty("topP", out var topP)) AgentTopP = topP.GetDouble();
if (root.TryGetProperty("timeoutSeconds", out var timeout)) AgentTimeoutSeconds = timeout.GetInt32();
- if (root.TryGetProperty("autoVerify", out var autoVerify)) AgentAutoVerify = autoVerify.GetBoolean();
}
}
catch (Exception) { AgentStatus = "模型连接设置无法读取,请重新填写地址和模型名。"; }
@@ -145,7 +144,7 @@ public partial class RecipeEditorViewModel
using (var stream = new FileStream(temporary, options))
JsonSerializer.Serialize(stream, new { endpoint = AgentEndpoint, model = AgentModel, apiKey = AgentApiKey,
maxFrames = AgentMaxFrames, contextLength = AgentContextLength, maxTokens = AgentMaxTokens,
- temperature = AgentTemperature, topP = AgentTopP, timeoutSeconds = AgentTimeoutSeconds, autoVerify = AgentAutoVerify });
+ temperature = AgentTemperature, topP = AgentTopP, timeoutSeconds = AgentTimeoutSeconds });
File.Move(temporary, AgentSettingsPath, overwrite: true);
}
catch (Exception error) when (error is IOException or UnauthorizedAccessException)
@@ -210,7 +209,7 @@ public partial class RecipeEditorViewModel
if (string.IsNullOrWhiteSpace(AgentVideoPath) && SopRecording is not null) AgentVideoPath = SopRecording.StandardVideoPath;
}
- private async Task AnalyzeVideoAsync(string? userMessage = null)
+ private async Task AnalyzeVideoAsync(string? userMessage = null, bool verifyDraft = false)
{
if (IsAgentBusy || IsCapturing) return;
if (SopRecording?.IsRecording == true) { AgentStatus = "请先停止并保存 SOP 录像,再开始分析。"; return; }
@@ -242,12 +241,13 @@ public partial class RecipeEditorViewModel
+ (string.IsNullOrWhiteSpace(prompt.Compression) ? "" : "\n" + prompt.Compression)));
});
var progress = new Progress(value => { if (IsAgentBusy && ReferenceEquals(_agentCancellation, activeAnalysis)) AgentStatus = value; });
- var verificationTemplate = CreateAgentVerificationTemplate();
- Func>? verify = AgentAutoVerify
+ var verificationRequired = verifyDraft || userMessage is not null && _agentVerificationRequired;
+ var verificationTemplate = verifyDraft ? CreateAgentVerificationTemplate() : null;
+ Func>? verify = verifyDraft
? async (draft, video, cancellation) =>
{
runLog?.Write(new("verification_start", 0, JsonSerializer.Serialize(draft)));
- var result = await VerifyAgentDraftAsync(draft, video, verificationTemplate, progress, cancellation);
+ var result = await VerifyAgentDraftAsync(draft, video, verificationTemplate!, progress, cancellation);
runLog?.Write(new("verification_end", 0, JsonSerializer.Serialize(result)));
return result;
} : null;
@@ -256,10 +256,10 @@ public partial class RecipeEditorViewModel
runLog = new SopAgentRunLog(DesktopPlatform.WorkspaceRoot, connection.ApiKey);
runLog.Write(new("session_start", 0, JsonSerializer.Serialize(new
{
- Recipe = recipeName, Video = path, Mode = userMessage is null ? "generate" : "chat",
+ Recipe = recipeName, Video = path, Mode = verifyDraft ? "verify_and_revise" : userMessage is null ? "generate" : "chat",
instructions, userMessage, Endpoint = new UriBuilder(endpoint) { UserName = "", Password = "", Query = "", Fragment = "" }.Uri.ToString(),
connection.Model, connection.ContextLength, connection.MaxTokens,
- connection.Temperature, connection.TopP, connection.TimeoutSeconds, MaxFrames = maxFrames, AutoVerify = AgentAutoVerify
+ connection.Temperature, connection.TopP, connection.TimeoutSeconds, MaxFrames = maxFrames, VerifyDraft = verifyDraft
})));
AgentChatMessages.Add(new("分析日志", "本次分析过程自动保存:" + runLog.Path));
var sample = await Task.Run(() => SopVideoSampler.ReadInfo(path, token), token);
@@ -298,6 +298,7 @@ public partial class RecipeEditorViewModel
token.ThrowIfCancellationRequested();
token.ThrowIfCancellationRequested();
ClearAgentDraft(clearConversation: false, forgetApplied: userMessage is null);
+ _agentVerificationRequired = verificationRequired;
for (var i = 0; i < draft.Steps.Count; i++)
{
var step = draft.Steps[i];
@@ -309,7 +310,9 @@ public partial class RecipeEditorViewModel
PresentVerification(draft);
AgentSummary = draft.Summary + (draft.Warnings.Count == 0 ? "" : "\n需核对:" + string.Join(";", draft.Warnings));
AgentStatus = draft.Verification is { Passed: false } ? "草稿回测未通过,未修改配方。可继续对话修订。"
- : draft.Verification?.Passed == true ? $"已更新 {draft.Steps.Count} 步草稿,标准视频回测通过。" : $"已更新 {draft.Steps.Count} 步草稿(未回测)。";
+ : draft.Verification?.Passed == true ? $"已更新 {draft.Steps.Count} 步草稿,标准视频回测通过。"
+ : _agentVerificationRequired ? $"已更新 {draft.Steps.Count} 步草稿,请单独点击“回测并修订”后更新配方。"
+ : $"已更新 {draft.Steps.Count} 步草稿。可先编辑或添加到配方,再按需点击“回测并修订”。";
}
else AgentStatus = "";
_agentSample = sample;
@@ -346,7 +349,7 @@ public partial class RecipeEditorViewModel
try { SopVideoDraftClient.Validate(draft, _agentSample, definitions.Keys.ToArray(), definitions); }
catch (FormatException error) { AgentStatus = "草稿未添加:" + error.Message; return; }
var resolved = SopDraftConfigBuilder.Build(CreateAgentVerificationTemplate(), draft);
- if (AgentAutoVerify && (_agentVerifiedFingerprint is null || _agentVerifiedFingerprint != SopDraftConfigBuilder.Fingerprint(resolved, _agentSample)))
+ if (_agentVerificationRequired && (_agentVerifiedFingerprint is null || _agentVerifiedFingerprint != SopDraftConfigBuilder.Fingerprint(resolved, _agentSample)))
{
_agentVerifiedFingerprint = null;
AgentVerificationSummary = "草稿、配方设置或区域已变化,请重新回测后应用。";
@@ -381,7 +384,7 @@ public partial class RecipeEditorViewModel
ApplyAgentDraftCommand.RaiseCanExecuteChanged();
RefreshWarnings();
AgentStatus = $"已写入 {AgentDraftSteps.Count} 步,待保存。"
- + (AgentAutoVerify && Recipe.Steps.Count > applied.Count ? "已验证草稿步骤;完整配方请到“SOP流程视频”测试。" : "");
+ + (_agentVerificationRequired && Recipe.Steps.Count > applied.Count ? "已验证草稿步骤;完整配方请到“SOP流程视频”测试。" : "");
}
private SopVideoDraft? CreateAgentDraftSnapshot()
@@ -418,6 +421,7 @@ public partial class RecipeEditorViewModel
{
foreach (var row in AgentDraftSteps) { row.PropertyChanged -= DraftRowChanged; row.Dispose(); }
_agentVerifiedFingerprint = null;
+ _agentVerificationRequired = false;
_agentRegionAdjustments.Clear();
AgentVerificationSummary = "";
RaisePropertyChanged(nameof(AgentRegionAdjustmentsSummary));
diff --git a/src/SopHelper.CrossPlatform.Engine/SopAgent/SopVideoAgentClient.cs b/src/SopHelper.CrossPlatform.Engine/SopAgent/SopVideoAgentClient.cs
index 0876263..53ff73e 100644
--- a/src/SopHelper.CrossPlatform.Engine/SopAgent/SopVideoAgentClient.cs
+++ b/src/SopHelper.CrossPlatform.Engine/SopAgent/SopVideoAgentClient.cs
@@ -34,9 +34,12 @@ public sealed class SopVideoAgentClient(HttpClient http) : ISopVideoDraftClient
var verificationAttempts = 0;
var pendingCompression = "";
string[]? verificationStepNames = null;
+ var verificationInstructions = request.VerifyDraft is null
+ ? "本次只生成或编辑草稿,不进行标准视频回测;完成后直接返回,不等待回测反馈,也不能声称已通过回测。"
+ : "本次为显式回测修订。软件会用标准视频回放当前草稿,并反馈真实手部触发、实际裁剪图和 AI 判定。收到 verification_feedback 后,先分析是触发、裁剪、防抖、判据还是视觉服务问题,再有依据地修改完整草稿,必要时读取动作前后画面。不得删掉失败步骤、改变工艺顺序、缩减完成要求或声称已通过而不依据回测结果;AI 阈值由软件保护,模型不能修改。";
var messages = new List