@lincoln504/pi-research 1.7.0 → 1.7.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.
@@ -2,7 +2,7 @@
2
2
  name: pi-research
3
3
  description: "Multi-agent web research for any coding agent. Use for anything requiring current information from the internet — news, trends, product/service/company facts, statistics, people, places, events, APIs, library behavior, or 'what is X / how does X work' questions. Also use to search a local knowledge store of previously researched findings before doing live research. Powered by the pi-research engine (search, stealth scraping, security databases, Stack Exchange). Not for reading local files, running project commands, or analyzing this repository's own source."
4
4
  license: MIT
5
- metadata: { "author": "Lincoln Deen", "version": "1.7.0", "package": "@lincoln504/pi-research", "engine": "pi-research-sdk", "openclaw": { "requires": { "bins": ["node"] } } }
5
+ metadata: { "author": "Lincoln Deen", "version": "1.7.1", "package": "@lincoln504/pi-research", "engine": "pi-research-sdk", "openclaw": { "requires": { "bins": ["node"] } } }
6
6
  allowed-tools: Bash(node:*)
7
7
  ---
8
8
 
@@ -27,7 +27,7 @@ over `config.env` for the CLI only. Precedence:
27
27
  | Variable | Default | Description |
28
28
  |----------|---------|-------------|
29
29
  | `PI_RESEARCH_MODEL` | _(required)_ | The `provider/model-id` all research runs on. |
30
- | `PI_RESEARCH_DEFAULT_RESEARCH_DEPTH` | `1` | Default depth (0–3) when `--depth` omitted. `0` is quick (single-pass, no researcher team) and requires `PI_RESEARCH_QUICK_RESEARCH` on the pi extension. |
30
+ | `PI_RESEARCH_DEFAULT_RESEARCH_DEPTH` | `1` | Default depth (0–3) when `--depth` omitted. `0` is quick (single-pass, no researcher team) and requires `PI_RESEARCH_QUICK_RESEARCH` on the pi extension. The agent-facing `research` tool's depth guidance renders relative to this setting — when quick is the configured default, depth 0 is the ordinary choice and 1+ is the escalation; keeping the default (1) renders byte-identically. |
31
31
  | `PI_RESEARCH_QUICK_MAX_QUERIES` | `5` | Max queries per `search` call in quick (depth 0) research (1–10). Applies to the CLI and SDK `--depth 0` runs too. |
32
32
  | `PI_RESEARCH_MAX_RESEARCHERS` | `3` | Parallel researchers (1–5). |
33
33
  | `PI_RESEARCH_TIMEOUT_MS` | `300000` | Per-researcher timeout (180000–1800000). |
