动态子智能体 (Dynamic subagents) [Beta]
从代码解释器中以编程方式派发子智能体,实现扇出并发、双重验证与复杂工作流编排
动态子智能体(Dynamic Subagents)将代码解释器与子智能体体系的优势合二为一。 解释器环境向 JavaScript 代码注入了全局的 task() 函数。智能体不再依靠脆弱的单次自然语言推理去逐个调用子智能体,而是直接编写程序代码:在循环、Promise.all 批处理中同时派发数十个并行子任务,并在内存中完成结果的清洗、过滤与综合。
快速起步 (Quickstart)
在创建 deep agent 时,同时配置代码解释器中间件与子智能体定义:
import { createDeepAgent } from "deepagents";
import { createCodeInterpreterMiddleware } from "@langchain/quickjs";
const agent = createDeepAgent({
model: "google: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()],
});工作原理解析 (How it works)
- 环境就绪:当智能体配置了子智能体并启用了解释器中间件时,解释器会自动暴露全局
task()异步函数。 - 代码派发:智能体在
eval工具中编写代码,例如并发调用多个子智能体审查不同模块。 - 隔离执行:每个派发的子任务以独立的上下文与工具环境并发运行。
- 内存聚合:子任务的全部返回值直接流回解释器的 JavaScript 变量中。解释器可以立即使用代码逻辑(如数组过滤、排序算法、去重逻辑)对成百上千条中间结果进行精炼,最后只向大语言模型提交一份高度浓缩的高质量报告。
核心架构设计模式 (Patterns)
动态子智能体能够优雅解决单智能体难以胜任的六大复杂编排场景:
1. 分类与针对性处理 (Classify and act)
首先派发一个快速分类子智能体给输入打标,随后根据返回的类别,在 JavaScript 的 switch/case 分支中动态派发对应的专业子智能体。
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()],
});2. 扇出与综合汇总 (Fan-out and synthesize)
对于涵盖海量文件、海量数据表的庞大任务,使用 Promise.all 并行将任务打散到数十个独立的子智能体上并发执行,全部返回后在代码中进行统计汇总。
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()],
});3. 对抗性验证 (Adversarial verification)
让第一组子智能体生成方案或查找代码漏洞,然后将产物移交给扮演“挑剔审查员”的验证子智能体进行逆向证伪,只有双方达成共识的结论才会被采纳。
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()],
});4. 生成与多维过滤 (Generate and filter)
子智能体批量生成大量候选创意或解决方案,随后在代码中通过确定性的业务规则(如长度、格式要求、黑名单关键词)结合验证子智能体进行严格筛选。
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()],
});5. 锦标赛淘汰赛制 (Tournament)
让多个不同视角的子智能体针对同一难题各自提出解决方案,然后以成对 PK 或裁判打分的方式在多轮循环中逐轮淘汰,直至决出最优解。
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()],
});6. 条件循环迭代直至完成 (Loop until done)
在 while 循环中不断派发子智能体执行优化,并在每次迭代后运行验证测试,直至所有测试用例完全通过或达到最大重试次数。
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()],
});禁用动态子智能体 (Disable dynamic subagents)
如果出于安全或风控考量,希望智能体只能通过传统的普通工具调用路径派发子智能体,可在配置解释器中间件时设置 subagents: false:
const result = await agent.invoke({
messages: [{ role: "user", content: "Run a workflow that reviews every file in src/routes/ and summarizes the top risks." }],
});另请参阅
- 代码解释器 (Interpreters):QuickJS 内存运行时规范。
- 子智能体体系 (Subagents):基础子智能体概念与配置。
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");When you pass responseSchema, the resolved value is already a typed JavaScript object; only call JSON.parse if a subagent intentionally returned a JSON string.
Patterns
The agent picks a strategy from the shape of the task; these emerge from how it writes interpreter code, not from configuration, and the subagents you make available determine what it can do. Every pattern shares the same orchestration approach: hold work in JS variables, dispatch subagents with task(), and combine results in code. The diagrams below show the common shapes, each with a runnable example.
Classify and act
Items are classified first, then each item is handled by a specialized subagent based on its classification. This lets you process mixed inputs where different items need different expertise.
graph LR
Task[Task] --> Classify{Classifier}
Classify --> |bug| A[Agent A]
Classify --> |feature| B[Agent B]
Classify --> |question| C[Agent C]Use cases: Triaging support tickets, error logs, user feedback, or any batch of items that need different handling depending on their type.
Example: classify and act
What you configure
> import { createDeepAgent } from "deepagents";
> import { createCodeInterpreterMiddleware } from "@langchain/quickjs";
>
> const agent = createDeepAgent({
> model: "google: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**
>
>
```ts theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
> // 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
The agent dispatches the same kind of work across many items in parallel, then combines the results.
```mermaid theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
graph LR
Items[Items] --> W1[Worker]
Items --> W2[Worker]
Items --> W3[Worker]
W1 --> Collect[Collect]
W2 --> Collect
W3 --> Collect
Collect --> Synth[Synthesize]Use cases: Code review across a directory, analyzing a batch of documents, processing log files, running the same check across many services.
Discovering files from interpreter code requires programmatic tool calling (PTC). Enable glob in the PTC allowlist on interpreter middleware.
Example: fan-out and synthesize
What you configure
> import { createDeepAgent } from "deepagents";
> import { createCodeInterpreterMiddleware } from "@langchain/quickjs";
>
> const agent = createDeepAgent({
> model: "google: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**
>
>
```ts theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
> // 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
A two-pass pattern. The first pass produces findings. The second pass sends each finding to independent verifiers, and only findings that survive agreement are kept. This reduces false positives when confidence matters more than speed.
```mermaid theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
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]Use cases: Security audits where false positives are costly, compliance checks, any review where you need high confidence in findings.
Example: adversarial verification
What you configure
> import { createDeepAgent } from "deepagents";
> import { createCodeInterpreterMiddleware } from "@langchain/quickjs";
>
> const agent = createDeepAgent({
> model: "google: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**
>
>
```ts theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
> // 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
Multiple subagents generate independent solutions to the same problem. The agent compares, scores, and filters the results in code, keeping only the best.
```mermaid theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
graph LR
Prompt[Prompt] --> G1[Generator]
Prompt --> G2[Generator]
Prompt --> G3[Generator]
G1 --> Filter[Filter + rank]
G2 --> Filter
G3 --> Filter
Filter --> Best[Best result]Use cases: Architecture proposals, refactoring strategies, content variations, any task where exploring multiple options before committing produces a better outcome.
Example: generate and filter
What you configure
> import { createDeepAgent } from "deepagents";
> import { createCodeInterpreterMiddleware } from "@langchain/quickjs";
>
> const agent = createDeepAgent({
> model: "google: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**
>
>
```ts theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
> // 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
Variations are compared head-to-head by a judge subagent, with winners advancing through elimination rounds.
```mermaid theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
graph LR
A1[Attempt] --> J1{Judge}
A2[Attempt] --> J1
A3[Attempt] --> J2{Judge}
A4[Attempt] --> J2
J1 --> JF{Final}
J2 --> JF
JF --> Winner[Winner]Use cases: Optimization under subjective criteria, style selection, choosing between competing implementations.
Example: tournament
What you configure
> import { createDeepAgent } from "deepagents";
> import { createCodeInterpreterMiddleware } from "@langchain/quickjs";
>
> const agent = createDeepAgent({
> model: "google: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**
>
>
```ts theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
> // 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
The agent runs a discovery loop, deduplicating against what it has already found, until no new results appear. Useful when the scope of the work is not known upfront.
```mermaid theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
graph LR
Agent[Agent] --> Check{New findings?}
Check --> |yes| Agent
Check --> |no| Done[Done]Use cases: Exhaustive search, dead code detection, dependency audits, any sweep where you want completeness rather than a fixed number of results.
Example: loop until done
What you configure
> import { createDeepAgent } from "deepagents";
> import { createCodeInterpreterMiddleware } from "@langchain/quickjs";
>
> const agent = createDeepAgent({
> model: "google: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**
>
>
```ts theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
> // 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;
> ```
> [!WARNING]
>
> `task()` dispatches from inside an already-running `eval` call. It does not go through the normal tool calling path, so `interruptOn` approval workflows on the parent agent are not enforced per dispatch. Gate the `eval` tool itself if you need approval before subagent orchestration runs.
## Disable dynamic subagents
Subagent dispatch is on by default whenever the agent has subagents. Disable it if you want subagents to be available only through the normal `task` tool path. For other middleware options, see [Configuration](/oss/javascript/deepagents/interpreters.md#configuration) on the interpreters page.
```ts Google theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
import { createDeepAgent } from "deepagents";
import { createCodeInterpreterMiddleware } from "@langchain/quickjs";
const agent = createDeepAgent({
model: "google:gemini-3.6-flash",
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: "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
- Interpreters: QuickJS setup, programmatic tool calling, persistence, security, and middleware configuration
- Subagents: Configure subagent names, descriptions, and system prompts
- Event streaming: Stream updates from the coordinator and delegated subagents
Connect these docs to your agent of choice via MCP for real-time answers.
