@yandy0725/pi-subagents 0.5.4 → 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 +42 -1
- package/README.zh.md +37 -1
- package/package.json +5 -5
- package/src/config/model-tiers.ts +23 -0
- package/src/layered-settings.ts +10 -3
- package/src/service/service-adapter.ts +2 -2
- package/src/session/model-resolver.ts +9 -0
- package/src/settings.ts +53 -1
- package/src/tools/agent-tool.ts +13 -0
package/README.md
CHANGED
|
@@ -13,6 +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** — map `fast` / `standard` / `advanced` to real models in config; the agent is guided to pick the configured model per task
|
|
16
17
|
- **Context inheritance** — optionally fork the parent conversation into a sub-agent
|
|
17
18
|
- **Styled notifications** — background results render as themed notification boxes
|
|
18
19
|
- **Event bus** — lifecycle events (`subagents:created`, `started`, `completed`, `failed`, `steered`, `compacted`) via `pi.events`
|
|
@@ -100,6 +101,38 @@ Send a steering message to a running agent.
|
|
|
100
101
|
| `agent_id` | string | yes | Agent ID to steer |
|
|
101
102
|
| `message` | string | yes | Message to inject into agent conversation |
|
|
102
103
|
|
|
104
|
+
## Model Tiers
|
|
105
|
+
|
|
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.
|
|
110
|
+
|
|
111
|
+
| Tier | Intent |
|
|
112
|
+
|------|--------|
|
|
113
|
+
| `fast` | Cheapest and fastest, least capable (flash / mini / haiku class) |
|
|
114
|
+
| `standard` | Balanced default (sonnet class) |
|
|
115
|
+
| `advanced` | Most capable, most expensive (opus class) |
|
|
116
|
+
|
|
117
|
+
The mapping lives in `subagents.json` — `~/.pi/agent/subagents.json` (global) and
|
|
118
|
+
`<cwd>/.pi/subagents.json` (project). The two layers merge **per tier**, so a project can
|
|
119
|
+
override one tier without restating the others:
|
|
120
|
+
|
|
121
|
+
```json
|
|
122
|
+
{
|
|
123
|
+
"modelTiers": {
|
|
124
|
+
"fast": "deepseek-flash",
|
|
125
|
+
"standard": "deepseek-flash",
|
|
126
|
+
"advanced": "qwen3.8-max"
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
```
|
|
130
|
+
|
|
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
|
+
|
|
103
136
|
## Commands
|
|
104
137
|
|
|
105
138
|
| Command | Description |
|
|
@@ -113,13 +146,21 @@ collapsed form (summaries and previews), so a `read` call is represented by its
|
|
|
113
146
|
call line only. The viewer has no expand key, so the "… to expand" hints some
|
|
114
147
|
tools print do not apply here.
|
|
115
148
|
|
|
149
|
+
The viewer follows the live tail: the newest lines stay pinned to the bottom until you scroll up.
|
|
150
|
+
Upward keys (`↑`/`k`, `PgUp`/`shift+up`, `Home`) **unconditionally** pause following — streaming can
|
|
151
|
+
add lines between a keypress and the render, so a "was I at the bottom?" test against that stale
|
|
152
|
+
value would snap a viewport you just left back down. A downward key that lands on the bottom
|
|
153
|
+
(`↓`/`j`, `PgDn`/`shift+down`) resumes following, and `end` jumps to the bottom and force-resumes;
|
|
154
|
+
`q`/`Esc` closes. The paused state has **no visual indicator** (the footer keeps showing
|
|
155
|
+
`<n> lines · <pct>%` and the key hints).
|
|
156
|
+
|
|
116
157
|
## Concurrency
|
|
117
158
|
|
|
118
159
|
Background agents are subject to a configurable concurrency limit (default: 4). Excess agents queue automatically. Foreground agents bypass the queue.
|
|
119
160
|
|
|
120
161
|
## Persistent Settings
|
|
121
162
|
|
|
122
|
-
Settings set via `/subagents:settings` persist in `<cwd>/.pi/subagents.json` (project) and can be overridden globally in `~/.pi/agent/subagents.json`.
|
|
163
|
+
Settings set via `/subagents:settings` persist in `<cwd>/.pi/subagents.json` (project) and can be overridden globally in `~/.pi/agent/subagents.json`. The same files also hold the [`modelTiers`](#model-tiers) mapping; saving other settings preserves it.
|
|
123
164
|
|
|
124
165
|
## Events
|
|
125
166
|
|
package/README.zh.md
CHANGED
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
- **优雅轮次限制** — 代理在硬中止前收到"收尾"警告
|
|
14
14
|
- **大小写不敏感** — `"explore"`、`"Explore"`、`"EXPLORE"` 均可
|
|
15
15
|
- **模糊模型选择** — 按名称(`"haiku"`、`"sonnet"`)而非完整 ID 指定模型
|
|
16
|
+
- **模型分层** — 在配置里把 `fast` / `standard` / `advanced` 档位映射到真实模型,代理按提示选择对应模型
|
|
16
17
|
- **上下文继承** — 可选择将父对话分叉给子代理
|
|
17
18
|
- **风格化通知** — 后台结果渲染为主题化通知框
|
|
18
19
|
- **事件总线** — 通过 `pi.events` 发出生命周期事件(`subagents:created`、`started`、`completed`、`failed`、`steered`、`compacted`)
|
|
@@ -100,6 +101,35 @@ max_turns: 30
|
|
|
100
101
|
| `agent_id` | string | 是 | 要转向的代理 ID |
|
|
101
102
|
| `message` | string | 是 | 注入代理对话的消息 |
|
|
102
103
|
|
|
104
|
+
## 模型分层
|
|
105
|
+
|
|
106
|
+
除了直接写模型 ID,还可以在 `subagents.json` 中把能力档位映射到真实模型。映射会生成
|
|
107
|
+
`subagent` 工具的 prompt guidelines,告诉代理每个档位应通过 `model` 参数传哪个模型——
|
|
108
|
+
不存在 `model_tier` 工具参数。
|
|
109
|
+
|
|
110
|
+
| 档位 | 定位 |
|
|
111
|
+
|------|------|
|
|
112
|
+
| `fast` | 最便宜、最快,能力最弱(flash / mini / haiku 级) |
|
|
113
|
+
| `standard` | 均衡的默认档(sonnet 级) |
|
|
114
|
+
| `advanced` | 能力最强、最贵(opus 级) |
|
|
115
|
+
|
|
116
|
+
映射写在 `subagents.json`:全局 `~/.pi/agent/subagents.json`,项目 `<cwd>/.pi/subagents.json`。
|
|
117
|
+
两层**按档位合并**,项目只改一档时无需重复其余档位:
|
|
118
|
+
|
|
119
|
+
```json
|
|
120
|
+
{
|
|
121
|
+
"modelTiers": {
|
|
122
|
+
"fast": "deepseek-flash",
|
|
123
|
+
"standard": "deepseek-flash",
|
|
124
|
+
"advanced": "qwen3.8-max"
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
代理会把映射值复制到 `model`,因此与普通 `model` 值走同一套解析:`provider/modelId` 与
|
|
130
|
+
模糊名称(如 `"haiku"`)都可以。未配置的档位不会出现在提示里——不会有其他模型被静默
|
|
131
|
+
顶替。若代理类型的 frontmatter 固定了 `model`,该模型始终优先。
|
|
132
|
+
|
|
103
133
|
## 命令
|
|
104
134
|
|
|
105
135
|
| 命令 | 描述 |
|
|
@@ -111,13 +141,19 @@ max_turns: 30
|
|
|
111
141
|
工具结果按 Pi 的折叠形态显示(摘要与预览),因此 `read` 调用只显示其调用行。
|
|
112
142
|
查看器没有展开键,部分工具调用行里提示的"to expand"键在此不适用。
|
|
113
143
|
|
|
144
|
+
查看器跟随实时尾部:未滚动时最新行始终贴在底部。向上键(`↑`/`k`、`PgUp`/`shift+up`、`Home`)会
|
|
145
|
+
**无条件**暂停跟随 —— 流式输出可能在按键与渲染之间新增行,用那个已经过期的值去判断"我是不是在底部"
|
|
146
|
+
会把刚刚离开的视口又拽回底部。向下键落到底部(`↓`/`j`、`PgDn`/`shift+down`)即恢复跟随,`end`
|
|
147
|
+
直接跳到底部并强制恢复;`q`/`Esc` 关闭。暂停状态**没有可视指示**(footer 始终显示 `<n> lines · <pct>%`
|
|
148
|
+
与键位提示)。
|
|
149
|
+
|
|
114
150
|
## 并发控制
|
|
115
151
|
|
|
116
152
|
后台代理受可配置并发限制约束(默认 4)。超出限制的代理自动排队。前台代理绕过队列。
|
|
117
153
|
|
|
118
154
|
## 持久化设置
|
|
119
155
|
|
|
120
|
-
通过 `/subagents:settings` 设置的参数持久化到 `<cwd>/.pi/subagents.json`(项目级),也可在 `~/.pi/agent/subagents.json`
|
|
156
|
+
通过 `/subagents:settings` 设置的参数持久化到 `<cwd>/.pi/subagents.json`(项目级),也可在 `~/.pi/agent/subagents.json` 中设置全局默认值。同一批文件也保存 [`modelTiers`](#模型分层) 映射;保存其他设置时会保留它。
|
|
121
157
|
|
|
122
158
|
## 事件
|
|
123
159
|
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"publishConfig": {
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
|
-
"version": "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": {
|
|
@@ -38,10 +38,10 @@
|
|
|
38
38
|
"typebox": "*"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
|
-
"@biomejs/biome": "^2.5.
|
|
42
|
-
"@types/node": "^26.6.
|
|
43
|
-
"typebox": "^1.3.
|
|
41
|
+
"@biomejs/biome": "^2.5.15",
|
|
42
|
+
"@types/node": "^26.6.5",
|
|
43
|
+
"typebox": "^1.3.37",
|
|
44
44
|
"typescript": "~7.0.2",
|
|
45
|
-
"vitest": "^5.0.
|
|
45
|
+
"vitest": "^5.0.4"
|
|
46
46
|
}
|
|
47
47
|
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* model-tiers.ts — Capability/cost tier vocabulary for subagent model selection.
|
|
3
|
+
*
|
|
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.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
export const MODEL_TIERS = ["fast", "standard", "advanced"] as const;
|
|
12
|
+
|
|
13
|
+
export type ModelTier = (typeof MODEL_TIERS)[number];
|
|
14
|
+
|
|
15
|
+
/** Partial tier → model mapping as configured in `subagents.json`. */
|
|
16
|
+
export type ModelTierMap = Partial<Record<ModelTier, string>>;
|
|
17
|
+
|
|
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/layered-settings.ts
CHANGED
|
@@ -67,6 +67,12 @@ export interface LayeredSettingsSource<T> {
|
|
|
67
67
|
* e.g. `"pi-subagents"` → `"[pi-subagents] Ignoring malformed settings at …"`.
|
|
68
68
|
*/
|
|
69
69
|
warnLabel: string;
|
|
70
|
+
/**
|
|
71
|
+
* Optional merge of the two layers (global first, project second).
|
|
72
|
+
* Defaults to a shallow spread with project keys winning. Supply this to
|
|
73
|
+
* merge nested objects field-by-field instead of replacing them wholesale.
|
|
74
|
+
*/
|
|
75
|
+
merge?: (global: Partial<T>, project: Partial<T>) => Partial<T>;
|
|
70
76
|
}
|
|
71
77
|
|
|
72
78
|
/**
|
|
@@ -75,17 +81,18 @@ export interface LayeredSettingsSource<T> {
|
|
|
75
81
|
* - A missing file is silent — returns `{}` for that layer.
|
|
76
82
|
* - A file that exists but cannot be parsed warns to stderr and returns `{}` for
|
|
77
83
|
* that layer, so startup proceeds normally.
|
|
78
|
-
* - The two layers are merged with a shallow spread; project keys win.
|
|
84
|
+
* - The two layers are merged with a shallow spread; project keys win. Pass
|
|
85
|
+
* `merge` to override that (e.g. to merge nested objects per field).
|
|
79
86
|
*
|
|
80
87
|
* Throws nothing. All error conditions produce a warning and fall back to `{}`.
|
|
81
88
|
*
|
|
82
89
|
* @public
|
|
83
90
|
*/
|
|
84
91
|
export function loadLayeredSettings<T>(source: LayeredSettingsSource<T>): Partial<T> {
|
|
85
|
-
const { agentDir, cwd, filename, sanitize, warnLabel } = source;
|
|
92
|
+
const { agentDir, cwd, filename, sanitize, warnLabel, merge } = source;
|
|
86
93
|
const global = readLayer(join(agentDir, filename), sanitize, warnLabel);
|
|
87
94
|
const project = readLayer(join(cwd, ".pi", filename), sanitize, warnLabel);
|
|
88
|
-
return { ...global, ...project };
|
|
95
|
+
return merge ? merge(global, project) : { ...global, ...project };
|
|
89
96
|
}
|
|
90
97
|
|
|
91
98
|
// ── Private helpers ──────────────────────────────────────────────────────────
|
|
@@ -102,8 +102,8 @@ export class SubagentsServiceAdapter implements SubagentsService {
|
|
|
102
102
|
if (record?.status !== "running") {
|
|
103
103
|
return false;
|
|
104
104
|
}
|
|
105
|
-
|
|
106
|
-
return
|
|
105
|
+
// 透传 Subagent.steer() 的返回:true = 已投递到会话,false = 会话未就绪已入队缓冲。
|
|
106
|
+
return record.steer(message);
|
|
107
107
|
}
|
|
108
108
|
|
|
109
109
|
async waitForAll(): Promise<void> {
|
|
@@ -61,6 +61,11 @@ export function resolveInvocationModel(
|
|
|
61
61
|
export function resolveModel(input: string, registry: ModelRegistry): any | string {
|
|
62
62
|
// Available models (those with auth configured)
|
|
63
63
|
const all = (registry.getAvailable?.() ?? registry.getAll()) as ModelEntry[];
|
|
64
|
+
|
|
65
|
+
// 空查询会让 substring/every 判定对每个模型恒真,从而任意命中第一个模型;显式拒绝。
|
|
66
|
+
if (input.trim() === "") {
|
|
67
|
+
return noMatchError(input, all);
|
|
68
|
+
}
|
|
64
69
|
const availableSet = new Set(all.map((m) => `${m.provider}/${m.id}`.toLowerCase()));
|
|
65
70
|
|
|
66
71
|
// 1. Exact match: "provider/modelId" — only if available (has auth)
|
|
@@ -113,6 +118,10 @@ export function resolveModel(input: string, registry: ModelRegistry): any | stri
|
|
|
113
118
|
}
|
|
114
119
|
|
|
115
120
|
// 3. No match — list available models
|
|
121
|
+
return noMatchError(input, all);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
function noMatchError(input: string, all: ModelEntry[]): string {
|
|
116
125
|
const modelList = all
|
|
117
126
|
.map((m) => ` ${m.provider}/${m.id}`)
|
|
118
127
|
.sort()
|
package/src/settings.ts
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
import { mkdirSync, writeFileSync } from "node:fs";
|
|
6
6
|
import { dirname, join } from "node:path";
|
|
7
|
+
import { MODEL_TIERS, type ModelTierMap } from "./config/model-tiers";
|
|
7
8
|
import { type LayeredSettingsSource, loadLayeredSettings } from "./layered-settings";
|
|
8
9
|
export interface SubagentsSettings {
|
|
9
10
|
maxConcurrent?: number;
|
|
@@ -14,6 +15,14 @@ export interface SubagentsSettings {
|
|
|
14
15
|
*/
|
|
15
16
|
defaultMaxTurns?: number;
|
|
16
17
|
graceTurns?: number;
|
|
18
|
+
/**
|
|
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").
|
|
24
|
+
*/
|
|
25
|
+
modelTiers?: ModelTierMap;
|
|
17
26
|
}
|
|
18
27
|
|
|
19
28
|
/** Emit callback — a subset of `pi.events.emit` to keep helpers testable. */
|
|
@@ -30,6 +39,7 @@ export class SettingsManager {
|
|
|
30
39
|
private _defaultMaxTurns: number | undefined = undefined;
|
|
31
40
|
private _graceTurns: number = DEFAULT_GRACE_TURNS;
|
|
32
41
|
private _maxConcurrent: number = DEFAULT_MAX_CONCURRENT;
|
|
42
|
+
private _modelTiers: ModelTierMap = {};
|
|
33
43
|
|
|
34
44
|
private readonly emit: SettingsEmit;
|
|
35
45
|
private readonly cwd: string;
|
|
@@ -77,6 +87,12 @@ export class SettingsManager {
|
|
|
77
87
|
this._maxConcurrent = Math.max(1, n);
|
|
78
88
|
}
|
|
79
89
|
|
|
90
|
+
// ── modelTiers: tier → model map used to generate the subagent prompt guidelines ──
|
|
91
|
+
|
|
92
|
+
get modelTiers(): ModelTierMap {
|
|
93
|
+
return this._modelTiers;
|
|
94
|
+
}
|
|
95
|
+
|
|
80
96
|
// ── Lifecycle methods ──
|
|
81
97
|
|
|
82
98
|
/**
|
|
@@ -89,6 +105,7 @@ export class SettingsManager {
|
|
|
89
105
|
if (typeof settings.maxConcurrent === "number") this.maxConcurrent = settings.maxConcurrent;
|
|
90
106
|
if (typeof settings.defaultMaxTurns === "number") this.defaultMaxTurns = settings.defaultMaxTurns;
|
|
91
107
|
if (typeof settings.graceTurns === "number") this.graceTurns = settings.graceTurns;
|
|
108
|
+
this._modelTiers = settings.modelTiers ? { ...settings.modelTiers } : {};
|
|
92
109
|
this.emit("subagents:settings_loaded", { settings });
|
|
93
110
|
return settings;
|
|
94
111
|
}
|
|
@@ -96,12 +113,15 @@ export class SettingsManager {
|
|
|
96
113
|
/**
|
|
97
114
|
* Snapshot current in-memory values for persistence.
|
|
98
115
|
* `defaultMaxTurns` uses 0 as the on-disk marker for unlimited (undefined).
|
|
116
|
+
* `modelTiers` is omitted when empty so hand-edited tier maps are only
|
|
117
|
+
* rewritten (not replaced with an empty object) when they exist.
|
|
99
118
|
*/
|
|
100
|
-
snapshot(): { maxConcurrent: number; defaultMaxTurns: number; graceTurns: number } {
|
|
119
|
+
snapshot(): { maxConcurrent: number; defaultMaxTurns: number; graceTurns: number; modelTiers?: ModelTierMap } {
|
|
101
120
|
return {
|
|
102
121
|
maxConcurrent: this._maxConcurrent,
|
|
103
122
|
defaultMaxTurns: this._defaultMaxTurns ?? 0,
|
|
104
123
|
graceTurns: this._graceTurns,
|
|
124
|
+
...(Object.keys(this._modelTiers).length > 0 ? { modelTiers: { ...this._modelTiers } } : {}),
|
|
105
125
|
};
|
|
106
126
|
}
|
|
107
127
|
|
|
@@ -178,9 +198,27 @@ function sanitize(raw: unknown): SubagentsSettings {
|
|
|
178
198
|
) {
|
|
179
199
|
out.graceTurns = r.graceTurns as number;
|
|
180
200
|
}
|
|
201
|
+
const modelTiers = sanitizeModelTiers(r.modelTiers);
|
|
202
|
+
if (modelTiers) out.modelTiers = modelTiers;
|
|
181
203
|
return out;
|
|
182
204
|
}
|
|
183
205
|
|
|
206
|
+
/**
|
|
207
|
+
* Keep only known tier names with non-empty string values (trimmed).
|
|
208
|
+
* Returns `undefined` when nothing survives — an empty map is the same as
|
|
209
|
+
* "not configured" everywhere else.
|
|
210
|
+
*/
|
|
211
|
+
function sanitizeModelTiers(raw: unknown): ModelTierMap | undefined {
|
|
212
|
+
if (!raw || typeof raw !== "object" || Array.isArray(raw)) return undefined;
|
|
213
|
+
const source = raw as Record<string, unknown>;
|
|
214
|
+
const out: ModelTierMap = {};
|
|
215
|
+
for (const tier of MODEL_TIERS) {
|
|
216
|
+
const value = source[tier];
|
|
217
|
+
if (typeof value === "string" && value.trim()) out[tier] = value.trim();
|
|
218
|
+
}
|
|
219
|
+
return Object.keys(out).length > 0 ? out : undefined;
|
|
220
|
+
}
|
|
221
|
+
|
|
184
222
|
function projectPath(cwd: string): string {
|
|
185
223
|
return join(cwd, ".pi", "subagents.json");
|
|
186
224
|
}
|
|
@@ -193,9 +231,23 @@ export function loadSettings(agentDir: string, cwd: string): SubagentsSettings {
|
|
|
193
231
|
filename: "subagents.json",
|
|
194
232
|
sanitize,
|
|
195
233
|
warnLabel: "pi-subagents",
|
|
234
|
+
merge: mergeSettings,
|
|
196
235
|
} satisfies LayeredSettingsSource<SubagentsSettings>);
|
|
197
236
|
}
|
|
198
237
|
|
|
238
|
+
/**
|
|
239
|
+
* Shallow-merge scalars (project wins), but merge `modelTiers` per tier so a
|
|
240
|
+
* project can override one tier without restating the global map.
|
|
241
|
+
*/
|
|
242
|
+
function mergeSettings(global: SubagentsSettings, project: SubagentsSettings): SubagentsSettings {
|
|
243
|
+
const modelTiers: ModelTierMap = { ...global.modelTiers, ...project.modelTiers };
|
|
244
|
+
return {
|
|
245
|
+
...global,
|
|
246
|
+
...project,
|
|
247
|
+
...(Object.keys(modelTiers).length > 0 ? { modelTiers } : {}),
|
|
248
|
+
};
|
|
249
|
+
}
|
|
250
|
+
|
|
199
251
|
/**
|
|
200
252
|
* Write project-local settings. Global is never touched from code.
|
|
201
253
|
* Returns `true` on success, `false` if the write (or mkdir) failed so the
|
package/src/tools/agent-tool.ts
CHANGED
|
@@ -4,6 +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, MODEL_TIER_INTENTS, type ModelTierMap } from "../config/model-tiers";
|
|
7
8
|
import type { ParentSnapshot } from "../lifecycle/parent-snapshot";
|
|
8
9
|
import type { AgentSpawnConfig } from "../lifecycle/subagent-manager";
|
|
9
10
|
import { spawnBackground } from "../tools/background-spawner";
|
|
@@ -40,8 +41,18 @@ export interface AgentToolRuntime {
|
|
|
40
41
|
export type AgentToolSettings = {
|
|
41
42
|
readonly defaultMaxTurns: number | undefined;
|
|
42
43
|
readonly maxConcurrent: number;
|
|
44
|
+
readonly modelTiers?: ModelTierMap;
|
|
43
45
|
};
|
|
44
46
|
|
|
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(", ")}.`;
|
|
54
|
+
}
|
|
55
|
+
|
|
45
56
|
// ---- Class ----
|
|
46
57
|
|
|
47
58
|
export class AgentTool {
|
|
@@ -113,12 +124,14 @@ export class AgentTool {
|
|
|
113
124
|
toToolDefinition() {
|
|
114
125
|
const typeListText = this.typeListText;
|
|
115
126
|
const availableTypesText = this.availableTypesText;
|
|
127
|
+
const tierGuideline = buildTierGuideline(this.settings.modelTiers);
|
|
116
128
|
const registry = this.registry;
|
|
117
129
|
|
|
118
130
|
return defineTool({
|
|
119
131
|
name: "subagent" as const,
|
|
120
132
|
label: "Subagent",
|
|
121
133
|
promptSnippet: "subagent: Launch a specialized agent for complex, multi-step tasks.",
|
|
134
|
+
...(tierGuideline ? { promptGuidelines: [tierGuideline] } : {}),
|
|
122
135
|
description: `Launch a new agent to handle complex, multi-step tasks autonomously.
|
|
123
136
|
|
|
124
137
|
The subagent tool launches specialized agents that autonomously handle complex tasks. Each agent type has specific capabilities and tools available to it.
|