@@ -0,0 +1,159 @@
1
+ /**
2
+ * Renders the DEPTH PARAMETER guidance for the agent-facing `research` tool,
3
+ * relative to the user's configured `DEFAULT_RESEARCH_DEPTH`.
4
+ *
5
+ * Background (PR #16, discussion point 2): the tool-usage prompt says
6
+ * "Always specify a depth" and mapped ~95% of queries to `depth: 1`, so a
7
+ * user-configured default (e.g. quick/0) was effectively never honored for
8
+ * agent-initiated research — even with quick set as the default the agent
9
+ * still sent `depth: 1`. This builder renders the guidance relative to the
10
+ * configured default: when quick is the configured default, depth 0 becomes
11
+ * the ordinary choice and depth 1+ reads as the escalation. A user who keeps
12
+ * the default (1) sees byte-identical guidance — quality-first behavior is
13
+ * unchanged.
14
+ *
15
+ * The anchor is the *effective* default — the depth `execute()` actually
16
+ * resolves an omitted depth to:
17
+ *
18
+ * effectiveDefault = quickEnabled ? defaultDepth : Math.max(1, defaultDepth)
19
+ *
20
+ * Depth 0 is only reachable when quick mode is enabled; otherwise a
21
+ * configured 0 clamps to 1 at runtime, so the guidance must not advertise it.
22
+ *
23
+ * This is a pure function of the two session-static snapshots the tool schema
24
+ * was built from (see quickResearchEnabledAtRegistration /
25
+ * defaultDepthAtRegistration in index.ts) so the rendered guidance can never
26
+ * advertise a depth the registered schema rejects.
27
+ */
28
+
29
+ /**
30
+ * The depth `execute()` applies when the agent omits depth — `Math.max(depthMin,
31
+ * configured)` where `depthMin = quickEnabled ? 0 : 1` (see
32
+ * research-tool-definition.ts). This is "the ordinary choice" every rendered
33
+ * surface steers to, and the value the tool schema's `default` annotation must
34
+ * match.
35
+ */
36
+ export function resolveEffectiveDefault(quickEnabled: boolean, defaultDepth: number): number {
37
+ return quickEnabled ? defaultDepth : Math.max(1, defaultDepth);
38
+ }
39
+
40
+ /**
41
+ * Build the DEPTH PARAMETER guidance block (everything between the
42
+ * "Always specify a depth." lead-in and the "How depth works internally:"
43
+ * section). The returned string has no leading or trailing newlines; the
44
+ * caller's template supplies the surrounding blank lines.
45
+ *
46
+ * @param quickEnabled Whether quick mode (depth 0) is enabled — the same
47
+ * session-static snapshot the tool schema was built from.
48
+ * @param defaultDepth The user-configured `DEFAULT_RESEARCH_DEPTH` (0–3).
49
+ */
50
+ export function buildResearchDepthGuidance(quickEnabled: boolean, defaultDepth: number): string {
51
+ const effectiveDefault = resolveEffectiveDefault(quickEnabled, defaultDepth);
52
+
53
+ if (!quickEnabled) {
54
+ return wordBlock(effectiveDefault) + '\n\n' + nothingBlock(effectiveDefault);
55
+ }
56
+ return quickDoc(effectiveDefault) + '\n' + wordBlock(effectiveDefault) + '\n\n' + nothingBlock(effectiveDefault);
57
+ }
58
+
59
+ /**
60
+ * The "user says a depth word" mapping. Byte-identical for effectiveDefault in
61
+ * {1,2,3}; only the "quick" line moves — to 0 — when the configured default IS
62
+ * 0. "normal" stays 1: the words form a shallow→max scale
63
+ * (quick < normal < deep < ultra = 0 < 1 < 2 < 3), so "normal" is always the
64
+ * standard orchestrated run.
65
+ */
66
+ function wordBlock(effectiveDefault: number): string {
67
+ const quickTarget = effectiveDefault === 0 ? 0 : 1;
68
+ return [
69
+ '**User says a depth word (highest priority):**',
70
+ '- "quick" / "brief" / "simple" → `depth: ' + quickTarget + '`',
71
+ '- "normal" / "moderate" / "standard" → `depth: 1`',
72
+ '- "deep" / "thorough" / "in-depth" → `depth: 2` (never depth 3)',
73
+ '- "ultra" / "exhaustive" / "comprehensive" / "deep-dive" / "maximum" → `depth: 3`',
74
+ ].join('\n');
75
+ }
76
+
77
+ /**
78
+ * The "user says nothing about depth — judge complexity:" section. Positions
79
+ * the effective default as the ordinary choice. effectiveDefault === 1
80
+ * reproduces the prior static text byte-for-byte.
81
+ */
82
+ function nothingBlock(effectiveDefault: number): string {
83
+ const header = '**User says nothing about depth — judge complexity:**';
84
+ const never = '- `depth: 3` — **ABSOLUTELY NEVER without explicit user request.** The user MUST use trigger words like "ultra", "exhaustive", "comprehensive deep-dive", or "maximum research".';
85
+ switch (effectiveDefault) {
86
+ case 0:
87
+ return [
88
+ header,
89
+ '- `depth: 0` — the ordinary choice: a single verifiable fact, a URL, a price, a version number, or a yes/no with a source. One search-and-read pass, no researcher team.',
90
+ '- `depth: 1` — Coordinated, thorough research: simple facts with sources, lookups, overviews, background research. Escalate here when the question needs more than a single verifiable fact.',
91
+ '- `depth: 2` — Complex multi-faceted topics: policy analysis, tech evaluations, academic-style research.',
92
+ never + ' If the user does not explicitly request this level, use depth 0, 1, or 2.',
93
+ ].join('\n');
94
+ case 2:
95
+ return [
96
+ header,
97
+ '- `depth: 1` — Simple facts, lookups, news, definitions, "what is X", overviews, background research.',
98
+ '- `depth: 2` — the ordinary choice (your configured default): complex multi-faceted topics, policy analysis, tech evaluations, academic-style research.',
99
+ never,
100
+ ].join('\n');
101
+ case 3:
102
+ return [
103
+ header,
104
+ '- `depth: 1` — Simple facts, lookups, news, definitions, "what is X", overviews, background research.',
105
+ '- `depth: 2` — Complex multi-faceted topics: policy analysis, tech evaluations, academic-style research.',
106
+ '- `depth: 3` — the ordinary choice (your configured default): comprehensive, multi-round, exhaustive research.',
107
+ ].join('\n');
108
+ case 1:
109
+ default:
110
+ return [
111
+ header,
112
+ '- `depth: 1` — Simple facts, lookups, news, definitions, "what is X", overviews, background research. This covers ~95%+ of queries.',
113
+ '- `depth: 2` — Complex multi-faceted topics: policy analysis, tech evaluations, academic-style research.',
114
+ never + ' If the user does not explicitly request this level, use depth 1 or depth 2.',
115
+ ].join('\n');
116
+ }
117
+ }
118
+
119
+ /**
120
+ * The quick-mode intro, rendered only when quick mode is enabled. The first
121
+ * paragraph (what depth 0 is) is constant; the second names the ordinary
122
+ * choice, relative to the effective default.
123
+ */
124
+ function quickDoc(effectiveDefault: number): string {
125
+ const first =
126
+ '**Depth 0 (quick) is available on this host.** Use `depth: 0` for a single verifiable fact, a URL, a price, a version number, or a yes/no with a source — or when the user says "just check", "one-liner", or "don\'t overdo it". It runs one search-and-read pass with no researcher team and answers concisely.';
127
+ let second: string;
128
+ switch (effectiveDefault) {
129
+ case 0:
130
+ second = '`depth: 0` is the ordinary choice; `depth: 1` is the escalation for coordinated research, `depth: 2` for complex or multi-faceted topics, `depth: 3` only on explicit request.';
131
+ break;
132
+ case 2:
133
+ second = '`depth: 2` is the ordinary choice (your configured default); `depth: 1` for simple lookups, `depth: 3` only on explicit request.';
134
+ break;
135
+ case 3:
136
+ second = '`depth: 3` is the ordinary choice (your configured default); `depth: 1` for simple lookups, `depth: 2` for complex topics.';
137
+ break;
138
+ case 1:
139
+ default:
140
+ second = '`depth: 1` remains the normal choice. `depth: 2` is the escalation for complex or multi-faceted questions; `depth: 3` only on explicit request.';
141
+ break;
142
+ }
143
+ return first + '\n\n' + second;
144
+ }
145
+
146
+ /**
147
+ * The closing escalation nudge — the tail of the "Do NOT escalate depth just
148
+ * because a topic is broad" line in the MULTIPLE RESEARCH CALLS section,
149
+ * rendered relative to the effective default the same way the DEPTH PARAMETER
150
+ * block is. effectiveDefault === 1 reproduces the prior static text
151
+ * byte-for-byte, so a user who keeps the default (1) — quick on or off — sees
152
+ * an unchanged prompt.
153
+ */
154
+ export function buildEscalationNudge(quickEnabled: boolean, defaultDepth: number): string {
155
+ const effectiveDefault = resolveEffectiveDefault(quickEnabled, defaultDepth);
156
+ return effectiveDefault === 1
157
+ ? 'depth 1 handles most cases well, and the higher depths have their own internal decomposition.'
158
+ : 'your configured default handles most cases well, and the higher depths have their own internal decomposition.';
159
+ }
@@ -49,17 +49,7 @@ The `research` tool retrieves from the internet. Do NOT use it when the answer c
49
49
 
