Skip to content

Commit 59058ff

Browse files
authored
fix: keep focused research reports to six passes (#156)
## Summary - fixes a production QA finding where a concise Research request silently expanded to ten branches and ran for over twelve minutes - gives focused deep research a deterministic 3-6-pass contract with a four-pass default - reserves larger multi-entity scans for the existing fan-out workflow - reorders focused passes so concise reports prioritize authoritative sources, implementation details, and risks ## Production finding A natural-language Research-mode request for a concise report invoked `research_deep` with `maxQueries: 10`. The single tool remained in Working state for more than twelve minutes before being stopped. There was no retry or disconnect; the excessive branch selection was the bottleneck. ## Decisions Made | Decision | Choice | Alternatives considered | Reasoning | |---|---|---|---| | Focused depth | 3-6 passes, default 4 | Advisory prompt only; retain maximum 12 | Enforces predictable latency regardless of model behavior | | Broad scans | Keep up to 12 in `research_fanout` | Remove broad coverage | Preserves deliberate exhaustive/multi-entity research | | Query order | Primary sources, implementation, risks first | Keep news/competitors first | Produces a useful concise report with only three passes | ## Verification - [x] `pnpm lint` - [x] `pnpm typecheck` - [x] `pnpm turbo build --force` - [x] `pnpm deadcode` - [x] `pnpm architecture:check` - [x] `pnpm turbo skills:build` - [ ] production Research run after deployment
1 parent 558e988 commit 59058ff

5 files changed

Lines changed: 18 additions & 16 deletions

File tree

packages/agent-core/src/mastra/system-prompt.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ Load the generate-media skill before creating or editing an image or generating
232232

233233
const RESEARCH_MODULE = `## Research
234234
235-
Gather sources with search_web / search_web_advanced / search_company / search_web_content, then use search_scrape or search_extract for source retrieval. For an explicit deep-research request, cited report, market analysis, due diligence, broad market scan, or comprehensive investigation, use research_deep; use research_fanout when the request compares many entities or independent angles. Those workflows produce the complete cited PDF deliverable automatically, so do not regenerate it with a document tool. Treat search snippets as leads, not sources — open the real pages and cross-check. Cite as you go: attribute each claim to its source inline with the page title and its URL, and make sure every citation resolves. End a research answer with a short Sources list of the URLs you actually used.`;
235+
Gather sources with search_web / search_web_advanced / search_company / search_web_content, then use search_scrape or search_extract for source retrieval. For an explicit deep-research request, cited report, market analysis, due diligence, or comprehensive investigation of one topic, use research_deep with 3 queries for a concise/narrow report, 4 by default, and 5-6 only when the user explicitly asks for deeper coverage. Use research_fanout when the request compares many entities or independent angles. Those workflows produce the complete cited PDF deliverable automatically, so do not regenerate it with a document tool. Treat search snippets as leads, not sources — open the real pages and cross-check. Cite as you go: attribute each claim to its source inline with the page title and its URL, and make sure every citation resolves. End a research answer with a short Sources list of the URLs you actually used.`;
236236

237237
/** Compact all-domains pointer for an ambiguous general request — keeps the model aware without the full modules. */
238238
const GENERALIST_MODULE = `## Choosing your approach

packages/agent-core/src/mastra/tool-defs/research-tools.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ export const mastraFirecrawlExtract = createTool({
248248
export const mastraDeepResearch = createTool({
249249
id: "research_deep",
250250
description:
251-
"Run the Deep Research workflow for a complex topic. It returns a cited report and saves the complete report as a PDF deliverable in the project.",
251+
"Run focused Deep Research for one complex topic and save the cited report as a project PDF. Use 3 queries for concise or narrow reports, 4 by default, and 5-6 only when the user explicitly requests deeper coverage; use research_fanout for broad multi-entity scans.",
252252
inputSchema: DeepResearchInputSchema,
253253
outputSchema: ResearchReportArtifactSchema,
254254
execute: async (input, context) => {

packages/agent-core/src/mastra/workflows/research-schemas.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,15 @@ export const ResearchQuerySchema = z.strictObject({
4545
});
4646

4747
export const DeepResearchInputSchema = z.strictObject({
48-
maxQueries: z.number().int().min(3).max(12).default(6),
48+
maxQueries: z
49+
.number()
50+
.int()
51+
.min(3)
52+
.max(6)
53+
.default(4)
54+
.describe(
55+
"Focused research pass count: use 3 for a concise or narrow report, 4 by default, and 5-6 only when the user explicitly asks for deeper coverage.",
56+
),
4957
topic: z.string().trim().min(1).max(2_000),
5058
});
5159

packages/agent-core/src/mastra/workflows/research-support.ts

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,12 @@ export function buildDeepResearchQueries(
44
): Array<{ query: string }> {
55
const trimmedTopic = topic.trim();
66
const templates = [
7-
`${trimmedTopic} current overview and key facts`,
8-
`${trimmedTopic} recent developments and news`,
9-
`${trimmedTopic} market landscape competitors and alternatives`,
10-
`${trimmedTopic} technical details implementation constraints`,
11-
`${trimmedTopic} risks limitations criticism`,
12-
`${trimmedTopic} primary sources documentation reports`,
13-
`${trimmedTopic} case studies adoption examples`,
14-
`${trimmedTopic} pricing business model economics`,
15-
`${trimmedTopic} legal regulatory policy considerations`,
16-
`${trimmedTopic} future roadmap trends forecasts`,
17-
`${trimmedTopic} expert analysis long-form review`,
18-
`${trimmedTopic} data benchmarks statistics`,
7+
`${trimmedTopic} current landscape overview and authoritative primary sources`,
8+
`${trimmedTopic} technical product and implementation details constraints`,
9+
`${trimmedTopic} risks limitations failure modes criticism`,
10+
`${trimmedTopic} evidence data benchmarks case studies adoption`,
11+
`${trimmedTopic} legal regulatory economic and operational considerations`,
12+
`${trimmedTopic} recent developments future trends disagreements open questions`,
1913
];
2014
return dedupeQueries(templates)
2115
.slice(0, maxQueries)

skills/deep-research/SKILL.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Answer complex questions with sourced synthesis. The output should read like an
1414
## Quick Start
1515

1616
1. Scope the user's ask, timeframe, geography, and decision use.
17-
2. Run the request through `research_deep`; it performs the parallel research, validates citations, and creates the PDF deliverable.
17+
2. Run the request through `research_deep`; use 3 queries for concise or narrow reports, 4 by default, and 5-6 only when the user explicitly asks for deeper coverage. It validates citations and creates the PDF deliverable.
1818
3. Return the key conclusion and important caveats in chat, with a short source list.
1919
4. Refer to the PDF naturally as ready below. Do not call a separate document tool or recreate the report.
2020

0 commit comments

Comments
 (0)