@yandy0725/pi-subagents 0.6.0 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -13,7 +13,7 @@ A [pi](https://pi.dev) extension providing a focused, in-process sub-agent core
13
13
  - **Graceful turn limits** — agents get a "wrap up" warning before hard abort
14
14
  - **Case-insensitive types** — `"explore"`, `"Explore"`, `"EXPLORE"` all work
15
15
  - **Fuzzy model selection** — specify models by name (`"haiku"`, `"sonnet"`) instead of full IDs
16
- - **Model tiers** — pick `fast` / `standard` / `advanced` and map each tier to a real model in config, instead of naming a model per call
16
+ - **Model tiers** — map `fast` / `standard` / `advanced` to real models in config; the agent is guided to pick the configured model per task
17
17
  - **Context inheritance** — optionally fork the parent conversation into a sub-agent
18
18
  - **Styled notifications** — background results render as themed notification boxes
19
19
  - **Event bus** — lifecycle events (`subagents:created`, `started`, `completed`, `failed`, `steered`, `compacted`) via `pi.events`
@@ -75,8 +75,7 @@ Launch a sub-agent.
75
75
  | `prompt` | string | yes | The task for the agent |
76
76
  | `description` | string | yes | Short 3-5 word summary (shown in UI) |
77
77
  | `subagent_type` | string | yes | Agent type (built-in or custom) |
78
- | `model` | string | no | Model override (`provider/modelId` or fuzzy name). Mutually exclusive with `model_tier` |
79
- | `model_tier` | string | no | Capability tier: `fast` / `standard` / `advanced`. Mutually exclusive with `model` |
78
+ | `model` | string | no | Model override (`provider/modelId` or fuzzy name) |
80
79
  | `thinking` | string | no | off / minimal / low / medium / high / xhigh |
81
80
  | `max_turns` | number | no | Max agentic turns (unlimited by default) |
82
81
  | `run_in_background` | boolean | no | Run without blocking |
@@ -104,8 +103,10 @@ Send a steering message to a running agent.
104
103
 
105
104
  ## Model Tiers
106
105
 
107
- The `subagent` tool accepts `model_tier` as an alternative to `model`: the caller asks for a
108
- capability class and each user decides which real model sits behind it.
106
+ Instead of hardcoding model IDs, you can map capability tiers to concrete models in
107
+ `subagents.json`. The mapping feeds the `subagent` tool's prompt guidelines, which tell the
108
+ agent which model to pass via the `model` parameter — there is no `model_tier` tool
109
+ parameter.
109
110
 
110
111
  | Tier | Intent |
111
112
  |------|--------|
@@ -127,11 +128,10 @@ override one tier without restating the others:
127
128
  }
