[Phase 17-D] 스킬 시스템 고도화 — paths:glob 자동주입 + context:fork 격리 실행

AgentLoopService.Skills.cs (신규, 95줄):
- InjectPathBasedSkills(): 파일 도구 성공 후 filePath로 GlobMatcher 매칭
  → 매칭 스킬 시스템 프롬프트를 시스템 메시지에 in-place 주입
  → SkillActivated JSONL 이벤트 로그 기록
- RunSkillInForkAsync(): context:fork 스킬 격리 LLM 실행 (도구 없음)
  → SkillCompleted JSONL 이벤트 로그 기록

SkillManagerTool.cs:
- SetForkRunner(Func<SkillDefinition, string, CancellationToken, Task<string>>) 추가
- exec 액션 + arguments 파라미터 추가
- ExecSkillAsync(): PrepareSkillBodyAsync 인자 치환
  → IsForkContext=true: fork runner 호출 → [Fork 스킬 결과] 반환
  → 일반 스킬: 시스템 프롬프트 + 준비된 본문 반환

AgentLoopService.cs:
- 생성자: SkillManagerTool.SetForkRunner(RunSkillInForkAsync) 주입

AgentLoopService.Execution.cs:
- 도구 성공 직후 InjectPathBasedSkills(result.FilePath, messages) 호출

빌드: 경고 0, 오류 0

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-04-04 00:39:25 +09:00
parent 0a58419c8a
commit 1313c65e5e
5 changed files with 225 additions and 9 deletions

View File

@@ -9,12 +9,20 @@ namespace AxCopilot.Services.Agent;
/// </summary>
public class SkillManagerTool : IAgentTool
{
// Phase 17-D: context:fork 스킬 격리 실행기 (AgentLoopService에서 주입)
private Func<SkillDefinition, string, CancellationToken, Task<string>>? _forkRunner;
/// <summary>context:fork 스킬 실행기를 주입합니다 (AgentLoopService 생성자에서 호출).</summary>
public void SetForkRunner(Func<SkillDefinition, string, CancellationToken, Task<string>> runner)
=> _forkRunner = runner;
public string Name => "skill_manager";
public string Description =>
"마크다운 기반 스킬(워크플로우)을 관리합니다.\n" +
"마크다운 기반 스킬(워크플로우)을 관리하고 실행합니다.\n" +
"- list: 사용 가능한 스킬 목록 조회\n" +
"- info: 특정 스킬의 상세 정보 확인\n" +
"- exec: 스킬 실행 (context:fork 스킬은 격리된 컨텍스트에서 실행)\n" +
"- reload: 스킬 폴더를 다시 스캔하여 새 스킬 로드";
public ToolParameterSchema Parameters => new()
@@ -24,13 +32,18 @@ public class SkillManagerTool : IAgentTool
["action"] = new ToolProperty
{
Type = "string",
Description = "list (목록), info (상세정보), reload (재로드)",
Enum = ["list", "info", "reload"]
Description = "list (목록), info (상세정보), exec (실행), reload (재로드)",
Enum = ["list", "info", "exec", "reload"]
},
["skill_name"] = new ToolProperty
{
Type = "string",
Description = "스킬 이름 (info 액션에서 사용)"
Description = "스킬 이름 (info / exec 액션에서 사용)"
},
["arguments"] = new ToolProperty
{
Type = "string",
Description = "스킬에 전달할 인자 문자열 (exec 액션에서 선택적으로 사용)"
},
},
Required = ["action"]
@@ -41,15 +54,17 @@ public class SkillManagerTool : IAgentTool
if (!(context.Llm?.EnableSkillSystem ?? true))
return ToolResult.Ok("스킬 시스템이 비활성 상태입니다. 설정 → AX Agent → 공통에서 활성화하세요.");
var action = args.TryGetProperty("action", out var a) ? a.GetString() ?? "" : "";
var action = args.TryGetProperty("action", out var a) ? a.GetString() ?? "" : "";
var skillName = args.TryGetProperty("skill_name", out var s) ? s.GetString() ?? "" : "";
var arguments = args.TryGetProperty("arguments", out var g) ? g.GetString() ?? "" : "";
return action switch
{
"list" => ListSkills(),
"info" => InfoSkill(skillName),
"list" => ListSkills(),
"info" => InfoSkill(skillName),
"exec" => await ExecSkillAsync(skillName, arguments, context, ct),
"reload" => ReloadSkills(context),
_ => ToolResult.Fail($"지원하지 않는 action: {action}. list, info, reload 중 선택하세요.")
_ => ToolResult.Fail($"지원하지 않는 action: {action}. list, info, exec, reload 중 선택하세요.")
};
}
@@ -94,4 +109,49 @@ public class SkillManagerTool : IAgentTool
SkillService.LoadSkills(customFolder);
return ToolResult.Ok($"스킬 재로드 완료. {SkillService.Skills.Count}개 로드됨.");
}
/// <summary>
/// Phase 17-D: 스킬을 실행합니다.
/// context:fork 스킬은 격리된 LLM 컨텍스트에서 실행합니다.
/// 일반 스킬은 시스템 프롬프트를 반환하여 에이전트가 컨텍스트로 활용합니다.
/// </summary>
private async Task<ToolResult> ExecSkillAsync(
string name, string arguments, AgentContext context, CancellationToken ct)
{
if (string.IsNullOrWhiteSpace(name))
return ToolResult.Fail("skill_name이 필요합니다. skill_manager(action: list)로 이름을 확인하세요.");
var skill = SkillService.Find(name);
if (skill == null)
return ToolResult.Fail($"'{name}' 스킬을 찾을 수 없습니다. skill_manager(action: list)로 목록을 확인하세요.");
if (!skill.IsAvailable)
return ToolResult.Fail($"스킬 '{skill.Label}'의 실행 환경이 충족되지 않습니다. {skill.UnavailableHint}");
// 인자 치환 + 인라인 명령 실행
var preparedBody = await SkillService.PrepareSkillBodyAsync(
skill, arguments, context.WorkFolder ?? "", ct);
// context:fork → 격리된 컨텍스트에서 실행
if (skill.IsForkContext && _forkRunner != null)
{
var forkResult = await _forkRunner(skill, preparedBody, ct);
return ToolResult.Ok($"[Fork 스킬 결과: {skill.Label}]\n\n{forkResult}");
}
// 일반 스킬 → 시스템 프롬프트 + 준비된 본문 반환 (에이전트가 컨텍스트로 사용)
var sb = new StringBuilder();
sb.AppendLine($"[스킬 '{skill.Label}' 활성화됨]");
if (!string.IsNullOrWhiteSpace(skill.SystemPrompt))
{
sb.AppendLine("\n--- 스킬 지시사항 ---");
sb.AppendLine(skill.SystemPrompt);
}
if (!string.IsNullOrWhiteSpace(preparedBody) && preparedBody != skill.SystemPrompt)
{
sb.AppendLine("\n--- 실행 내용 ---");
sb.AppendLine(preparedBody);
}
return ToolResult.Ok(sb.ToString());
}
}