Skip to content

A local-first multi-agent app development platform, built on PenguinHarness

feat(core): optional `thinking_level` argument on run_subagent (#323)

Yaowei Zheng32c1717b74f1
diff --git a/changelog/unreleased/2026-08-18-subagent-thinking-level.md b/changelog/unreleased/2026-08-18-subagent-thinking-level.md
new file mode 100644
index 00000000..cfdd3c3c
--- /dev/null
+++ b/changelog/unreleased/2026-08-18-subagent-thinking-level.md
@@ -0,0 +1,29 @@
+# Subagent thinking level: `thinking_level` on `run_subagent`
+
+- **Date:** 2026-08-18
+- **Type:** feature
+- **Scope:** `core`, `docs`
+- **PR:** [#323](https://github.com/Prism-Shadow/penguin-harness/pull/323)
+- **Issue:** [#306](https://github.com/Prism-Shadow/penguin-harness/issues/306)
+
+[中文版](2026-08-18-subagent-thinking-level.zh.md)
+
+The `run_subagent` tool gained an optional `thinking_level` argument, so the model can pick the thinking level a subagent runs at — lower for cheap mechanical subtasks, higher for hard analysis — instead of every child Session always running at the parent Session's level. Changing the default tool entry advanced the config kernel to a new generation, so existing Agents take a kernel update.
+
+## Details
+
+- The tool schema declares `thinking_level` as an enum of the four selectable tiers, `low` / `medium` / `high` / `xhigh`, mirroring the thinking-level pickers. `none` was left out of the offered set because many models cannot disable thinking, and stayed valid as a stored and wire value.
+- Omitting the argument reproduces the previous behavior exactly: the child inherits the parent Session's effective level, including the tri-state `null` that stands for "no level" when the parent has none. A JSON `null` counts as omitted.
+- An unrecognized value fails the call and names the valid options, instead of quietly running the child at an inherited level the caller did not ask for.
+- The override travels through a new optional `thinkingLevel` on `SubagentRunner.spawn` into the spawn closure's `createSession` call, resolved above the inherit-or-null fallback, so an explicit level also applies when the parent Session has no level of its own.
+- The four tiers were exported as `SUBAGENT_THINKING_LEVELS` and pinned by a test against the project-default tier list and the shipped tool schema, so the parallel copies of that set cannot drift apart.
+
+## Compatibility
+
+- The default `run_subagent` tool entry changed, so `KERNEL_VERSION` advanced to generation `2026-08-18`, with `tools.builtin.run_subagent` as its only changed leaf. Every existing Agent therefore takes a kernel update.
+- An Agent whose stored `run_subagent` entry still matches an older default advances to the new schema on its own. An entry the user edited is kept untouched, and an entry the user deleted to switch the tool off stays deleted rather than being re-added. Nothing has to be done by hand either way.
+- This was the first generation whose defaults differ from the previous one in a tool leaf, which brought the kernel update's "a stored tool entry matching an older generation advances" branch under test for the first time, driven through the history seam so the coverage cannot rot. The pre-toggles reconstruction proof was rescoped to retire per leaf rather than per generation, so it kept proving `system_prompt`, the leaf its frozen `LEGACY_*` constants are about.
+
+## Docs
+
+- The bilingual tools and interfaces pages documented the new argument and the matching `spawn` field. The `SubagentRunner` snippet also caught up on the `provider` half of the model pair it had been missing.
diff --git a/changelog/unreleased/2026-08-18-subagent-thinking-level.zh.md b/changelog/unreleased/2026-08-18-subagent-thinking-level.zh.md
new file mode 100644
index 00000000..91a1edd9
--- /dev/null
+++ b/changelog/unreleased/2026-08-18-subagent-thinking-level.zh.md
@@ -0,0 +1,29 @@
+# Subagent 思考等级:`run_subagent` 的 `thinking_level` 参数
+
+- **Date:** 2026-08-18
+- **Type:** feature
+- **Scope:** `core`, `docs`
+- **PR:** [#323](https://github.com/Prism-Shadow/penguin-harness/pull/323)
+- **Issue:** [#306](https://github.com/Prism-Shadow/penguin-harness/issues/306)
+
+[English](2026-08-18-subagent-thinking-level.md)
+
+`run_subagent` 工具新增可选参数 `thinking_level`,模型因此可以自行决定 Subagent 以哪一档思考等级运行——机械性的廉价子任务调低,硬骨头式的分析调高——而不再是每个子 Session 都只能跟着父 Session 的等级跑。默认工具条目的这次变化让配置 kernel 推进了一代,因此现有 Agent 会经历一次 kernel 更新。
+
+## 细节
+
+- 工具 schema 把 `thinking_level` 声明为一个枚举,取值是四个可选档位 `low` / `medium` / `high` / `xhigh`,与思考等级选择器保持一致。`none` 没有出现在可选集合里,因为不少模型无法关闭思考;它作为已存储值和线上传输值依然有效。
+- 不传该参数时行为与此前完全一致:子 Session 继承父 Session 的有效等级,包括父级没有等级时那个表示「无等级」的三态 `null`。JSON `null` 等同于不传。
+- 传入无法识别的取值会让这次调用直接失败,并列出有效选项,而不是悄悄让子 Session 跑在一个调用方并未要求的继承等级上。
+- 该覆盖值经由 `SubagentRunner.spawn` 上新增的可选字段 `thinkingLevel`,一路送到 spawn 闭包里的 `createSession` 调用,其解析位置在「继承或 null」这层回退之上,因此父 Session 自身没有等级时,显式指定的等级同样生效。
+- 四个档位以 `SUBAGENT_THINKING_LEVELS` 导出,并由一个测试对着 Project 默认档位表和随包发布的工具 schema 钉住,使这份集合的几处平行副本不会各自漂移。
+
+## 兼容性
+
+- 默认的 `run_subagent` 工具条目发生了变化,于是 `KERNEL_VERSION` 推进到 `2026-08-18` 这一代,其中唯一改动的叶子是 `tools.builtin.run_subagent`。因此现有的每个 Agent 都会经历一次 kernel 更新。
+- 若某个 Agent 存储的 `run_subagent` 条目仍与某个旧默认值一致,它会自动推进到新 schema;用户改写过的条目原样保留;用户为关闭该工具而删除的条目继续保持删除状态,不会被重新加回。两种情况都无需手工操作。
+- 这是第一代在某个工具叶子上与上一代默认值不同的 kernel,也因此第一次让 kernel 更新中「存储条目匹配某个旧代则推进」这条分支进入测试覆盖,并且是经由 history 接缝驱动的,覆盖不会随代际推移而失效。pre-toggles 的重建证明被改为按叶子而非按代退役,所以它继续为 `system_prompt` 提供证明——那正是被冻结的 `LEGACY_*` 常量所对应的叶子。
+
+## 文档
+
+- 双语的 tools 与 interfaces 文档页记录了新参数以及 `spawn` 上与之对应的字段。`SubagentRunner` 代码片段也顺带补上了此前遗漏的模型二元组中 `provider` 那一半。
diff --git a/packages/core/src/agent.ts b/packages/core/src/agent.ts
index 1e25f522..4db0809b 100644
--- a/packages/core/src/agent.ts
+++ b/packages/core/src/agent.ts
@@ -113,9 +113,10 @@ export interface CreateSessionOptions {
* `"medium"` (see `configuredThinkingLevel`);
* - `null` means "no thinking level": the config fallback is suppressed entirely
* (nothing goes into the LLM config; session_meta echoes `"default"`).
- * Subagent spawning always passes the parent Session's effective level (its level, or
- * `null` when the parent has none), so a child Session thinks at the parent's level and
- * never falls back to the child Agent's own config.
+ * Subagent spawning passes the parent Session's effective level (its level, or `null`
+ * when the parent has none) unless the spawn requests an explicit level (`run_subagent`'s
+ * `thinking_level`) — either way a child Session never falls back to the child Agent's
+ * own config.
*/
thinkingLevel?: ThinkingLevelName | null;
/** Explicit credentials; if unspecified, falls back to credentials in the Project config, then to AgentHub reading environment variables. */
@@ -597,8 +598,9 @@ export class Agent {
} = args;
// Child-Agent runner: injected into the run_subagent tool so it doesn't need to
// depend on Agent/Session (breaking a circular dependency). The model can
- // optionally choose agentId (omitted = call the current Agent) and the child
- // Session's model (omitted = the parent Session's model); an explicit model reference
+ // optionally choose agentId (omitted = call the current Agent), the child
+ // Session's model (omitted = the parent Session's model), and its thinking level
+ // (omitted = the parent Session's effective level); an explicit model reference
// is forwarded to createSession as-is and must be a complete (provider, model_id)
// pair — half a reference is rejected there rather than being guessed here. Precheck
// errors (depth limit exceeded / agent doesn't exist) are expressed as throws, which
@@ -610,7 +612,7 @@ export class Agent {
// Spawn and run are separate: the same child Session can run for multiple turns
// (continuing via input_subagent appending a prompt); resource cleanup is
// consolidated in handle.dispose (called by the managing ManagedSubagentSession).
- async spawn({ agentId, modelId, provider }) {
+ async spawn({ agentId, modelId, provider, thinkingLevel: spawnThinkingLevel }) {
if (subagentDepth >= MAX_SUBAGENT_DEPTH) {
throw new Error(
`subagent depth limit ${MAX_SUBAGENT_DEPTH} reached; not spawning another subagent`,
@@ -650,13 +652,15 @@ export class Agent {
...(modelId !== undefined ? { modelId } : {}),
...(provider !== undefined ? { provider } : {}),
};
- // The parent Session's effective thinking level (`thinkingLevel` in scope) is passed
- // down too, as a tri-state: `null` when the parent has none, so the child never falls
- // back to its own Agent config (which would otherwise apply on a cross-agent spawn).
+ // An explicit spawn-time level (run_subagent's `thinking_level`) pins the child;
+ // otherwise the parent Session's effective thinking level (`thinkingLevel` in scope)
+ // is passed down, as a tri-state: `null` when the parent has none, so the child never
+ // falls back to its own Agent config (which would otherwise apply on a cross-agent
+ // spawn).
const childSession = await childAgent.createSession({
workspaceDir,
...childModel,
- thinkingLevel: thinkingLevel ?? null,
+ thinkingLevel: spawnThinkingLevel ?? thinkingLevel ?? null,
subagentDepth: subagentDepth + 1,
source: "subagent",
});
diff --git a/packages/core/src/environment/tools/run-subagent.ts b/packages/core/src/environment/tools/run-subagent.ts
index fd21cdd7..67acd657 100644
--- a/packages/core/src/environment/tools/run-subagent.ts
+++ b/packages/core/src/environment/tools/run-subagent.ts
@@ -3,11 +3,11 @@
* background execution.
*
* The tool itself doesn't depend on Agent/Session, only holding an injected `SubagentRunner`
- * (breaking the circular dependency). The model may freely choose the child Agent (`agent_id`)
- * and model (`model_id`) via arguments; if omitted, it falls back to reusing the current Agent
- * and inheriting the parent session's model respectively. The spawned child session is managed by
- * `ManagedSubagentSession` (sharing the `SubagentSessionManager` injected by Environment with
- * `input_subagent`).
+ * (breaking the circular dependency). The model may freely choose the child Agent (`agent_id`),
+ * model (`model_id`), and thinking level (`thinking_level`) via arguments; if omitted, it falls
+ * back to reusing the current Agent and inheriting the parent session's model and thinking level
+ * respectively. The spawned child session is managed by `ManagedSubagentSession` (sharing the
+ * `SubagentSessionManager` injected by Environment with `input_subagent`).
*
* The two-phase semantics mirror `exec_command`: within the `yield_time_ms` window, child-session
* messages are forwarded live (tagged with origin, so the frontend can see the child Agent's tool
@@ -27,7 +27,12 @@
*/
import { partialToolCallOutput } from "../../omnimessage/index.js";
import type { OmniMessage } from "../../omnimessage/index.js";
-import type { EnvironmentServices, ToolDefinitionConfig } from "../../interfaces.js";
+import { SUBAGENT_THINKING_LEVELS } from "../../interfaces.js";
+import type {
+ EnvironmentServices,
+ ThinkingLevelName,
+ ToolDefinitionConfig,
+} from "../../interfaces.js";
import type { BuiltinTool, ToolExecutionContext, ToolResult } from "./types.js";
import {
DEFAULT_SUBAGENT_YIELD_MS,
@@ -91,6 +96,21 @@ export function createSubagentTool(
);
return { stopReason: "failed" };
}
+ // Thinking-level override: an explicit value must be one of the selectable tiers — a typo
+ // must fail loudly rather than silently running the child at an inherited level the caller
+ // did not ask for. JSON `null` counts as omitted (= inherit), like a missing key.
+ const rawThinkingLevel = args.thinking_level ?? undefined;
+ if (
+ rawThinkingLevel !== undefined &&
+ !(SUBAGENT_THINKING_LEVELS as readonly unknown[]).includes(rawThinkingLevel)
+ ) {
+ yield* fail(
+ `[run_subagent error: invalid \`thinking_level\` ${JSON.stringify(rawThinkingLevel)}; ` +
+ `use one of ${SUBAGENT_THINKING_LEVELS.join(" / ")}, or omit it to inherit the parent session's level]`,
+ );
+ return { stopReason: "failed" };
+ }
+ const thinkingLevel = rawThinkingLevel as ThinkingLevelName | undefined;
const yieldMs = clampYield(
args.yield_time_ms,
DEFAULT_SUBAGENT_YIELD_MS,
@@ -116,6 +136,7 @@ export function createSubagentTool(
...(agentId !== undefined ? { agentId } : {}),
...(modelId !== undefined ? { modelId } : {}),
...(provider !== undefined ? { provider } : {}),
+ ...(thinkingLevel !== undefined ? { thinkingLevel } : {}),
});
session = new ManagedSubagentSession(handle);
} catch (err) {
diff --git a/packages/core/src/interfaces.ts b/packages/core/src/interfaces.ts
index 0f9c7291..5a7aed34 100644
--- a/packages/core/src/interfaces.ts
+++ b/packages/core/src/interfaces.ts
@@ -238,6 +238,21 @@ export interface SubagentHandle {
dispose(): void;
}
+/**
+ * Thinking levels the model may request for a spawned child Session (`run_subagent`'s
+ * `thinking_level` argument): the four selectable tiers only — never `"none"`, mirroring the
+ * user-facing pickers (many models cannot disable thinking; see the web picker's
+ * SELECTABLE_THINKING_LEVELS and project-config's DEFAULT_CHAT_THINKING_LEVELS). Omitting the
+ * argument inherits the parent Session's effective level, so a parent genuinely running
+ * without a level still passes that down.
+ */
+export const SUBAGENT_THINKING_LEVELS: readonly ThinkingLevelName[] = [
+ "low",
+ "medium",
+ "high",
+ "xhigh",
+];
+
/**
* Child Agent runner: injected into the `run_subagent` tool so it can
* derive and run a child Agent without a reverse dependency on Agent/Session, avoiding circular
@@ -263,6 +278,12 @@ export interface SubagentRunner {
modelId?: string;
/** Provider group for `modelId`; required whenever `modelId` is given. */
provider?: string;
+ /**
+ * Explicit thinking level for the child Session; omitted inherits the parent Session's
+ * effective level (including "no level" when the parent has none). The `run_subagent`
+ * tool restricts its `thinking_level` argument to {@link SUBAGENT_THINKING_LEVELS}.
+ */
+ thinkingLevel?: ThinkingLevelName;
}): Promise<SubagentHandle>;
}
diff --git a/packages/core/src/state/default-config.ts b/packages/core/src/state/default-config.ts
index 295a118f..dea6c88f 100644
--- a/packages/core/src/state/default-config.ts
+++ b/packages/core/src/state/default-config.ts
@@ -17,6 +17,7 @@
* such as \`<app_data_dir>\`, \`<agent_id>\`, \`<session_id>\` — these are **not substituted**;
* the model fills in the actual values from the Environment section itself.
*/
+import { SUBAGENT_THINKING_LEVELS } from "../interfaces.js";
import type { MCPServerConfig, ThinkingLevelName, ToolDefinitionConfig } from "../interfaces.js";
import type { CompactionMode } from "../omnimessage/types.js";
import { KERNEL_VERSION } from "./kernel-history.js";
@@ -714,7 +715,7 @@ function defaultBuiltinTools(): ToolDefinitionConfig[] {
{
name: "run_subagent",
description:
- "Delegate a self-contained subtask to a subagent that runs autonomously in the same workspace and returns its final answer. Use it for focused sub-tasks you can fully specify in one prompt. Optionally choose a specific agent via `agent_id` and a model via `model_id`. " +
+ "Delegate a self-contained subtask to a subagent that runs autonomously in the same workspace and returns its final answer. Use it for focused sub-tasks you can fully specify in one prompt. Optionally choose a specific agent via `agent_id`, a model via `model_id`, and a thinking level via `thinking_level`. " +
'Begin the prompt by identifying yourself with your own agent id (from the Environment section), e.g. "Caller agent: default_agent" — the subagent cannot otherwise tell who invoked it.',
parameters: {
type: "object",
@@ -744,6 +745,12 @@ function defaultBuiltinTools(): ToolDefinitionConfig[] {
description:
"The provider group that model_id belongs to (see the Environment section's Provider). Required whenever model_id is given.",
},
+ thinking_level: {
+ type: "string",
+ enum: [...SUBAGENT_THINKING_LEVELS],
+ description:
+ "Thinking level for the subagent. Omit to inherit the current session's level. Lower it for cheap mechanical subtasks; raise it for hard analysis or design subtasks.",
+ },
yield_time_ms: {
type: "number",
description:
diff --git a/packages/core/src/state/kernel-history.ts b/packages/core/src/state/kernel-history.ts
index e41ecc02..6867fa08 100644
--- a/packages/core/src/state/kernel-history.ts
+++ b/packages/core/src/state/kernel-history.ts
@@ -26,7 +26,7 @@ import type { SystemConfig } from "./default-config.js";
* pinned-hash test enforces both directions (bump without new hashes, or changed defaults
* without a bump, both fail).
*/
-export const KERNEL_VERSION = "2026-08-11";
+export const KERNEL_VERSION = "2026-08-18";
/**
* Identity / user-data fields excluded from kernel management: never hashed, never written
@@ -137,9 +137,12 @@ export function isKernelOutdated(kernelVersion: string | null | undefined): bool
* legacy # Vault / # Skills sections instead of the `{{VAULT}}` / `{{SKILLS}}` /
* `{{SCHEDULES}}` placeholders. The date is a retroactive label (configs of that era carry
* no stamp, so the key never has to match anything on disk; matching is purely by hash).
- * The test suite proves these hashes equal a byte-exact reconstruction of that era's
- * defaults from the frozen LEGACY_* constants.
- * - `"2026-08-11"` (current) — the toggles generation, pinned by the guard test.
+ * While the toggles generation was current, the test suite proved these hashes equal a
+ * byte-exact reconstruction of that era's defaults from the frozen LEGACY_* constants;
+ * that proof self-retired once the defaults evolved past the toggles generation.
+ * - `"2026-08-11"` — the toggles generation.
+ * - `"2026-08-18"` (current) — `run_subagent` gained the optional `thinking_level` argument
+ * (issue #306): only the `tools.builtin.run_subagent` leaf changed.
*
* Generations older than the seeded ones cannot be fully reconstructed; their values match
* no recorded hash and are conservatively kept by a kernel update (restore-default-config is
@@ -212,6 +215,42 @@ export const KERNEL_HASH_HISTORY: Readonly<Record<string, Readonly<Record<string
"tools.builtin.describe_image":
"fad6d0cdd483eb53b5d243c0508024ab3b708ce6d3c81933acd291f05d4a265f",
},
+ "2026-08-18": {
+ system_prompt: "de8952daede04db17400c5cd59b279eccf523cf2d8a0ecedfa37a96de7925b44",
+ max_turns: "1bad6b8cf97131fceab8543e81f7757195fbb1d36b376ee994ad1cf17699c464",
+ "model.max_tokens": "492f431bae35265f2e5f4ed49bd8c58dda912431be561504846988d00d05d117",
+ "model.thinking_level": "60d4c90eee5e731df8d3ef2891de541d2e755ff8ee9db358e26bdec49f6e0db9",
+ "model.timeoutMs": "4f9f73b34c5b89879aad65a48025f3187dd9ce6dc3d4e88eecb2fc79227350f1",
+ "compaction.max_context_length":
+ "8eda794b86cb709202a0023fd5273e3de6d24117b7e36b9bdb53c0238dac4785",
+ "compaction.max_session_turns":
+ "1bad6b8cf97131fceab8543e81f7757195fbb1d36b376ee994ad1cf17699c464",
+ "compaction.mode": "e58fac0b4b9c0f29b3d224da119dff5f6517a40d139faf92e309705b98bd410a",
+ "compaction.prompt": "8ed55781e8071083f8246ed70d9e063ee729d3872d5bc6a2bedfa9c99aed6ae5",
+ "memory.enabled": "b5bea41b6c623f7c09f1bf24dcae58ebab3c0cdd90ad966bc43a45b44867e12b",
+ "memory.prompt": "9380e2382e5dd3d37a6470b0bc0d27c9ed113fa9a54ff78122784c57a16b992c",
+ "memory.workspace_prompt": "76c5a8e18a568f471593ef1da6d75d2596f27619cb877703b2dd28bb0554e0d5",
+ "vault.enabled": "b5bea41b6c623f7c09f1bf24dcae58ebab3c0cdd90ad966bc43a45b44867e12b",
+ "vault.prompt": "66e607aa4e205413f1816a677bed31af2d8c24218e71b55adba54aff5aa094ce",
+ "skills.enabled": "b5bea41b6c623f7c09f1bf24dcae58ebab3c0cdd90ad966bc43a45b44867e12b",
+ "skills.prompt": "42934d17f5dd9c02dfa7c1d37f255dea92bd36905c96a54775c65ef7db713bd9",
+ "schedules.enabled": "b5bea41b6c623f7c09f1bf24dcae58ebab3c0cdd90ad966bc43a45b44867e12b",
+ "schedules.prompt": "3c690ff9bb3e4d423b2d5dfce74f5890d52bf8ae159cfe135a671ac3d46da75a",
+ "tools.builtin.read_file": "858f128945421043f5f373c908a0ee081e93e9413debaa49c8c7af1c1c76db3c",
+ "tools.builtin.edit_file": "165a3e2dabe3d13200a1670f3c23ed2d6561c508439db1972db066719f3549ef",
+ "tools.builtin.write_file": "c98253bd5a3b6ff021accda91af016a809a9b50ce56f38a3ed60eeb673c0b130",
+ "tools.builtin.exec_command":
+ "16b327e5c3617b7c4d21505c9d1a72dd33a74de97cd5c60d6c4538b8ec408421",
+ "tools.builtin.input_command":
+ "4c907500cda145161a9481803cfb57ed814b6793e762fd6284510187e9d781c8",
+ "tools.builtin.run_subagent":
+ "be00af47c7098cde840a662c99f9f6d0cdf8358883e09974ce840b0c4683a9af",
+ "tools.builtin.input_subagent":
+ "22cc4648d773e8422e80a12a7a095b00b7f7eb01ab5a9ea080858dcd7517b4e3",
+ "tools.builtin.read_image": "05b797a88df1e6a90fb3da67ec654b206f8d81291f89d160a505620afcea38bb",
+ "tools.builtin.describe_image":
+ "fad6d0cdd483eb53b5d243c0508024ab3b708ce6d3c81933acd291f05d4a265f",
+ },
};
/**
diff --git a/packages/core/test/agent.test.ts b/packages/core/test/agent.test.ts
index d47954a5..ca6edd31 100644
--- a/packages/core/test/agent.test.ts
+++ b/packages/core/test/agent.test.ts
@@ -492,6 +492,43 @@ describe("run_subagent spawning follows the PARENT session (never the Project de
}
});
+ it("pins an explicit spawn-time thinking level over inheritance (run_subagent's thinking_level)", async () => {
+ const agent = await createAgent();
+ agent.state.systemConfig.model = {
+ ...(agent.state.systemConfig.model ?? {}),
+ thinking_level: "high",
+ };
+ const ws = path.join(tmpRoot, "ws-thinking-override");
+ await fs.mkdir(ws, { recursive: true });
+ const parent = await agent.createSession({ workspaceDir: ws });
+ const runner = lastSpawnedRunner();
+ try {
+ const child = await spawnedChildMeta(runner, { thinkingLevel: "low" });
+ // The explicit level wins over the parent's effective "high"; the rest of the spawn
+ // still follows the parent (workspace locked here as the cheap witness).
+ expect(child.llm.thinkingLevel).toBe("low");
+ expect(child.workspace).toBe(ws);
+ } finally {
+ parent.dispose();
+ }
+ });
+
+ it("pins an explicit spawn-time thinking level even when the parent has no level at all", async () => {
+ // With the parent suppressing the config chain (tri-state null), an explicit spawn level
+ // must still apply — the override sits above the inherit-or-null resolution, not below it.
+ const agent = await createAgent();
+ const ws = path.join(tmpRoot, "ws-thinking-override-none");
+ await fs.mkdir(ws, { recursive: true });
+ const parent = await agent.createSession({ workspaceDir: ws, thinkingLevel: null });
+ const runner = lastSpawnedRunner();
+ try {
+ const child = await spawnedChildMeta(runner, { thinkingLevel: "xhigh" });
+ expect(child.llm.thinkingLevel).toBe("xhigh");
+ } finally {
+ parent.dispose();
+ }
+ });
+
it("rejects half a model reference at the runner layer (never completed from the parent's half)", async () => {
const agent = await createAgent();
const ws = path.join(tmpRoot, "ws-inherit-half");
diff --git a/packages/core/test/kernel-version.test.ts b/packages/core/test/kernel-version.test.ts
index 5e88d2a9..adadb2fa 100644
--- a/packages/core/test/kernel-version.test.ts
+++ b/packages/core/test/kernel-version.test.ts
@@ -23,6 +23,7 @@ import {
applyKernelUpdate,
computeKernelHashes,
defaultSystemConfig,
+ hashKernelValue,
isKernelOutdated,
kernelLeafEntries,
loadOrInitAgentState,
@@ -41,11 +42,14 @@ function mutableConfig(config: SystemConfig): Record<string, unknown> {
}
/**
- * Reconstructs the pre-#257 (pre-toggles) default config from the current one: the frozen
+ * Reconstructs a pre-#257 (pre-toggles) shaped config from the current defaults: the frozen
* LEGACY_* sections swapped back into the template in place of the section placeholders, no
- * `{{SCHEDULES}}` line, and no vault/skills/schedules config sections — exactly what a
- * `system_config.yaml` of that era carries (the same recipe prompt-sections.test.ts proves
- * byte-exact for the template).
+ * `{{SCHEDULES}}` line, and no vault/skills/schedules config sections (the recipe
+ * prompt-sections.test.ts proves byte-exact for the template). Leaves outside the swap — the
+ * tool entries — carry the *current* defaults, so the smart-merge tests below treat them as
+ * already-current; the seeding exercises the old-template migration paths regardless. The
+ * reconstruction proof below therefore speaks only for the leaves whose default has not
+ * drifted since the toggles generation (see there).
*/
function preTogglesDefaultConfig(): SystemConfig {
const current = defaultSystemConfig();
@@ -95,18 +99,30 @@ describe("kernel hash history (pinned-hash guard)", () => {
).toEqual([]);
});
- // Anchored to the first shipped generation: the reconstruction recipe reads the *current*
- // defaults, so it only reproduces the pre-toggles era while the current generation is
- // still the toggles one. Once the defaults evolve past it this proof self-retires — the
- // pinned hashes remain the frozen source of truth on their own.
- it.runIf(KERNEL_VERSION === TOGGLES_GENERATION)(
- "the pre-toggles generation's pinned hashes equal the LEGACY_* reconstruction",
- () => {
- expect(computeKernelHashes(preTogglesDefaultConfig())).toEqual(
- KERNEL_HASH_HISTORY[PRE_TOGGLES_GENERATION],
- );
- },
- );
+ // Keeps the oldest seeded generation honest: its pinned hashes are the only record of what
+ // a pre-#257 `system_config.yaml` actually contains, and nothing else can catch a typo in
+ // them. The recipe reads the *current* defaults, so it can only speak for leaves whose
+ // default has not drifted since the toggles generation — chiefly `system_prompt`, the leaf
+ // the LEGACY_* swap is actually about. Retirement is therefore per leaf and automatic: a
+ // generation that changes some other leaf (e.g. run_subagent's thinking_level in
+ // "2026-08-18") drops just that leaf and leaves the proof standing.
+ it("the pre-toggles generation's pinned hashes equal the LEGACY_* reconstruction", () => {
+ const preToggles = KERNEL_HASH_HISTORY[PRE_TOGGLES_GENERATION]!;
+ const toggles = KERNEL_HASH_HISTORY[TOGGLES_GENERATION]!;
+ const current = computeKernelHashes(defaultSystemConfig());
+ const reconstructed = computeKernelHashes(preTogglesDefaultConfig());
+ const reconstructible = Object.keys(preToggles).filter((p) => current[p] === toggles[p]);
+ // If the template itself ever moves, this proof has nothing left to say and must be
+ // re-anchored (or retired) deliberately rather than quietly passing on leftovers.
+ expect(reconstructible).toContain("system_prompt");
+ expect(Object.fromEntries(reconstructible.map((p) => [p, reconstructed[p]]))).toEqual(
+ Object.fromEntries(reconstructible.map((p) => [p, preToggles[p]])),
+ );
+ // The recipe's other half: an era config carries no vault/skills/schedules sections at all.
+ expect(Object.keys(reconstructed).filter((p) => /^(vault|skills|schedules)\./.test(p))).toEqual(
+ [],
+ );
+ });
it("excludes identity fields and mcpServers from the managed leaves", () => {
const paths = kernelLeafEntries({
@@ -274,6 +290,38 @@ describe("applyKernelUpdate", () => {
);
});
+ it("advances a stored tool entry that matches an older generation's hash", async () => {
+ // The path every existing config takes when a tool's default schema changes (the first
+ // such bump is run_subagent's thinking_level, "2026-08-18"): the stored entry is not the
+ // current default, but it hash-matches a recorded generation, so it is an untouched old
+ // default and must be replaced — not kept as if the user had edited it. Driven through
+ // the history seam so the test cannot rot when the real generations move on.
+ const defaults = defaultSystemConfig();
+ const current = computeKernelHashes(defaults);
+ const currentEntry = defaults.tools?.builtin?.find((t) => t.name === "run_subagent");
+ const oldEntry = { ...currentEntry!, description: "the previous generation's wording" };
+ const history = {
+ "2000-01-01": { ...current, "tools.builtin.run_subagent": hashKernelValue(oldEntry) },
+ [KERNEL_VERSION]: current,
+ };
+ const config = mutableConfig(defaults);
+ config.kernel_version = "2000-01-01";
+ const tools = config.tools as { builtin: Array<Record<string, unknown>> };
+ tools.builtin = tools.builtin.map((t) =>
+ t.name === "run_subagent" ? (oldEntry as unknown as Record<string, unknown>) : t,
+ );
+ await seedConfig(config);
+
+ const result = await applyKernelUpdate(root, DEFAULT_PROJECT_ID, DEFAULT_AGENT_ID, {
+ history,
+ });
+ expect(result.advanced).toEqual(["tools.builtin.run_subagent"]);
+ expect(result.kept).toEqual([]);
+ const written = await readConfig();
+ expect(written.tools?.builtin?.find((t) => t.name === "run_subagent")).toEqual(currentEntry);
+ expect(written.kernel_version).toBe(KERNEL_VERSION);
+ });
+
it("materializes the whole default toolset when tools.builtin is missing", async () => {
const config = mutableConfig(defaultSystemConfig());
delete config.kernel_version;
diff --git a/packages/core/test/state.test.ts b/packages/core/test/state.test.ts
index 0090cd4b..a6b1b985 100644
--- a/packages/core/test/state.test.ts
+++ b/packages/core/test/state.test.ts
@@ -6,6 +6,7 @@ import { afterEach, beforeEach, describe, expect, it } from "vitest";
import {
AGENT_ID_PLACEHOLDER,
AGENTS_MD_PLACEHOLDER,
+ DEFAULT_CHAT_THINKING_LEVELS,
VAULT_KEYS_PLACEHOLDER,
SKILL_METADATA_PLACEHOLDER,
VAULT_PLACEHOLDER,
@@ -59,6 +60,7 @@ import {
type ProjectConfig,
type SystemConfig,
} from "../src/state/index.js";
+import { SUBAGENT_THINKING_LEVELS } from "../src/interfaces.js";
import { sessionEnvironment } from "../src/internal/session-support.js";
let tmpRoot: string;
@@ -1462,6 +1464,22 @@ describe("default_chat (new-chat defaults block)", () => {
});
});
+describe("selectable thinking tiers (the parallel lists must agree)", () => {
+ it("run_subagent's enum is exactly the project-default tiers, and never offers none", () => {
+ // The same rule is spelled out in three places — this constant, the web picker's
+ // SELECTABLE_THINKING_LEVELS (pinned by its own test), and run_subagent's schema — while
+ // nothing checked the two core lists against each other. `"none"` stays a legal stored and
+ // wire value (a legacy config may carry it, and it is inherited verbatim by a subagent),
+ // it is simply never *offered*, because many models cannot disable thinking.
+ expect(SUBAGENT_THINKING_LEVELS).toEqual(DEFAULT_CHAT_THINKING_LEVELS);
+ expect(SUBAGENT_THINKING_LEVELS).not.toContain("none");
+ const entry = defaultSystemConfig().tools?.builtin?.find((t) => t.name === "run_subagent");
+ const properties = (entry?.parameters as { properties?: Record<string, { enum?: unknown }> })
+ ?.properties;
+ expect(properties?.thinking_level?.enum).toEqual([...SUBAGENT_THINKING_LEVELS]);
+ });
+});
+
describe("resolveModelRef (validates a (provider, model_id) pair against the config)", () => {
const cfg: ProjectConfig = {
models: [
diff --git a/packages/core/test/subagent.test.ts b/packages/core/test/subagent.test.ts
index ee2adb7a..a95f1c72 100644
--- a/packages/core/test/subagent.test.ts
+++ b/packages/core/test/subagent.test.ts
@@ -56,7 +56,12 @@ type RunInput = { prompt: string; signal?: AbortSignal; approve?: ApproveFn };
/** Builds a SubagentRunner from a run implementation (spawn arguments observed via a spy). */
function runnerOf(
run: (input: RunInput) => AsyncGenerator<OmniMessage>,
- spawnSpy?: (input: { agentId?: string; modelId?: string; provider?: string }) => void,
+ spawnSpy?: (input: {
+ agentId?: string;
+ modelId?: string;
+ provider?: string;
+ thinkingLevel?: string;
+ }) => void,
): SubagentRunner {
return {
async spawn(input) {
@@ -136,8 +141,13 @@ afterEach(() => {
describe("run_subagent tool (foreground)", () => {
it("forwards stamped child messages and mirrors child text as its own output deltas", async () => {
- const seen: Array<{ prompt?: string; agentId?: string; modelId?: string; provider?: string }> =
- [];
+ const seen: Array<{
+ prompt?: string;
+ agentId?: string;
+ modelId?: string;
+ provider?: string;
+ thinkingLevel?: string;
+ }> = [];
const runner = runnerOf(
async function* (input) {
seen[0] = { ...seen[0], prompt: input.prompt };
@@ -152,7 +162,13 @@ describe("run_subagent tool (foreground)", () => {
const tool = createSubagentTool(DEF, services);
const { out, result } = await collectWithReturn(
tool.execute(
- { prompt: "world", agent_id: "researcher", model_id: "m1", provider: "p1" },
+ {
+ prompt: "world",
+ agent_id: "researcher",
+ model_id: "m1",
+ provider: "p1",
+ thinking_level: "high",
+ },
CTX,
),
);
@@ -165,13 +181,14 @@ describe("run_subagent tool (foreground)", () => {
// complete tool_call_output from this).
expect(ownDeltas(out)).toBe("Hello world");
expect(result?.stopReason).toBe("completed");
- // The model is free to choose the agent and model (spawn arguments); the prompt is
- // handed to run.
+ // The model is free to choose the agent, model, and thinking level (spawn arguments); the
+ // prompt is handed to run.
expect(seen[0]).toEqual({
prompt: "world",
agentId: "researcher",
modelId: "m1",
provider: "p1",
+ thinkingLevel: "high",
});
});
@@ -216,6 +233,49 @@ describe("run_subagent tool (foreground)", () => {
expect(seen[0]?.provider).toBeUndefined();
});
+ it("rejects a thinking_level outside the selectable tiers, and never spawns", async () => {
+ // A typo must fail loudly: silently inheriting a level the caller did not ask for would
+ // defeat the override. "none" is deliberately not offered (mirroring the pickers — many
+ // models cannot disable thinking), so it is rejected like any other unknown value.
+ for (const thinking_level of ["hgih", "none", "", 3]) {
+ const spawned: unknown[] = [];
+ const runner = runnerOf(
+ async function* () {},
+ (input) => spawned.push(input),
+ );
+ const { services } = makeServices(runner);
+ const tool = createSubagentTool(DEF, services);
+ const { out, result } = await collectWithReturn(
+ tool.execute({ prompt: "x", thinking_level }, CTX),
+ );
+ expect(result?.stopReason).toBe("failed");
+ expect(ownDeltas(out)).toContain("invalid `thinking_level`");
+ expect(ownDeltas(out)).toContain("low / medium / high / xhigh");
+ expect(spawned).toHaveLength(0);
+ }
+ });
+
+ it("forwards NO thinking level when the argument is omitted or null (the runner inherits)", async () => {
+ // Omission means "inherit the parent session's effective level" — the tool forwards
+ // nothing and the real runner (the spawn closure in agent.ts) resolves the inheritance
+ // (locked in agent.test.ts). A JSON null counts as omitted, like a missing key.
+ for (const args of [{ prompt: "x" }, { prompt: "x", thinking_level: null }]) {
+ const seen: Array<{ thinkingLevel?: string }> = [];
+ const runner = runnerOf(
+ async function* () {
+ yield withOrigin(partialText("delta", "ok"), HOP);
+ },
+ (input) => seen.push(input),
+ );
+ const { services } = makeServices(runner);
+ const tool = createSubagentTool(DEF, services);
+ const { result } = await collectWithReturn(tool.execute(args, CTX));
+ expect(result?.stopReason).toBe("completed");
+ expect(seen).toHaveLength(1);
+ expect("thinkingLevel" in seen[0]!).toBe(false);
+ }
+ });
+
it("does not mirror deeper-nested (origin.length > 1) text into its own output", async () => {
const grandHop: MessageOrigin = "sess_grandchild";
const runner = runnerOf(async function* () {
diff --git a/packages/docs/content/interfaces.en.md b/packages/docs/content/interfaces.en.md
index 837d2a50..312458d3 100644
--- a/packages/docs/content/interfaces.en.md
+++ b/packages/docs/content/interfaces.en.md
@@ -228,7 +228,9 @@ interface SubagentRunner {
// Precheck errors (depth limit, unknown agent) are thrown — Environment collapses them to failed
spawn(input: {
agentId?: string; // defaults to the current Agent (self-spawn)
- modelId?: string; // omitted = inherit the parent Session's model
+ modelId?: string; // paired with provider; both omitted = inherit the parent Session's model
+ provider?: string; // required whenever modelId is given (a model reference is the pair)
+ thinkingLevel?: ThinkingLevelName; // omitted = inherit the parent Session's effective level
}): Promise<SubagentHandle>;
}
diff --git a/packages/docs/content/interfaces.zh.md b/packages/docs/content/interfaces.zh.md
index 8b532394..0e84cd9b 100644
--- a/packages/docs/content/interfaces.zh.md
+++ b/packages/docs/content/interfaces.zh.md
@@ -226,7 +226,9 @@ interface SubagentRunner {
// 深度超限、目标 Agent 不存在等前置错误以抛出表达(由 Environment 收敛为 failed)
spawn(input: {
agentId?: string; // 缺省复用当前 Agent(自派生)
- modelId?: string; // 缺省继承父 Session 的模型
+ modelId?: string; // 与 provider 成对给出;两者都缺省时继承父 Session 的模型
+ provider?: string; // 给出 modelId 时必填(模型引用即二元组)
+ thinkingLevel?: ThinkingLevelName; // 缺省继承父 Session 的有效思考等级
}): Promise<SubagentHandle>;
}
diff --git a/packages/docs/content/tools.en.md b/packages/docs/content/tools.en.md
index 07ada54d..7d273973 100644
--- a/packages/docs/content/tools.en.md
+++ b/packages/docs/content/tools.en.md
@@ -172,6 +172,7 @@ On POSIX, Ctrl-C sends `SIGINT` to the session's process group, interrupting the
agent_id?: string; // the child Agent; defaults to the current Agent
model_id?: string; // the child Session's model, paired with provider; omit both to inherit the parent Session's model
provider?: string; // the provider group model_id belongs to; required whenever model_id is given
+ thinking_level?: string; // "low" | "medium" | "high" | "xhigh"; omit to inherit the parent Session's level
yield_time_ms?: number; // foreground wait; default 300000
description: string; // required while call_description is on
}
@@ -186,7 +187,7 @@ On POSIX, Ctrl-C sends `SIGINT` to the session's process group, interrupting the
```
- Depth is capped at 1: a subagent cannot spawn another subagent.
-- The child Session follows the parent Session — its model (unless `model_id`/`provider` pick another), thinking level, and Workspace — never the Project defaults.
+- The child Session follows the parent Session — its model (unless `model_id`/`provider` pick another), thinking level (unless `thinking_level` picks another — lower for cheap mechanical subtasks, higher for hard analysis), and Workspace — never the Project defaults.
- The child Session inherits the parent Agent's approval callback, so the approval mode follows the parent.
- The child Session gets its own Trace, linked from the parent by a `subagent` pointer event; child messages stream back into the parent flow tagged with `origin`. See [Sessions & Traces](/sessions-and-traces).
diff --git a/packages/docs/content/tools.zh.md b/packages/docs/content/tools.zh.md
index 73937712..26b7ec14 100644
--- a/packages/docs/content/tools.zh.md
+++ b/packages/docs/content/tools.zh.md
@@ -170,6 +170,7 @@ POSIX 上 Ctrl-C 向会话进程组发送 `SIGINT`,中断前台命令。Window
agent_id?: string; // 子 Agent;缺省复用当前 Agent
model_id?: string; // 子 Session 模型,须与 provider 成对给出;两者都缺省时继承父 Session 的模型
provider?: string; // model_id 所属的 provider 组;给出 model_id 时必填
+ thinking_level?: string; // "low" | "medium" | "high" | "xhigh";缺省继承父 Session 的思考等级
yield_time_ms?: number; // 前台等待时长;默认 300000
description: string; // 开关开启时必填
}
@@ -184,7 +185,7 @@ POSIX 上 Ctrl-C 向会话进程组发送 `SIGINT`,中断前台命令。Window
```
- 深度上限为 1:Subagent 不能再派生 Subagent。
-- 子 Session 跟随父 Session:模型(除非以 `model_id`/`provider` 显式指定)、thinking level 与 Workspace 均继承父级,而非 Project 默认值。
+- 子 Session 跟随父 Session:模型(除非以 `model_id`/`provider` 显式指定)、thinking level(除非以 `thinking_level` 显式指定——机械性子任务可调低,深度分析可调高)与 Workspace 均继承父级,而非 Project 默认值。
- 子 Session 继承父 Agent 的审批回调,审批模式随父生效。
- 子 Session 拥有独立 Trace,父 Trace 以 `subagent` 指针事件链接;子消息带 `origin` 标记回流到父级消息流。见 [Session 与 Trace](/sessions-and-traces)。