128
129
  ```
129
130
 
130
- Tier values go through the same resolver as `model`, so `provider/modelId` and fuzzy names
131
- (e.g. `"haiku"`) both work. `model` and `model_tier` are mutually exclusive, and calling a
132
- tier that is not configured returns an error naming the file to fix — a tier request is
133
- never silently downgraded to the parent model. If an agent type pins `model` in its
134
- frontmatter, that model wins over both parameters.
131
+ Because the agent copies the mapped value into `model`, it goes through the same resolver as
132
+ any other model value: `provider/modelId` and fuzzy names (e.g. `"haiku"`) both work. Tiers
133
+ without a mapping are omitted from the guidelines — nothing is silently substituted for
134
+ them. If an agent type pins `model` in its frontmatter, that model always wins.
135
135
 
136
136
  ## Commands
137
137
 
package/README.zh.md CHANGED
@@ -13,7 +13,7 @@
13
13
  - **优雅轮次限制** — 代理在硬中止前收到"收尾"警告
14
14
  - **大小写不敏感** — `"explore"`、`"Explore"`、`"EXPLORE"` 均可
15
15
  - **模糊模型选择** — 按名称(`"haiku"`、`"sonnet"`)而非完整 ID 指定模型
16
- - **模型分层** — 用 `fast` / `standard` / `advanced` 档位代替逐次点名模型,每档对应的真实模型写在配置里
16
+ - **模型分层** — 在配置里把 `fast` / `standard` / `advanced` 档位映射到真实模型,代理按提示选择对应模型
17
17
  - **上下文继承** — 可选择将父对话分叉给子代理
18
18
  - **风格化通知** — 后台结果渲染为主题化通知框
19
19
  - **事件总线** — 通过 `pi.events` 发出生命周期事件(`subagents:created`、`started`、`completed`、`failed`、`steered`、`compacted`)
@@ -75,8 +75,7 @@ max_turns: 30
75
75
  | `prompt` | string | 是 | 代理要执行的任务 |
76
76
  | `description` | string | 是 | 3-5 词简短描述(UI 中显示) |
77
77
  | `subagent_type` | string | 是 | 代理类型(内置或自定义) |
78
- | `model` | string | 否 | 模型覆盖(`provider/modelId` 或模糊名称;与 `model_tier` 互斥) |
79
- | `model_tier` | string | 否 | 能力档位:`fast` / `standard` / `advanced`(与 `model` 互斥) |
78
+ | `model` | string | 否 | 模型覆盖(`provider/modelId` 或模糊名称) |
80
79
  | `thinking` | string | 否 | off / minimal / low / medium / high / xhigh |
81
80
  | `max_turns` | number | 否 | 最大代理轮次(默认无限制) |
82
81
  | `run_in_background` | boolean | 否 | 后台运行不阻塞 |
@@ -104,8 +103,9 @@ max_turns: 30
104
103
 
105
104
  ## 模型分层
106
105
 
107
- `subagent` 工具除 `model` 外还接受 `model_tier`:调用方只表达"要什么档位的模型",
108
- 由使用者在配置里决定每档对应哪个真实模型。
106
+ 除了直接写模型 ID,还可以在 `subagents.json` 中把能力档位映射到真实模型。映射会生成
107
+ `subagent` 工具的 prompt guidelines,告诉代理每个档位应通过 `model` 参数传哪个模型——
108
+ 不存在 `model_tier` 工具参数。
109
109
 
110
110
  | 档位 | 定位 |
111
111
  |------|------|
@@ -126,9 +126,9 @@ max_turns: 30
126
126
  }
127
127
  ```
128
128
 
129
- 档位取值与 `model` 走同一套解析,`provider/modelId` 和模糊名称(如 `"haiku"`)都可以。
130
- `model` 与 `model_tier` 互斥;调用未配置的档位会直接报错并指出该改哪个文件——不会静默
131
- 降级为父模型。若代理类型的 frontmatter 固定了 `model`,该模型优先于两个参数。
129
+ 代理会把映射值复制到 `model`,因此与普通 `model` 值走同一套解析:`provider/modelId` 与
130
+ 模糊名称(如 `"haiku"`)都可以。未配置的档位不会出现在提示里——不会有其他模型被静默
131
+ 顶替。若代理类型的 frontmatter 固定了 `model`,该模型始终优先。
132
132
 
133
133
  ## 命令
134
134
 
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "0.6.0",
6
+ "version": "0.7.0",
7
7
  "description": "Focused, in-process sub-agent core for pi — autonomous agents plus a typed API and lifecycle events",
8
8
  "license": "MIT",