50
50
  **Always specify a depth.** Judge it from the user's language and task complexity.
51
51
 
52
- {{QUICK_MODE_DOC}}
53
- **User says a depth word (highest priority):**
54
- - "quick" / "brief" / "simple" → `depth: 1`
55
- - "normal" / "moderate" / "standard" → `depth: 1`
56
- - "deep" / "thorough" / "in-depth" → `depth: 2` (never depth 3)
57
- - "ultra" / "exhaustive" / "comprehensive" / "deep-dive" / "maximum" → `depth: 3`
58
-
59
- **User says nothing about depth — judge complexity:**
60
- - `depth: 1` — Simple facts, lookups, news, definitions, "what is X", overviews, background research. This covers ~95%+ of queries.
61
- - `depth: 2` — Complex multi-faceted topics: policy analysis, tech evaluations, academic-style research.
62
- - `depth: 3` — **ABSOLUTELY NEVER without explicit user request.** The user MUST use trigger words like "ultra", "exhaustive", "comprehensive deep-dive", or "maximum research". If the user does not explicitly request this level, use depth 1 or depth 2.
52
+ {{DEPTH_GUIDANCE}}
63
53
 
64
54
  **How depth works internally:**
65
55
  - `depth: 1-3` — AI-orchestrated: coordinator plans a team, researchers execute, a research lead decides whether to continue deeper and writes the final report. Team size and number of rounds scale with complexity. The coordinator and the lead dynamically determine how many researchers are needed each round — it's not a fixed number.
@@ -92,4 +82,4 @@ The coordinator will plan as many researchers as needed (up to the max). You do
92
82
  - **Group related topics**: If topics share ANY scope or could inform each other, combine them into a single `research` call. The internal coordinator will decompose them into parallel researcher agents. Do NOT split related sub-topics into separate calls.
93
83
  - Example: `research("Python async performance and Rust async performance comparison")` — NOT separate calls for Python and Rust, since the comparison IS the research goal.
