import { createDeepAgent, SubAgent } from "deepagents";// Research subagent with its own skillsconst researchSubagent: SubAgent = { name: "researcher", description: "Research assistant with specialized skills", systemPrompt: "You are a researcher.", tools: [webSearch], skills: ["/skills/research/", "/skills/web-search/"], // Subagent-specific skills};const agent = createDeepAgent({ model: "google_genai:gemini-3.1-pro-preview", skills: ["/skills/main/"], // Main agent and GP subagent get these subagents: [researchSubagent], // Gets only /skills/research/ and /skills/web-search/});
const researchSubagent = { name: "research-agent", description: "Conducts in-depth research using web search and synthesizes findings", systemPrompt: `You are a thorough researcher. Your job is to: 1. Break down the research question into searchable queries 2. Use internet_search to find relevant information 3. Synthesize findings into a comprehensive but concise summary 4. Cite sources when making claims Output format: - Summary (2-3 paragraphs) - Key findings (bullet points) - Sources (with URLs) Keep your response under 500 words to maintain clean context.`, tools: [internetSearch],};
const dataAnalyst = { systemPrompt: `Analyze the data and return: 1. Key insights (3-5 bullet points) 2. Overall confidence score 3. Recommended next actions Do NOT include: - Raw data - Intermediate calculations - Detailed tool outputs Keep response under 300 words.`,};
import { createDeepAgent } from "deepagents";const subagents = [ { name: "data-collector", description: "Gathers raw data from various sources", systemPrompt: "Collect comprehensive data on the topic", tools: [webSearch, apiCall, databaseQuery], }, { name: "data-analyzer", description: "Analyzes collected data for insights", systemPrompt: "Analyze data and extract key insights", tools: [statisticalAnalysis], }, { name: "report-writer", description: "Writes polished reports from analysis", systemPrompt: "Create professional reports from insights", tools: [formatDocument], },];const agent = createDeepAgent({ model: "google_genai:gemini-3.1-pro-preview", systemPrompt: "You coordinate data analysis and reporting. Use subagents for specialized tasks.", subagents: subagents,});
import { createDeepAgent } from "deepagents";import { tool } from "langchain";import type { ToolRuntime } from "@langchain/core/tools";import { z } from "zod";const contextSchema = z.object({ userId: z.string(), sessionId: z.string(),});const getUserData = tool( async (input, runtime: ToolRuntime<unknown, typeof contextSchema>) => { const userId = runtime.context?.userId; return `Data for user ${userId}: ${input.query}`; }, { name: "get_user_data", description: "Fetch data for the current user", schema: z.object({ query: z.string() }), });const researchSubagent = { name: "researcher", description: "Conducts research for the current user", systemPrompt: "You are a research assistant.", tools: [getUserData],};const agent = createDeepAgent({ model: "google_genai:gemini-3.1-pro-preview", subagents: [researchSubagent], contextSchema,});// Context flows to the researcher subagent and its tools automaticallyconst result = await agent.invoke( { messages: [new HumanMessage("Look up my recent activity")] }, { context: { userId: "user-123", sessionId: "abc" } },);
// ✅ Good{ name: "research-specialist", description: "Conducts in-depth research on specific topics using web search. Use when you need detailed information that requires multiple searches." }// ❌ Bad{ name: "helper", description: "helps with stuff" }
指示主智能体进行委派
const agent = createDeepAgent({ systemPrompt: `...your instructions... IMPORTANT: For complex tasks, delegate to your subagents using the task() tool. This keeps your context clean and improves results.`, subagents: [...]});
systemPrompt: `...IMPORTANT: Return only the essential summary.Do NOT include raw data, intermediate search results, or detailed tool outputs.Your response should be under 500 words.`
为大数据使用文件系统
systemPrompt: `When you gather large amounts of data:1. Save raw data to /data/raw_results.txt2. Process and analyze the data3. Return only the analysis summaryThis keeps context clean.`
const subagents = [ { name: "quick-researcher", description: "For simple, quick research questions that need 1-2 searches. Use when you need basic facts or definitions.", }, { name: "deep-researcher", description: "For complex, in-depth research requiring multiple searches, synthesis, and analysis. Use for comprehensive reports.", }];