拆分Agent步骤生成与标准视频回测修订流程
This commit is contained in:
parent
4de0450c08
commit
8d356af57c
@ -65,3 +65,5 @@ dotnet run --project tests/TensorPreprocessing.Smoke
|
||||
```
|
||||
|
||||
界面检查使用假相机,覆盖新设置入口、手部触发、区域取图和实际送检图保存。D3 的工位误判率及间歇请求延迟仍需现场验证,当前不承诺每次请求都低于 200ms。
|
||||
|
||||
Agent 助手的“生成步骤”和“回测并修订”独立运行:生成只产出草稿,普通对话只修改草稿,不自动回测;草稿可直接编辑或添加到配方。点击“回测并修订”后才启用标准视频验证与按证据修订,显式回测未通过或已验证草稿发生变化时需重新回测才能应用。旧设置中的 autoVerify 字段不再生效。
|
||||
|
||||
@ -510,14 +510,12 @@
|
||||
<WrapPanel>
|
||||
<TextBlock Text="每次最大抽帧" VerticalAlignment="Center" Margin="0,0,8,0" />
|
||||
<NumericUpDown Value="{Binding AgentMaxFrames, Mode=TwoWay}" Minimum="2" Maximum="60" Increment="1" Width="100" IsEnabled="{Binding AgentIsIdle}" />
|
||||
<Button Content="生成步骤" Command="{Binding GenerateStepsCommand}" Margin="12,0,0,0" />
|
||||
<Button Content="回测并修订" Command="{Binding VerifyAgentDraftCommand}" Margin="8,0,0,0" />
|
||||
<Button x:Name="GenerateAgentStepsButton" Content="生成步骤" Command="{Binding GenerateStepsCommand}" Margin="12,0,0,0" />
|
||||
<Button x:Name="VerifyAgentStepsButton" Content="回测并修订" Command="{Binding VerifyAgentDraftCommand}" Margin="8,0,0,0" />
|
||||
<Button Content="取消分析" Command="{Binding CancelAgentCommand}" Margin="8,0,0,0" />
|
||||
<Button Content="{Binding AgentApplyLabel}" Command="{Binding ApplyAgentDraftCommand}" Margin="8,0,0,0" />
|
||||
</WrapPanel>
|
||||
<CheckBox IsChecked="{Binding AgentAutoVerify, Mode=TwoWay}" IsEnabled="{Binding AgentIsIdle}">
|
||||
<TextBlock Text="生成后自动用标准视频回测并修订(最多3轮)" TextWrapping="Wrap" />
|
||||
</CheckBox>
|
||||
<TextBlock Text="先生成步骤草稿,可直接编辑或添加到配方;需要检查效果时,再单独点击“回测并修订”。生成和普通对话不会自动回测。" TextWrapping="Wrap" Foreground="{StaticResource FgDim}" FontSize="12" />
|
||||
<ProgressBar IsIndeterminate="True" IsVisible="{Binding IsAgentBusy}" Height="4" />
|
||||
<TextBlock x:Name="AgentStatusText" Text="{Binding AgentStatus}" TextWrapping="Wrap" Foreground="{StaticResource Accent}" />
|
||||
<Expander Header="标准视频回测与区域校正" IsExpanded="True">
|
||||
|
||||
@ -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<SopDraftVerification>? _agentVerificationTask;
|
||||
private readonly List<SopDraftRegion> _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<SopDraftVerification> VerifyAgentDraftAsync(SopVideoDraft draft, SopVideoSample video, SopConfig template,
|
||||
IProgress<string> progress, CancellationToken token)
|
||||
|
||||
@ -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<string>(value => { if (IsAgentBusy && ReferenceEquals(_agentCancellation, activeAnalysis)) AgentStatus = value; });
|
||||
var verificationTemplate = CreateAgentVerificationTemplate();
|
||||
Func<SopVideoDraft, SopVideoSample, CancellationToken, Task<SopDraftVerification>>? verify = AgentAutoVerify
|
||||
var verificationRequired = verifyDraft || userMessage is not null && _agentVerificationRequired;
|
||||
var verificationTemplate = verifyDraft ? CreateAgentVerificationTemplate() : null;
|
||||
Func<SopVideoDraft, SopVideoSample, CancellationToken, Task<SopDraftVerification>>? 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));
|
||||
|
||||
@ -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<object>
|
||||
{
|
||||
new { role = "system", content = SopStepDesignPrompt.SingleFrameRules + "\n" + """
|
||||
new { role = "system", content = SopStepDesignPrompt.SingleFrameRules + "\n" + verificationInstructions + "\n" + """
|
||||
你是本地 SOP Agent。用户给你一个标准操作视频路径。必须调用工具读取视频,不能仅凭文件名、元数据或常识生成步骤。
|
||||
先了解视频时长,再自行选择查看时间点,按需继续查看动作前后、过渡和细节,最后归纳顺序步骤。
|
||||
read_video_frames 的 times_seconds 是你选择的秒数数组,每次最多 max_frames_per_read 张;可重复调用检查其他时间段。
|
||||
@ -48,7 +51,6 @@ public sealed class SopVideoAgentClient(HttpClient http) : ISopVideoDraftClient
|
||||
若现有区域偏离目标,可依据实际读取画面在 region_adjustments 中提出区域校正或独立触发区,坐标使用视频原始像素,必须附 evidence_frame 和原因;这些修改只进入草稿,不自动保存。没有可见证据时不能编造坐标,应返回 blocked_reason 或 draft:null。
|
||||
每步可指定 stable_frames(1–120)、tolerance、image_mode(fixed_region/full_frame/hand)、image_region。触发区和送检区可以不同:触发区跟踪手部动作,送检区必须完整覆盖完成判据需要的物体。未指定时沿用现有配置或默认值。
|
||||
region_adjustments 是可选数组,每项包含 key、name、x1、y1、x2、y2、evidence_frame、note,四个坐标必须是视频原始像素整数。回测修订阶段保留首次草稿的步骤名称、数量与顺序;用户明确要求合并或拆分时在本次聊天首版草稿中处理。stable_frames 按实际处理帧计数;回放不等待 AI,手部短暂漏检可能需要增加离开防抖,不能改用视频时间点直接判完成。
|
||||
软件会自动用标准视频回放草稿,并反馈真实手部触发、实际裁剪图和 AI 判定。收到 verification_feedback 后,先分析是触发、裁剪、防抖、判据还是视觉服务问题,再有依据地修改完整草稿,必要时读取动作前后画面。不得删掉失败步骤、改变工艺顺序、缩减完成要求或声称已通过而不依据回测结果;AI 阈值由软件保护,模型不能修改。
|
||||
时间段以秒为单位,按发生顺序且不重叠,不超过视频时长;evidence_frame 必须引用工具实际返回的 frame_index。
|
||||
用户可以继续和你讨论、要求拆分合并或修改步骤。当前草稿包含用户手动编辑,以其工艺意图为准,不要恢复旧版本;完成判据仍须符合单帧可见性要求。
|
||||
修改步骤时返回完整的新草稿,保留未要求修改的步骤,不能只返回变化的几步。必要时继续调用视频工具核对;仅讨论或澄清时不修改草稿。
|
||||
|
||||
@ -901,7 +901,6 @@ internal static class Smoke
|
||||
for(var i=0;i<40;i++){using var frame=new Mat(48,64,MatType.CV_8UC3,new Scalar(i*4,60,90));writer.Write(frame);}
|
||||
}
|
||||
var client=new UiSopAgent();model.AgentClient=client;
|
||||
model.AgentAutoVerify=false; // 此组只测草稿编辑;自动回测在专门的闭环测试中验证。
|
||||
Check(model.AgentContextLength==131702&&model.AgentMaxTokens==8192,"Assistant defaults use the requested context and output lengths");
|
||||
Check(model.AgentMaxFrames==3,"Assistant defaults to at most three sampled frames");
|
||||
model.AgentVideoPath=video;model.AgentEndpoint="https://custom.invalid/v1/chat/completions";
|
||||
|
||||
@ -116,6 +116,8 @@ try
|
||||
{
|
||||
var agent=new SopVideoAgentClient(agentHttp);
|
||||
var agentDraft=await agent.AnalyzeAsync(request with {Video=info,MaxFramesPerRead=3},connection with {ContextLength=32768},default);
|
||||
using(var generationRequest=JsonDocument.Parse(agentHandler.Bodies[0]))
|
||||
Check(generationRequest.RootElement.GetProperty("messages")[0].GetProperty("content").GetString()!.Contains("不进行标准视频回测"),"生成提示词必须明确不自动回测");
|
||||
Check(agentHandler.Bodies.Count==4&&agentDraft.ObservedFrames.Count==4,"Agent 应多轮选择不同时间点,累计读取数可超过单次上限");
|
||||
Check(agentDraft.ObservedFrames.Select(frame=>frame.Seconds).SequenceEqual(new[]{0d,2d,1d,3.9d}),"读取时间必须由 Agent 工具参数决定");
|
||||
Check(!agentHandler.Bodies[0].Contains("data:image")&&agentHandler.Bodies[0].Contains("video_path"),"首轮仅交付路径,不上传整段视频或固定图片");
|
||||
|
||||
@ -28,6 +28,8 @@ internal static class VerificationLoopChecks
|
||||
"verified-locally", mode == "infrastructure"));
|
||||
}, Trace: traces.Add);
|
||||
var result = await new SopVideoAgentClient(http).AnalyzeAsync(request, connection, default);
|
||||
using(var verificationRequest=JsonDocument.Parse(handler.Bodies[0]))
|
||||
Check(verificationRequest.RootElement.GetProperty("messages")[0].GetProperty("content").GetString()!.Contains("本次为显式回测修订"),"只有显式回测请求才能启用回测修订提示词");
|
||||
Check(attempts == (mode is "repair" or "shrink" ? 2 : mode == "never" ? 3 : 1), "回测修订最多三轮;基础设施故障不能让模型瞎改工艺");
|
||||
Check(result.Verification?.Passed == (mode is "repair" or "shrink"), "未通过的回测不能被模型自行宣称通过");
|
||||
foreach (var kind in new[] { "model_request", "model_response", "tool_call", "tool_result", "video_frames", "verification_result", "final_result" })
|
||||
|
||||
@ -25,13 +25,14 @@ internal static class AgentDraftVerificationChecks
|
||||
var config = new SopConfig(); config.Sop.Name = "代理草稿验证"; config.Sop.Parts = [];
|
||||
config.Sop.Regions["work"] = new() { X2 = 64, Y2 = 48 };
|
||||
config.Sop.Steps = [new() { Id = 1, Name = "保留人工步骤", Description = "人工要求" }];
|
||||
Directory.CreateDirectory(Path.Combine(root,"workspace"));
|
||||
File.WriteAllText(Path.Combine(root,"workspace","sop-agent.json"),"{\"endpoint\":\"http://127.0.0.1:1/v1\",\"model\":\"unit-test\",\"autoVerify\":true}");
|
||||
var model = new RecipeEditorViewModel();
|
||||
var verifier = new ProbeVerifier(); var client = new ProbeClient(); model.DraftVerifier = verifier; model.AgentClient = client;
|
||||
model.OnDialogOpened(new DialogParameters { { "directory", store.RecipesDirectory }, { "config", config }, { "new", true } });
|
||||
model.SaveCommand.Execute();
|
||||
var path = store.ConfigPath(config.Sop.Name); var before = File.ReadAllBytes(path);
|
||||
model.AgentVideoPath = video; model.AgentEndpoint = "http://127.0.0.1:1/v1"; model.AgentModel = "unit-test";
|
||||
model.AgentAutoVerify = true;
|
||||
var view = new RecipeEditor { DataContext = model };
|
||||
var window = new Window { Width = 1040, Height = 900, Content = view }; window.Show(); window.UpdateLayout();
|
||||
var tabs = view.GetVisualDescendants().OfType<TabControl>().Single();
|
||||
@ -42,16 +43,27 @@ internal static class AgentDraftVerificationChecks
|
||||
Check(model.AgentChatMessages.Any(m => m.IsPrompt && m.Text.Contains("实际系统提示词")), "Generation retains sent prompts in the chat after replacing the draft");
|
||||
window.UpdateLayout();
|
||||
Check(view.GetVisualDescendants().OfType<Expander>().Any(e => e.Header?.ToString()?.Contains("展开实际提示词") == true), "Chat exposes collapsible actual prompt details");
|
||||
Check(verifier.Calls == 1 && model.AgentDraftSteps.Count == 1 && model.ApplyAgentDraftCommand.CanExecute(), $"Generated draft passes local verification before it becomes applicable: calls={verifier.Calls}, rows={model.AgentDraftSteps.Count}, status={model.AgentStatus}");
|
||||
var preview=Path.GetFullPath("artifacts/agent-split-preview.png");Directory.CreateDirectory(Path.GetDirectoryName(preview)!);
|
||||
using(var bitmap=new Avalonia.Media.Imaging.RenderTargetBitmap(new Avalonia.PixelSize((int)window.Bounds.Width,(int)window.Bounds.Height)))
|
||||
{ bitmap.Render(window);bitmap.Save(preview); }
|
||||
Check(verifier.Calls == 0 && model.AgentDraftSteps.Count == 1 && model.ApplyAgentDraftCommand.CanExecute(), $"Generation finishes without verification even with legacy autoVerify enabled: calls={verifier.Calls}, rows={model.AgentDraftSteps.Count}, status={model.AgentStatus}");
|
||||
Check(!view.GetVisualDescendants().OfType<CheckBox>().Any(c=>c.GetVisualDescendants().OfType<TextBlock>().Any(t=>t.Text?.Contains("生成后自动") == true)),
|
||||
"Generation and verification are separate actions without an automatic chaining checkbox");
|
||||
Check(model.Recipe.Regions.Count == 1 && model.Recipe.Steps.Count == 1 && File.ReadAllBytes(path).SequenceEqual(before), "Generating and verifying region proposals never edits or saves the recipe");
|
||||
Check(model.AgentRegionAdjustmentsSummary.Contains("trigger"), "Region corrections are visible as draft proposals");
|
||||
var logsFolder = Path.Combine(root, "workspace", "agent-logs");
|
||||
var savedLog = Directory.GetFiles(logsFolder, "analysis-*.jsonl").Single();
|
||||
var logText = File.ReadAllText(savedLog);
|
||||
Check(logText.Contains("session_start") && logText.Contains("video_info") && logText.Contains("model_response")
|
||||
&& logText.Contains("verification_end") && logText.Contains("session_end"), "Every analysis saves its lifecycle and model events automatically");
|
||||
&& !logText.Contains("verification_start") && logText.Contains("session_end"), "Generation logs finish without starting local verification");
|
||||
Check(Directory.GetFiles(Path.ChangeExtension(savedLog, null) + "-images", "*.jpg").Length == 1,
|
||||
"Actual model image evidence is saved beside the analysis log");
|
||||
model.AgentChatInput="保留当前工艺要求,润色说明";model.SendAgentChatCommand.Execute();Until(()=>!model.IsAgentBusy);
|
||||
Check(verifier.Calls==0&&client.SawCurrentDraft&&model.ApplyAgentDraftCommand.CanExecute(),"Ordinary chat edits the current draft without running verification");
|
||||
model.VerifyAgentDraftCommand.Execute();Until(()=>!model.IsAgentBusy);
|
||||
Check(verifier.Calls==1&&client.SawVerification&&client.SawCurrentDraft&&model.ApplyAgentDraftCommand.CanExecute(),"Explicit verification reuses the generated draft and runs only when requested");
|
||||
Check(Directory.GetFiles(logsFolder,"analysis-*.jsonl").Select(File.ReadAllText).Any(text=>text.Contains("verify_and_revise")&&text.Contains("verification_end")),
|
||||
"Verification and revision use their own complete session log");
|
||||
model.AgentApiKey = "never-show-secret";
|
||||
client.Failure = new System.Net.Http.HttpRequestException("连接重置 Bearer never-show-secret data:image/jpeg;base64,AAAA");
|
||||
model.GenerateStepsCommand.Execute(); Until(() => !model.IsAgentBusy);
|
||||
@ -84,12 +96,15 @@ internal static class AgentDraftVerificationChecks
|
||||
"Explicit application uses the exact tested trigger, crop and debounce while preserving existing steps and AI threshold");
|
||||
Check(File.ReadAllBytes(path).SequenceEqual(before), "Applying verified draft still requires explicit recipe save");
|
||||
verifier.Passed = false;
|
||||
var previousCalls=verifier.Calls;
|
||||
model.GenerateStepsCommand.Execute(); Until(() => !model.IsAgentBusy);
|
||||
Check(verifier.Calls==previousCalls&&model.ApplyAgentDraftCommand.CanExecute(),"Regeneration remains independent from a prior verified workflow");
|
||||
model.VerifyAgentDraftCommand.Execute();Until(()=>!model.IsAgentBusy);
|
||||
Check(!model.ApplyAgentDraftCommand.CanExecute() && model.AgentVerificationSummary.Contains("未通过") && model.Recipe.Steps.Count == 2,
|
||||
"Failed verification leaves the draft visible but blocks automatic application");
|
||||
verifier.Hold = true;
|
||||
var completedLogs = Directory.GetFiles(logsFolder, "analysis-*.jsonl");
|
||||
model.GenerateStepsCommand.Execute(); Until(() => verifier.Entered);
|
||||
model.VerifyAgentDraftCommand.Execute(); Until(() => verifier.Entered);
|
||||
var runningLog = Directory.GetFiles(logsFolder, "analysis-*.jsonl").Except(completedLogs).Single();
|
||||
using (var stream = new FileStream(runningLog, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
|
||||
using (var reader = new StreamReader(stream))
|
||||
@ -117,8 +132,10 @@ internal static class AgentDraftVerificationChecks
|
||||
private sealed class ProbeClient : ISopVideoDraftClient
|
||||
{
|
||||
public Exception? Failure;
|
||||
public bool SawVerification, SawCurrentDraft;
|
||||
public async Task<SopVideoDraft> AnalyzeAsync(SopVideoAnalysisRequest request, SopAgentConnection connection, CancellationToken token)
|
||||
{
|
||||
SawVerification=request.VerifyDraft is not null;SawCurrentDraft=request.CurrentDraft is not null;
|
||||
if (Failure is { } error) throw error;
|
||||
request.PromptSent?.Report(new(1, 1234, connection.ContextLength, "", "实际系统提示词和当前用户要求"));
|
||||
var frames = SopVideoSampler.ReadFrames(request.Video, [.5, 1.5], 0, token);
|
||||
@ -134,7 +151,7 @@ internal static class AgentDraftVerificationChecks
|
||||
return draft;
|
||||
}
|
||||
public async Task<SopAgentChatResult> ChatAsync(SopVideoAnalysisRequest request, SopAgentConnection connection, CancellationToken token)
|
||||
{ var draft = await AnalyzeAsync(request, connection, token); return new("已回测", draft, draft.ObservedFrames); }
|
||||
{ var draft = await AnalyzeAsync(request, connection, token); return new(request.VerifyDraft is null ? "已更新草稿" : "已回测", draft, draft.ObservedFrames); }
|
||||
}
|
||||
private sealed class ProbeVerifier : ISopDraftVideoVerifier
|
||||
{
|
||||
|
||||
Loading…
Reference in New Issue
Block a user