- AxAgentExecutionEngine에 PreparedExecution, PrepareExecution, NormalizeAssistantContent를 추가해 실행 준비와 최종 응답 보정 책임을 더 모음 - ChatWindow의 일반 전송과 재생성이 PrepareExecutionForConversation을 통해 같은 준비 경로를 쓰도록 정리함 - Cowork/Code 시스템 프롬프트 선택, 실행 모드 판정, 프롬프트 스택 조합, outbound message 준비의 중복 분기를 줄임 - 검증: dotnet build src/AxCopilot/AxCopilot.csproj -c Release -v minimal -p:OutputPath=bin\\verify\\ -p:IntermediateOutputPath=obj\\verify\\ 경고 0 / 오류 0
This commit is contained in:
@@ -12,6 +12,10 @@ public sealed class AxAgentExecutionEngine
|
||||
{
|
||||
public sealed record PreparedTurn(List<ChatMessage> Messages);
|
||||
public sealed record ExecutionMode(bool UseAgentLoop, bool UseStreamingTransport, string? TaskSystemPrompt);
|
||||
public sealed record PreparedExecution(
|
||||
ExecutionMode Mode,
|
||||
IReadOnlyList<string> PromptStack,
|
||||
List<ChatMessage> Messages);
|
||||
|
||||
public IReadOnlyList<string> BuildPromptStack(
|
||||
string? conversationSystem,
|
||||
@@ -44,6 +48,32 @@ public sealed class AxAgentExecutionEngine
|
||||
return new ExecutionMode(false, false, null);
|
||||
}
|
||||
|
||||
public PreparedExecution PrepareExecution(
|
||||
ChatConversation conversation,
|
||||
string runTab,
|
||||
bool streamingEnabled,
|
||||
string resolvedService,
|
||||
string? conversationSystem,
|
||||
string? slashSystem,
|
||||
string? coworkSystemPrompt,
|
||||
string? codeSystemPrompt,
|
||||
string? fileContext = null,
|
||||
IReadOnlyList<ImageAttachment>? images = null)
|
||||
{
|
||||
var mode = ResolveExecutionMode(
|
||||
runTab,
|
||||
streamingEnabled,
|
||||
resolvedService,
|
||||
coworkSystemPrompt,
|
||||
codeSystemPrompt);
|
||||
var promptStack = BuildPromptStack(
|
||||
conversationSystem,
|
||||
slashSystem,
|
||||
mode.TaskSystemPrompt);
|
||||
var preparedTurn = PrepareTurn(conversation, promptStack, fileContext, images);
|
||||
return new PreparedExecution(mode, promptStack, preparedTurn.Messages);
|
||||
}
|
||||
|
||||
public PreparedTurn PrepareTurn(
|
||||
ChatConversation conversation,
|
||||
IEnumerable<string?> systemPrompts,
|
||||
@@ -103,6 +133,33 @@ public sealed class AxAgentExecutionEngine
|
||||
return assistant;
|
||||
}
|
||||
|
||||
public string NormalizeAssistantContent(
|
||||
ChatConversation conversation,
|
||||
string runTab,
|
||||
string? content)
|
||||
{
|
||||
if (!string.IsNullOrWhiteSpace(content))
|
||||
return content;
|
||||
|
||||
var latestEventSummary = conversation.ExecutionEvents?
|
||||
.Where(evt => !string.IsNullOrWhiteSpace(evt.Summary))
|
||||
.OrderByDescending(evt => evt.Timestamp)
|
||||
.Select(evt => evt.Summary.Trim())
|
||||
.FirstOrDefault();
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(latestEventSummary))
|
||||
{
|
||||
return runTab switch
|
||||
{
|
||||
"Cowork" => $"코워크 작업이 완료되었습니다.\n\n{latestEventSummary}",
|
||||
"Code" => $"코드 작업이 완료되었습니다.\n\n{latestEventSummary}",
|
||||
_ => latestEventSummary,
|
||||
};
|
||||
}
|
||||
|
||||
return "(빈 응답)";
|
||||
}
|
||||
|
||||
private static ChatMessage CloneMessage(ChatMessage source)
|
||||
{
|
||||
return new ChatMessage
|
||||
|
||||
@@ -5728,30 +5728,6 @@ public partial class ChatWindow : Window
|
||||
: ScrollBarVisibility.Disabled;
|
||||
}
|
||||
|
||||
private static string BuildAssistantFallbackContent(ChatConversation conv, string runTab, string? content)
|
||||
{
|
||||
if (!string.IsNullOrWhiteSpace(content))
|
||||
return content;
|
||||
|
||||
var latestEventSummary = conv.ExecutionEvents?
|
||||
.Where(evt => !string.IsNullOrWhiteSpace(evt.Summary))
|
||||
.OrderByDescending(evt => evt.Timestamp)
|
||||
.Select(evt => evt.Summary.Trim())
|
||||
.FirstOrDefault();
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(latestEventSummary))
|
||||
{
|
||||
return runTab switch
|
||||
{
|
||||
"Cowork" => $"코워크 작업이 완료되었습니다.\n\n{latestEventSummary}",
|
||||
"Code" => $"코드 작업이 완료되었습니다.\n\n{latestEventSummary}",
|
||||
_ => latestEventSummary,
|
||||
};
|
||||
}
|
||||
|
||||
return "(빈 응답)";
|
||||
}
|
||||
|
||||
private static void SyncLatestAssistantMessage(ChatConversation conv, string content)
|
||||
{
|
||||
if (conv.Messages.Count == 0)
|
||||
@@ -8393,27 +8369,14 @@ public partial class ChatWindow : Window
|
||||
if (_attachedFiles.Count == 0) AttachedFilesPanel.Visibility = Visibility.Collapsed;
|
||||
}
|
||||
|
||||
var coworkSystem = string.Equals(runTab, "Cowork", StringComparison.OrdinalIgnoreCase)
|
||||
? BuildCoworkSystemPrompt()
|
||||
: null;
|
||||
var codeSystem = string.Equals(runTab, "Code", StringComparison.OrdinalIgnoreCase)
|
||||
? BuildCodeSystemPrompt()
|
||||
: null;
|
||||
var (resolvedService, _) = _llm.GetCurrentModelInfo();
|
||||
var executionMode = _chatEngine.ResolveExecutionMode(
|
||||
var preparedExecution = PrepareExecutionForConversation(
|
||||
conv,
|
||||
runTab,
|
||||
_settings.Settings.Llm.Streaming,
|
||||
resolvedService,
|
||||
coworkSystem,
|
||||
codeSystem);
|
||||
var promptStack = _chatEngine.BuildPromptStack(
|
||||
conv.SystemCommand,
|
||||
slashSystem,
|
||||
executionMode.TaskSystemPrompt);
|
||||
|
||||
sendMessages = _chatEngine
|
||||
.PrepareTurn(conv, promptStack, fileContext, outboundImages)
|
||||
.Messages;
|
||||
fileContext,
|
||||
outboundImages);
|
||||
var executionMode = preparedExecution.Mode;
|
||||
sendMessages = preparedExecution.Messages;
|
||||
|
||||
// ── 전송 전 컨텍스트 사전 압축 ──
|
||||
{
|
||||
@@ -8502,7 +8465,7 @@ public partial class ChatWindow : Window
|
||||
SetStatusIdle();
|
||||
}
|
||||
|
||||
assistantContent = BuildAssistantFallbackContent(conv, runTab, assistantContent);
|
||||
assistantContent = _chatEngine.NormalizeAssistantContent(conv, runTab, assistantContent);
|
||||
if (runTab is "Cowork" or "Code")
|
||||
conv.ShowExecutionHistory = false;
|
||||
|
||||
@@ -8596,6 +8559,34 @@ public partial class ChatWindow : Window
|
||||
}
|
||||
}
|
||||
|
||||
private AxAgentExecutionEngine.PreparedExecution PrepareExecutionForConversation(
|
||||
ChatConversation conversation,
|
||||
string runTab,
|
||||
string? slashSystem,
|
||||
string? fileContext = null,
|
||||
IReadOnlyList<ImageAttachment>? images = null)
|
||||
{
|
||||
var coworkSystem = string.Equals(runTab, "Cowork", StringComparison.OrdinalIgnoreCase)
|
||||
? BuildCoworkSystemPrompt()
|
||||
: null;
|
||||
var codeSystem = string.Equals(runTab, "Code", StringComparison.OrdinalIgnoreCase)
|
||||
? BuildCodeSystemPrompt()
|
||||
: null;
|
||||
var (resolvedService, _) = _llm.GetCurrentModelInfo();
|
||||
|
||||
return _chatEngine.PrepareExecution(
|
||||
conversation,
|
||||
runTab,
|
||||
_settings.Settings.Llm.Streaming,
|
||||
resolvedService,
|
||||
conversation.SystemCommand,
|
||||
slashSystem,
|
||||
coworkSystem,
|
||||
codeSystem,
|
||||
fileContext,
|
||||
images);
|
||||
}
|
||||
|
||||
// ─── 코워크 에이전트 지원 ────────────────────────────────────────────
|
||||
|
||||
private string BuildCoworkSystemPrompt()
|
||||
@@ -10987,27 +10978,12 @@ public partial class ChatWindow : Window
|
||||
|
||||
try
|
||||
{
|
||||
var coworkSystem = string.Equals(runTab, "Cowork", StringComparison.OrdinalIgnoreCase)
|
||||
? BuildCoworkSystemPrompt()
|
||||
: null;
|
||||
var codeSystem = string.Equals(runTab, "Code", StringComparison.OrdinalIgnoreCase)
|
||||
? BuildCodeSystemPrompt()
|
||||
: null;
|
||||
var (resolvedService, _) = _llm.GetCurrentModelInfo();
|
||||
var executionMode = _chatEngine.ResolveExecutionMode(
|
||||
runTab,
|
||||
_settings.Settings.Llm.Streaming,
|
||||
resolvedService,
|
||||
coworkSystem,
|
||||
codeSystem);
|
||||
var promptStack = _chatEngine.BuildPromptStack(
|
||||
conv.SystemCommand,
|
||||
null,
|
||||
executionMode.TaskSystemPrompt);
|
||||
|
||||
List<ChatMessage> sendMessages;
|
||||
AxAgentExecutionEngine.PreparedExecution preparedExecution;
|
||||
lock (_convLock)
|
||||
sendMessages = _chatEngine.PrepareTurn(conv, promptStack, null, null).Messages;
|
||||
preparedExecution = PrepareExecutionForConversation(conv, runTab, null);
|
||||
var executionMode = preparedExecution.Mode;
|
||||
sendMessages = preparedExecution.Messages;
|
||||
|
||||
var response = executionMode.UseAgentLoop
|
||||
? await RunAgentLoopAsync(runTab, runTab, conv, sendMessages, _streamCts.Token)
|
||||
@@ -11046,7 +11022,7 @@ public partial class ChatWindow : Window
|
||||
SetStatusIdle();
|
||||
}
|
||||
|
||||
assistantContent = BuildAssistantFallbackContent(conv, runTab, assistantContent);
|
||||
assistantContent = _chatEngine.NormalizeAssistantContent(conv, runTab, assistantContent);
|
||||
if (runTab is "Cowork" or "Code")
|
||||
conv.ShowExecutionHistory = false;
|
||||
lock (_convLock)
|
||||
|
||||
Reference in New Issue
Block a user