@deepagents/orchestrator 6.1.2 → 7.0.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/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/lib/arxiv/arxiv.js +153 -0
- package/dist/lib/arxiv/arxiv.js.map +7 -0
- package/dist/lib/citation.js +120 -0
- package/dist/lib/citation.js.map +7 -0
- package/dist/lib/deepplan/demo.js +518 -0
- package/dist/lib/deepplan/demo.js.map +7 -0
- package/dist/lib/deepplan/executors/generic-executor.js +196 -0
- package/dist/lib/deepplan/executors/generic-executor.js.map +7 -0
- package/dist/lib/deepplan/executors/hackernews-executor.js +210 -0
- package/dist/lib/deepplan/executors/hackernews-executor.js.map +7 -0
- package/dist/lib/deepplan/executors/product-manager-executor.js +226 -0
- package/dist/lib/deepplan/executors/product-manager-executor.js.map +7 -0
- package/dist/lib/deepplan/executors/repo-search-executor.js +76 -0
- package/dist/lib/deepplan/executors/repo-search-executor.js.map +7 -0
- package/dist/lib/deepplan/executors/research-executor.js +196 -0
- package/dist/lib/deepplan/executors/research-executor.js.map +7 -0
- package/dist/lib/deepplan/next/plan.js +1 -0
- package/dist/lib/deepplan/next/plan.js.map +7 -0
- package/dist/lib/deepplan/plan-and-solve.js +826 -0
- package/dist/lib/deepplan/plan-and-solve.js.map +7 -0
- package/dist/lib/deepplan/planner-agent.js +416 -0
- package/dist/lib/deepplan/planner-agent.js.map +7 -0
- package/dist/lib/deepplan/replanner-agent.js +418 -0
- package/dist/lib/deepplan/replanner-agent.js.map +7 -0
- package/dist/lib/deepplan/synthesizer.js +75 -0
- package/dist/lib/deepplan/synthesizer.js.map +7 -0
- package/dist/lib/deepresearch.v0.js +297 -0
- package/dist/lib/deepresearch.v0.js.map +7 -0
- package/dist/lib/deepresearch.v1.js +260 -0
- package/dist/lib/deepresearch.v1.js.map +7 -0
- package/dist/lib/deepwiki/complete-wiki.js +319 -0
- package/dist/lib/deepwiki/complete-wiki.js.map +7 -0
- package/dist/lib/deepwiki/deepwiki.js +370 -0
- package/dist/lib/deepwiki/deepwiki.js.map +7 -0
- package/dist/lib/deepwiki/gitignore-agent.js +40 -0
- package/dist/lib/deepwiki/gitignore-agent.js.map +7 -0
- package/dist/lib/deepwiki/outline-agent.js +186 -0
- package/dist/lib/deepwiki/outline-agent.js.map +7 -0
- package/dist/lib/deepwiki/wiki-writer.js +242 -0
- package/dist/lib/deepwiki/wiki-writer.js.map +7 -0
- package/dist/lib/deepwiki/writer.js +407 -0
- package/dist/lib/deepwiki/writer.js.map +7 -0
- package/dist/lib/evolving.js +204 -0
- package/dist/lib/evolving.js.map +7 -0
- package/dist/lib/graph.js +12 -0
- package/dist/lib/graph.js.map +7 -0
- package/dist/lib/openai-deepresearch/clarrify-agent.js +67 -0
- package/dist/lib/openai-deepresearch/clarrify-agent.js.map +7 -0
- package/dist/lib/openai-deepresearch/lead-research.js +168 -0
- package/dist/lib/openai-deepresearch/lead-research.js.map +7 -0
- package/dist/lib/openai-deepresearch/openai-deepresearch.js +179 -0
- package/dist/lib/openai-deepresearch/openai-deepresearch.js.map +7 -0
- package/dist/lib/openai-deepresearch/reasearcher.js +62 -0
- package/dist/lib/openai-deepresearch/reasearcher.js.map +7 -0
- package/dist/lib/openai-deepresearch/research-brief.js +59 -0
- package/dist/lib/openai-deepresearch/research-brief.js.map +7 -0
- package/dist/lib/repo-context.js +11 -0
- package/dist/lib/repo-context.js.map +7 -0
- package/package.json +8 -8
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/lib/evolving.ts"],
|
|
4
|
+
"sourcesContent": ["import { groq } from '@ai-sdk/groq';\nimport { type ToolExecutionOptions, toUIMessageStream, tool } from 'ai';\nimport dedent from 'dedent';\nimport { mkdir, readFile, writeFile } from 'node:fs/promises';\nimport { dirname, extname, join } from 'node:path';\nimport z from 'zod';\n\nimport { agent, generate, stream, user } from '@deepagents/agent';\n\nconst defaultPrompt = dedent`\n\n<SystemContext>\n\tYou are a code execution agent that writes and runs TypeScript code to accomplish user requests.\n\n\t<Identity>\n\tYour role is to translate user instructions into executable TypeScript code that produces results.\n\tYou excel at:\n\t- Breaking down requests into simple, executable code\n\t- Choosing appropriate Node.js APIs for the task\n\t- Writing clear, correct TypeScript with proper imports\n\t- Analyzing errors and adjusting approach when needed\n\t</Identity>\n\n\t<ExecutionEnvironment>\n\tRuntime: Node.js with ES module support\n\tExecution Model: Files are dynamically imported after creation\n\tProject Root: Accessible via process.cwd()\n\t</ExecutionEnvironment>\n\n\t<Tools>\n\twrite_content(fileName: string, content: string)\n\t- Creates or overwrites a .ts file in .evolving/ directory\n\t- Only .ts extensions permitted\n\t- Parent directories created automatically\n\n\trun_code(fileName: string)\n\t- Executes a TypeScript file via dynamic import()\n\t- File must exist before execution (write first, then run)\n\t- Returns module exports object\n\t</Tools>\n\n\t<Methodology>\n\tPhase 1: Analysis\n\t- Understand what data or result the user needs\n\t- Identify which Node.js APIs are appropriate (fs, path, etc.)\n\n\tPhase 2: Implementation\n\t- Write TypeScript code using appropriate imports\n\t- Use process.cwd() for project root references\n\t- Include console.log statements for output visibility\n\t- Export data if needed for further processing\n\n\tPhase 3: Execution\n\t- Run the code file\n\t- Observe results and determine if goal is achieved\n\t</Methodology>\n\n\t<Principles>\n\tCode Approach:\n\t\u2713 Start with synchronous operations (readdirSync, readFileSync)\n\t\u2713 Use ES module imports (import { x } from 'module')\n\t\u2713 Reference project root with process.cwd()\n\t\u2713 Write self-contained code with clear variable names\n\t\u2717 Avoid async callbacks when synchronous versions exist\n\t\u2717 Avoid complex path manipulations when simple ones suffice\n\t\u2717 Avoid mixing CommonJS (require) with ES modules (import)\n\n\tError Handling:\n\t\u2713 Read error messages carefully to understand root cause\n\t\u2713 Check if the issue is environmental, syntactic, or logical\n\t\u2713 Adjust approach based on specific error, not generic retries\n\t\u2717 Avoid repeating the same approach if it failed\n\t\u2717 Avoid trying multiple variations without understanding why previous attempts failed\n\n\tIteration Management:\n\t\u2713 Attempt a straightforward solution first\n\t\u2713 If first attempt fails, analyze the error and make ONE targeted fix\n\t\u2713 If second attempt fails, reconsider the approach entirely\n\t\u2717 Stop after 3 failed attempts and report the issue\n\t\u2717 Avoid trial-and-error loops without clear reasoning\n\t</Principles>\n\n\t<CriticalInstructions>\n\t- Maximum 3 retry attempts per task before reporting the issue\n\t- Each file write should be purposeful, not exploratory\n\t- run_code must only be called on files that were written via write_content\n\t- Follow the user's instructions precisely and deliver the requested results\n\t</CriticalInstructions>\n\n</SystemContext>\n\n`;\n\nconst PROMPT_FILE_PATH = join(\n process.cwd(),\n '.evolving',\n 'executor-prompt.txt',\n);\n\nconst prompt =\n (await readFile(PROMPT_FILE_PATH, 'utf-8').catch(() => defaultPrompt)) ||\n defaultPrompt;\n\nasync function savePrompt(promptText: string): Promise<void> {\n await mkdir(dirname(PROMPT_FILE_PATH), { recursive: true });\n await writeFile(PROMPT_FILE_PATH, promptText, 'utf-8');\n console.log('Saved revised prompt to file');\n}\n\nconst write_content_tool = tool({\n description: 'Writes content based on given instructions.',\n inputSchema: z.object({\n fileName: z.string().describe('The name of the file to write to.'),\n content: z.string().describe('The content to be written.'),\n }),\n execute: async (\n { fileName, content }: { fileName: string; content: string },\n _options: ToolExecutionOptions<any>,\n ) => {\n if (extname(fileName) !== '.ts') {\n return 'Error: Can only write .ts files.';\n }\n await mkdir(dirname(join(process.cwd(), '.evolving', fileName)), {\n recursive: true,\n });\n await writeFile(\n join(process.cwd(), '.evolving', fileName),\n content,\n 'utf-8',\n );\n return `File written: ${fileName}`;\n },\n});\n\nconst run_code_tool = tool({\n description: 'Executes provided code snippets and returns the output.',\n inputSchema: z.object({\n fileName: z\n .string()\n .describe('The name of the file containing the code to run.'),\n }),\n execute: async (\n { fileName }: { fileName: string },\n _options: ToolExecutionOptions<any>,\n ) => {\n return await import(join(process.cwd(), '.evolving', fileName));\n },\n});\n\nconst executorTools = {\n write_content: write_content_tool,\n run_code: run_code_tool,\n};\n\nconst adaptingAgent = agent({\n model: groq('openai/gpt-oss-20b'),\n name: 'adapting_agent',\n prompt: dedent`\n\t\tYou are an adapting agent that update other agents system prompt and behavior based on execution results.\n\t\tYour job is to analyze execution results and refine the executor agent's prompt to improve future performance.\n\t\tConsider what changes to the system context, identity, methodology, principles, or critical instructions could help the executor succeed.\n\t\tProvide a revised prompt that addresses any shortcomings revealed by the execution results.\n`,\n output: z.object({\n revisedPrompt: z\n .string()\n .describe('The revised system prompt for the executor.'),\n }),\n});\n\nconst USER_TASK = `Using typescript compiler, count how many times the agent function have been invoked. use tsconfig.base.json as project configuration.`;\nconst MAX_REFINEMENTS = 3;\n\n// Main adaptation loop\nasync function runAdaptationCycle() {\n let currentPrompt = prompt;\n for (let iteration = 1; iteration <= MAX_REFINEMENTS; iteration++) {\n console.log(\n `\\n========== Iteration ${iteration}/${MAX_REFINEMENTS} ==========`,\n );\n\n // Create executor with current prompt\n const executor = agent({\n name: 'executor_agent',\n model: groq('openai/gpt-oss-120b'),\n prompt: currentPrompt,\n tools: executorTools,\n });\n\n // Run executor\n const result$ = await stream(executor, [user(USER_TASK)], {});\n const messages = await Array.fromAsync(\n toUIMessageStream({\n stream: result$.stream,\n tools: executor.toToolset(),\n }),\n );\n await result$.consumeStream();\n\n const reasoning = messages\n .filter((it) => it.type === 'reasoning-delta')\n .map((it) => it.delta)\n .join('');\n\n const text = messages\n .filter((it) => it.type === 'text-delta')\n .map((it) => it.delta)\n .join('');\n\n console.log('Final Result Text:', text);\n\n // Run adapting agent\n const { output } = await generate(\n adaptingAgent,\n [\n user(\n `\n\t\t\t\t\t<ExecutionResults>\n\t\t\t\t\t\t${text}\n\t\t\t\t\t</ExecutionResults>\n\n\t\t\t\t\t<AgentReasoning>\n\t\t\t\t\t\t${reasoning}\n\t\t\t\t\t</AgentReasoning>\n\n\t\t\t\t\t<AgentPrompt>\n\t\t\t\t\t\t${currentPrompt}\n\t\t\t\t\t</AgentPrompt>\n\t\t\t\t`,\n ),\n ],\n {},\n );\n const { revisedPrompt } = output as { revisedPrompt: string };\n\n // Save and use revised prompt for next iteration\n await savePrompt(revisedPrompt);\n currentPrompt = revisedPrompt;\n }\n\n console.log('\\n========== Adaptation Complete ==========');\n}\n\nrunAdaptationCycle();\n"],
|
|
5
|
+
"mappings": ";AAAA,SAAS,YAAY;AACrB,SAAoC,mBAAmB,YAAY;AACnE,OAAO,YAAY;AACnB,SAAS,OAAO,UAAU,iBAAiB;AAC3C,SAAS,SAAS,SAAS,YAAY;AACvC,OAAO,OAAO;AAEd,SAAS,OAAO,UAAU,QAAQ,YAAY;AAE9C,IAAM,gBAAgB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAoFtB,IAAM,mBAAmB;AAAA,EACvB,QAAQ,IAAI;AAAA,EACZ;AAAA,EACA;AACF;AAEA,IAAM,SACH,MAAM,SAAS,kBAAkB,OAAO,EAAE,MAAM,MAAM,aAAa,KACpE;AAEF,eAAe,WAAW,YAAmC;AAC3D,QAAM,MAAM,QAAQ,gBAAgB,GAAG,EAAE,WAAW,KAAK,CAAC;AAC1D,QAAM,UAAU,kBAAkB,YAAY,OAAO;AACrD,UAAQ,IAAI,8BAA8B;AAC5C;AAEA,I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item.sections || [];
|
|
4
|
+
for (const section of sections) {
|
|
5
|
+
await fold(section, item, write, store);
|
|
6
|
+
}
|
|
7
|
+
await store.set(item.title, await write(item));
|
|
8
|
+
}
|
|
9
|
+
export {
|
|
10
|
+
fold
|
|
11
|
+
};
|
|
12
|
+
//# sourceMappingURL=graph.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/lib/graph.ts"],
|
|
4
|
+
"sourcesContent": ["import type { Outline } from './deepwiki/outline-agent.ts';\n\ntype WithParent = {\n title: string;\n parent?: WithParent;\n sections?: WithParent[];\n};\n\nfunction flat(item: WithParent) {\n const paths: string[][] = [];\n if (!item.sections || item.sections.length === 0) {\n let current: WithParent | undefined = item;\n const path: string[] = [];\n while (current.parent) {\n current = current.parent;\n path.unshift(current.title);\n }\n path.push(item.title);\n paths.push(path);\n return paths;\n }\n for (const section of item.sections) {\n paths.push(...flat({ ...section, parent: item }));\n }\n return paths;\n}\n\nexport async function fold(\n item: Outline[number],\n parent: Outline[number],\n write: (section: Outline[number]) => Promise<string>,\n store: {\n set: (key: string, value: string) => Promise<void>;\n },\n) {\n const sections = item.sections || [];\n for (const section of sections) {\n await fold(section, item, write, store);\n }\n await store.set(item.title, await write(item));\n}\n"],
|
|
5
|
+
"mappings": ";AA2BA,eAAsB,KACpB,MACA,QACA,OACA,OAGA;AACA,QAAM,WAAW,KAAK,YAAY,CAAC;AACnC,aAAW,WAAW,UAAU;AAC9B,UAAM,KAAK,SAAS,MAAM,OAAO,KAAK;AAAA,EACxC;AACA,QAAM,MAAM,IAAI,KAAK,OAAO,MAAM,MAAM,IAAI,CAAC;AAC/C;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
// packages/orchestrator/src/lib/openai-deepresearch/clarrify-agent.ts
|
|
2
|
+
import { groq } from "@ai-sdk/groq";
|
|
3
|
+
import z from "zod";
|
|
4
|
+
import { agent, generate } from "@deepagents/agent";
|
|
5
|
+
var clarify_with_user_instructions = `
|
|
6
|
+
Today's date is ${(/* @__PURE__ */ new Date()).toISOString()}.
|
|
7
|
+
|
|
8
|
+
Assess whether you need to ask a clarifying question, or if the user has already provided enough information for you to start research.
|
|
9
|
+
IMPORTANT: If you can see in the messages history that you have already asked a clarifying question, you almost always do not need to ask another one. Only ask another question if ABSOLUTELY NECESSARY.
|
|
10
|
+
|
|
11
|
+
If there are acronyms, abbreviations, or unknown terms, ask the user to clarify.
|
|
12
|
+
If you need to ask a question, follow these guidelines:
|
|
13
|
+
- Be concise while gathering all necessary information
|
|
14
|
+
- Make sure to gather all the information needed to carry out the research task in a concise, well-structured manner.
|
|
15
|
+
- Use bullet points or numbered lists if appropriate for clarity. Make sure that this uses markdown formatting and will be rendered correctly if the string output is passed to a markdown renderer.
|
|
16
|
+
- Don't ask for unnecessary information, or information that the user has already provided. If you can see that the user has already provided the information, do not ask for it again.
|
|
17
|
+
|
|
18
|
+
Respond in valid JSON format with these exact keys:
|
|
19
|
+
"need_clarification": boolean,
|
|
20
|
+
"question": "<question to ask the user to clarify the report scope>",
|
|
21
|
+
"verification": "<verification message that we will start research>"
|
|
22
|
+
|
|
23
|
+
If you need to ask a clarifying question, return:
|
|
24
|
+
"need_clarification": true,
|
|
25
|
+
"question": "<your clarifying question>",
|
|
26
|
+
"verification": ""
|
|
27
|
+
|
|
28
|
+
If you do not need to ask a clarifying question, return:
|
|
29
|
+
"need_clarification": false,
|
|
30
|
+
"question": "",
|
|
31
|
+
"verification": "<acknowledgement message that you will now start research based on the provided information>"
|
|
32
|
+
|
|
33
|
+
For the verification message when no clarification is needed:
|
|
34
|
+
- Acknowledge that you have sufficient information to proceed
|
|
35
|
+
- Briefly summarize the key aspects of what you understand from their request
|
|
36
|
+
- Confirm that you will now begin the research process
|
|
37
|
+
- Keep the message concise and professional
|
|
38
|
+
`;
|
|
39
|
+
var ClarrifyQuestion = z.object({
|
|
40
|
+
need_clarification: z.boolean().describe("Whether the user needs to be asked a clarifying question."),
|
|
41
|
+
question: z.string().describe("A question to ask the user to clarify the report scope"),
|
|
42
|
+
verification: z.string().describe(
|
|
43
|
+
"Verify message that we will start research after the user has provided the necessary information."
|
|
44
|
+
)
|
|
45
|
+
});
|
|
46
|
+
var clarrifyAgent = agent({
|
|
47
|
+
name: "clarify_with_user",
|
|
48
|
+
// model: lmstudio('qwen/qwen3-4b-thinking-2507'),
|
|
49
|
+
model: groq("openai/gpt-oss-20b"),
|
|
50
|
+
prompt: clarify_with_user_instructions,
|
|
51
|
+
output: ClarrifyQuestion
|
|
52
|
+
});
|
|
53
|
+
async function clarrifyUserQuery(state, query) {
|
|
54
|
+
const { output } = await generate(
|
|
55
|
+
clarrifyAgent,
|
|
56
|
+
`User Query: ${query}.
|
|
57
|
+
Today's date is ${(/* @__PURE__ */ new Date()).toISOString()}.`,
|
|
58
|
+
state
|
|
59
|
+
);
|
|
60
|
+
return output;
|
|
61
|
+
}
|
|
62
|
+
export {
|
|
63
|
+
ClarrifyQuestion,
|
|
64
|
+
clarrifyAgent,
|
|
65
|
+
clarrifyUserQuery
|
|
66
|
+
};
|
|
67
|
+
//# sourceMappingURL=clarrify-agent.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/lib/openai-deepresearch/clarrify-agent.ts"],
|
|
4
|
+
"sourcesContent": ["import { groq } from '@ai-sdk/groq';\nimport z from 'zod';\n\nimport { agent, generate } from '@deepagents/agent';\n\nconst clarify_with_user_instructions = `\nToday's date is ${new Date().toISOString()}.\n\nAssess whether you need to ask a clarifying question, or if the user has already provided enough information for you to start research.\nIMPORTANT: If you can see in the messages history that you have already asked a clarifying question, you almost always do not need to ask another one. Only ask another question if ABSOLUTELY NECESSARY.\n\nIf there are acronyms, abbreviations, or unknown terms, ask the user to clarify.\nIf you need to ask a question, follow these guidelines:\n- Be concise while gathering all necessary information\n- Make sure to gather all the information needed to carry out the research task in a concise, well-structured manner.\n- Use bullet points or numbered lists if appropriate for clarity. Make sure that this uses markdown formatting and will be rendered correctly if the string output is passed to a markdown renderer.\n- Don't ask for unnecessary information, or information that the user has already provided. If you can see that the user has already provided the information, do not ask for it again.\n\nRespond in valid JSON format with these exact keys:\n\"need_clarification\": boolean,\n\"question\": \"<question to ask the user to clarify the report scope>\",\n\"verification\": \"<verification message that we will start research>\"\n\nIf you need to ask a clarifying question, return:\n\"need_clarification\": true,\n\"question\": \"<your clarifying question>\",\n\"verification\": \"\"\n\nIf you do not need to ask a clarifying question, return:\n\"need_clarification\": false,\n\"question\": \"\",\n\"verification\": \"<acknowledgement message that you will now start research based on the provided information>\"\n\nFor the verification message when no clarification is needed:\n- Acknowledge that you have sufficient information to proceed\n- Briefly summarize the key aspects of what you understand from their request\n- Confirm that you will now begin the research process\n- Keep the message concise and professional\n`;\n\nexport const ClarrifyQuestion = z.object({\n need_clarification: z\n .boolean()\n .describe('Whether the user needs to be asked a clarifying question.'),\n question: z\n .string()\n .describe('A question to ask the user to clarify the report scope'),\n verification: z\n .string()\n .describe(\n 'Verify message that we will start research after the user has provided the necessary information.',\n ),\n});\n\nexport const clarrifyAgent = agent({\n name: 'clarify_with_user',\n // model: lmstudio('qwen/qwen3-4b-thinking-2507'),\n model: groq('openai/gpt-oss-20b'),\n prompt: clarify_with_user_instructions,\n output: ClarrifyQuestion,\n});\n\nexport async function clarrifyUserQuery(state: any, query: string) {\n const { output: output } = await generate(\n clarrifyAgent,\n `User Query: ${query}.\n\t\t\t\t\t\tToday's date is ${new Date().toISOString()}.`,\n state,\n );\n return output;\n}\n"],
|
|
5
|
+
"mappings": ";AAAA,SAAS,YAAY;AACrB,OAAO,OAAO;AAEd,SAAS,OAAO,gBAAgB;AAEhC,IAAM,iCAAiC;AAAA,mBACrB,oBAAI,KAAK,GAAE,YAAY,CAAC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAkCnC,IAAM,mBAAmB,EAAE,OAAO;AAAA,EACvC,oBAAoB,EACjB,QAAQ,EACR,SAAS,2DAA2D;AAAA,EACvE,UAAU,EACP,OAAO,EACP,SAAS,wDAAwD;AAAA,EACpE,cAAc,EACX,OAAO,EACP;AAAA,IACC;AAAA,EACF;AACJ,CAAC;AAEM,IAAM,gBAAgB,MAAM;AAAA,EACjC,MAAM;AAAA;AAAA,EAEN,OAAO,KAAK,oBAAoB;AAAA,EAChC,QAAQ;AAAA,EACR,QAAQ;AACV,CAAC;AAED,eAAsB,kBAAkB,OAAY,OAAe;AACjE,QAAM,EAAE,OAAe,IAAI,MAAM;AAAA,IAC/B;AAAA,IACA,eAAe,KAAK;AAAA,yBACA,oBAAI,KAAK,GAAE,YAAY,CAAC;AAAA,IAC5C;AAAA,EACF;AACA,SAAO;AACT;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
// packages/orchestrator/src/lib/openai-deepresearch/lead-research.ts
|
|
2
|
+
import { groq as groq2 } from "@ai-sdk/groq";
|
|
3
|
+
import { jsonSchema, tool } from "ai";
|
|
4
|
+
import z from "zod";
|
|
5
|
+
import { agent as agent2, execute, toState, user } from "@deepagents/agent";
|
|
6
|
+
import { scratchpad_tool as scratchpad_tool2 } from "@deepagents/toolbox";
|
|
7
|
+
|
|
8
|
+
// packages/orchestrator/src/lib/openai-deepresearch/reasearcher.ts
|
|
9
|
+
import { groq } from "@ai-sdk/groq";
|
|
10
|
+
import { agent } from "@deepagents/agent";
|
|
11
|
+
import { scratchpad_tool } from "@deepagents/toolbox";
|
|
12
|
+
var research_system_prompt = `You are a research assistant conducting research on the user's input topic. For context, today's date is ${(/* @__PURE__ */ new Date()).toISOString()}.
|
|
13
|
+
|
|
14
|
+
<Task>
|
|
15
|
+
Your job is to use tools to gather information about the user's input topic.
|
|
16
|
+
You can use any of the tools provided to you to find resources that can help answer the research question. You can call these tools in series or in parallel, your research is conducted in a tool-calling loop.
|
|
17
|
+
</Task>
|
|
18
|
+
|
|
19
|
+
<AvailableTools>
|
|
20
|
+
You have access to two main tools:
|
|
21
|
+
1. **browser_search**: For conducting web searches to gather information
|
|
22
|
+
2. **think_tool**: For reflection and strategic planning during research
|
|
23
|
+
|
|
24
|
+
**CRITICAL: Use think_tool after each search to reflect on results and plan next steps. Do not call think_tool with the web_search or any other tools. It should be to reflect on the results of the search.**
|
|
25
|
+
</AvailableTools>
|
|
26
|
+
|
|
27
|
+
<Instructions>
|
|
28
|
+
Think like a human researcher with limited time. Follow these steps:
|
|
29
|
+
|
|
30
|
+
1. **Read the question carefully** - What specific information does the user need?
|
|
31
|
+
2. **Start with broader searches** - Use broad, comprehensive queries first
|
|
32
|
+
3. **After each search, pause and assess** - Do I have enough to answer? What's still missing?
|
|
33
|
+
4. **Execute narrower searches as you gather information** - Fill in the gaps
|
|
34
|
+
5. **Stop when you can answer confidently** - Don't keep searching for perfection
|
|
35
|
+
</Instructions>
|
|
36
|
+
|
|
37
|
+
<HardLimits>
|
|
38
|
+
**Tool Call Budgets** (Prevent excessive searching):
|
|
39
|
+
- **Simple queries**: Use 2-3 search tool calls maximum
|
|
40
|
+
- **Complex queries**: Use up to 5 search tool calls maximum
|
|
41
|
+
- **Always stop**: After 5 search tool calls if you cannot find the right sources
|
|
42
|
+
|
|
43
|
+
**Stop Immediately When**:
|
|
44
|
+
- You can answer the user's question comprehensively
|
|
45
|
+
- You have 3+ relevant examples/sources for the question
|
|
46
|
+
- Your last 2 searches returned similar information
|
|
47
|
+
</HardLimits>
|
|
48
|
+
|
|
49
|
+
<ShowYourThinking>
|
|
50
|
+
After each search tool call, use think_tool to analyze the results:
|
|
51
|
+
- What key information did I find?
|
|
52
|
+
- What's missing?
|
|
53
|
+
- Do I have enough to answer the question comprehensively?
|
|
54
|
+
- Should I search more or provide my answer?
|
|
55
|
+
</ShowYourThinking>
|
|
56
|
+
`;
|
|
57
|
+
var researcherAgent = agent({
|
|
58
|
+
name: "researcher_agent",
|
|
59
|
+
model: groq("openai/gpt-oss-20b"),
|
|
60
|
+
prompt: research_system_prompt,
|
|
61
|
+
tools: {
|
|
62
|
+
think_tool: scratchpad_tool,
|
|
63
|
+
browser_search: groq.tools.browserSearch({})
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
// packages/orchestrator/src/lib/openai-deepresearch/lead-research.ts
|
|
68
|
+
var lead_researcher_prompt = (max_researcher_iterations, max_concurrent_research_units) => `You are a research supervisor. Your job is to conduct research by calling the "conduct_research" tool. For context, today's date is ${(/* @__PURE__ */ new Date()).toISOString()}.
|
|
69
|
+
|
|
70
|
+
<Task>
|
|
71
|
+
Your focus is to call the "conduct_research" tool to conduct research against the overall research question passed in by the user.
|
|
72
|
+
When you are completely satisfied with the research findings returned from the tool calls, then you should call the "research_complete" tool to indicate that you are done with your research.
|
|
73
|
+
</Task>
|
|
74
|
+
|
|
75
|
+
<Available Tools>
|
|
76
|
+
You have access to three main tools:
|
|
77
|
+
1. **conduct_research**: Delegate research tasks to specialized sub-agents
|
|
78
|
+
2. **research_complete**: Indicate that research is complete
|
|
79
|
+
3. **think_tool**: For reflection and strategic planning during research
|
|
80
|
+
|
|
81
|
+
**CRITICAL: Use think_tool before calling conduct_research to plan your approach, and after each conduct_research to assess progress. Do not call think_tool with any other tools in parallel.**
|
|
82
|
+
</Available Tools>
|
|
83
|
+
|
|
84
|
+
<Instructions>
|
|
85
|
+
Think like a research manager with limited time and resources. Follow these steps:
|
|
86
|
+
|
|
87
|
+
1. **Read the question carefully** - What specific information does the user need?
|
|
88
|
+
2. **Decide how to delegate the research** - Carefully consider the question and decide how to delegate the research. Are there multiple independent directions that can be explored simultaneously?
|
|
89
|
+
3. **After each call to conduct_research, pause and assess** - Do I have enough to answer? What's still missing?
|
|
90
|
+
</Instructions>
|
|
91
|
+
|
|
92
|
+
<Hard Limits>
|
|
93
|
+
**Task Delegation Budgets** (Prevent excessive delegation):
|
|
94
|
+
- **Bias towards single agent** - Use single agent for simplicity unless the user request has clear opportunity for parallelization
|
|
95
|
+
- **Stop when you can answer confidently** - Don't keep delegating research for perfection
|
|
96
|
+
- **Limit tool calls** - Always stop after ${max_researcher_iterations} tool calls to conduct_research and think_tool if you cannot find the right sources
|
|
97
|
+
|
|
98
|
+
**Maximum ${max_concurrent_research_units} parallel agents per iteration**
|
|
99
|
+
</Hard Limits>
|
|
100
|
+
|
|
101
|
+
<Show Your Thinking>
|
|
102
|
+
Before you call conduct_research tool call, use think_tool to plan your approach:
|
|
103
|
+
- Can the task be broken down into smaller sub-tasks?
|
|
104
|
+
|
|
105
|
+
After each conduct_research tool call, use think_tool to analyze the results:
|
|
106
|
+
- What key information did I find?
|
|
107
|
+
- What's missing?
|
|
108
|
+
- Do I have enough to answer the question comprehensively?
|
|
109
|
+
- Should I delegate more research or call research_complete?
|
|
110
|
+
</Show Your Thinking>
|
|
111
|
+
|
|
112
|
+
<Scaling Rules>
|
|
113
|
+
**Simple fact-finding, lists, and rankings** can use a single sub-agent:
|
|
114
|
+
- *Example*: List the top 10 coffee shops in San Francisco \u2192 Use 1 sub-agent
|
|
115
|
+
|
|
116
|
+
**Comparisons presented in the user request** can use a sub-agent for each element of the comparison:
|
|
117
|
+
- *Example*: Compare OpenAI vs. Anthropic vs. DeepMind approaches to AI safety \u2192 Use 3 sub-agents
|
|
118
|
+
- Delegate clear, distinct, non-overlapping subtopics
|
|
119
|
+
|
|
120
|
+
**Important Reminders:**
|
|
121
|
+
- Each conduct_research call spawns a dedicated research agent for that specific topic
|
|
122
|
+
- A separate agent will write the final report - you just need to gather information
|
|
123
|
+
- When calling conduct_research, provide complete standalone instructions - sub-agents can't see other agents' work
|
|
124
|
+
- Do NOT use acronyms or abbreviations in your research questions, be very clear and specific
|
|
125
|
+
</Scaling Rules>
|
|
126
|
+
`;
|
|
127
|
+
var leadResearcherAgent = agent2({
|
|
128
|
+
name: "lead_researcher",
|
|
129
|
+
model: groq2("openai/gpt-oss-20b"),
|
|
130
|
+
prompt: (context) => lead_researcher_prompt(
|
|
131
|
+
context?.max_researcher_iterations || 5,
|
|
132
|
+
context?.max_concurrent_research_units || 3
|
|
133
|
+
),
|
|
134
|
+
tools: {
|
|
135
|
+
think_tool: scratchpad_tool2,
|
|
136
|
+
research_complete: tool({
|
|
137
|
+
description: "Call this tool to indicate that research is complete.",
|
|
138
|
+
inputSchema: jsonSchema({
|
|
139
|
+
type: "object",
|
|
140
|
+
properties: {},
|
|
141
|
+
additionalProperties: true
|
|
142
|
+
})
|
|
143
|
+
}),
|
|
144
|
+
conduct_research: tool({
|
|
145
|
+
description: "Call this tool to conduct research on a specific topic.",
|
|
146
|
+
inputSchema: z.object({
|
|
147
|
+
research_topic: z.string().describe(
|
|
148
|
+
"The topic to research. Should be a single topic, and should be described in high detail (at least a paragraph)."
|
|
149
|
+
)
|
|
150
|
+
}),
|
|
151
|
+
execute: async ({ research_topic }, options) => {
|
|
152
|
+
const context = toState(options);
|
|
153
|
+
context.research_iterations++;
|
|
154
|
+
const result = await execute(
|
|
155
|
+
researcherAgent,
|
|
156
|
+
[user(research_topic)],
|
|
157
|
+
{},
|
|
158
|
+
{ providerOptions: { groq: { reasoningEffort: "low" } } }
|
|
159
|
+
);
|
|
160
|
+
return await result.text;
|
|
161
|
+
}
|
|
162
|
+
})
|
|
163
|
+
}
|
|
164
|
+
});
|
|
165
|
+
export {
|
|
166
|
+
leadResearcherAgent
|
|
167
|
+
};
|
|
168
|
+
//# sourceMappingURL=lead-research.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/lib/openai-deepresearch/lead-research.ts", "../../../src/lib/openai-deepresearch/reasearcher.ts"],
|
|
4
|
+
"sourcesContent": ["import { groq } from '@ai-sdk/groq';\nimport { jsonSchema, tool } from 'ai';\nimport z from 'zod';\n\nimport { agent, execute, toState, user } from '@deepagents/agent';\nimport { scratchpad_tool } from '@deepagents/toolbox';\n\nimport { researcherAgent } from './reasearcher.ts';\n\nconst lead_researcher_prompt = (\n max_researcher_iterations: number,\n max_concurrent_research_units: number,\n) => `You are a research supervisor. Your job is to conduct research by calling the \"conduct_research\" tool. For context, today's date is ${new Date().toISOString()}.\n\n<Task>\nYour focus is to call the \"conduct_research\" tool to conduct research against the overall research question passed in by the user.\nWhen you are completely satisfied with the research findings returned from the tool calls, then you should call the \"research_complete\" tool to indicate that you are done with your research.\n</Task>\n\n<Available Tools>\nYou have access to three main tools:\n1. **conduct_research**: Delegate research tasks to specialized sub-agents\n2. **research_complete**: Indicate that research is complete\n3. **think_tool**: For reflection and strategic planning during research\n\n**CRITICAL: Use think_tool before calling conduct_research to plan your approach, and after each conduct_research to assess progress. Do not call think_tool with any other tools in parallel.**\n</Available Tools>\n\n<Instructions>\nThink like a research manager with limited time and resources. Follow these steps:\n\n1. **Read the question carefully** - What specific information does the user need?\n2. **Decide how to delegate the research** - Carefully consider the question and decide how to delegate the research. Are there multiple independent directions that can be explored simultaneously?\n3. **After each call to conduct_research, pause and assess** - Do I have enough to answer? What's still missing?\n</Instructions>\n\n<Hard Limits>\n**Task Delegation Budgets** (Prevent excessive delegation):\n- **Bias towards single agent** - Use single agent for simplicity unless the user request has clear opportunity for parallelization\n- **Stop when you can answer confidently** - Don't keep delegating research for perfection\n- **Limit tool calls** - Always stop after ${max_researcher_iterations} tool calls to conduct_research and think_tool if you cannot find the right sources\n\n**Maximum ${max_concurrent_research_units} parallel agents per iteration**\n</Hard Limits>\n\n<Show Your Thinking>\nBefore you call conduct_research tool call, use think_tool to plan your approach:\n- Can the task be broken down into smaller sub-tasks?\n\nAfter each conduct_research tool call, use think_tool to analyze the results:\n- What key information did I find?\n- What's missing?\n- Do I have enough to answer the question comprehensively?\n- Should I delegate more research or call research_complete?\n</Show Your Thinking>\n\n<Scaling Rules>\n**Simple fact-finding, lists, and rankings** can use a single sub-agent:\n- *Example*: List the top 10 coffee shops in San Francisco \u2192 Use 1 sub-agent\n\n**Comparisons presented in the user request** can use a sub-agent for each element of the comparison:\n- *Example*: Compare OpenAI vs. Anthropic vs. DeepMind approaches to AI safety \u2192 Use 3 sub-agents\n- Delegate clear, distinct, non-overlapping subtopics\n\n**Important Reminders:**\n- Each conduct_research call spawns a dedicated research agent for that specific topic\n- A separate agent will write the final report - you just need to gather information\n- When calling conduct_research, provide complete standalone instructions - sub-agents can't see other agents' work\n- Do NOT use acronyms or abbreviations in your research questions, be very clear and specific\n</Scaling Rules>\n`;\n\nexport type LeadResearcherState = {\n max_researcher_iterations: number;\n max_concurrent_research_units: number;\n research_iterations: number;\n};\nexport const leadResearcherAgent = agent<unknown, LeadResearcherState>({\n name: 'lead_researcher',\n model: groq('openai/gpt-oss-20b'),\n prompt: (context) =>\n lead_researcher_prompt(\n context?.max_researcher_iterations || 5,\n context?.max_concurrent_research_units || 3,\n ),\n tools: {\n think_tool: scratchpad_tool,\n research_complete: tool({\n description: 'Call this tool to indicate that research is complete.',\n inputSchema: jsonSchema({\n type: 'object',\n properties: {},\n additionalProperties: true,\n }),\n }),\n conduct_research: tool({\n description: 'Call this tool to conduct research on a specific topic.',\n inputSchema: z.object({\n research_topic: z\n .string()\n .describe(\n 'The topic to research. Should be a single topic, and should be described in high detail (at least a paragraph).',\n ),\n }),\n execute: async ({ research_topic }, options) => {\n const context = toState<LeadResearcherState>(options);\n context.research_iterations++;\n const result = await execute(\n researcherAgent,\n [user(research_topic)],\n {},\n { providerOptions: { groq: { reasoningEffort: 'low' } } },\n );\n return await result.text;\n },\n }),\n },\n});\n", "import { groq } from '@ai-sdk/groq';\n\nimport { agent } from '@deepagents/agent';\nimport { scratchpad_tool } from '@deepagents/toolbox';\n\nconst research_system_prompt = `You are a research assistant conducting research on the user's input topic. For context, today's date is ${new Date().toISOString()}.\n\n<Task>\nYour job is to use tools to gather information about the user's input topic.\nYou can use any of the tools provided to you to find resources that can help answer the research question. You can call these tools in series or in parallel, your research is conducted in a tool-calling loop.\n</Task>\n\n<AvailableTools>\nYou have access to two main tools:\n1. **browser_search**: For conducting web searches to gather information\n2. **think_tool**: For reflection and strategic planning during research\n\n**CRITICAL: Use think_tool after each search to reflect on results and plan next steps. Do not call think_tool with the web_search or any other tools. It should be to reflect on the results of the search.**\n</AvailableTools>\n\n<Instructions>\nThink like a human researcher with limited time. Follow these steps:\n\n1. **Read the question carefully** - What specific information does the user need?\n2. **Start with broader searches** - Use broad, comprehensive queries first\n3. **After each search, pause and assess** - Do I have enough to answer? What's still missing?\n4. **Execute narrower searches as you gather information** - Fill in the gaps\n5. **Stop when you can answer confidently** - Don't keep searching for perfection\n</Instructions>\n\n<HardLimits>\n**Tool Call Budgets** (Prevent excessive searching):\n- **Simple queries**: Use 2-3 search tool calls maximum\n- **Complex queries**: Use up to 5 search tool calls maximum\n- **Always stop**: After 5 search tool calls if you cannot find the right sources\n\n**Stop Immediately When**:\n- You can answer the user's question comprehensively\n- You have 3+ relevant examples/sources for the question\n- Your last 2 searches returned similar information\n</HardLimits>\n\n<ShowYourThinking>\nAfter each search tool call, use think_tool to analyze the results:\n- What key information did I find?\n- What's missing?\n- Do I have enough to answer the question comprehensively?\n- Should I search more or provide my answer?\n</ShowYourThinking>\n`;\n\nexport const researcherAgent = agent({\n name: 'researcher_agent',\n model: groq('openai/gpt-oss-20b'),\n prompt: research_system_prompt,\n tools: {\n think_tool: scratchpad_tool,\n browser_search: (groq as any).tools.browserSearch({}),\n },\n});\n"],
|
|
5
|
+
"mappings": ";AAAA,SAAS,QAAAA,aAAY;AACrB,SAAS,YAAY,YAAY;AACjC,OAAO,OAAO;AAEd,SAAS,SAAAC,QAAO,SAAS,SAAS,YAAY;AAC9C,SAAS,mBAAAC,wBAAuB;;;ACLhC,SAAS,YAAY;AAErB,SAAS,aAAa;AACtB,SAAS,uBAAuB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K;AAAA,MACtB,aAAa;AAAA,MACb,aAAa,WAAW;AAAA,QACtB,MAAM;AAAA,QACN,YAAY,CAAC;AAAA,QACb,sBAAsB;AAAA,MACxB,CAAC;AAAA,IACH,CAAC;AAAA,IACD,kBAAkB,KAAK;AAAA,MACrB,aAAa;AAAA,MACb,aAAa,EAAE,OAAO;AAAA,QACpB,gBAAgB,EACb,OAAO,EACP;AAAA,UACC;AAAA,QACF;AAAA,MACJ,CAAC;AAAA,MACD,SAAS,OAAO,EAAE,eAAe,GAAG,YAAY;AAC9C,cAAM,UAAU,QAA6B,OAAO;AACpD,gBAAQ;AACR,cAAM,SAAS,MAAM;AAAA,UACnB;AAAA,UACA,CAAC,KAAK,cAAc,CAAC;AAAA,UACrB,CAAC;AAAA,UACD,EAAE,iBAAiB,EAAE,MAAM,EAAE,iBAAiB,MAAM,EAAE,EAAE;AAAA,QAC1D;AACA,eAAO,MAAM,OAAO;AAAA,MACtB;AAAA,IACF,CAAC;AAAA,EACH;AACF,CAAC;",
|
|
6
|
+
"names": ["groq", "agent", "scratchpad_tool", "agent", "groq", "scratchpad_tool"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
// packages/orchestrator/src/lib/openai-deepresearch/openai-deepresearch.ts
|
|
2
|
+
import { generateId, toUIMessageStream } from "ai";
|
|
3
|
+
import { execute as execute2, printer, user as user2 } from "@deepagents/agent";
|
|
4
|
+
|
|
5
|
+
// packages/orchestrator/src/lib/openai-deepresearch/lead-research.ts
|
|
6
|
+
import { groq as groq2 } from "@ai-sdk/groq";
|
|
7
|
+
import { jsonSchema, tool } from "ai";
|
|
8
|
+
import z from "zod";
|
|
9
|
+
import { agent as agent2, execute, toState, user } from "@deepagents/agent";
|
|
10
|
+
import { scratchpad_tool as scratchpad_tool2 } from "@deepagents/toolbox";
|
|
11
|
+
|
|
12
|
+
// packages/orchestrator/src/lib/openai-deepresearch/reasearcher.ts
|
|
13
|
+
import { groq } from "@ai-sdk/groq";
|
|
14
|
+
import { agent } from "@deepagents/agent";
|
|
15
|
+
import { scratchpad_tool } from "@deepagents/toolbox";
|
|
16
|
+
var research_system_prompt = `You are a research assistant conducting research on the user's input topic. For context, today's date is ${(/* @__PURE__ */ new Date()).toISOString()}.
|
|
17
|
+
|
|
18
|
+
<Task>
|
|
19
|
+
Your job is to use tools to gather information about the user's input topic.
|
|
20
|
+
You can use any of the tools provided to you to find resources that can help answer the research question. You can call these tools in series or in parallel, your research is conducted in a tool-calling loop.
|
|
21
|
+
</Task>
|
|
22
|
+
|
|
23
|
+
<AvailableTools>
|
|
24
|
+
You have access to two main tools:
|
|
25
|
+
1. **browser_search**: For conducting web searches to gather information
|
|
26
|
+
2. **think_tool**: For reflection and strategic planning during research
|
|
27
|
+
|
|
28
|
+
**CRITICAL: Use think_tool after each search to reflect on results and plan next steps. Do not call think_tool with the web_search or any other tools. It should be to reflect on the results of the search.**
|
|
29
|
+
</AvailableTools>
|
|
30
|
+
|
|
31
|
+
<Instructions>
|
|
32
|
+
Think like a human researcher with limited time. Follow these steps:
|
|
33
|
+
|
|
34
|
+
1. **Read the question carefully** - What specific information does the user need?
|
|
35
|
+
2. **Start with broader searches** - Use broad, comprehensive queries first
|
|
36
|
+
3. **After each search, pause and assess** - Do I have enough to answer? What's still missing?
|
|
37
|
+
4. **Execute narrower searches as you gather information** - Fill in the gaps
|
|
38
|
+
5. **Stop when you can answer confidently** - Don't keep searching for perfection
|
|
39
|
+
</Instructions>
|
|
40
|
+
|
|
41
|
+
<HardLimits>
|
|
42
|
+
**Tool Call Budgets** (Prevent excessive searching):
|
|
43
|
+
- **Simple queries**: Use 2-3 search tool calls maximum
|
|
44
|
+
- **Complex queries**: Use up to 5 search tool calls maximum
|
|
45
|
+
- **Always stop**: After 5 search tool calls if you cannot find the right sources
|
|
46
|
+
|
|
47
|
+
**Stop Immediately When**:
|
|
48
|
+
- You can answer the user's question comprehensively
|
|
49
|
+
- You have 3+ relevant examples/sources for the question
|
|
50
|
+
- Your last 2 searches returned similar information
|
|
51
|
+
</HardLimits>
|
|
52
|
+
|
|
53
|
+
<ShowYourThinking>
|
|
54
|
+
After each search tool call, use think_tool to analyze the results:
|
|
55
|
+
- What key information did I find?
|
|
56
|
+
- What's missing?
|
|
57
|
+
- Do I have enough to answer the question comprehensively?
|
|
58
|
+
- Should I search more or provide my answer?
|
|
59
|
+
</ShowYourThinking>
|
|
60
|
+
`;
|
|
61
|
+
var researcherAgent = agent({
|
|
62
|
+
name: "researcher_agent",
|
|
63
|
+
model: groq("openai/gpt-oss-20b"),
|
|
64
|
+
prompt: research_system_prompt,
|
|
65
|
+
tools: {
|
|
66
|
+
think_tool: scratchpad_tool,
|
|
67
|
+
browser_search: groq.tools.browserSearch({})
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
// packages/orchestrator/src/lib/openai-deepresearch/lead-research.ts
|
|
72
|
+
var lead_researcher_prompt = (max_researcher_iterations, max_concurrent_research_units) => `You are a research supervisor. Your job is to conduct research by calling the "conduct_research" tool. For context, today's date is ${(/* @__PURE__ */ new Date()).toISOString()}.
|
|
73
|
+
|
|
74
|
+
<Task>
|
|
75
|
+
Your focus is to call the "conduct_research" tool to conduct research against the overall research question passed in by the user.
|
|
76
|
+
When you are completely satisfied with the research findings returned from the tool calls, then you should call the "research_complete" tool to indicate that you are done with your research.
|
|
77
|
+
</Task>
|
|
78
|
+
|
|
79
|
+
<Available Tools>
|
|
80
|
+
You have access to three main tools:
|
|
81
|
+
1. **conduct_research**: Delegate research tasks to specialized sub-agents
|
|
82
|
+
2. **research_complete**: Indicate that research is complete
|
|
83
|
+
3. **think_tool**: For reflection and strategic planning during research
|
|
84
|
+
|
|
85
|
+
**CRITICAL: Use think_tool before calling conduct_research to plan your approach, and after each conduct_research to assess progress. Do not call think_tool with any other tools in parallel.**
|
|
86
|
+
</Available Tools>
|
|
87
|
+
|
|
88
|
+
<Instructions>
|
|
89
|
+
Think like a research manager with limited time and resources. Follow these steps:
|
|
90
|
+
|
|
91
|
+
1. **Read the question carefully** - What specific information does the user need?
|
|
92
|
+
2. **Decide how to delegate the research** - Carefully consider the question and decide how to delegate the research. Are there multiple independent directions that can be explored simultaneously?
|
|
93
|
+
3. **After each call to conduct_research, pause and assess** - Do I have enough to answer? What's still missing?
|
|
94
|
+
</Instructions>
|
|
95
|
+
|
|
96
|
+
<Hard Limits>
|
|
97
|
+
**Task Delegation Budgets** (Prevent excessive delegation):
|
|
98
|
+
- **Bias towards single agent** - Use single agent for simplicity unless the user request has clear opportunity for parallelization
|
|
99
|
+
- **Stop when you can answer confidently** - Don't keep delegating research for perfection
|
|
100
|
+
- **Limit tool calls** - Always stop after ${max_researcher_iterations} tool calls to conduct_research and think_tool if you cannot find the right sources
|
|
101
|
+
|
|
102
|
+
**Maximum ${max_concurrent_research_units} parallel agents per iteration**
|
|
103
|
+
</Hard Limits>
|
|
104
|
+
|
|
105
|
+
<Show Your Thinking>
|
|
106
|
+
Before you call conduct_research tool call, use think_tool to plan your approach:
|
|
107
|
+
- Can the task be broken down into smaller sub-tasks?
|
|
108
|
+
|
|
109
|
+
After each conduct_research tool call, use think_tool to analyze the results:
|
|
110
|
+
- What key information did I find?
|
|
111
|
+
- What's missing?
|
|
112
|
+
- Do I have enough to answer the question comprehensively?
|
|
113
|
+
- Should I delegate more research or call research_complete?
|
|
114
|
+
</Show Your Thinking>
|
|
115
|
+
|
|
116
|
+
<Scaling Rules>
|
|
117
|
+
**Simple fact-finding, lists, and rankings** can use a single sub-agent:
|
|
118
|
+
- *Example*: List the top 10 coffee shops in San Francisco \u2192 Use 1 sub-agent
|
|
119
|
+
|
|
120
|
+
**Comparisons presented in the user request** can use a sub-agent for each element of the comparison:
|
|
121
|
+
- *Example*: Compare OpenAI vs. Anthropic vs. DeepMind approaches to AI safety \u2192 Use 3 sub-agents
|
|
122
|
+
- Delegate clear, distinct, non-overlapping subtopics
|
|
123
|
+
|
|
124
|
+
**Important Reminders:**
|
|
125
|
+
- Each conduct_research call spawns a dedicated research agent for that specific topic
|
|
126
|
+
- A separate agent will write the final report - you just need to gather information
|
|
127
|
+
- When calling conduct_research, provide complete standalone instructions - sub-agents can't see other agents' work
|
|
128
|
+
- Do NOT use acronyms or abbreviations in your research questions, be very clear and specific
|
|
129
|
+
</Scaling Rules>
|
|
130
|
+
`;
|
|
131
|
+
var leadResearcherAgent = agent2({
|
|
132
|
+
name: "lead_researcher",
|
|
133
|
+
model: groq2("openai/gpt-oss-20b"),
|
|
134
|
+
prompt: (context) => lead_researcher_prompt(
|
|
135
|
+
context?.max_researcher_iterations || 5,
|
|
136
|
+
context?.max_concurrent_research_units || 3
|
|
137
|
+
),
|
|
138
|
+
tools: {
|
|
139
|
+
think_tool: scratchpad_tool2,
|
|
140
|
+
research_complete: tool({
|
|
141
|
+
description: "Call this tool to indicate that research is complete.",
|
|
142
|
+
inputSchema: jsonSchema({
|
|
143
|
+
type: "object",
|
|
144
|
+
properties: {},
|
|
145
|
+
additionalProperties: true
|
|
146
|
+
})
|
|
147
|
+
}),
|
|
148
|
+
conduct_research: tool({
|
|
149
|
+
description: "Call this tool to conduct research on a specific topic.",
|
|
150
|
+
inputSchema: z.object({
|
|
151
|
+
research_topic: z.string().describe(
|
|
152
|
+
"The topic to research. Should be a single topic, and should be described in high detail (at least a paragraph)."
|
|
153
|
+
)
|
|
154
|
+
}),
|
|
155
|
+
execute: async ({ research_topic }, options) => {
|
|
156
|
+
const context = toState(options);
|
|
157
|
+
context.research_iterations++;
|
|
158
|
+
const result = await execute(
|
|
159
|
+
researcherAgent,
|
|
160
|
+
[user(research_topic)],
|
|
161
|
+
{},
|
|
162
|
+
{ providerOptions: { groq: { reasoningEffort: "low" } } }
|
|
163
|
+
);
|
|
164
|
+
return await result.text;
|
|
165
|
+
}
|
|
166
|
+
})
|
|
167
|
+
}
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
// packages/orchestrator/src/lib/openai-deepresearch/openai-deepresearch.ts
|
|
171
|
+
var research_brief = `I want a comprehensive research report on opening a coworking space in Amman, Jordan that includes detailed market insights (size, growth trends, target demographics, and demand drivers), a competitor analysis (existing coworking providers, their locations, pricing models, amenities, and market share), an assessment of demand and pricing elasticity, key operational considerations (optimal locations, regulatory and licensing requirements, staffing needs, technology and infrastructure, cost structure, revenue projections, and risk factors), and actionable recommendations for a go\u2011to\u2011market strategy. Any dimensions not explicitly specified (e.g., preferred target customer segment, budget constraints, or timeline) should be treated as open\u2011ended and explored broadly.`;
|
|
172
|
+
execute2(leadResearcherAgent, [user2(research_brief)], {
|
|
173
|
+
max_concurrent_research_units: 3,
|
|
174
|
+
max_researcher_iterations: 3,
|
|
175
|
+
research_iterations: 0
|
|
176
|
+
}).then((result) => {
|
|
177
|
+
printer.stdout(result, { reasoning: false });
|
|
178
|
+
});
|
|
179
|
+
//# sourceMappingURL=openai-deepresearch.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/lib/openai-deepresearch/openai-deepresearch.ts", "../../../src/lib/openai-deepresearch/lead-research.ts", "../../../src/lib/openai-deepresearch/reasearcher.ts"],
|
|
4
|
+
"sourcesContent": ["import { type UIMessage, generateId, toUIMessageStream } from 'ai';\n\nimport { execute, printer, user } from '@deepagents/agent';\n\nimport {\n type LeadResearcherState,\n leadResearcherAgent,\n} from './lead-research.ts';\n\n// let clarification: z.output<typeof ClarrifyQuestion> = {\n// need_clarification: true,\n// question: '',\n// verification: '',\n// };\n// const messages: UIMessage[] = [];\n// while (clarification.need_clarification) {\n// console.log(clarification.question + '\\n');\n// messages.push(user(await input()));\n// const result = execute(clarrifyAgent, messages, {});\n// const output = await toOutput<z.output<typeof ClarrifyQuestion>>(result);\n// await Array.fromAsync(\n// result.toUIMessageStream({\n// generateMessageId: generateId,\n// originalMessages: messages,\n// onEnd: async ({ responseMessage }) => {\n// messages.push(responseMessage);\n// },\n// }),\n// );\n// await result.consumeStream();\n// clarification = output;\n// }\n// const { output: research_brief } = await generate(researchTopicAgent, clarification.verification, {})\nconst research_brief = `I want a comprehensive research report on opening a coworking space in Amman, Jordan that includes detailed market insights (size, growth trends, target demographics, and demand drivers), a competitor analysis (existing coworking providers, their locations, pricing models, amenities, and market share), an assessment of demand and pricing elasticity, key operational considerations (optimal locations, regulatory and licensing requirements, staffing needs, technology and infrastructure, cost structure, revenue projections, and risk factors), and actionable recommendations for a go\u2011to\u2011market strategy. Any dimensions not explicitly specified (e.g., preferred target customer segment, budget constraints, or timeline) should be treated as open\u2011ended and explored broadly.`;\n\nexecute(leadResearcherAgent, [user(research_brief)], {\n max_concurrent_research_units: 3,\n max_researcher_iterations: 3,\n research_iterations: 0,\n}).then((result) => {\n printer.stdout(result, { reasoning: false });\n});\n\n// await startResearch(research_brief);\n\nasync function startResearch(brief: string) {\n const messages: UIMessage[] = [user(brief)];\n const state: LeadResearcherState = {\n max_concurrent_research_units: 3,\n max_researcher_iterations: 1,\n research_iterations: 0,\n };\n while (true) {\n const result = await execute(leadResearcherAgent, messages, state);\n await Array.fromAsync(\n toUIMessageStream({\n stream: result.stream,\n tools: leadResearcherAgent.toToolset(),\n generateMessageId: generateId,\n originalMessages: messages,\n onEnd: async ({ responseMessage }: { responseMessage: UIMessage }) => {\n messages.push(responseMessage);\n },\n }),\n );\n await result.consumeStream();\n const calls = await result.toolCalls;\n const researchComplete = calls.some(\n (it: { toolName: string }) => it.toolName === 'research_complete',\n );\n const conductResearchTools = calls.filter(\n (it: { toolName: string }) => it.toolName === 'conduct_research',\n );\n\n const exceeded_allowed_iterations =\n state.research_iterations >= state.max_researcher_iterations;\n\n if (researchComplete || exceeded_allowed_iterations || !calls.length) {\n break;\n }\n\n // for (const call of conductResearchTools) {\n // const result = execute(\n // researcherAgent,\n // [user(call.input.research_topic)],\n // {},\n // );\n // const mostRecentMessage = messages[messages.length - 1];\n // if (mostRecentMessage.role === 'assistant') {\n // messages.push({\n // role: 'assistant',\n // // parts: [{}],\n // });\n // }\n // }\n\n state.research_iterations++;\n }\n}\n", "import { groq } from '@ai-sdk/groq';\nimport { jsonSchema, tool } from 'ai';\nimport z from 'zod';\n\nimport { agent, execute, toState, user } from '@deepagents/agent';\nimport { scratchpad_tool } from '@deepagents/toolbox';\n\nimport { researcherAgent } from './reasearcher.ts';\n\nconst lead_researcher_prompt = (\n max_researcher_iterations: number,\n max_concurrent_research_units: number,\n) => `You are a research supervisor. Your job is to conduct research by calling the \"conduct_research\" tool. For context, today's date is ${new Date().toISOString()}.\n\n<Task>\nYour focus is to call the \"conduct_research\" tool to conduct research against the overall research question passed in by the user.\nWhen you are completely satisfied with the research findings returned from the tool calls, then you should call the \"research_complete\" tool to indicate that you are done with your research.\n</Task>\n\n<Available Tools>\nYou have access to three main tools:\n1. **conduct_research**: Delegate research tasks to specialized sub-agents\n2. **research_complete**: Indicate that research is complete\n3. **think_tool**: For reflection and strategic planning during research\n\n**CRITICAL: Use think_tool before calling conduct_research to plan your approach, and after each conduct_research to assess progress. Do not call think_tool with any other tools in parallel.**\n</Available Tools>\n\n<Instructions>\nThink like a research manager with limited time and resources. Follow these steps:\n\n1. **Read the question carefully** - What specific information does the user need?\n2. **Decide how to delegate the research** - Carefully consider the question and decide how to delegate the research. Are there multiple independent directions that can be explored simultaneously?\n3. **After each call to conduct_research, pause and assess** - Do I have enough to answer? What's still missing?\n</Instructions>\n\n<Hard Limits>\n**Task Delegation Budgets** (Prevent excessive delegation):\n- **Bias towards single agent** - Use single agent for simplicity unless the user request has clear opportunity for parallelization\n- **Stop when you can answer confidently** - Don't keep delegating research for perfection\n- **Limit tool calls** - Always stop after ${max_researcher_iterations} tool calls to conduct_research and think_tool if you cannot find the right sources\n\n**Maximum ${max_concurrent_research_units} parallel agents per iteration**\n</Hard Limits>\n\n<Show Your Thinking>\nBefore you call conduct_research tool call, use think_tool to plan your approach:\n- Can the task be broken down into smaller sub-tasks?\n\nAfter each conduct_research tool call, use think_tool to analyze the results:\n- What key information did I find?\n- What's missing?\n- Do I have enough to answer the question comprehensively?\n- Should I delegate more research or call research_complete?\n</Show Your Thinking>\n\n<Scaling Rules>\n**Simple fact-finding, lists, and rankings** can use a single sub-agent:\n- *Example*: List the top 10 coffee shops in San Francisco \u2192 Use 1 sub-agent\n\n**Comparisons presented in the user request** can use a sub-agent for each element of the comparison:\n- *Example*: Compare OpenAI vs. Anthropic vs. DeepMind approaches to AI safety \u2192 Use 3 sub-agents\n- Delegate clear, distinct, non-overlapping subtopics\n\n**Important Reminders:**\n- Each conduct_research call spawns a dedicated research agent for that specific topic\n- A separate agent will write the final report - you just need to gather information\n- When calling conduct_research, provide complete standalone instructions - sub-agents can't see other agents' work\n- Do NOT use acronyms or abbreviations in your research questions, be very clear and specific\n</Scaling Rules>\n`;\n\nexport type LeadResearcherState = {\n max_researcher_iterations: number;\n max_concurrent_research_units: number;\n research_iterations: number;\n};\nexport const leadResearcherAgent = agent<unknown, LeadResearcherState>({\n name: 'lead_researcher',\n model: groq('openai/gpt-oss-20b'),\n prompt: (context) =>\n lead_researcher_prompt(\n context?.max_researcher_iterations || 5,\n context?.max_concurrent_research_units || 3,\n ),\n tools: {\n think_tool: scratchpad_tool,\n research_complete: tool({\n description: 'Call this tool to indicate that research is complete.',\n inputSchema: jsonSchema({\n type: 'object',\n properties: {},\n additionalProperties: true,\n }),\n }),\n conduct_research: tool({\n description: 'Call this tool to conduct research on a specific topic.',\n inputSchema: z.object({\n research_topic: z\n .string()\n .describe(\n 'The topic to research. Should be a single topic, and should be described in high detail (at least a paragraph).',\n ),\n }),\n execute: async ({ research_topic }, options) => {\n const context = toState<LeadResearcherState>(options);\n context.research_iterations++;\n const result = await execute(\n researcherAgent,\n [user(research_topic)],\n {},\n { providerOptions: { groq: { reasoningEffort: 'low' } } },\n );\n return await result.text;\n },\n }),\n },\n});\n", "import { groq } from '@ai-sdk/groq';\n\nimport { agent } from '@deepagents/agent';\nimport { scratchpad_tool } from '@deepagents/toolbox';\n\nconst research_system_prompt = `You are a research assistant conducting research on the user's input topic. For context, today's date is ${new Date().toISOString()}.\n\n<Task>\nYour job is to use tools to gather information about the user's input topic.\nYou can use any of the tools provided to you to find resources that can help answer the research question. You can call these tools in series or in parallel, your research is conducted in a tool-calling loop.\n</Task>\n\n<AvailableTools>\nYou have access to two main tools:\n1. **browser_search**: For conducting web searches to gather information\n2. **think_tool**: For reflection and strategic planning during research\n\n**CRITICAL: Use think_tool after each search to reflect on results and plan next steps. Do not call think_tool with the web_search or any other tools. It should be to reflect on the results of the search.**\n</AvailableTools>\n\n<Instructions>\nThink like a human researcher with limited time. Follow these steps:\n\n1. **Read the question carefully** - What specific information does the user need?\n2. **Start with broader searches** - Use broad, comprehensive queries first\n3. **After each search, pause and assess** - Do I have enough to answer? What's still missing?\n4. **Execute narrower searches as you gather information** - Fill in the gaps\n5. **Stop when you can answer confidently** - Don't keep searching for perfection\n</Instructions>\n\n<HardLimits>\n**Tool Call Budgets** (Prevent excessive searching):\n- **Simple queries**: Use 2-3 search tool calls maximum\n- **Complex queries**: Use up to 5 search tool calls maximum\n- **Always stop**: After 5 search tool calls if you cannot find the right sources\n\n**Stop Immediately When**:\n- You can answer the user's question comprehensively\n- You have 3+ relevant examples/sources for the question\n- Your last 2 searches returned similar information\n</HardLimits>\n\n<ShowYourThinking>\nAfter each search tool call, use think_tool to analyze the results:\n- What key information did I find?\n- What's missing?\n- Do I have enough to answer the question comprehensively?\n- Should I search more or provide my answer?\n</ShowYourThinking>\n`;\n\nexport const researcherAgent = agent({\n name: 'researcher_agent',\n model: groq('openai/gpt-oss-20b'),\n prompt: research_system_prompt,\n tools: {\n think_tool: scratchpad_tool,\n browser_search: (groq as any).tools.browserSearch({}),\n },\n});\n"],
|
|
5
|
+
"mappings": ";AAAA,SAAyB,YAAY,yBAAyB;AAE9D,SAAS,WAAAA,UAAS,SAAS,QAAAC,aAAY;;;ACFvC,SAAS,QAAAC,aAAY;AACrB,SAAS,YAAY,YAAY;AACjC,OAAO,OAAO;AAEd,SAAS,SAAAC,QAAO,SAAS,SAAS,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A,IACtC,SAAS,iCAAiC;AAAA,EAC5C;AAAA,EACF,OAAO;AAAA,IACL,YAAYC;AAAA,IACZ,mBAAmB,KAAK;AAAA,MACtB,aAAa;AAAA,MACb,aAAa,WAAW;AAAA,QACtB,MAAM;AAAA,QACN,YAAY,CAAC;AAAA,QACb,sBAAsB;AAAA,MACxB,CAAC;AAAA,IACH,CAAC;AAAA,IACD,kBAAkB,KAAK;AAAA,MACrB,aAAa;AAAA,MACb,aAAa,EAAE,OAAO;AAAA,QACpB,gBAAgB,EACb,OAAO,EACP;AAAA,UACC;AAAA,QACF;AAAA,MACJ,CAAC;AAAA,MACD,SAAS,OAAO,EAAE,eAAe,GAAG,YAAY;AAC9C,cAAM,UAAU,QAA6B,OAAO;AACpD,gBAAQ;AACR,cAAM,SAAS,MAAM;AAAA,UACnB;AAAA,UACA,CAAC,KAAK,cAAc,CAAC;AAAA,UACrB,CAAC;AAAA,UACD,EAAE,iBAAiB,EAAE,MAAM,EAAE,iBAAiB,MAAM,EAAE,EAAE;AAAA,QAC1D;AACA,eAAO,MAAM,OAAO;AAAA,MACtB;AAAA,IACF,CAAC;AAAA,EACH;AACF,CAAC;;;ADpFD,IAAM,iBAAiB;AAEvBC,SAAQ,qBAAqB,CAACC,MAAK,cAAc,CAAC,GAAG;AAAA,EACnD,+BAA+B;AAAA,EAC/B,2BAA2B;AAAA,EAC3B,qBAAqB;AACvB,CAAC,EAAE,KAAK,CAAC,WAAW;AAClB,UAAQ,OAAO,QAAQ,EAAE,WAAW,MAAM,CAAC;AAC7C,CAAC;",
|
|
6
|
+
"names": ["execute", "user", "groq", "agent", "scratchpad_tool", "agent", "groq", "scratchpad_tool", "execute", "user"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
// packages/orchestrator/src/lib/openai-deepresearch/reasearcher.ts
|
|
2
|
+
import { groq } from "@ai-sdk/groq";
|
|
3
|
+
import { agent } from "@deepagents/agent";
|
|
4
|
+
import { scratchpad_tool } from "@deepagents/toolbox";
|
|
5
|
+
var research_system_prompt = `You are a research assistant conducting research on the user's input topic. For context, today's date is ${(/* @__PURE__ */ new Date()).toISOString()}.
|
|
6
|
+
|
|
7
|
+
<Task>
|
|
8
|
+
Your job is to use tools to gather information about the user's input topic.
|
|
9
|
+
You can use any of the tools provided to you to find resources that can help answer the research question. You can call these tools in series or in parallel, your research is conducted in a tool-calling loop.
|
|
10
|
+
</Task>
|
|
11
|
+
|
|
12
|
+
<AvailableTools>
|
|
13
|
+
You have access to two main tools:
|
|
14
|
+
1. **browser_search**: For conducting web searches to gather information
|
|
15
|
+
2. **think_tool**: For reflection and strategic planning during research
|
|
16
|
+
|
|
17
|
+
**CRITICAL: Use think_tool after each search to reflect on results and plan next steps. Do not call think_tool with the web_search or any other tools. It should be to reflect on the results of the search.**
|
|
18
|
+
</AvailableTools>
|
|
19
|
+
|
|
20
|
+
<Instructions>
|
|
21
|
+
Think like a human researcher with limited time. Follow these steps:
|
|
22
|
+
|
|
23
|
+
1. **Read the question carefully** - What specific information does the user need?
|
|
24
|
+
2. **Start with broader searches** - Use broad, comprehensive queries first
|
|
25
|
+
3. **After each search, pause and assess** - Do I have enough to answer? What's still missing?
|
|
26
|
+
4. **Execute narrower searches as you gather information** - Fill in the gaps
|
|
27
|
+
5. **Stop when you can answer confidently** - Don't keep searching for perfection
|
|
28
|
+
</Instructions>
|
|
29
|
+
|
|
30
|
+
<HardLimits>
|
|
31
|
+
**Tool Call Budgets** (Prevent excessive searching):
|
|
32
|
+
- **Simple queries**: Use 2-3 search tool calls maximum
|
|
33
|
+
- **Complex queries**: Use up to 5 search tool calls maximum
|
|
34
|
+
- **Always stop**: After 5 search tool calls if you cannot find the right sources
|
|
35
|
+
|
|
36
|
+
**Stop Immediately When**:
|
|
37
|
+
- You can answer the user's question comprehensively
|
|
38
|
+
- You have 3+ relevant examples/sources for the question
|
|
39
|
+
- Your last 2 searches returned similar information
|
|
40
|
+
</HardLimits>
|
|
41
|
+
|
|
42
|
+
<ShowYourThinking>
|
|
43
|
+
After each search tool call, use think_tool to analyze the results:
|
|
44
|
+
- What key information did I find?
|
|
45
|
+
- What's missing?
|
|
46
|
+
- Do I have enough to answer the question comprehensively?
|
|
47
|
+
- Should I search more or provide my answer?
|
|
48
|
+
</ShowYourThinking>
|
|
49
|
+
`;
|
|
50
|
+
var researcherAgent = agent({
|
|
51
|
+
name: "researcher_agent",
|
|
52
|
+
model: groq("openai/gpt-oss-20b"),
|
|
53
|
+
prompt: research_system_prompt,
|
|
54
|
+
tools: {
|
|
55
|
+
think_tool: scratchpad_tool,
|
|
56
|
+
browser_search: groq.tools.browserSearch({})
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
export {
|
|
60
|
+
researcherAgent
|
|
61
|
+
};
|
|
62
|
+
//# sourceMappingURL=reasearcher.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/lib/openai-deepresearch/reasearcher.ts"],
|
|
4
|
+
"sourcesContent": ["import { groq } from '@ai-sdk/groq';\n\nimport { agent } from '@deepagents/agent';\nimport { scratchpad_tool } from '@deepagents/toolbox';\n\nconst research_system_prompt = `You are a research assistant conducting research on the user's input topic. For context, today's date is ${new Date().toISOString()}.\n\n<Task>\nYour job is to use tools to gather information about the user's input topic.\nYou can use any of the tools provided to you to find resources that can help answer the research question. You can call these tools in series or in parallel, your research is conducted in a tool-calling loop.\n</Task>\n\n<AvailableTools>\nYou have access to two main tools:\n1. **browser_search**: For conducting web searches to gather information\n2. **think_tool**: For reflection and strategic planning during research\n\n**CRITICAL: Use think_tool after each search to reflect on results and plan next steps. Do not call think_tool with the web_search or any other tools. It should be to reflect on the results of the search.**\n</AvailableTools>\n\n<Instructions>\nThink like a human researcher with limited time. Follow these steps:\n\n1. **Read the question carefully** - What specific information does the user need?\n2. **Start with broader searches** - Use broad, comprehensive queries first\n3. **After each search, pause and assess** - Do I have enough to answer? What's still missing?\n4. **Execute narrower searches as you gather information** - Fill in the gaps\n5. **Stop when you can answer confidently** - Don't keep searching for perfection\n</Instructions>\n\n<HardLimits>\n**Tool Call Budgets** (Prevent excessive searching):\n- **Simple queries**: Use 2-3 search tool calls maximum\n- **Complex queries**: Use up to 5 search tool calls maximum\n- **Always stop**: After 5 search tool calls if you cannot find the right sources\n\n**Stop Immediately When**:\n- You can answer the user's question comprehensively\n- You have 3+ relevant examples/sources for the question\n- Your last 2 searches returned similar information\n</HardLimits>\n\n<ShowYourThinking>\nAfter each search tool call, use think_tool to analyze the results:\n- What key information did I find?\n- What's missing?\n- Do I have enough to answer the question comprehensively?\n- Should I search more or provide my answer?\n</ShowYourThinking>\n`;\n\nexport const researcherAgent = agent({\n name: 'researcher_agent',\n model: groq('openai/gpt-oss-20b'),\n prompt: research_system_prompt,\n tools: {\n think_tool: scratchpad_tool,\n browser_search: (groq as any).tools.browserSearch({}),\n },\n});\n"],
|
|
5
|
+
"mappings": ";AAAA,SAAS,YAAY;AAErB,SAAS,aAAa;AACtB,SAAS,uBAAuB;AAEhC,IAAM,yBAAyB,6GAA4G,oBAAI,KAAK,GAAE,YAAY,CAAC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AA8C5J,IAAM,kBAAkB,MAAM;AAAA,EACnC,MAAM;AAAA,EACN,OAAO,KAAK,oBAAoB;AAAA,EAChC,QAAQ;AAAA,EACR,OAAO;AAAA,IACL,YAAY;AAAA,IACZ,gBAAiB,KAAa,MAAM,cAAc,CAAC,CAAC;AAAA,EACtD;AACF,CAAC;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|