9
9
  "repository": {
@@ -2,7 +2,6 @@ import type { AgentConfig, ThinkingLevel } from "../types";
2
2
 
3
3
  interface AgentInvocationParams {
4
4
  model?: string;
5
- model_tier?: string;
6
5
  thinking?: string;
7
6
  max_turns?: number;
8
7
  run_in_background?: boolean;
@@ -12,12 +11,6 @@ interface AgentInvocationParams {
12
11
  export function resolveAgentInvocationConfig(
13
12
  agentConfig: AgentConfig | undefined,
14
13
  params: AgentInvocationParams,
15
- /**
16
- * Model reference already resolved from `params.model_tier` by the caller
17
- * (spawn-config resolves the tier so it can surface config errors). Precedence
18
- * matches `params.model`: agent config wins, then params, then the tier.
19
- */
20
- tierModel?: string,
21
14
  ): {
22
15
  modelInput?: string;
23
16
  modelFromParams: boolean;
@@ -27,8 +20,8 @@ export function resolveAgentInvocationConfig(
27
20
  runInBackground: boolean;
28
21
  } {
29
22
  return {
30
- modelInput: agentConfig?.model ?? params.model ?? tierModel,
31
- modelFromParams: agentConfig?.model == null && (params.model ?? tierModel) != null,
23
+ modelInput: agentConfig?.model ?? params.model,
24
+ modelFromParams: agentConfig?.model == null && params.model != null,
32
25
  thinking: (agentConfig?.thinking ?? params.thinking) as ThinkingLevel | undefined,
33
26
  maxTurns: agentConfig?.maxTurns ?? params.max_turns,
34
27
  inheritContext: agentConfig?.inheritContext ?? params.inherit_context ?? false,
@@ -1,10 +1,11 @@
1
1
  /**
2
- * model-tiers.ts — Capability/cost tiers for the subagent tool's `model_tier` param.
2
+ * model-tiers.ts — Capability/cost tier vocabulary for subagent model selection.
3
3
  *
4
- * A tier is an indirection: the calling agent asks for a class of model
5
- * (`fast` | `standard` | `advanced`) and the user decides which real model each
6
- * class maps to in `subagents.json` (`modelTiers`). See README for the intended
7
- * semantics of each tier.
4
+ * A tier is a user-facing class of model (`fast` | `standard` | `advanced`).
5
+ * Users map each tier to a real model in `subagents.json` (`modelTiers`); the
6
+ * mapping is surfaced to the agent through the `subagent` tool's prompt
7
+ * guidelines so it can pass the configured model via the `model` parameter.
8
+ * There is no `model_tier` tool parameter. See README for tier semantics.
8
9
  */
9
10
 
10
11
  export const MODEL_TIERS = ["fast", "standard", "advanced"] as const;
@@ -14,53 +15,9 @@ export type ModelTier = (typeof MODEL_TIERS)[number];
14
15
  /** Partial tier → model mapping as configured in `subagents.json`. */
15
16
  export type ModelTierMap = Partial<Record<ModelTier, string>>;
16
17
 
17
- /**
18
- * Case-insensitively map a raw value to a canonical tier.
19
- * Returns undefined for unknown names and non-strings.
20
- */
21
- export function normalizeModelTier(value: unknown): ModelTier | undefined {
22
- if (typeof value !== "string") return undefined;
23
- const lower = value.trim().toLowerCase();
24
- return (MODEL_TIERS as readonly string[]).includes(lower) ? (lower as ModelTier) : undefined;
25
- }
26
-
27
- /** Successful resolution — `model` is the configured model reference, not a Model instance. */
28
- export interface ModelTierResolutionResult {
29
- model: string;
30
- error?: undefined;
31
- }
32
-
33
- /** Failed resolution: unknown tier name or no mapping configured for a known tier. */
34
- export interface ModelTierResolutionError {
35
- model?: undefined;
36
- error: string;
37
- }
38
-
39
- export type ModelTierResolution = ModelTierResolutionResult | ModelTierResolutionError;
40
-
41
- /** Where users configure the tier map — repeated in error messages. */
42
- const SETTINGS_HINT = "Configure it in .pi/subagents.json or ~/.pi/agent/subagents.json";
43
-
44
- /**
45
- * Resolve a `model_tier` param value to the model reference configured for it.
46
- * An unknown tier or an unconfigured mapping is an explicit error — a tier
47
- * request is never silently downgraded to another model.
48
- */
49
- export function resolveModelTier(input: unknown, tiers: ModelTierMap | undefined): ModelTierResolution {
50
- const tier = normalizeModelTier(input);
51
- if (!tier) {
52
- return {
53
- error: `Unknown model tier: "${String(input)}". Valid tiers: ${MODEL_TIERS.join(", ")}.`,
54
- };
55
- }
56
-
57
- const configured = tiers?.[tier];
58
- const model = typeof configured === "string" ? configured.trim() : "";
59
- if (!model) {
60
- return {
61
- error: `Model tier "${tier}" is not configured. ${SETTINGS_HINT}, e.g. {"modelTiers": {"${tier}": "provider/modelId"}}.`,
62
- };
63
- }
64
-
65
- return { model };
66
- }
18
+ /** LLM-facing intent of each tier — mirrors the README table. */
19
+ export const MODEL_TIER_INTENTS: Record<ModelTier, string> = {
20
+ fast: "cheapest, fastest, least capable",
21
+ standard: "balanced default",
22
+ advanced: "most capable, most expensive",
23
+ };
package/src/settings.ts CHANGED
@@ -16,10 +16,11 @@ export interface SubagentsSettings {
16
16
  defaultMaxTurns?: number;
17
17
  graceTurns?: number;
18
18
  /**
19
- * Capability/cost tier → real model mapping for the `subagent` tool's
20
- * `model_tier` param. Tier names are fixed (`fast` | `standard` | `advanced`);
21
- * values accept anything `resolveModel` understands (e.g. "provider/modelId"
22
- * or a fuzzy name like "haiku").
19
+ * Capability/cost tier → real model mapping. Used only to generate the
20
+ * `subagent` tool's prompt guidelines, which tell the agent which model to
21
+ * pass via `model` for each capability level. Tier names are fixed
22
+ * (`fast` | `standard` | `advanced`); values accept anything `resolveModel`
23
+ * understands (e.g. "provider/modelId" or a fuzzy name like "haiku").
23
24
  */
24
25
  modelTiers?: ModelTierMap;
25
26
  }
@@ -86,7 +87,7 @@ export class SettingsManager {
86
87
  this._maxConcurrent = Math.max(1, n);
87
88
  }
88
89
 
89
- // ── modelTiers: tier → model map for the subagent tool's model_tier param ──
90
+ // ── modelTiers: tier → model map used to generate the subagent prompt guidelines ──
90
91
 
91
92
  get modelTiers(): ModelTierMap {
92
93
  return this._modelTiers;
@@ -4,7 +4,7 @@ import { defineTool } from "@earendil-works/pi-coding-agent";
4
4
  import { Text } from "@earendil-works/pi-tui";
5
5
  import { Type } from "typebox";
6
6
  import type { AgentTypeRegistry } from "../config/agent-types";
7
- import { MODEL_TIERS, type ModelTierMap } from "../config/model-tiers";
7
+ import { MODEL_TIERS, MODEL_TIER_INTENTS, type ModelTierMap } from "../config/model-tiers";
8
8
  import type { ParentSnapshot } from "../lifecycle/parent-snapshot";
9
9
  import type { AgentSpawnConfig } from "../lifecycle/subagent-manager";
10
10
  import { spawnBackground } from "../tools/background-spawner";
@@ -44,10 +44,13 @@ export type AgentToolSettings = {
44
44
  readonly modelTiers?: ModelTierMap;
45
45
  };
46
46
 
47
- /** LLM-facing summary of which tiers are configured, e.g. `fast → deepseek-flash`. */
48
- function buildTierListText(tiers: ModelTierMap | undefined): string {
49
- const configured = MODEL_TIERS.filter((tier) => tiers?.[tier]).map((tier) => `${tier} → ${tiers?.[tier]}`);
50
- return configured.length > 0 ? configured.join(", ") : "none configured";
47
+ /** LLM-facing guidance to map a capability tier to the model to pass via the `model` parameter, or undefined when none configured. */
48
+ function buildTierGuideline(tiers: ModelTierMap | undefined): string | undefined {
49
+ const configured = MODEL_TIERS.filter((tier) => tiers?.[tier]).map(
50
+ (tier) => `${tier} → ${tiers?.[tier]} (${MODEL_TIER_INTENTS[tier]})`,
51
+ );
52
+ if (configured.length === 0) return undefined;
53
+ return `User-configured subagent model tiers — when a task needs one of these capability levels, pass the mapped model via the model parameter: ${configured.join(", ")}.`;
51
54
  }
52
55
 
53
56
  // ---- Class ----
@@ -121,13 +124,14 @@ export class AgentTool {
121
124
  toToolDefinition() {
122
125
  const typeListText = this.typeListText;
123
126
  const availableTypesText = this.availableTypesText;
124
- const tierListText = buildTierListText(this.settings.modelTiers);
127
+ const tierGuideline = buildTierGuideline(this.settings.modelTiers);
125
128
  const registry = this.registry;
126
129
 
127
130
  return defineTool({
128
131
  name: "subagent" as const,
129
132
  label: "Subagent",
130
133
  promptSnippet: "subagent: Launch a specialized agent for complex, multi-step tasks.",
134
+ ...(tierGuideline ? { promptGuidelines: [tierGuideline] } : {}),
131
135
  description: `Launch a new agent to handle complex, multi-step tasks autonomously.
132
136
 
133
137
  The subagent tool launches specialized agents that autonomously handle complex tasks. Each agent type has specific capabilities and tools available to it.
@@ -143,7 +147,6 @@ Guidelines:
143
147
  - Use resume with an agent ID to continue a previous agent's work.
144
148
  - Use steer_subagent to send mid-run messages to a running background agent.
145
149
  - Use model to specify a different model (as "provider/modelId", or fuzzy e.g. "haiku", "sonnet").
146
- - Use model_tier to pick a preconfigured capability tier instead of naming a model — never pass both. Tiers: fast (cheapest, fastest, least capable), standard (balanced default), advanced (most capable, most expensive). Configured: ${tierListText}.
147
150
  - Use thinking to control extended thinking level.
148
151
  - Use inherit_context if the agent needs the parent conversation history.
149
152
  `,
@@ -160,13 +163,7 @@ Guidelines:
160
163
  model: Type.Optional(
161
164
  Type.String({
162
165
  description:
163
- 'Optional model override. Accepts "provider/modelId" or fuzzy name (e.g. "haiku", "sonnet"). Omit to use the agent type\'s default. Mutually exclusive with model_tier.',
164
- }),
165
- ),
166
- model_tier: Type.Optional(
167
- Type.Union([Type.Literal("fast"), Type.Literal("standard"), Type.Literal("advanced")], {
168
- description:
169
- 'Optional capability tier: "fast" (cheapest and fastest, least capable), "standard" (balanced default), or "advanced" (most capable, most expensive). Mutually exclusive with model. The real model behind each tier is configured in subagents.json (modelTiers).',
166
+ 'Optional model override. Accepts "provider/modelId" or fuzzy name (e.g. "haiku", "sonnet"). Omit to use the agent type\'s default.',
170
167
  }),
171
168
  ),
172
169
  thinking: Type.Optional(
@@ -10,7 +10,6 @@
10
10
  import type { Model } from "@earendil-works/pi-ai";
11
11
  import type { AgentTypeRegistry } from "../config/agent-types";
12
12
  import { resolveAgentInvocationConfig } from "../config/invocation-config";
13
- import { type ModelTierMap, resolveModelTier } from "../config/model-tiers";
14
13
  import { normalizeMaxTurns } from "../lifecycle/turn-limits";
15
14
  import { resolveInvocationModel } from "../session/model-resolver";
16
15
  import type { AgentInvocation, SubagentType, ThinkingLevel } from "../types";
@@ -82,7 +81,7 @@ export function resolveSpawnConfig(
82
81
  params: Record<string, unknown>,
83
82
  registry: AgentTypeRegistry,
84
83
  modelInfo: ModelInfo,
85
- settings: { readonly defaultMaxTurns: number | undefined; readonly modelTiers?: ModelTierMap },
84
+ settings: { readonly defaultMaxTurns: number | undefined },
86
85
  ): ResolvedSpawnConfig | SpawnConfigError {
87
86
  const rawType = params.subagent_type as SubagentType;
88
87
  const resolved = registry.resolveType(rawType);
@@ -97,26 +96,9 @@ export function resolveSpawnConfig(
97
96
 
98
97
  const displayName = getDisplayName(subagentType, registry);
99
98
 
100
- // `model` and `model_tier` are two ways to express the same choice — never both.
101
- const tierInput = params.model_tier;
102
- if (params.model != null && tierInput != null) {
103
- return { error: 'Specify either "model" or "model_tier" (capability tier), not both.' };
104
- }
105
-
106
99
  // Merge agent config defaults with tool-call params
107
100
  const customConfig = registry.resolveAgentConfig(subagentType);
108
-
109
- // A model pinned by the agent type wins over tool-call params, so the tier is
110
- // only resolved when it can actually apply (mirrors how a locked config model
111
- // makes an unresolvable `model` param a silent no-op).
112
- let tierModel: string | undefined;
113
- if (tierInput != null && customConfig?.model == null) {
114
- const tierResolution = resolveModelTier(tierInput, settings.modelTiers);
115
- if (tierResolution.error) return { error: tierResolution.error };
116
- tierModel = tierResolution.model;
117
- }
118
-
119
- const resolvedConfig = resolveAgentInvocationConfig(customConfig, params, tierModel);
101
+ const resolvedConfig = resolveAgentInvocationConfig(customConfig, params);
120
102
 
121
103
  // Resolve model
122
104
  const resolution = resolveInvocationModel(