동적 서브에이전트
동적 서브에이전트 (Dynamic subagents)
인터프리터를 사용해 코드에서 Deep Agents 서브에이전트를 파견하고 오케스트레이션하세요
동적 서브에이전트는 에이전트가 인터프리터 코드에서 서브에이전트를 파견할 수 있게 해줍니다. 모델에게 한 번에 하나의 서브에이전트 호출을 선택하라고 하는 대신, 에이전트는 JavaScript 루프, 분기, 병렬 배치를 사용해 작업을 구성된 서브에이전트들에 걸쳐 라우팅하고 결과를 종합할 수 있습니다.
작업이 많은 독립적인 단위에 걸쳐 있거나, 여러 관점이 필요하거나, 재귀적 분석이 유리할 때 이 패턴을 사용하세요. 일반적인 인터프리터 설정은 인터프리터를 참고하세요.
퀵스타트 (Quickstart)
동적 서브에이전트는 인터프리터 미들웨어가 필요합니다. 먼저 인터프리터를 설치하고 연결하세요. 기본 제공 범용(general-purpose) 서브에이전트는 추가 설정 없이 기본적인 팬아웃을 처리합니다.
const agent = createDeepAgent({ model: "google-genai:gemini-3.6-flash", subagents: [{ name: "reviewer", description: "Reviews code for security issues, citing lines and severity", systemPrompt: "You are a security-focused code reviewer. Report issues with line numbers and severity.", }], middleware: [createCodeInterpreterMiddleware()], });
```ts OpenAI theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
import { createDeepAgent } from "deepagents";
import { createCodeInterpreterMiddleware } from "@langchain/quickjs";
const agent = createDeepAgent({
model: "openai:gpt-5.5",
subagents: [{
name: "reviewer",
description: "Reviews code for security issues, citing lines and severity",
systemPrompt: "You are a security-focused code reviewer. Report issues with line numbers and severity.",
}],
middleware: [createCodeInterpreterMiddleware()],
});
import { createDeepAgent } from "deepagents";
import { createCodeInterpreterMiddleware } from "@langchain/quickjs";
const agent = createDeepAgent({
model: "anthropic:claude-sonnet-5",
subagents: [{
name: "reviewer",
description: "Reviews code for security issues, citing lines and severity",
systemPrompt: "You are a security-focused code reviewer. Report issues with line numbers and severity.",
}],
middleware: [createCodeInterpreterMiddleware()],
});
import { createDeepAgent } from "deepagents";
import { createCodeInterpreterMiddleware } from "@langchain/quickjs";
const agent = createDeepAgent({
model: "openrouter:z-ai/glm-5.2",
subagents: [{
name: "reviewer",
description: "Reviews code for security issues, citing lines and severity",
systemPrompt: "You are a security-focused code reviewer. Report issues with line numbers and severity.",
}],
middleware: [createCodeInterpreterMiddleware()],
});
import { createDeepAgent } from "deepagents";
import { createCodeInterpreterMiddleware } from "@langchain/quickjs";
const agent = createDeepAgent({
model: "fireworks:accounts/fireworks/models/glm-5p2",
subagents: [{
name: "reviewer",
description: "Reviews code for security issues, citing lines and severity",
systemPrompt: "You are a security-focused code reviewer. Report issues with line numbers and severity.",
}],
middleware: [createCodeInterpreterMiddleware()],
});
import { createDeepAgent } from "deepagents";
import { createCodeInterpreterMiddleware } from "@langchain/quickjs";
const agent = createDeepAgent({
model: "baseten:zai-org/GLM-5.2",
subagents: [{
name: "reviewer",
description: "Reviews code for security issues, citing lines and severity",
systemPrompt: "You are a security-focused code reviewer. Report issues with line numbers and severity.",
}],
middleware: [createCodeInterpreterMiddleware()],
});
import { createDeepAgent } from "deepagents";
import { createCodeInterpreterMiddleware } from "@langchain/quickjs";
const agent = createDeepAgent({
model: "ollama:north-mini-code-1.0",
subagents: [{
name: "reviewer",
description: "Reviews code for security issues, citing lines and severity",
systemPrompt: "You are a security-focused code reviewer. Report issues with line numbers and severity.",
}],
middleware: [createCodeInterpreterMiddleware()],
});
설치 단계와 인터프리터 설정은 인터프리터를 참고하세요.
전문적인 작업을 위해 고유한 이름, 설명, 시스템 프롬프트를 가진 커스텀 서브에이전트를 구성하세요. 서브에이전트의 이름과 설명은 에이전트가 어떤 역할을 선택할지 평가하는 데 쓰이는 정보 역할을 합니다.
동적 서브에이전트를 트리거하려면 에이전트에게 "workflow"라는 단어로 프롬프트하세요:
const result = await agent.invoke({
messages: [{ role: "user", content: "Run a workflow that reviews every file in src/routes/ and summarizes the top risks." }],
});
작동 방식 (How it works)
에이전트에 서브에이전트와 인터프리터 미들웨어가 있으면, 인터프리터는 코드에서 서브에이전트를 파견하는 내장 task() 전역을 노출합니다. 많은 독립적인 단위에 걸친 작업(디렉터리의 모든 파일 검토, 티켓 배치 트라이지)은 작업을 팬아웃하는 루프가 되어, 모델이 선택한 도구 호출을 한 번에 하나씩 처리하는 대신 결정적으로 실행됩니다.
서브에이전트 오케스트레이션은 Recursive Language Models 논문에서 설명한 접근 방식인 재귀 언어 모델(RLM) 워크플로우도 지원합니다: 작업 집합을 인터프리터 변수에 유지하고, 슬라이스를 선택하고, task()로 서브에이전트를 호출하고, 결과를 종합하세요.
많은 오케스트레이션 워크플로우는 동적 서브에이전트를 프로그래매틱 도구 호출(PTC)과 결합합니다: 인터프리터 코드에서 tools.*를 사용해 입력을 발견하거나 필터링한 다음, task()로 서브에이전트를 파견하세요. PTC는 기본적으로 꺼져 있으므로 인터프리터 미들웨어에서 명시적 allowlist로 활성화해야 합니다.
task()는 도구의 PTC와 유사한, 서브에이전트 실행으로의 기능 브리지입니다. 격리 기본값, 승인 경계, 미들웨어 옵션은 보안과 구성을 참고하세요.
task()는 다음 입력을 받습니다:
description: 서브에이전트에 대한 프롬프트subagentType: 실행할 구성된 서브에이전트responseSchema(선택): 구조화된 출력
task()는 전체 에이전트 루프를 실행하고 서브에이전트의 결과로 resolve됩니다:
const review = await task({
description: "Review src/auth/login.ts for auth issues. Cite line numbers.",
subagentType: "reviewer",
responseSchema: {
type: "object",
properties: {
issues: { type: "array", items: { type: "object", properties: {
file: { type: "string" }, line: { type: "number" },
severity: { type: "string" }, description: { type: "string" },
}}},
},
},
});
// With responseSchema, the result is already a typed value, so no JSON.parse is needed.
const critical = review.issues.filter((issue) => issue.severity === "high");
responseSchema를 전달하면 resolve된 값은 이미 타입이 지정된 JavaScript 객체입니다. 서브에이전트가 의도적으로 JSON 문자열을 반환한 경우에만 JSON.parse를 호출하세요.
패턴 (Patterns)
에이전트는 작업의 형태에서 전략을 고릅니다. 이는 설정이 아니라 에이전트가 인터프리터 코드를 작성하는 방식에서 나오며, 여러분이 제공하는 서브에이전트가 무엇을 할 수 있는지를 결정합니다. 모든 패턴은 동일한 오케스트레이션 접근 방식을 공유합니다: 작업을 JS 변수에 유지하고, task()로 서브에이전트를 파견하고, 코드에서 결과를 결합합니다. 아래 다이어그램은 공통된 형태를 보여주며, 각각 실행 가능한 예제가 함께 제공됩니다.
분류 후 실행 (Classify and act)
항목을 먼저 분류한 다음, 각 항목을 분류 결과에 따라 전문 서브에이전트가 처리합니다. 서로 다른 전문성이 필요한 혼합 입력을 처리할 수 있게 해줍니다.
graph LR
Task[Task] --> Classify{Classifier}
Classify --> |bug| A[Agent A]
Classify --> |feature| B[Agent B]
Classify --> |question| C[Agent C]
사용 사례: 지원 티켓, 오류 로그, 사용자 피드백 트라이지, 또는 유형에 따라 서로 다른 처리가 필요한 항목 배치.
const agent = createDeepAgent({
model: "google-genai:gemini-3.6-flash",
subagents: [
{
name: "bug-fixer",
description: "Investigates bug reports and provides reproduction steps",
systemPrompt: "You are a bug triage specialist. Investigate each bug report and provide clear reproduction steps.",
},
{
name: "feature-analyst",
description: "Evaluates feature requests for feasibility and effort",
systemPrompt: "You are a product analyst. Evaluate each feature request for technical feasibility, estimated effort, and potential impact.",
},
{
name: "support-agent",
description: "Answers user questions based on documentation",
systemPrompt: "You are a support specialist. Answer user questions clearly based on the available documentation.",
},
],
middleware: [createCodeInterpreterMiddleware()],
});
```
```ts OpenAI theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
import { createDeepAgent } from "deepagents";
import { createCodeInterpreterMiddleware } from "@langchain/quickjs";
const agent = createDeepAgent({
model: "openai:gpt-5.5",
subagents: [
{
name: "bug-fixer",
description: "Investigates bug reports and provides reproduction steps",
systemPrompt: "You are a bug triage specialist. Investigate each bug report and provide clear reproduction steps.",
},
{
name: "feature-analyst",
description: "Evaluates feature requests for feasibility and effort",
systemPrompt: "You are a product analyst. Evaluate each feature request for technical feasibility, estimated effort, and potential impact.",
},
{
name: "support-agent",
description: "Answers user questions based on documentation",
systemPrompt: "You are a support specialist. Answer user questions clearly based on the available documentation.",
},
],
middleware: [createCodeInterpreterMiddleware()],
});
```
```ts Anthropic theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
import { createDeepAgent } from "deepagents";
import { createCodeInterpreterMiddleware } from "@langchain/quickjs";
const agent = createDeepAgent({
model: "anthropic:claude-sonnet-5",
subagents: [
{
name: "bug-fixer",
description: "Investigates bug reports and provides reproduction steps",
systemPrompt: "You are a bug triage specialist. Investigate each bug report and provide clear reproduction steps.",
},
{
name: "feature-analyst",
description: "Evaluates feature requests for feasibility and effort",
systemPrompt: "You are a product analyst. Evaluate each feature request for technical feasibility, estimated effort, and potential impact.",
},
{
name: "support-agent",
description: "Answers user questions based on documentation",
systemPrompt: "You are a support specialist. Answer user questions clearly based on the available documentation.",
},
],
middleware: [createCodeInterpreterMiddleware()],
});
```
```ts OpenRouter theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
import { createDeepAgent } from "deepagents";
import { createCodeInterpreterMiddleware } from "@langchain/quickjs";
const agent = createDeepAgent({
model: "openrouter:z-ai/glm-5.2",
subagents: [
{
name: "bug-fixer",
description: "Investigates bug reports and provides reproduction steps",
systemPrompt: "You are a bug triage specialist. Investigate each bug report and provide clear reproduction steps.",
},
{
name: "feature-analyst",
description: "Evaluates feature requests for feasibility and effort",
systemPrompt: "You are a product analyst. Evaluate each feature request for technical feasibility, estimated effort, and potential impact.",
},
{
name: "support-agent",
description: "Answers user questions based on documentation",
systemPrompt: "You are a support specialist. Answer user questions clearly based on the available documentation.",
},
],
middleware: [createCodeInterpreterMiddleware()],
});
```
```ts Fireworks theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
import { createDeepAgent } from "deepagents";
import { createCodeInterpreterMiddleware } from "@langchain/quickjs";
const agent = createDeepAgent({
model: "fireworks:accounts/fireworks/models/glm-5p2",
subagents: [
{
name: "bug-fixer",
description: "Investigates bug reports and provides reproduction steps",
systemPrompt: "You are a bug triage specialist. Investigate each bug report and provide clear reproduction steps.",
},
{
name: "feature-analyst",
description: "Evaluates feature requests for feasibility and effort",
systemPrompt: "You are a product analyst. Evaluate each feature request for technical feasibility, estimated effort, and potential impact.",
},
{
name: "support-agent",
description: "Answers user questions based on documentation",
systemPrompt: "You are a support specialist. Answer user questions clearly based on the available documentation.",
},
],
middleware: [createCodeInterpreterMiddleware()],
});
```
```ts Baseten theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
import { createDeepAgent } from "deepagents";
import { createCodeInterpreterMiddleware } from "@langchain/quickjs";
const agent = createDeepAgent({
model: "baseten:zai-org/GLM-5.2",
subagents: [
{
name: "bug-fixer",
description: "Investigates bug reports and provides reproduction steps",
systemPrompt: "You are a bug triage specialist. Investigate each bug report and provide clear reproduction steps.",
},
{
name: "feature-analyst",
description: "Evaluates feature requests for feasibility and effort",
systemPrompt: "You are a product analyst. Evaluate each feature request for technical feasibility, estimated effort, and potential impact.",
},
{
name: "support-agent",
description: "Answers user questions based on documentation",
systemPrompt: "You are a support specialist. Answer user questions clearly based on the available documentation.",
},
],
middleware: [createCodeInterpreterMiddleware()],
});
```
```ts Ollama theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
import { createDeepAgent } from "deepagents";
import { createCodeInterpreterMiddleware } from "@langchain/quickjs";
const agent = createDeepAgent({
model: "ollama:north-mini-code-1.0",
subagents: [
{
name: "bug-fixer",
description: "Investigates bug reports and provides reproduction steps",
systemPrompt: "You are a bug triage specialist. Investigate each bug report and provide clear reproduction steps.",
},
{
name: "feature-analyst",
description: "Evaluates feature requests for feasibility and effort",
systemPrompt: "You are a product analyst. Evaluate each feature request for technical feasibility, estimated effort, and potential impact.",
},
{
name: "support-agent",
description: "Answers user questions based on documentation",
systemPrompt: "You are a support specialist. Answer user questions clearly based on the available documentation.",
},
],
middleware: [createCodeInterpreterMiddleware()],
});
```
에이전트가 작성하는 것 (What the agent writes)
// The agent has already classified each ticket; this routes every item to
// the right specialist and collects the handled results.
const SPECIALIST = { bug: "bug-fixer", feature: "feature-analyst", question: "support-agent" };
const handled = await Promise.all(
tickets.map((ticket) =>
task({
description: `Handle this ${ticket.category}:\n${ticket.text}`,
subagentType: SPECIALIST[ticket.category],
}),
),
);
// ... group handled results by category into a single triage report
handled;
팬아웃 후 종합 (Fan-out and synthesize)
에이전트는 동일한 종류의 작업을 많은 항목에 걸쳐 병렬로 파견한 다음 결과를 결합합니다.
graph LR
Items[Items] --> W1[Worker]
Items --> W2[Worker]
Items --> W3[Worker]
W1 --> Collect[Collect]
W2 --> Collect
W3 --> Collect
Collect --> Synth[Synthesize]
사용 사례: 디렉터리에 걸친 코드 리뷰, 문서 배치 분석, 로그 파일 처리, 여러 서비스에 걸친 동일 검사 실행.
인터프리터 코드에서 파일을 발견하려면 프로그래매틱 도구 호출(PTC)이 필요합니다. 인터프리터 미들웨어의 PTC allowlist에서 glob을 활성화하세요.
const agent = createDeepAgent({
model: "google-genai:gemini-3.6-flash",
subagents: [{
name: "reviewer",
description: "Reviews code for security issues, citing lines and severity",
systemPrompt: "You are a security-focused code reviewer. Read the file carefully and report any authentication or authorization issues with line numbers and severity.",
}],
middleware: [createCodeInterpreterMiddleware({ ptc: ["glob"] })],
});
```
```ts OpenAI theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
import { createDeepAgent } from "deepagents";
import { createCodeInterpreterMiddleware } from "@langchain/quickjs";
const agent = createDeepAgent({
model: "openai:gpt-5.5",
subagents: [{
name: "reviewer",
description: "Reviews code for security issues, citing lines and severity",
systemPrompt: "You are a security-focused code reviewer. Read the file carefully and report any authentication or authorization issues with line numbers and severity.",
}],
middleware: [createCodeInterpreterMiddleware({ ptc: ["glob"] })],
});
```
```ts Anthropic theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
import { createDeepAgent } from "deepagents";
import { createCodeInterpreterMiddleware } from "@langchain/quickjs";
const agent = createDeepAgent({
model: "anthropic:claude-sonnet-5",
subagents: [{
name: "reviewer",
description: "Reviews code for security issues, citing lines and severity",
systemPrompt: "You are a security-focused code reviewer. Read the file carefully and report any authentication or authorization issues with line numbers and severity.",
}],
middleware: [createCodeInterpreterMiddleware({ ptc: ["glob"] })],
});
```
```ts OpenRouter theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
import { createDeepAgent } from "deepagents";
import { createCodeInterpreterMiddleware } from "@langchain/quickjs";
const agent = createDeepAgent({
model: "openrouter:z-ai/glm-5.2",
subagents: [{
name: "reviewer",
description: "Reviews code for security issues, citing lines and severity",
systemPrompt: "You are a security-focused code reviewer. Read the file carefully and report any authentication or authorization issues with line numbers and severity.",
}],
middleware: [createCodeInterpreterMiddleware({ ptc: ["glob"] })],
});
```
```ts Fireworks theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
import { createDeepAgent } from "deepagents";
import { createCodeInterpreterMiddleware } from "@langchain/quickjs";
const agent = createDeepAgent({
model: "fireworks:accounts/fireworks/models/glm-5p2",
subagents: [{
name: "reviewer",
description: "Reviews code for security issues, citing lines and severity",
systemPrompt: "You are a security-focused code reviewer. Read the file carefully and report any authentication or authorization issues with line numbers and severity.",
}],
middleware: [createCodeInterpreterMiddleware({ ptc: ["glob"] })],
});
```
```ts Baseten theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
import { createDeepAgent } from "deepagents";
import { createCodeInterpreterMiddleware } from "@langchain/quickjs";
const agent = createDeepAgent({
model: "baseten:zai-org/GLM-5.2",
subagents: [{
name: "reviewer",
description: "Reviews code for security issues, citing lines and severity",
systemPrompt: "You are a security-focused code reviewer. Read the file carefully and report any authentication or authorization issues with line numbers and severity.",
}],
middleware: [createCodeInterpreterMiddleware({ ptc: ["glob"] })],
});
```
```ts Ollama theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
import { createDeepAgent } from "deepagents";
import { createCodeInterpreterMiddleware } from "@langchain/quickjs";
const agent = createDeepAgent({
model: "ollama:north-mini-code-1.0",
subagents: [{
name: "reviewer",
description: "Reviews code for security issues, citing lines and severity",
systemPrompt: "You are a security-focused code reviewer. Read the file carefully and report any authentication or authorization issues with line numbers and severity.",
}],
middleware: [createCodeInterpreterMiddleware({ ptc: ["glob"] })],
});
```
에이전트가 작성하는 것 (What the agent writes)
// One reviewer per file, dispatched in parallel, then findings merged.
const files = (await tools.glob({ pattern: "src/routes/**/*.ts" }))
.split("\n")
.filter(Boolean);
const reviews = await Promise.all(
files.map((file) =>
task({
description: `Review ${file} for authentication issues. Cite line numbers.`,
subagentType: "reviewer",
responseSchema: issuesSchema, // -> { issues: [{ file, line, severity }] }
}),
),
);
const issues = reviews.flatMap((r) => r.issues);
// ... sort by severity, drop duplicates, summarize the top risks
issues;
적대적 검증 (Adversarial verification)
2패스 패턴입니다. 첫 번째 패스는 결과를 만들어냅니다. 두 번째 패스는 각 결과를 독립적인 검증자에게 보내며, 합의에 도달한 결과만 유지됩니다. 속도보다 신뢰도가 중요할 때 거짓 긍정을 줄여줍니다.
graph LR
Items[Items] --> Workers[Workers]
Workers --> Findings[Findings]
Findings --> V1[Verifier]
Findings --> V2[Verifier]
Findings --> V3[Verifier]
V1 --> Vote[Majority vote]
V2 --> Vote
V3 --> Vote
Vote --> Confirmed[Confirmed]
사용 사례: 거짓 긍정 비용이 큰 보안 감사, 규정 준수 검사, 결과에 높은 신뢰도가 필요한 모든 검토.
const agent = createDeepAgent({
model: "google-genai:gemini-3.6-flash",
subagents: [
{
name: "reviewer",
description: "Finds potential security vulnerabilities in code",
systemPrompt: "You are a security auditor. Find potential vulnerabilities and report each with file, line, and description.",
},
{
name: "verifier",
description: "Independently verifies whether a reported vulnerability is real",
systemPrompt: "You are a security verification specialist. Given a reported vulnerability, independently verify whether it is exploitable. Be skeptical. Only confirm real issues.",
},
],
middleware: [createCodeInterpreterMiddleware()],
});
```
```ts OpenAI theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
import { createDeepAgent } from "deepagents";
import { createCodeInterpreterMiddleware } from "@langchain/quickjs";
const agent = createDeepAgent({
model: "openai:gpt-5.5",
subagents: [
{
name: "reviewer",
description: "Finds potential security vulnerabilities in code",
systemPrompt: "You are a security auditor. Find potential vulnerabilities and report each with file, line, and description.",
},
{
name: "verifier",
description: "Independently verifies whether a reported vulnerability is real",
systemPrompt: "You are a security verification specialist. Given a reported vulnerability, independently verify whether it is exploitable. Be skeptical. Only confirm real issues.",
},
],
middleware: [createCodeInterpreterMiddleware()],
});
```
```ts Anthropic theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
import { createDeepAgent } from "deepagents";
import { createCodeInterpreterMiddleware } from "@langchain/quickjs";
const agent = createDeepAgent({
model: "anthropic:claude-sonnet-5",
subagents: [
{
name: "reviewer",
description: "Finds potential security vulnerabilities in code",
systemPrompt: "You are a security auditor. Find potential vulnerabilities and report each with file, line, and description.",
},
{
name: "verifier",
description: "Independently verifies whether a reported vulnerability is real",
systemPrompt: "You are a security verification specialist. Given a reported vulnerability, independently verify whether it is exploitable. Be skeptical. Only confirm real issues.",
},
],
middleware: [createCodeInterpreterMiddleware()],
});
```
```ts OpenRouter theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
import { createDeepAgent } from "deepagents";
import { createCodeInterpreterMiddleware } from "@langchain/quickjs";
const agent = createDeepAgent({
model: "openrouter:z-ai/glm-5.2",
subagents: [
{
name: "reviewer",
description: "Finds potential security vulnerabilities in code",
systemPrompt: "You are a security auditor. Find potential vulnerabilities and report each with file, line, and description.",
},
{
name: "verifier",
description: "Independently verifies whether a reported vulnerability is real",
systemPrompt: "You are a security verification specialist. Given a reported vulnerability, independently verify whether it is exploitable. Be skeptical. Only confirm real issues.",
},
],
middleware: [createCodeInterpreterMiddleware()],
});
```
```ts Fireworks theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
import { createDeepAgent } from "deepagents";
import { createCodeInterpreterMiddleware } from "@langchain/quickjs";
const agent = createDeepAgent({
model: "fireworks:accounts/fireworks/models/glm-5p2",
subagents: [
{
name: "reviewer",
description: "Finds potential security vulnerabilities in code",
systemPrompt: "You are a security auditor. Find potential vulnerabilities and report each with file, line, and description.",
},
{
name: "verifier",
description: "Independently verifies whether a reported vulnerability is real",
systemPrompt: "You are a security verification specialist. Given a reported vulnerability, independently verify whether it is exploitable. Be skeptical. Only confirm real issues.",
},
],
middleware: [createCodeInterpreterMiddleware()],
});
```
```ts Baseten theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
import { createDeepAgent } from "deepagents";
import { createCodeInterpreterMiddleware } from "@langchain/quickjs";
const agent = createDeepAgent({
model: "baseten:zai-org/GLM-5.2",
subagents: [
{
name: "reviewer",
description: "Finds potential security vulnerabilities in code",
systemPrompt: "You are a security auditor. Find potential vulnerabilities and report each with file, line, and description.",
},
{
name: "verifier",
description: "Independently verifies whether a reported vulnerability is real",
systemPrompt: "You are a security verification specialist. Given a reported vulnerability, independently verify whether it is exploitable. Be skeptical. Only confirm real issues.",
},
],
middleware: [createCodeInterpreterMiddleware()],
});
```
```ts Ollama theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
import { createDeepAgent } from "deepagents";
import { createCodeInterpreterMiddleware } from "@langchain/quickjs";
const agent = createDeepAgent({
model: "ollama:north-mini-code-1.0",
subagents: [
{
name: "reviewer",
description: "Finds potential security vulnerabilities in code",
systemPrompt: "You are a security auditor. Find potential vulnerabilities and report each with file, line, and description.",
},
{
name: "verifier",
description: "Independently verifies whether a reported vulnerability is real",
systemPrompt: "You are a security verification specialist. Given a reported vulnerability, independently verify whether it is exploitable. Be skeptical. Only confirm real issues.",
},
],
middleware: [createCodeInterpreterMiddleware()],
});
```
에이전트가 작성하는 것 (What the agent writes)
// Pass 1: audit. Pass 2: verify each finding independently; keep only confirmed.
const { findings } = await task({
description: "Audit the payments module for vulnerabilities.",
subagentType: "reviewer",
responseSchema: findingsSchema, // -> { findings: [{ id, file, line, description }] }
});
const verdicts = await Promise.all(
findings.map((f) =>
task({
description: `Verify ${f.file}:${f.line} (${f.description}). Confirm or refute.`,
subagentType: "verifier",
responseSchema: verdictSchema, // -> { confirmed: boolean }
}),
),
);
const confirmed = findings.filter((_, i) => verdicts[i]?.confirmed);
// ... report only the confirmed vulnerabilities
confirmed;
생성 후 필터링 (Generate and filter)
여러 서브에이전트가 같은 문제에 대한 독립적인 해결책을 생성합니다. 에이전트는 코드에서 결과를 비교·점수화·필터링하여 최상의 것만 유지합니다.
graph LR
Prompt[Prompt] --> G1[Generator]
Prompt --> G2[Generator]
Prompt --> G3[Generator]
G1 --> Filter[Filter + rank]
G2 --> Filter
G3 --> Filter
Filter --> Best[Best result]
사용 사례: 아키텍처 제안, 리팩토링 전략, 콘텐츠 변형, 결정을 내리기 전에 여러 옵션을 탐색하면 더 나은 결과가 나오는 모든 작업.
const agent = createDeepAgent({
model: "google-genai:gemini-3.6-flash",
subagents: [{
name: "architect",
description: "Proposes a database schema design with tradeoff analysis",
systemPrompt: "You are a database architect. Propose a schema design for the given requirements. Include tradeoffs, migration considerations, and a clear rationale.",
}],
middleware: [createCodeInterpreterMiddleware()],
});
```
```ts OpenAI theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
import { createDeepAgent } from "deepagents";
import { createCodeInterpreterMiddleware } from "@langchain/quickjs";
const agent = createDeepAgent({
model: "openai:gpt-5.5",
subagents: [{
name: "architect",
description: "Proposes a database schema design with tradeoff analysis",
systemPrompt: "You are a database architect. Propose a schema design for the given requirements. Include tradeoffs, migration considerations, and a clear rationale.",
}],
middleware: [createCodeInterpreterMiddleware()],
});
```
```ts Anthropic theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
import { createDeepAgent } from "deepagents";
import { createCodeInterpreterMiddleware } from "@langchain/quickjs";
const agent = createDeepAgent({
model: "anthropic:claude-sonnet-5",
subagents: [{
name: "architect",
description: "Proposes a database schema design with tradeoff analysis",
systemPrompt: "You are a database architect. Propose a schema design for the given requirements. Include tradeoffs, migration considerations, and a clear rationale.",
}],
middleware: [createCodeInterpreterMiddleware()],
});
```
```ts OpenRouter theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
import { createDeepAgent } from "deepagents";
import { createCodeInterpreterMiddleware } from "@langchain/quickjs";
const agent = createDeepAgent({
model: "openrouter:z-ai/glm-5.2",
subagents: [{
name: "architect",
description: "Proposes a database schema design with tradeoff analysis",
systemPrompt: "You are a database architect. Propose a schema design for the given requirements. Include tradeoffs, migration considerations, and a clear rationale.",
}],
middleware: [createCodeInterpreterMiddleware()],
});
```
```ts Fireworks theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
import { createDeepAgent } from "deepagents";
import { createCodeInterpreterMiddleware } from "@langchain/quickjs";
const agent = createDeepAgent({
model: "fireworks:accounts/fireworks/models/glm-5p2",
subagents: [{
name: "architect",
description: "Proposes a database schema design with tradeoff analysis",
systemPrompt: "You are a database architect. Propose a schema design for the given requirements. Include tradeoffs, migration considerations, and a clear rationale.",
}],
middleware: [createCodeInterpreterMiddleware()],
});
```
```ts Baseten theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
import { createDeepAgent } from "deepagents";
import { createCodeInterpreterMiddleware } from "@langchain/quickjs";
const agent = createDeepAgent({
model: "baseten:zai-org/GLM-5.2",
subagents: [{
name: "architect",
description: "Proposes a database schema design with tradeoff analysis",
systemPrompt: "You are a database architect. Propose a schema design for the given requirements. Include tradeoffs, migration considerations, and a clear rationale.",
}],
middleware: [createCodeInterpreterMiddleware()],
});
```
```ts Ollama theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
import { createDeepAgent } from "deepagents";
import { createCodeInterpreterMiddleware } from "@langchain/quickjs";
const agent = createDeepAgent({
model: "ollama:north-mini-code-1.0",
subagents: [{
name: "architect",
description: "Proposes a database schema design with tradeoff analysis",
systemPrompt: "You are a database architect. Propose a schema design for the given requirements. Include tradeoffs, migration considerations, and a clear rationale.",
}],
middleware: [createCodeInterpreterMiddleware()],
});
```
에이전트가 작성하는 것 (What the agent writes)
// Generate independent proposals in parallel, then score and keep the best.
const proposals = await Promise.all(
[1, 2, 3].map((n) =>
task({
description: `Approach ${n}: redesign the orders schema, with tradeoffs.`,
subagentType: "architect",
responseSchema: designSchema, // -> { design, tradeoffs }
}),
),
);
// ... score each proposal against the requirements
const best = proposals.sort((a, b) => score(b) - score(a))[0];
best;
토너먼트 (Tournament)
변형을 심판(judge) 서브에이전트가 1:1로 비교하며, 승자가 토너먼트 식 제거 라운드를 거쳐 전진합니다.
graph LR
A1[Attempt] --> J1{Judge}
A2[Attempt] --> J1
A3[Attempt] --> J2{Judge}
A4[Attempt] --> J2
J1 --> JF{Final}
J2 --> JF
JF --> Winner[Winner]
사용 사례: 주관적 기준 하의 최적화, 스타일 선택, 경쟁 구현 간 선택.
const agent = createDeepAgent({
model: "google-genai:gemini-3.6-flash",
subagents: [
{
name: "writer",
description: "Rewrites a function with a focus on readability and clarity",
systemPrompt: "You are an expert programmer focused on clean code. Rewrite the given function to maximize readability. Explain your choices.",
},
{
name: "judge",
description: "Compares two code implementations and picks the more readable one",
systemPrompt: "You are a code quality judge. Compare two implementations and pick the more readable one. Justify your choice with specific criteria.",
},
],
middleware: [createCodeInterpreterMiddleware()],
});
```
```ts OpenAI theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
import { createDeepAgent } from "deepagents";
import { createCodeInterpreterMiddleware } from "@langchain/quickjs";
const agent = createDeepAgent({
model: "openai:gpt-5.5",
subagents: [
{
name: "writer",
description: "Rewrites a function with a focus on readability and clarity",
systemPrompt: "You are an expert programmer focused on clean code. Rewrite the given function to maximize readability. Explain your choices.",
},
{
name: "judge",
description: "Compares two code implementations and picks the more readable one",
systemPrompt: "You are a code quality judge. Compare two implementations and pick the more readable one. Justify your choice with specific criteria.",
},
],
middleware: [createCodeInterpreterMiddleware()],
});
```
```ts Anthropic theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
import { createDeepAgent } from "deepagents";
import { createCodeInterpreterMiddleware } from "@langchain/quickjs";
const agent = createDeepAgent({
model: "anthropic:claude-sonnet-5",
subagents: [
{
name: "writer",
description: "Rewrites a function with a focus on readability and clarity",
systemPrompt: "You are an expert programmer focused on clean code. Rewrite the given function to maximize readability. Explain your choices.",
},
{
name: "judge",
description: "Compares two code implementations and picks the more readable one",
systemPrompt: "You are a code quality judge. Compare two implementations and pick the more readable one. Justify your choice with specific criteria.",
},
],
middleware: [createCodeInterpreterMiddleware()],
});
```
```ts OpenRouter theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
import { createDeepAgent } from "deepagents";
import { createCodeInterpreterMiddleware } from "@langchain/quickjs";
const agent = createDeepAgent({
model: "openrouter:z-ai/glm-5.2",
subagents: [
{
name: "writer",
description: "Rewrites a function with a focus on readability and clarity",
systemPrompt: "You are an expert programmer focused on clean code. Rewrite the given function to maximize readability. Explain your choices.",
},
{
name: "judge",
description: "Compares two code implementations and picks the more readable one",
systemPrompt: "You are a code quality judge. Compare two implementations and pick the more readable one. Justify your choice with specific criteria.",
},
],
middleware: [createCodeInterpreterMiddleware()],
});
```
```ts Fireworks theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
import { createDeepAgent } from "deepagents";
import { createCodeInterpreterMiddleware } from "@langchain/quickjs";
const agent = createDeepAgent({
model: "fireworks:accounts/fireworks/models/glm-5p2",
subagents: [
{
name: "writer",
description: "Rewrites a function with a focus on readability and clarity",
systemPrompt: "You are an expert programmer focused on clean code. Rewrite the given function to maximize readability. Explain your choices.",
},
{
name: "judge",
description: "Compares two code implementations and picks the more readable one",
systemPrompt: "You are a code quality judge. Compare two implementations and pick the more readable one. Justify your choice with specific criteria.",
},
],
middleware: [createCodeInterpreterMiddleware()],
});
```
```ts Baseten theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
import { createDeepAgent } from "deepagents";
import { createCodeInterpreterMiddleware } from "@langchain/quickjs";
const agent = createDeepAgent({
model: "baseten:zai-org/GLM-5.2",
subagents: [
{
name: "writer",
description: "Rewrites a function with a focus on readability and clarity",
systemPrompt: "You are an expert programmer focused on clean code. Rewrite the given function to maximize readability. Explain your choices.",
},
{
name: "judge",
description: "Compares two code implementations and picks the more readable one",
systemPrompt: "You are a code quality judge. Compare two implementations and pick the more readable one. Justify your choice with specific criteria.",
},
],
middleware: [createCodeInterpreterMiddleware()],
});
```
```ts Ollama theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
import { createDeepAgent } from "deepagents";
import { createCodeInterpreterMiddleware } from "@langchain/quickjs";
const agent = createDeepAgent({
model: "ollama:north-mini-code-1.0",
subagents: [
{
name: "writer",
description: "Rewrites a function with a focus on readability and clarity",
systemPrompt: "You are an expert programmer focused on clean code. Rewrite the given function to maximize readability. Explain your choices.",
},
{
name: "judge",
description: "Compares two code implementations and picks the more readable one",
systemPrompt: "You are a code quality judge. Compare two implementations and pick the more readable one. Justify your choice with specific criteria.",
},
],
middleware: [createCodeInterpreterMiddleware()],
});
```
에이전트가 작성하는 것 (What the agent writes)
// Generate variants, then judge pairwise until a single winner remains.
let bracket = await Promise.all(
[1, 2, 3, 4, 5].map((n) =>
task({ description: `Rewrite processOrder for readability (variant ${n}).`, subagentType: "writer" }),
),
);
while (bracket.length > 1) {
const winners = [];
for (let i = 0; i < bracket.length; i += 2) {
if (bracket[i + 1] === undefined) { winners.push(bracket[i]); break; }
const { winner } = await task({
description: `Pick the more readable:\n\nA:\n${bracket[i]}\n\nB:\n${bracket[i + 1]}`,
subagentType: "judge",
responseSchema: pickSchema, // -> { winner: "A" | "B" }
});
winners.push(winner === "A" ? bracket[i] : bracket[i + 1]);
}
bracket = winners;
}
bracket[0]; // the winning rewrite
완료될 때까지 반복 (Loop until done)
에이전트는 이미 찾은 것에 대해 중복을 제거하면서 새로운 결과가 나오지 않을 때까지 발견 루프를 실행합니다. 작업 범위가 사전에 알려지지 않았을 때 유용합니다.
graph LR
Agent[Agent] --> Check{New findings?}
Check --> |yes| Agent
Check --> |no| Done[Done]
사용 사례: 철저한 검색, 죽은 코드 탐지, 의존성 감사, 고정된 수의 결과보다 완전성을 원하는 모든 스윕(sweep).
const agent = createDeepAgent({
model: "google-genai:gemini-3.6-flash",
subagents: [{
name: "analyzer",
description: "Analyzes code for unused exports, functions, and dead code paths",
systemPrompt: "You are a code analyst specializing in dead code detection. Find unused exports, unreachable functions, and orphaned modules. Report each with file path and evidence.",
}],
middleware: [createCodeInterpreterMiddleware()],
});
```
```ts OpenAI theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
import { createDeepAgent } from "deepagents";
import { createCodeInterpreterMiddleware } from "@langchain/quickjs";
const agent = createDeepAgent({
model: "openai:gpt-5.5",
subagents: [{
name: "analyzer",
description: "Analyzes code for unused exports, functions, and dead code paths",
systemPrompt: "You are a code analyst specializing in dead code detection. Find unused exports, unreachable functions, and orphaned modules. Report each with file path and evidence.",
}],
middleware: [createCodeInterpreterMiddleware()],
});
```
```ts Anthropic theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
import { createDeepAgent } from "deepagents";
import { createCodeInterpreterMiddleware } from "@langchain/quickjs";
const agent = createDeepAgent({
model: "anthropic:claude-sonnet-5",
subagents: [{
name: "analyzer",
description: "Analyzes code for unused exports, functions, and dead code paths",
systemPrompt: "You are a code analyst specializing in dead code detection. Find unused exports, unreachable functions, and orphaned modules. Report each with file path and evidence.",
}],
middleware: [createCodeInterpreterMiddleware()],
});
```
```ts OpenRouter theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
import { createDeepAgent } from "deepagents";
import { createCodeInterpreterMiddleware } from "@langchain/quickjs";
const agent = createDeepAgent({
model: "openrouter:z-ai/glm-5.2",
subagents: [{
name: "analyzer",
description: "Analyzes code for unused exports, functions, and dead code paths",
systemPrompt: "You are a code analyst specializing in dead code detection. Find unused exports, unreachable functions, and orphaned modules. Report each with file path and evidence.",
}],
middleware: [createCodeInterpreterMiddleware()],
});
```
```ts Fireworks theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
import { createDeepAgent } from "deepagents";
import { createCodeInterpreterMiddleware } from "@langchain/quickjs";
const agent = createDeepAgent({
model: "fireworks:accounts/fireworks/models/glm-5p2",
subagents: [{
name: "analyzer",
description: "Analyzes code for unused exports, functions, and dead code paths",
systemPrompt: "You are a code analyst specializing in dead code detection. Find unused exports, unreachable functions, and orphaned modules. Report each with file path and evidence.",
}],
middleware: [createCodeInterpreterMiddleware()],
});
```
```ts Baseten theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
import { createDeepAgent } from "deepagents";
import { createCodeInterpreterMiddleware } from "@langchain/quickjs";
const agent = createDeepAgent({
model: "baseten:zai-org/GLM-5.2",
subagents: [{
name: "analyzer",
description: "Analyzes code for unused exports, functions, and dead code paths",
systemPrompt: "You are a code analyst specializing in dead code detection. Find unused exports, unreachable functions, and orphaned modules. Report each with file path and evidence.",
}],
middleware: [createCodeInterpreterMiddleware()],
});
```
```ts Ollama theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
import { createDeepAgent } from "deepagents";
import { createCodeInterpreterMiddleware } from "@langchain/quickjs";
const agent = createDeepAgent({
model: "ollama:north-mini-code-1.0",
subagents: [{
name: "analyzer",
description: "Analyzes code for unused exports, functions, and dead code paths",
systemPrompt: "You are a code analyst specializing in dead code detection. Find unused exports, unreachable functions, and orphaned modules. Report each with file path and evidence.",
}],
middleware: [createCodeInterpreterMiddleware()],
});
```
에이전트가 작성하는 것 (What the agent writes)
// Keep dispatching rounds, deduping against what's found, until a round adds nothing.
const seen = new Set();
const found = [];
while (true) {
const { items } = await task({
description: `Find dead code. Already found: ${[...seen].join(", ") || "(none)"}.`,
subagentType: "analyzer",
responseSchema: itemsSchema, // -> { items: [{ id, file }] }
});
const fresh = items.filter((i) => !seen.has(i.id));
if (fresh.length === 0) break; // converged: nothing new
for (const i of fresh) { seen.add(i.id); found.push(i); }
}
found;
동적 서브에이전트 비활성화 (Disable dynamic subagents)
에이전트에 서브에이전트가 있을 때마다 서브에이전트 파견은 기본적으로 켜져 있습니다. 서브에이전트를 정상적인 task 도구 경로를 통해서만 사용할 수 있게 하려면 비활성화하세요. 다른 미들웨어 옵션은 인터프리터 페이지의 구성을 참고하세요.
const agent = createDeepAgent({ model: "google-genai:gemini-3.6-flash", subagents: [{ name: "reviewer", description: "Reviews code", systemPrompt: "Review code." }], middleware: [createCodeInterpreterMiddleware({ subagents: false })], });
```ts OpenAI theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
import { createDeepAgent } from "deepagents";
import { createCodeInterpreterMiddleware } from "@langchain/quickjs";
const agent = createDeepAgent({
model: "openai:gpt-5.5",
subagents: [{ name: "reviewer", description: "Reviews code", systemPrompt: "Review code." }],
middleware: [createCodeInterpreterMiddleware({ subagents: false })],
});
import { createDeepAgent } from "deepagents";
import { createCodeInterpreterMiddleware } from "@langchain/quickjs";
const agent = createDeepAgent({
model: "anthropic:claude-sonnet-5",
subagents: [{ name: "reviewer", description: "Reviews code", systemPrompt: "Review code." }],
middleware: [createCodeInterpreterMiddleware({ subagents: false })],
});
import { createDeepAgent } from "deepagents";
import { createCodeInterpreterMiddleware } from "@langchain/quickjs";
const agent = createDeepAgent({
model: "openrouter:z-ai/glm-5.2",
subagents: [{ name: "reviewer", description: "Reviews code", systemPrompt: "Review code." }],
middleware: [createCodeInterpreterMiddleware({ subagents: false })],
});
import { createDeepAgent } from "deepagents";
import { createCodeInterpreterMiddleware } from "@langchain/quickjs";
const agent = createDeepAgent({
model: "fireworks:accounts/fireworks/models/glm-5p2",
subagents: [{ name: "reviewer", description: "Reviews code", systemPrompt: "Review code." }],
middleware: [createCodeInterpreterMiddleware({ subagents: false })],
});
import { createDeepAgent } from "deepagents";
import { createCodeInterpreterMiddleware } from "@langchain/quickjs";
const agent = createDeepAgent({
model: "baseten:zai-org/GLM-5.2",
subagents: [{ name: "reviewer", description: "Reviews code", systemPrompt: "Review code." }],
middleware: [createCodeInterpreterMiddleware({ subagents: false })],
});
import { createDeepAgent } from "deepagents";
import { createCodeInterpreterMiddleware } from "@langchain/quickjs";
const agent = createDeepAgent({
model: "ollama:north-mini-code-1.0",
subagents: [{ name: "reviewer", description: "Reviews code", systemPrompt: "Review code." }],
middleware: [createCodeInterpreterMiddleware({ subagents: false })],
});
더 알아보기 (See also)
- 인터프리터: QuickJS 설정, 프로그래매틱 도구 호출, 지속성, 보안, 미들웨어 구성
- 서브에이전트: 서브에이전트 이름, 설명, 시스템 프롬프트 구성
- 이벤트 스트리밍: 코디네이터와 위임된 서브에이전트의 업데이트 스트리밍
더 알아보기 (Learn more)
- 이 문서를 MCP로 연결하면 Claude, VSCode 등에서 실시간 답변을 받을 수 있어요.
- GitHub에서 이 페이지 편집하기 또는 이슈 제출하기.