94
84
 
95
- **Do NOT escalate depth just because a topic is broad** — depth 1 handles most cases well, and the higher depths have their own internal decomposition.
85
+ **Do NOT escalate depth just because a topic is broad** — {{ESCALATION_NUDGE}}
package/docs/CHANGELOG.md CHANGED
@@ -5,6 +5,13 @@ All notable changes to this project will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## [1.7.1] - 2026-09-27
9
+
10
+ ### Changed
11
+
12
+ - **The remaining static `depth: 1` references in the agent-facing surface now follow the configured default too.** Two spots still said `1` where the runtime applies the configured default: the tool schema's model-facing `default` annotation on the `depth` parameter (hardcoded `default: 1`, so a user who configured default 2 saw `"default": 1` in the schema while the prompt said depth 2 is the ordinary choice), and the closing "Do NOT escalate depth just because a topic is broad" line ("depth 1 handles most cases well"). Both are now rendered against the same effective default the DEPTH PARAMETER block uses — `Math.max(depthMin, configured)` where `depthMin = quickEnabled ? 0 : 1` — via `resolveEffectiveDefault` / `buildEscalationNudge` in `src/prompts/research-depth-guidance.ts`. A user whose effective default is 1 (the default install, quick on or off) sees byte-identical prompt and schema; the tests pin that.
13
+ - **The agent-facing `research` tool-usage prompt now renders its depth guidance relative to the user's configured `DEFAULT_RESEARCH_DEPTH`.** The DEPTH PARAMETER block was static and always steered to `depth: 1` — the "Always specify a depth" prompt mapped ~95% of queries there — so a user-configured default (e.g. quick/0) was effectively never honored for agent-initiated research: even with quick set as the default the agent still sent `depth: 1` (only `/research` and the CLI honored it). The block is now rendered by `buildResearchDepthGuidance` (new `src/prompts/research-depth-guidance.ts`) against the same session-static snapshots the tool schema is built from, so it can never advertise a depth the registered schema rejects. When quick is the configured default, depth 0 becomes the ordinary choice and depth 1+ reads as the escalation — a real cost lever. A user who keeps the default (1) sees **byte-identical** guidance, for both the quick-on and quick-off renderings (the green-light condition on PR #16); `test/unit/prompts/research-depth-guidance.test.ts` pins that byte-identity and the `effectiveDefault` the guidance anchors on (`quickEnabled ? defaultDepth : max(1, defaultDepth)`, the depth `execute()` applies to an omitted depth).
14
+
8
15
  ## [1.7.0] - 2026-09-22
9
16
 
10
17
  ### Added
@@ -73,7 +73,7 @@ Research
73
73
  |----------|---------|-------|-------------|
74
74
  | `PI_RESEARCH_TIMEOUT_MS` (TUI) | `300000` | 180000–1800000 | Per-researcher timeout (3–30 min). |
75
75
  | `PI_RESEARCH_MAX_RESEARCHERS` (TUI) | `3` | 1–5 | Parallel researchers. |
76
- | `PI_RESEARCH_DEFAULT_RESEARCH_DEPTH` (TUI) `[project]` | `1` | 0–3 | Depth for `/research` and the CLI when `--depth` is omitted (0=quick single-pass — requires `PI_RESEARCH_QUICK_RESEARCH` —, 1=normal, 2=deep, 3=ultra). |
76
+ | `PI_RESEARCH_DEFAULT_RESEARCH_DEPTH` (TUI) `[project]` | `1` | 0–3 | Depth for `/research` and the CLI when `--depth` is omitted (0=quick single-pass — requires `PI_RESEARCH_QUICK_RESEARCH` —, 1=normal, 2=deep, 3=ultra). The agent-facing `research` tool-usage prompt renders its depth guidance relative to this setting too: when quick is the configured default, depth 0 is the ordinary choice; a user who keeps the default (1) gets byte-identical guidance. |
77
77
  | `PI_RESEARCH_QUICK_RESEARCH` (TUI) `[project]` | `false` | `true` · `false` | Opt-in gate for depth-0 (quick) research. When `false` (default), the agent-facing `research` tool keeps its upstream `minimum: 1` schema — agents can neither see nor send depth 0 — and a `DEFAULT_RESEARCH_DEPTH` of 0 resolves to 1. Toggling applies on the next session. |
78
78
  | `PI_RESEARCH_QUICK_MAX_QUERIES` | `5` | 1–10 | Max queries per `search` call in quick (depth 0) research. Applies to every quick run — the pi extension tool, the CLI, and the SDK's `--depth 0` — since they share the same researcher session factory. Deliberately below deep research's 30-query cap; the ceiling of 10 keeps quick mode from ever exceeding the old 5–10 prompt guidance. |
