@yandy0725/pi-subagents 0.9.0 → 0.10.1

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
@@ -121,9 +121,10 @@ Send a steering message to a running agent.
121
121
  ## Model Tiers
122
122
 
123
123
  Instead of hardcoding model IDs, you can map capability tiers to concrete models in
124
- `subagents.json`. The mapping feeds the `subagent` tool's prompt guidelines, which tell the
125
- agent which model to pass via the `model` parameter — there is no `model_tier` tool
126
- parameter.
124
+ `subagents.json`. The mapping is listed in the `subagent` tool's `model` parameter
125
+ description, alongside a prompt guideline telling the agent to pick the configured
126
+ tier when a task calls for a specific cost or capability level — there is no
127
+ `model_tier` tool parameter.
127
128
 
128
129
  | Tier | Intent |
129
130
  |------|--------|
@@ -147,8 +148,8 @@ override one tier without restating the others:
147
148
 
148
149
  Because the agent copies the mapped value into `model`, it goes through the same resolver as
149
150
  any other model value: `provider/modelId` and fuzzy names (e.g. `"haiku"`) both work. Tiers
150
- without a mapping are omitted from the guidelines — nothing is silently substituted for
151
- them. If an agent type pins `model` in its frontmatter, that model always wins.
151
+ without a mapping are omitted from the description and its guideline — nothing is silently
152
+ substituted for them. If an agent type pins `model` in its frontmatter, that model always wins.
152
153
 
153
154
  ## Commands
154
155
 
package/README.zh.md CHANGED
@@ -120,9 +120,9 @@ timeout: 300
120
120
 
121
121
  ## 模型分层
122
122
 
123
- 除了直接写模型 ID,还可以在 `subagents.json` 中把能力档位映射到真实模型。映射会生成
124
- `subagent` 工具的 prompt guidelines,告诉代理每个档位应通过 `model` 参数传哪个模型——
125
- 不存在 `model_tier` 工具参数。
123
+ 除了直接写模型 ID,还可以在 `subagents.json` 中把能力档位映射到真实模型。映射表会列在
124
+ `subagent` 工具的 `model` 参数描述里,同时有一条 prompt guideline 提醒代理在任务需要
125
+ 特定成本/能力档位时选用对应配置模型——不存在 `model_tier` 工具参数。
126
126
 
127
127
  | 档位 | 定位 |
128
128
  |------|------|
@@ -144,8 +144,8 @@ timeout: 300
144
144
  ```
145
145
 
146
146
  代理会把映射值复制到 `model`,因此与普通 `model` 值走同一套解析:`provider/modelId` 与
147
- 模糊名称(如 `"haiku"`)都可以。未配置的档位不会出现在提示里——不会有其他模型被静默
148
- 顶替。若代理类型的 frontmatter 固定了 `model`,该模型始终优先。
147
+ 模糊名称(如 `"haiku"`)都可以。未配置的档位不会出现在参数描述与提示里——不会有其他
148
+ 模型被静默顶替。若代理类型的 frontmatter 固定了 `model`,该模型始终优先。
149
149
 
150
150
  ## 命令
151
151
 
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "0.9.0",
6
+ "version": "0.10.1",
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": {
@@ -3,8 +3,9 @@
3
3
  *
4
4
  * A tier is a user-facing class of model (`fast` | `standard` | `advanced`).
5
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.
6
+ * mapping is surfaced to the agent in the `subagent` tool's `model` parameter
7
+ * description (a fact about that parameter's allowed values), plus one prompt
8
+ * guideline telling it to pick the matching tier when a task warrants it.
8
9
  * There is no `model_tier` tool parameter. See README for tier semantics.
9
10
  */
10
11
 
@@ -1,6 +1,7 @@
1
1
  /* eslint-disable @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-base-to-string, @typescript-eslint/restrict-template-expressions -- Pi SDK types are not fully exported; see upstream Pi SDK for type improvements */
2
2
  import type { AgentToolResult } from "@earendil-works/pi-coding-agent";
3
3
  import { defineTool } from "@earendil-works/pi-coding-agent";
4
+ import { StringEnum } from "@earendil-works/pi-ai";
4
5
  import { Text } from "@earendil-works/pi-tui";
5
6
  import { Type } from "typebox";
6
7
  import type { AgentTypeRegistry } from "../config/agent-types";
@@ -45,15 +46,50 @@ export type AgentToolSettings = {
45
46
  readonly modelTiers?: ModelTierMap;
46
47
  };
47
48
 
48
- /** LLM-facing guidance to map a capability tier to the model to pass via the `model` parameter, or undefined when none configured. */
49
- function buildTierGuideline(tiers: ModelTierMap | undefined): string | undefined {
49
+ /**
50
+ * `model` 参数描述的事实部分;配置了 tiers 时再追加档位表。
51
+ *
52
+ * 档位表是 `model` 的**允许值**(R1「允许值」+ R2「参数级细节放参数」),所以落在这里;
53
+ * 之前整段(表 + 纪律)写在 `promptGuidelines` 里有两个问题:自定义 system prompt 时
54
+ * guidelines 被整体丢弃(用户配的 tier 随之静默失效,README 承诺的映射无处可查),
55
+ * 且把配置数据混进了行为纪律列表。纪律侧现在只留 TIER_GUIDELINE。
56
+ */
57
+ const MODEL_PARAM_DESCRIPTION =
58
+ 'Optional model override. Accepts "provider/modelId" or fuzzy name (e.g. "haiku", "sonnet"). Omit to use the agent type\'s default.';
59
+
60
+ /** Tier → model table for the `model` parameter description, or undefined when none configured. */
61
+ function buildTierTable(tiers: ModelTierMap | undefined): string | undefined {
50
62
  const configured = MODEL_TIERS.filter((tier) => tiers?.[tier]).map(
51
63
  (tier) => `${tier} → ${tiers?.[tier]} (${MODEL_TIER_INTENTS[tier]})`,
52
64
  );
53
65
  if (configured.length === 0) return undefined;
54
- 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(", ")}.`;
66
+ return configured.join(", ");
55
67
  }
