You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix(agent): bound deep research subrequests (#157)
## Why
Production deep-research runs could exhaust Cloudflare's per-invocation
subrequest budget. Each query launched a nested tool-using agent loop,
invalid structured output retried the workflow step three times, and the
outer agent could call the workflow again. The run then failed before it
could package the expected PDF deliverable.
## What changed
- collect a bounded provider evidence pack per query with one Exa search
and at most one best-effort Firecrawl extraction
- structure each evidence pack with one tool-free model call
- cap query concurrency at three and disable workflow-step retries
- turn invalid nested structured output into a stable upstream error
instead of leaking a Zod failure
- instruct the agent and deep-research skill to call the selected
research workflow once per request
- document the bounded provenance and retry boundary
The existing validated citation, PDF packaging, Daytona project-file
persistence, and R2 generated-output paths remain unchanged.
## Architecture and migration effects
- no database or migration changes
- no environment changes
- no new provider or dependency
- moves provider network I/O out of nested agent tool loops and into the
existing bounded research adapters
## Verification
- `pnpm lint`
- `pnpm typecheck`
- `pnpm turbo build --force`
- `pnpm deadcode`
- `pnpm architecture:check`
- `pnpm turbo skills:build`
Production acceptance will be run against the exact merged SHA after
Cloudflare deployment, covering natural-language research intent, one
workflow invocation, PDF delivery, project file persistence, download
validity, reload persistence, and `/` file recall.
Copy file name to clipboardExpand all lines: packages/agent-core/src/mastra/system-prompt.ts
+1-1Lines changed: 1 addition & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -232,7 +232,7 @@ Load the generate-media skill before creating or editing an image or generating
232
232
233
233
constRESEARCH_MODULE=`## Research
234
234
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.`;
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. Call the selected research workflow once per user request; if it fails, explain the failure instead of immediately rerunning it. 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.`;
236
236
237
237
/** Compact all-domains pointer for an ambiguous general request — keeps the model aware without the full modules. */
"Run a breadth-first research pass for the query below.",
14
-
"Prefer search_web or search_company for discovery, then search_scrape for official pages.",
15
-
"Do not call research_deep or research_fanout from inside this workflow step.",
16
-
"Return structured claims only from provider results. Cite every claim with the exact Exa result ID and URL or exact Firecrawl URL returned by the tools.",
13
+
"Analyze the breadth-first provider evidence pack for the query below.",
14
+
"Return structured claims only from that evidence. Cite every claim with the exact Exa result ID and URL or exact Firecrawl URL present in the pack.",
17
15
"Do not infer citation IDs from prose and do not cite a URL that no tool returned.",
"Run a focused research pass for the query below.",
14
-
"Use search_web_advanced for discovery and search_scrape for source pages that need extraction.",
15
-
"Do not call research_deep or research_fanout from inside this workflow step.",
16
-
"Return structured claims only from provider results. Cite every claim with the exact Exa result ID and URL or exact Firecrawl URL returned by the tools.",
13
+
"Analyze the focused provider evidence pack for the query below.",
14
+
"Return structured claims only from that evidence. Cite every claim with the exact Exa result ID and URL or exact Firecrawl URL present in the pack.",
17
15
"Do not infer citation IDs from prose and do not cite a URL that no tool returned.",
Copy file name to clipboardExpand all lines: skills/deep-research/SKILL.md
+1Lines changed: 1 addition & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -17,6 +17,7 @@ Answer complex questions with sourced synthesis. The output should read like an
17
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.
18
18
3. Return the key conclusion and important caveats in chat, with a short source list.
19
19
4. Refer to the PDF naturally as ready below. Do not call a separate document tool or recreate the report.
20
+
5. Call the workflow once per user request. If it fails, explain the failure instead of immediately rerunning it.
0 commit comments