79
79
  | `PI_RESEARCH_MAX_SCRAPE_BATCHES` (TUI) | `2` | 0–99 | Scrape batches per researcher (0 = unlimited). When prompt caching is known to be active for the resolved research model (Anthropic API models, or a provider route explicitly configured for Anthropic-style cache control), the effective limit is this value plus one — the cached prompt prefix makes the extra batch cheap. |
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lincoln504/pi-research",
3
- "version": "1.7.0",
3
+ "version": "1.7.1",
4
4
  "description": "Web research for your agents with smart and safe tooling + knowledge store",
5
5
  "type": "module",
6
6
  "private": false,
package/src/index.ts CHANGED
@@ -20,6 +20,7 @@ import { getConfig, validateConfig } from './config.ts';
20
20
  import { metrics } from './utils/metrics.ts';
21
21
  import { handleResearchConfigCommand } from './research-config.ts';
22
22
  import { loadPrompt } from './core/llm/prompts.ts';
23
+ import { buildResearchDepthGuidance, buildEscalationNudge } from './prompts/research-depth-guidance.ts';
23
24
  import { clearAllSessionState, addSteeringMessage, getSteeringMessages, normalizeSessionId, getActiveSessionCount, popQueuedMessages, requeuePoppedMessage, getAllTrackedSessions, getPiActiveSessionOrder, getPiActivePanels } from './orchestration/session-state.ts';
24
25
  import { initGlobalTuiController, disposeGlobalTuiController } from './tui/tui-controller.ts';
25
26
  import { registerCoreServices, initializeCoreServices, disposeCoreServices } from './core/service-initialization.ts';
