/Part 5: 멀티 에이전트/에이전트 생성과 격리
🤝
Part 5고급⏱ 약 55분 · 2개 섹션

에이전트 생성과 격리

재귀적 에이전트 아키텍처

에이전트 생성과 격리 대표 이미지
이 챕터에서 배울 것
  • AgentTool은 동기/비동기/포크/원격/Worktree 모드 지원
  • 하위 에이전트에서 AgentTool 제외로 재귀 방지
  • Worktree 격리로 파일 시스템 충돌 방지
전체 아키텍처에서 현재 위치
⚙️코어 엔진
🔧도구 시스템
🛡️보안
🧠컨텍스트
🤝멀티 에이전트
🌐생태계
인프라
1

AgentTool 구현

하위 에이전트 생성과 실행 모드

에이전트 생성실행 모드스키마 합성도구 풀 필터링|tools/AgentTool/AgentTool.tsxtools/AgentTool/runAgent.ts

AgentTool은 14개 파일로 구성된 하위 에이전트 생성 도구입니다. 동기/비동기/포크/원격/Worktree 5가지 모드를 지원합니다.

src/tools/AgentTool/AgentTool.tsx:82-120
1// src/tools/AgentTool/AgentTool.tsx — 입력 스키마
2
3// 기본 스키마
4const baseInputSchema = lazySchema(() => z.object({💡
5 description: z.string()
6 .describe('A short (3-5 word) description of the task'),
7 prompt: z.string()
8 .describe('The task for the agent to perform'),
9 subagent_type: z.string().optional()
10 .describe('The type of specialized agent to use'),
11 model: z.enum(['sonnet', 'opus', 'haiku']).optional()
12 .describe("Optional model override"),
13 run_in_background: z.boolean().optional()
14 .describe('Set to true to run in the background'),
15}))
16
17// 멀티 에이전트 확장 스키마
18const fullInputSchema = lazySchema(() => {💡
19 const multiAgentSchema = z.object({
20 name: z.string().optional()
21 .describe('Makes it addressable via SendMessage'),
22 team_name: z.string().optional(),
23 mode: permissionModeSchema().optional(),
24 })
25 return baseInputSchema()💡
26 .merge(multiAgentSchema) // 스키마 합성!
27 .extend({
28 isolation: z.enum(['worktree']).optional()
29 .describe('Isolation mode'),
30 })
31})
32
33// 피처 게이트로 불필요한 필드 제거
34export const inputSchema = lazySchema(() => {💡
35 return feature('KAIROS')
36 ? fullInputSchema()
37 : fullInputSchema().omit({ cwd: true })
38})
2

에이전트 격리 수준

기본, Worktree, 원격, AsyncLocalStorage 격리

WorktreeCCR 원격AsyncLocalStorage도구 풀 제한|tools/EnterWorktreeTool/EnterWorktreeTool.tstools/ExitWorktreeTool/ExitWorktreeTool.ts

에이전트 격리에는 4가지 수준이 있습니다. 각 수준은 서로 다른 리소스 격리를 제공합니다.

에이전트 격리 수준과 도구 제한
1// 에이전트 격리 4단계
2
3// 1. 기본 격리 (같은 프로세스)
4// - 도구 풀 필터링 (AgentTool 제외 → 재귀 방지)
5// - 격리된 ToolUseContext
6// - 같은 파일 시스템 접근
7
8// 2. Worktree 격리 (별도 git worktree)
9// - createAgentWorktree() → 새 git worktree 생성
10// - 파일 시스템 충돌 방지
11// - 작업 완료 후 변경 사항 병합 또는 브랜치 반환
12
13// 3. AsyncLocalStorage 격리 (인프로세스 팀원)
14// - Node.js AsyncLocalStorage로 컨텍스트 격리
15// - 팀 기반 아이덴티티 (agentId@teamName)
16// - 비동기 메시지 큐
17
18// 4. 원격 격리 (CCR 환경) — Ant 전용
19// - 완전히 별도의 환경에서 실행
20// - JWT + 디바이스 토큰 인증
21// - 독립적인 파일 시스템/네트워크
22
23// 도구 풀 필터링 (src/constants/tools.ts)
24const ALL_AGENT_DISALLOWED_TOOLS = new Set([💡
25 'Agent', // 재귀 방지
26 'TaskOutput', // 부모만 사용
27 'ExitPlanMode', // 부모만 사용
28 'TaskStop', // 부모만 사용
29])
30
31const ASYNC_AGENT_ALLOWED_TOOLS = new Set([💡
32 'Bash', 'FileRead', 'FileEdit', 'FileWrite',
33 'Glob', 'Grep', 'WebFetch', 'WebSearch',
34 'NotebookEdit', 'TodoWrite', 'AskUserQuestion',
35 // Agent 제외 → 비동기 에이전트는 하위 에이전트 생성 불가
36])