56
68
 
69
+ /**
70
+ * 纪律侧只点名「按配置档位选模型」,映射表本身在 `model` 参数描述里。
71
+ *
72
+ * 这条同时覆盖了 guidelines 通道的可用性风险:即便自定义 system prompt 让 guidelines 消失,
73
+ * 参数描述里的档位表仍在,模型仍能查到映射(只是少了这条主动提示)。
74
+ */
75
+ const TIER_GUIDELINE =
76
+ "When a subagent task needs a specific cost or capability level, use the matching configured tier's model rather than the agent type's default.";
77
+
78
+ /**
79
+ * 行为纪律(进 system prompt 的 Guidelines,不进 description)。
80
+ *
81
+ * 之前这些写在 `description` 里,同时与参数描述重复(`run_in_background` / `resume` / `model` /
82
+ * `thinking` / `timeout` / `inherit_context` 各说两遍,共 516 字符),而 description 是每工具
83
+ * 各一份、不参与去重。现在只留“何时用 / 怎么配合”这一类,参数细节全交给参数描述。
84
+ */
85
+ const PROMPT_GUIDELINES: readonly string[] = [
86
+ "Use subagent for work that needs its own context or a different model; finish inline work yourself.",
87
+ "For parallel work set run_in_background: true on each agent — sibling foreground calls run concurrently anyway, but they block the current turn and bypass the concurrency limit.",
88
+ "Give each subagent a self-contained prompt; it cannot see the parent conversation unless inherit_context is true.",
89
+ "Subagent results come back as text — summarize them for the user.",
90
+ "Use steer_subagent to redirect a running background agent, and get_subagent_result with wait: true to block for one result.",
91
+ ];
92
+
57
93
  // ---- Class ----
58
94
 