@@ -332,6 +333,10 @@ export default async function (pi: ExtensionAPI) {
332
333
  // live config here would tell the agent depth 0 exists while the tool still
333
334
  // rejects it with invalid_parameters until restart.
334
335
  const quickResearchEnabledAtRegistration = getConfig(process.cwd(), 'pi').QUICK_RESEARCH === true;
336
+ // Session-static snapshot of the user's configured DEFAULT_RESEARCH_DEPTH, taken
337
+ // at the same moment as quickResearchEnabledAtRegistration so the depth guidance
338
+ // (rendered relative to it) agrees with the schema the session was built with.
339
+ const defaultDepthAtRegistration = getConfig(process.cwd(), 'pi').DEFAULT_RESEARCH_DEPTH;
335
340
 
336
341
  // Create and register the health check tool
337
342
  const healthTool: ToolDefinition = createHealthTool();
@@ -612,17 +617,16 @@ export default async function (pi: ExtensionAPI) {
612
617
  (!event.systemPromptOptions || event.systemPromptOptions.selectedTools?.includes(researchKnowledgeSearchTool.name));
613
618
 
614
619
  if (isResearchToolAvailable || isKnowledgeSearchAvailable) {
615
- // Quick-mode (depth 0) prompt documentation is gated on the SAME session-
616
- // static snapshot the tool schema was built from (see
617
- // quickResearchEnabledAtRegistration) — not live config — so the prompt can
618
- // never advertise a depth the registered schema rejects. A mid-session
619
- // QUICK_RESEARCH toggle therefore fully applies on the next session, both
620
- // schema and prompt together.
621
- const quickModeDoc = quickResearchEnabledAtRegistration
622
- ? '**Depth 0 (quick) is available on this host.** Use `depth: 0` for a single verifiable fact, a URL, a price, a version number, or a yes/no with a source — or when the user says "just check", "one-liner", or "don\'t overdo it". It runs one search-and-read pass with no researcher team and answers concisely.\n\n`depth: 1` remains the normal choice. `depth: 2` is the escalation for complex or multi-faceted questions; `depth: 3` only on explicit request.\n'
623
- : '';
620
+ // The DEPTH PARAMETER guidance is rendered relative to the user's configured
621
+ // DEFAULT_RESEARCH_DEPTH (buildResearchDepthGuidance), gated on the SAME
622
+ // session-static snapshots the tool schema was built from (see
623
+ // quickResearchEnabledAtRegistration / defaultDepthAtRegistration) — not live
624
+ // config — so the prompt can never advertise a depth the registered schema
625
+ // rejects. A mid-session config toggle therefore fully applies on the next
626
+ // session, both schema and prompt together.
624
627
  let researchPrompt = loadPrompt('research-tool-usage')
625
- .replace(/\n?\{\{QUICK_MODE_DOC\}\}\n?/, '\n' + quickModeDoc)
628
+ .replace('{{DEPTH_GUIDANCE}}', buildResearchDepthGuidance(quickResearchEnabledAtRegistration, defaultDepthAtRegistration))
629
+ .replace('{{ESCALATION_NUDGE}}', buildEscalationNudge(quickResearchEnabledAtRegistration, defaultDepthAtRegistration))
626
630
  .replace('{{max_team_size_l1}}', MAX_TEAM_SIZE_LEVEL_1.toString())
627
631
  .replace('{{max_team_size_l2}}', MAX_TEAM_SIZE_LEVEL_2.toString())
628
632
  .replace('{{max_team_size_l3}}', MAX_TEAM_SIZE_LEVEL_3.toString());
@@ -0,0 +1,159 @@
1
+ /**
2
+ * Renders the DEPTH PARAMETER guidance for the agent-facing `research` tool,
3
+ * relative to the user's configured `DEFAULT_RESEARCH_DEPTH`.
4
+ *
5
+ * Background (PR #16, discussion point 2): the tool-usage prompt says
6
+ * "Always specify a depth" and mapped ~95% of queries to `depth: 1`, so a
7
+ * user-configured default (e.g. quick/0) was effectively never honored for
8
+ * agent-initiated research — even with quick set as the default the agent
9
+ * still sent `depth: 1`. This builder renders the guidance relative to the
10
+ * configured default: when quick is the configured default, depth 0 becomes
11
+ * the ordinary choice and depth 1+ reads as the escalation. A user who keeps
12
+ * the default (1) sees byte-identical guidance — quality-first behavior is
13
+ * unchanged.
14
+ *
15
+ * The anchor is the *effective* default — the depth `execute()` actually
16
+ * resolves an omitted depth to:
17
+ *
18
+ * effectiveDefault = quickEnabled ? defaultDepth : Math.max(1, defaultDepth)
19
+ *
20
+ * Depth 0 is only reachable when quick mode is enabled; otherwise a
21
+ * configured 0 clamps to 1 at runtime, so the guidance must not advertise it.
22
+ *
23
+ * This is a pure function of the two session-static snapshots the tool schema
24
+ * was built from (see quickResearchEnabledAtRegistration /
25
+ * defaultDepthAtRegistration in index.ts) so the rendered guidance can never
26
+ * advertise a depth the registered schema rejects.
27
+ */
28
+
29
+ /**
30
+ * The depth `execute()` applies when the agent omits depth — `Math.max(depthMin,
31
+ * configured)` where `depthMin = quickEnabled ? 0 : 1` (see
32
+ * research-tool-definition.ts). This is "the ordinary choice" every rendered
33
+ * surface steers to, and the value the tool schema's `default` annotation must
34
+ * match.
35
+ */
36
+ export function resolveEffectiveDefault(quickEnabled: boolean, defaultDepth: number): number {
37
+ return quickEnabled ? defaultDepth : Math.max(1, defaultDepth);
38
+ }
39
+
40
+ /**
41
+ * Build the DEPTH PARAMETER guidance block (everything between the
42
+ * "Always specify a depth." lead-in and the "How depth works internally:"
43
+ * section). The returned string has no leading or trailing newlines; the
44
+ * caller's template supplies the surrounding blank lines.
45
+ *
46
+ * @param quickEnabled Whether quick mode (depth 0) is enabled — the same
47
+ * session-static snapshot the tool schema was built from.
48
+ * @param defaultDepth The user-configured `DEFAULT_RESEARCH_DEPTH` (0–3).
49
+ */
50
+ export function buildResearchDepthGuidance(quickEnabled: boolean, defaultDepth: number): string {
51
+ const effectiveDefault = resolveEffectiveDefault(quickEnabled, defaultDepth);
52
+
53
+ if (!quickEnabled) {
54
+ return wordBlock(effectiveDefault) + '\n\n' + nothingBlock(effectiveDefault);
55
+ }
56
+ return quickDoc(effectiveDefault) + '\n' + wordBlock(effectiveDefault) + '\n\n' + nothingBlock(effectiveDefault);
57
+ }
58
+
59
+ /**
60
+ * The "user says a depth word" mapping. Byte-identical for effectiveDefault in
61
+ * {1,2,3}; only the "quick" line moves — to 0 — when the configured default IS
62
+ * 0. "normal" stays 1: the words form a shallow→max scale
63
+ * (quick < normal < deep < ultra = 0 < 1 < 2 < 3), so "normal" is always the
64
+ * standard orchestrated run.
65
+ */
66
+ function wordBlock(effectiveDefault: number): string {
67
+ const quickTarget = effectiveDefault === 0 ? 0 : 1;
68
+ return [
69
+ '**User says a depth word (highest priority):**',
70
+ '- "quick" / "brief" / "simple" → `depth: ' + quickTarget + '`',
71
+ '- "normal" / "moderate" / "standard" → `depth: 1`',
72
+ '- "deep" / "thorough" / "in-depth" → `depth: 2` (never depth 3)',
73
+ '- "ultra" / "exhaustive" / "comprehensive" / "deep-dive" / "maximum" → `depth: 3`',
74
+ ].join('\n');
75
+ }
76
+
77
+ /**
78
+ * The "user says nothing about depth — judge complexity:" section. Positions
79
+ * the effective default as the ordinary choice. effectiveDefault === 1
80
+ * reproduces the prior static text byte-for-byte.
81
+ */
82
+ function nothingBlock(effectiveDefault: number): string {
83
+ const header = '**User says nothing about depth — judge complexity:**';
84
+ const never = '- `depth: 3` — **ABSOLUTELY NEVER without explicit user request.** The user MUST use trigger words like "ultra", "exhaustive", "comprehensive deep-dive", or "maximum research".';
85
+ switch (effectiveDefault) {
86
+ case 0:
87
+ return [
88
+ header,
89
+ '- `depth: 0` — the ordinary choice: a single verifiable fact, a URL, a price, a version number, or a yes/no with a source. One search-and-read pass, no researcher team.',
90
+ '- `depth: 1` — Coordinated, thorough research: simple facts with sources, lookups, overviews, background research. Escalate here when the question needs more than a single verifiable fact.',
91
+ '- `depth: 2` — Complex multi-faceted topics: policy analysis, tech evaluations, academic-style research.',
92
+ never + ' If the user does not explicitly request this level, use depth 0, 1, or 2.',
93
+ ].join('\n');
94
+ case 2:
95
+ return [
96
+ header,
97
+ '- `depth: 1` — Simple facts, lookups, news, definitions, "what is X", overviews, background research.',
98
+ '- `depth: 2` — the ordinary choice (your configured default): complex multi-faceted topics, policy analysis, tech evaluations, academic-style research.',
99
+ never,
100
+ ].join('\n');
101
+ case 3:
102
+ return [
103
+ header,
104
+ '- `depth: 1` — Simple facts, lookups, news, definitions, "what is X", overviews, background research.',
105
+ '- `depth: 2` — Complex multi-faceted topics: policy analysis, tech evaluations, academic-style research.',
106
+ '- `depth: 3` — the ordinary choice (your configured default): comprehensive, multi-round, exhaustive research.',
107
+ ].join('\n');
108
+ case 1:
109
+ default:
110
+ return [
111
+ header,
112
+ '- `depth: 1` — Simple facts, lookups, news, definitions, "what is X", overviews, background research. This covers ~95%+ of queries.',
113
+ '- `depth: 2` — Complex multi-faceted topics: policy analysis, tech evaluations, academic-style research.',
114
+ never + ' If the user does not explicitly request this level, use depth 1 or depth 2.',
115
+ ].join('\n');
116
+ }
117
+ }
118
+
119
+ /**
120
+ * The quick-mode intro, rendered only when quick mode is enabled. The first
121
+ * paragraph (what depth 0 is) is constant; the second names the ordinary
122
+ * choice, relative to the effective default.
123
+ */
124
+ function quickDoc(effectiveDefault: number): string {
125
+ const first =
126
+ '**Depth 0 (quick) is available on this host.** Use `depth: 0` for a single verifiable fact, a URL, a price, a version number, or a yes/no with a source — or when the user says "just check", "one-liner", or "don\'t overdo it". It runs one search-and-read pass with no researcher team and answers concisely.';
127
+ let second: string;
128
+ switch (effectiveDefault) {
129
+ case 0:
130
+ second = '`depth: 0` is the ordinary choice; `depth: 1` is the escalation for coordinated research, `depth: 2` for complex or multi-faceted topics, `depth: 3` only on explicit request.';
131
+ break;
132
+ case 2:
133
+ second = '`depth: 2` is the ordinary choice (your configured default); `depth: 1` for simple lookups, `depth: 3` only on explicit request.';
134
+ break;
135
+ case 3:
136
+ second = '`depth: 3` is the ordinary choice (your configured default); `depth: 1` for simple lookups, `depth: 2` for complex topics.';
137
+ break;
138
+ case 1:
139
+ default:
140
+ second = '`depth: 1` remains the normal choice. `depth: 2` is the escalation for complex or multi-faceted questions; `depth: 3` only on explicit request.';
141
+ break;
142
+ }
143
+ return first + '\n\n' + second;
144
+ }
145
+
146
+ /**
147
+ * The closing escalation nudge — the tail of the "Do NOT escalate depth just
148
+ * because a topic is broad" line in the MULTIPLE RESEARCH CALLS section,
149
+ * rendered relative to the effective default the same way the DEPTH PARAMETER
150
+ * block is. effectiveDefault === 1 reproduces the prior static text
151
+ * byte-for-byte, so a user who keeps the default (1) — quick on or off — sees
152
+ * an unchanged prompt.
153
+ */
154
+ export function buildEscalationNudge(quickEnabled: boolean, defaultDepth: number): string {
155
+ const effectiveDefault = resolveEffectiveDefault(quickEnabled, defaultDepth);
156
+ return effectiveDefault === 1
157
+ ? 'depth 1 handles most cases well, and the higher depths have their own internal decomposition.'
158
+ : 'your configured default handles most cases well, and the higher depths have their own internal decomposition.';
159
+ }
@@ -49,17 +49,7 @@ The `research` tool retrieves from the internet. Do NOT use it when the answer c
49
49
 
50
50
  **Always specify a depth.** Judge it from the user's language and task complexity.
51
51
 
52
- {{QUICK_MODE_DOC}}
53
- **User says a depth word (highest priority):**
54
- - "quick" / "brief" / "simple" → `depth: 1`
55
- - "normal" / "moderate" / "standard" → `depth: 1`
56
- - "deep" / "thorough" / "in-depth" → `depth: 2` (never depth 3)
57
- - "ultra" / "exhaustive" / "comprehensive" / "deep-dive" / "maximum" → `depth: 3`
58
-
59
- **User says nothing about depth — judge complexity:**
60
- - `depth: 1` — Simple facts, lookups, news, definitions, "what is X", overviews, background research. This covers ~95%+ of queries.
61
- - `depth: 2` — Complex multi-faceted topics: policy analysis, tech evaluations, academic-style research.
62
- - `depth: 3` — **ABSOLUTELY NEVER without explicit user request.** The user MUST use trigger words like "ultra", "exhaustive", "comprehensive deep-dive", or "maximum research". If the user does not explicitly request this level, use depth 1 or depth 2.
52
+ {{DEPTH_GUIDANCE}}
63
53
 
64
54
  **How depth works internally:**
65
55
  - `depth: 1-3` — AI-orchestrated: coordinator plans a team, researchers execute, a research lead decides whether to continue deeper and writes the final report. Team size and number of rounds scale with complexity. The coordinator and the lead dynamically determine how many researchers are needed each round — it's not a fixed number.
@@ -92,4 +82,4 @@ The coordinator will plan as many researchers as needed (up to the max). You do
92
82
  - **Group related topics**: If topics share ANY scope or could inform each other, combine them into a single `research` call. The internal coordinator will decompose them into parallel researcher agents. Do NOT split related sub-topics into separate calls.
93
83
  - Example: `research("Python async performance and Rust async performance comparison")` — NOT separate calls for Python and Rust, since the comparison IS the research goal.
94
84
 
95
- **Do NOT escalate depth just because a topic is broad** — depth 1 handles most cases well, and the higher depths have their own internal decomposition.
85
+ **Do NOT escalate depth just because a topic is broad** — {{ESCALATION_NUDGE}}
@@ -93,8 +93,16 @@ export function createResearchTool(iface?: ConfigInterface): ToolDefinition {
93
93
  // a mid-session QUICK_RESEARCH toggle takes effect on the next session. When
94
94
  // disabled (the default) the schema is byte-identical to the upstream
95
95
  // minimum: 1 surface — agents can neither see nor send depth 0.
96
- const quickEnabled = getConfig(undefined, iface).QUICK_RESEARCH === true;
96
+ const toolConfig = getConfig(undefined, iface);
97
+ const quickEnabled = toolConfig.QUICK_RESEARCH === true;
97
98
  const depthMin = quickEnabled ? 0 : 1;
99
+ // The depth execute() applies to an omitted depth: Math.max(depthMin,
100
+ // configured DEFAULT_RESEARCH_DEPTH) — the same value the agent-facing DEPTH
101
+ // guidance renders relative to (buildResearchDepthGuidance). The annotation
102
+ // must match it, or a user who configured e.g. default 2 sees `default: 1`
103
+ // in the model-facing schema while the prompt says "depth 2 is the ordinary
104
+ // choice (your configured default)".
105
+ const effectiveDefault = Math.max(depthMin, toolConfig.DEFAULT_RESEARCH_DEPTH);
98
106
 
99
107
  const parameters = Type.Object({
100
108
  query: Type.String({
@@ -110,7 +118,7 @@ export function createResearchTool(iface?: ConfigInterface): ToolDefinition {
110
118
  '2: Deep (multi-round, exhaustive).',
111
119
  '3: Ultra (maximum depth, extreme rigor).',
112
120
  ].join('\n'),
113
- default: 1,
121
+ default: effectiveDefault,
114
122
  })),
115
123
  model: Type.Optional(Type.String({
116
124
  description: 'Optional model ID override for coordination.',