From 010c8750d424f8171975f8b1a3d785b680aff22d Mon Sep 17 00:00:00 2001 From: Nicolas Date: Sun, 16 Mar 2025 23:14:44 -0400 Subject: [PATCH 1/2] Nick: let user format the analysis --- apps/api/src/controllers/v1/deep-research.ts | 1 + apps/api/src/lib/deep-research/deep-research-service.ts | 2 ++ apps/api/src/lib/deep-research/research-manager.ts | 5 ++++- apps/api/src/services/queue-worker.ts | 1 + 4 files changed, 8 insertions(+), 1 deletion(-) diff --git a/apps/api/src/controllers/v1/deep-research.ts b/apps/api/src/controllers/v1/deep-research.ts index df3f49c8..7e454c3d 100644 --- a/apps/api/src/controllers/v1/deep-research.ts +++ b/apps/api/src/controllers/v1/deep-research.ts @@ -10,6 +10,7 @@ export const deepResearchRequestSchema = z.object({ maxDepth: z.number().min(1).max(12).default(7).describe('Maximum depth of research iterations'), maxUrls: z.number().min(1).max(1000).default(20).describe('Maximum number of URLs to analyze'), timeLimit: z.number().min(30).max(600).default(300).describe('Time limit in seconds'), + analysisPrompt: z.string().describe('The prompt to use for the final analysis').optional(), // @deprecated Use query instead topic: z.string().describe('The topic or question to research').optional(), }).refine(data => data.query || data.topic, { diff --git a/apps/api/src/lib/deep-research/deep-research-service.ts b/apps/api/src/lib/deep-research/deep-research-service.ts index d801ab3c..8a404d10 100644 --- a/apps/api/src/lib/deep-research/deep-research-service.ts +++ b/apps/api/src/lib/deep-research/deep-research-service.ts @@ -14,6 +14,7 @@ interface DeepResearchServiceOptions { maxDepth: number; maxUrls: number; timeLimit: number; + analysisPrompt: string; subId?: string; } @@ -262,6 +263,7 @@ export async function performDeepResearch(options: DeepResearchServiceOptions) { options.query, state.getFindings(), state.getSummaries(), + options.analysisPrompt, ); await state.addActivity({ diff --git a/apps/api/src/lib/deep-research/research-manager.ts b/apps/api/src/lib/deep-research/research-manager.ts index 8a5bf839..d5f4fdd9 100644 --- a/apps/api/src/lib/deep-research/research-manager.ts +++ b/apps/api/src/lib/deep-research/research-manager.ts @@ -253,6 +253,7 @@ export class ResearchLLMService { topic: string, findings: DeepResearchFinding[], summaries: string[], + analysisPrompt: string, ): Promise { const { extract } = await generateCompletions({ logger: this.logger.child({ @@ -265,7 +266,9 @@ export class ResearchLLMService { "You are an expert research analyst who creates comprehensive, well-structured reports. Your reports are detailed, properly formatted in Markdown, and include clear sections with citations. Today's date is " + new Date().toISOString().split("T")[0], prompt: trimToTokenLimit( - `Create a comprehensive research report on "${topic}" based on the collected findings and analysis. + analysisPrompt + ? `${analysisPrompt}\n\nResearch data:\n${findings.map((f) => `[From ${f.source}]: ${f.text}`).join("\n")}` + : `Create a comprehensive research report on "${topic}" based on the collected findings and analysis. Research data: ${findings.map((f) => `[From ${f.source}]: ${f.text}`).join("\n")} diff --git a/apps/api/src/services/queue-worker.ts b/apps/api/src/services/queue-worker.ts index 52f1f55a..66931fce 100644 --- a/apps/api/src/services/queue-worker.ts +++ b/apps/api/src/services/queue-worker.ts @@ -412,6 +412,7 @@ const processDeepResearchJobInternal = async ( timeLimit: job.data.request.timeLimit, subId: job.data.subId, maxUrls: job.data.request.maxUrls, + analysisPrompt: job.data.request.analysisPrompt, }); if(result.success) { From 4fc5e6f6ca0c1a0fc4e0f887360eeb2cfddf3d44 Mon Sep 17 00:00:00 2001 From: Nicolas Date: Tue, 18 Mar 2025 15:52:55 -0400 Subject: [PATCH 2/2] Nick: added analysis prompt to the sdks --- apps/js-sdk/firecrawl/src/index.ts | 4 ++++ apps/python-sdk/firecrawl/firecrawl.py | 1 + 2 files changed, 5 insertions(+) diff --git a/apps/js-sdk/firecrawl/src/index.ts b/apps/js-sdk/firecrawl/src/index.ts index 54bb6f4f..9f8d00d3 100644 --- a/apps/js-sdk/firecrawl/src/index.ts +++ b/apps/js-sdk/firecrawl/src/index.ts @@ -371,6 +371,10 @@ export interface DeepResearchParams { * @default 20 */ maxUrls?: number; + /** + * The prompt to use for the final analysis + */ + analysisPrompt?: string; /** * Experimental flag for streaming steps */ diff --git a/apps/python-sdk/firecrawl/firecrawl.py b/apps/python-sdk/firecrawl/firecrawl.py index f4ddb91e..c315eb20 100644 --- a/apps/python-sdk/firecrawl/firecrawl.py +++ b/apps/python-sdk/firecrawl/firecrawl.py @@ -48,6 +48,7 @@ class DeepResearchParams(pydantic.BaseModel): maxDepth: Optional[int] = 7 timeLimit: Optional[int] = 270 maxUrls: Optional[int] = 20 + analysisPrompt: Optional[str] = None __experimental_streamSteps: Optional[bool] = None class DeepResearchResponse(pydantic.BaseModel):