59
95
  export class AgentTool {
@@ -125,33 +161,18 @@ export class AgentTool {
125
161
  toToolDefinition() {
126
162
  const typeListText = this.typeListText;
127
163
  const availableTypesText = this.availableTypesText;
128
- const tierGuideline = buildTierGuideline(this.settings.modelTiers);
164
+ const tierTable = buildTierTable(this.settings.modelTiers);
129
165
  const registry = this.registry;
130
166
 
131
167
  return defineTool({
132
168
  name: "subagent" as const,
133
169
  label: "Subagent",
134
- promptSnippet: "subagent: Launch a specialized agent for complex, multi-step tasks.",
135
- ...(tierGuideline ? { promptGuidelines: [tierGuideline] } : {}),
136
- description: `Launch a new agent to handle complex, multi-step tasks autonomously.
137
-
138
- The subagent tool launches specialized agents that autonomously handle complex tasks. Each agent type has specific capabilities and tools available to it.
170
+ promptSnippet: "Launch a specialized agent for complex, multi-step tasks",
171
+ promptGuidelines: tierTable ? [...PROMPT_GUIDELINES, TIER_GUIDELINE] : [...PROMPT_GUIDELINES],
172
+ description: `Launch a subagent that works autonomously on a task.
139
173
 
140
174
  Available agent types:
141
- ${typeListText}
142
-
143
- Guidelines:
144
- - For parallel work, use run_in_background: true on each agent. Foreground calls run sequentially — only one executes at a time.
145
- - Provide clear, detailed prompts so the agent can work autonomously.
146
- - Subagent results are returned as text — summarize them for the user.
147
- - Use run_in_background for work you don't need immediately. You will be notified when it completes.
148
- - Use resume with an agent ID to continue a previous agent's work.
149
- - Use steer_subagent to send mid-run messages to a running background agent.
150
- - Use model to specify a different model (as "provider/modelId", or fuzzy e.g. "haiku", "sonnet").
151
- - Use thinking to control extended thinking level.
152
- - Use timeout (seconds) as a hard safety net for tasks that might run away — the agent is killed at the deadline and output may be truncated.
153
- - Use inherit_context if the agent needs the parent conversation history.
154
- `,
175
+ ${typeListText}`,
155
176
  parameters: Type.Object({
156
177
  prompt: Type.String({
157
178
  description: "The task for the agent to perform.",
@@ -164,13 +185,14 @@ Guidelines:
164
185
  }),
165
186
  model: Type.Optional(
166
187
  Type.String({
167
- description:
168
- 'Optional model override. Accepts "provider/modelId" or fuzzy name (e.g. "haiku", "sonnet"). Omit to use the agent type\'s default.',
188
+ description: tierTable
189
+ ? `${MODEL_PARAM_DESCRIPTION} Configured tiers: ${tierTable}.`
190
+ : MODEL_PARAM_DESCRIPTION,
169
191
  }),
170
192
  ),
171
193
  thinking: Type.Optional(
172
- Type.String({
173
- description: "Thinking level: off, minimal, low, medium, high, xhigh. Overrides agent default.",
194
+ StringEnum(["off", "minimal", "low", "medium", "high", "xhigh"] as const, {
195
+ description: "Thinking level override. Default: inherit the agent type's setting.",
174
196
  }),
175
197
  ),
176
198
  max_turns: Type.Optional(
@@ -90,9 +90,9 @@ export class GetResultTool {
90
90
  return defineTool({
91
91
  name: "get_subagent_result" as const,
92
92
  label: "Get Agent Result",
93
- promptSnippet: "get_subagent_result: Check status and retrieve results from a background agent.",
93
+ promptSnippet: "Check status and retrieve a background subagent's result",
94
94
  description:
95
- "Check status and retrieve results from a background agent. Use the agent ID returned by Agent with run_in_background.",
95
+ "Check status and retrieve the result of a background subagent (agent_id comes from the subagent tool).",
96
96
  parameters: Type.Object({
97
97
  agent_id: Type.String({
98
98
  description: "The agent ID to check.",
@@ -92,7 +92,7 @@ export function buildTypeListText(registry: TypeListRegistry, agentDir: string):
92
92
  ...defaultDescs,
93
93
  ...(customDescs.length > 0 ? ["", "Custom agents:", ...customDescs] : []),
94
94
  "",
95
- `Custom agents can be defined in .pi/agents/<name>.md (project) or ${agentDir}/agents/<name>.md (global) — they are picked up automatically. Project-level agents override global ones. Creating a .md file with the same name as a default agent overrides it.`,
95
+ `Custom agents live in .pi/agents/<name>.md (project) or ${agentDir}/agents/<name>.md (global); a file with a default agent's name overrides it.`,
96
96
  ].join("\n");
97
97
  }
98
98
 
@@ -66,10 +66,8 @@ export class SteerTool {
66
66
  return defineTool({
67
67
  name: "steer_subagent" as const,
68
68
  label: "Steer Agent",
69
- promptSnippet: "steer_subagent: Send a mid-run message to redirect a running background agent.",
70
- description:
71
- "Send a steering message to a running agent. The message will interrupt the agent after its current tool execution " +
72
- "and be injected into its conversation, allowing you to redirect its work mid-run. Only works on running agents.",
69
+ promptSnippet: "Send a mid-run message to redirect a running subagent",
70
+ description: "Send a mid-run steering message to a running subagent.",
73
71
  parameters: Type.Object({
74
72
  agent_id: Type.String({
75
73
  description: "The agent ID to steer (must be currently running).",