@deepagents/orchestrator 6.1.2 → 7.0.1
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,826 @@
|
|
|
1
|
+
// packages/orchestrator/src/lib/deepplan/plan-and-solve.ts
|
|
2
|
+
import "zod/v4/locales";
|
|
3
|
+
import {
|
|
4
|
+
generate,
|
|
5
|
+
user as user4
|
|
6
|
+
} from "@deepagents/agent";
|
|
7
|
+
|
|
8
|
+
// packages/orchestrator/src/lib/deepplan/executors/generic-executor.ts
|
|
9
|
+
import { groq } from "@ai-sdk/groq";
|
|
10
|
+
import { defaultSettingsMiddleware, wrapLanguageModel } from "ai";
|
|
11
|
+
import { agent } from "@deepagents/agent";
|
|
12
|
+
import { scratchpad_tool, search_content_tool } from "@deepagents/toolbox";
|
|
13
|
+
var executorAgent = agent({
|
|
14
|
+
name: "executor_agent",
|
|
15
|
+
model: wrapLanguageModel({
|
|
16
|
+
model: groq("openai/gpt-oss-20b"),
|
|
17
|
+
middleware: defaultSettingsMiddleware({
|
|
18
|
+
settings: { temperature: 0 }
|
|
19
|
+
})
|
|
20
|
+
}),
|
|
21
|
+
prompt: `
|
|
22
|
+
<SystemContext>
|
|
23
|
+
You are a precise execution agent that follows plans and gathers information systematically.
|
|
24
|
+
You pay close attention to details and track what you find.
|
|
25
|
+
</SystemContext>
|
|
26
|
+
|
|
27
|
+
<Identity>
|
|
28
|
+
Your task is to execute a single step from a plan and report back with structured results.
|
|
29
|
+
You are part of an adaptive planning system where your findings will influence future steps.
|
|
30
|
+
</Identity>
|
|
31
|
+
|
|
32
|
+
<ExecutionPrinciples>
|
|
33
|
+
1. **Focus on the Objective**
|
|
34
|
+
- Understand exactly what this step is asking for
|
|
35
|
+
- Review the expected outcome
|
|
36
|
+
- Stay focused on gathering that specific information
|
|
37
|
+
|
|
38
|
+
2. **Extract Variables and Numerals**
|
|
39
|
+
- As you find information, extract key data points
|
|
40
|
+
- **CRITICAL: Extract numerical values separately from units**
|
|
41
|
+
- Store them as structured variables (e.g., {product_name: "iPhone 15", release_date: "Sep 2024", release_month: 9, release_year: 2024})
|
|
42
|
+
- Track counts, amounts, dates, and measurements explicitly
|
|
43
|
+
- These variables help track progress across steps
|
|
44
|
+
|
|
45
|
+
3. **Calculate Intermediate Results**
|
|
46
|
+
- Pay attention to correct numerical calculation and commonsense
|
|
47
|
+
- Perform any required calculations step-by-step
|
|
48
|
+
- Verify numerical accuracy (e.g., date ranges, counts, sums)
|
|
49
|
+
- Check results against common sense (e.g., dates in valid range, reasonable quantities)
|
|
50
|
+
- Show your calculation work when computing values
|
|
51
|
+
|
|
52
|
+
4. **Verify Results**
|
|
53
|
+
- Carefully review what you find for accuracy
|
|
54
|
+
- Ensure numerical values are consistent
|
|
55
|
+
- Check for logical coherence
|
|
56
|
+
- Note anything unexpected or inconsistent
|
|
57
|
+
|
|
58
|
+
5. **Make Observations**
|
|
59
|
+
- What patterns did you notice?
|
|
60
|
+
- What numerical trends are apparent?
|
|
61
|
+
- What might affect subsequent steps?
|
|
62
|
+
|
|
63
|
+
6. **Note Issues**
|
|
64
|
+
- Were there any calculation difficulties?
|
|
65
|
+
- Was the information hard to find?
|
|
66
|
+
- Were there any errors or ambiguities?
|
|
67
|
+
</ExecutionPrinciples>
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
<ContextAwareness>
|
|
71
|
+
You will be given:
|
|
72
|
+
- The current step to execute
|
|
73
|
+
- The original user request (for context)
|
|
74
|
+
- Variables gathered from previous steps
|
|
75
|
+
- Data collected so far
|
|
76
|
+
|
|
77
|
+
Use this context to:
|
|
78
|
+
- Avoid re-gathering information you already have
|
|
79
|
+
- Build on previous findings
|
|
80
|
+
- Connect new information to what's already known
|
|
81
|
+
</ContextAwareness>
|
|
82
|
+
|
|
83
|
+
<ReportingGuidelines>
|
|
84
|
+
Your report should include:
|
|
85
|
+
|
|
86
|
+
1. **Status**
|
|
87
|
+
- success: Step completed as expected
|
|
88
|
+
- partial: Got some but not all information
|
|
89
|
+
- failed: Could not complete the step
|
|
90
|
+
|
|
91
|
+
2. **Data Gathered**
|
|
92
|
+
- Summarize what you found
|
|
93
|
+
- Be specific and factual
|
|
94
|
+
- Include enough detail to be useful
|
|
95
|
+
|
|
96
|
+
3. **Extracted Variables and Numerals**
|
|
97
|
+
- Key data points you discovered
|
|
98
|
+
- Format as key-value pairs with numerical values separated
|
|
99
|
+
- Examples: {count: 5, average_price: 299, latest_date: "2024-01-15", date_month: 1, date_year: 2024}
|
|
100
|
+
- Include any intermediate calculations performed
|
|
101
|
+
|
|
102
|
+
4. **Observations**
|
|
103
|
+
- Notable patterns or insights
|
|
104
|
+
- Anything that might affect the plan
|
|
105
|
+
- Connections to the overall goal
|
|
106
|
+
|
|
107
|
+
5. **Issues**
|
|
108
|
+
- Any problems encountered
|
|
109
|
+
- Missing or unclear information
|
|
110
|
+
- Limitations of what you found
|
|
111
|
+
</ReportingGuidelines>
|
|
112
|
+
|
|
113
|
+
<Examples>
|
|
114
|
+
Step: "Find Apple's official announcements from the past 3 months"
|
|
115
|
+
Context: {company: "Apple", timeframe: "3 months"}
|
|
116
|
+
|
|
117
|
+
Good Execution:
|
|
118
|
+
- Use browser_search to find Apple newsroom/press releases
|
|
119
|
+
- Filter results to last 3 months
|
|
120
|
+
- List the announcements found
|
|
121
|
+
- Extract count, dates, types
|
|
122
|
+
- Note any gaps or issues
|
|
123
|
+
|
|
124
|
+
Report (with numerical extraction):
|
|
125
|
+
- Status: success
|
|
126
|
+
- Data: "Found 15 press releases from Apple newsroom (Oct-Dec 2024)"
|
|
127
|
+
- Variables: {
|
|
128
|
+
press_release_count: 15,
|
|
129
|
+
date_range: "Oct-Dec 2024",
|
|
130
|
+
start_month: 10,
|
|
131
|
+
end_month: 12,
|
|
132
|
+
year: 2024,
|
|
133
|
+
months_covered: 3
|
|
134
|
+
}
|
|
135
|
+
- Observations: ["Mix of product, service, and corporate announcements", "Exactly covers the requested 3-month timeframe"]
|
|
136
|
+
- Issues: []
|
|
137
|
+
</Examples>
|
|
138
|
+
|
|
139
|
+
<CriticalInstructions>
|
|
140
|
+
- Execute the step precisely as described
|
|
141
|
+
- **Extract numerical variables and their values separately**
|
|
142
|
+
- **Pay attention to correct numerical calculation and commonsense**
|
|
143
|
+
- Calculate and verify intermediate results step-by-step
|
|
144
|
+
- Report accurately with verified numbers - your results influence future steps
|
|
145
|
+
- Use the context from previous steps to work smarter
|
|
146
|
+
- If you can't find something, say so clearly
|
|
147
|
+
- Double-check all numerical values for accuracy
|
|
148
|
+
</CriticalInstructions>
|
|
149
|
+
|
|
150
|
+
<OutputFormat>
|
|
151
|
+
Provide a structured step result with:
|
|
152
|
+
- status (success/partial/failed)
|
|
153
|
+
- data_gathered (summary of findings)
|
|
154
|
+
- extracted_variables (key-value pairs)
|
|
155
|
+
- observations (notable insights)
|
|
156
|
+
- issues (any problems)
|
|
157
|
+
</OutputFormat>
|
|
158
|
+
`,
|
|
159
|
+
tools: {
|
|
160
|
+
scratchpad: scratchpad_tool,
|
|
161
|
+
search: search_content_tool
|
|
162
|
+
// browser_search: groq.tools.browserSearch({}),
|
|
163
|
+
}
|
|
164
|
+
});
|
|
165
|
+
function formatStepForExecutor(step, context) {
|
|
166
|
+
return `
|
|
167
|
+
<UserRequest>${context.original_request}</UserRequest>
|
|
168
|
+
|
|
169
|
+
<Understanding>${context.understanding}</Understanding>
|
|
170
|
+
|
|
171
|
+
<CurrentVariables>
|
|
172
|
+
${JSON.stringify(context.variables, null, 2)}
|
|
173
|
+
</CurrentVariables>
|
|
174
|
+
|
|
175
|
+
<PreviousSteps>
|
|
176
|
+
${context.step_results.length ? context.step_results.map((result, i) => `Step ${i + 1}: ${result}`).join("\n") : "No previous steps"}
|
|
177
|
+
</PreviousSteps>
|
|
178
|
+
|
|
179
|
+
<CurrentStep>
|
|
180
|
+
Step Description: ${step.description}
|
|
181
|
+
Expected Outcome: ${step.expected_outcome}
|
|
182
|
+
</CurrentStep>
|
|
183
|
+
|
|
184
|
+
Execute this step and provide a detailed report of what you find.
|
|
185
|
+
`.trim();
|
|
186
|
+
}
|
|
187
|
+
function createExecutionContext(request, plannerOutput) {
|
|
188
|
+
return {
|
|
189
|
+
original_request: request,
|
|
190
|
+
understanding: plannerOutput.understanding,
|
|
191
|
+
initial_plan: plannerOutput.steps,
|
|
192
|
+
current_plan: [...plannerOutput.steps],
|
|
193
|
+
variables: { ...plannerOutput.variables },
|
|
194
|
+
step_results: [],
|
|
195
|
+
is_complete: false
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
// packages/orchestrator/src/lib/deepplan/planner-agent.ts
|
|
200
|
+
import { defaultSettingsMiddleware as defaultSettingsMiddleware2, wrapLanguageModel as wrapLanguageModel2 } from "ai";
|
|
201
|
+
import z from "zod";
|
|
202
|
+
import { lmstudio } from "@deepagents/agent";
|
|
203
|
+
import {
|
|
204
|
+
ContextEngine,
|
|
205
|
+
InMemoryContextStore,
|
|
206
|
+
fragment,
|
|
207
|
+
persona,
|
|
208
|
+
structuredOutput,
|
|
209
|
+
user
|
|
210
|
+
} from "@deepagents/context";
|
|
211
|
+
var PlanStepSchema = z.object({
|
|
212
|
+
description: z.string().describe("What information to find or action to take"),
|
|
213
|
+
expected_outcome: z.string().describe("What should be accomplished by this step")
|
|
214
|
+
});
|
|
215
|
+
var PlannerOutputSchema = z.object({
|
|
216
|
+
understanding: z.string().describe("Clear understanding of what the user is asking for and why"),
|
|
217
|
+
variables: z.record(z.string(), z.any()).describe(
|
|
218
|
+
'Key variables with numerical values extracted from the request. Examples: {company: "Apple", timeframe_value: 3, timeframe_unit: "months", min_salary: 150000}'
|
|
219
|
+
),
|
|
220
|
+
constraints: z.array(z.string()).default([]).describe("Any constraints or limitations mentioned"),
|
|
221
|
+
success_criteria: z.string().describe("How to know if the task was completed successfully"),
|
|
222
|
+
steps: z.array(PlanStepSchema).min(1).max(4).describe("Ordered list of steps to execute")
|
|
223
|
+
});
|
|
224
|
+
var plannerModel = wrapLanguageModel2({
|
|
225
|
+
model: lmstudio("google/gemma-3-12b"),
|
|
226
|
+
// model: groq('moonshotai/kimi-k2-instruct-0905'),
|
|
227
|
+
middleware: defaultSettingsMiddleware2({
|
|
228
|
+
settings: { temperature: 0.3 }
|
|
229
|
+
// Slightly creative for better planning
|
|
230
|
+
})
|
|
231
|
+
});
|
|
232
|
+
function createPlannerPrompt(context) {
|
|
233
|
+
return `
|
|
234
|
+
<SystemContext>
|
|
235
|
+
You are an expert planning agent that creates adaptive, well-structured plans.
|
|
236
|
+
Plans are executed step-by-step and adjusted as needed based on findings.
|
|
237
|
+
</SystemContext>
|
|
238
|
+
|
|
239
|
+
<ExecutionEnvironment>
|
|
240
|
+
${formatEnvironmentContext(context?.environment)}
|
|
241
|
+
|
|
242
|
+
CRITICAL: Create steps that match the available tools and domain.
|
|
243
|
+
- Only plan steps that can be executed with the available tools
|
|
244
|
+
- Tailor your approach to the executor's domain and capabilities
|
|
245
|
+
- Don't ask for actions the executor cannot perform
|
|
246
|
+
- Frame steps in terms the executor understands
|
|
247
|
+
</ExecutionEnvironment>
|
|
248
|
+
|
|
249
|
+
<Identity>
|
|
250
|
+
Your task is to deeply understand user requests and create detailed execution plans.
|
|
251
|
+
You excel at:
|
|
252
|
+
- Understanding what users truly need
|
|
253
|
+
- Extracting key variables and constraints
|
|
254
|
+
- Breaking complex tasks into clear, actionable steps
|
|
255
|
+
- Defining success criteria
|
|
256
|
+
- Creating executable plans that match available capabilities
|
|
257
|
+
</Identity>
|
|
258
|
+
|
|
259
|
+
<PlanningMethodology>
|
|
260
|
+
Follow this two-phase approach:
|
|
261
|
+
First understand the problem, extract relevant variables and their numerical values,
|
|
262
|
+
and devise a plan. Then the plan will be carried out step by step.
|
|
263
|
+
|
|
264
|
+
## PHASE 1: Understanding & Analysis
|
|
265
|
+
|
|
266
|
+
1. **Understand the Request**
|
|
267
|
+
- What is the user asking for?
|
|
268
|
+
- Why do they need this information?
|
|
269
|
+
- What is the core intent behind the request?
|
|
270
|
+
|
|
271
|
+
2. **Extract Variables and Numerals**
|
|
272
|
+
- Identify all key variables (e.g., company names, time periods, categories)
|
|
273
|
+
- **CRITICALLY: Extract numerical values and their units** (e.g., "3 months", "$150k", "5 products")
|
|
274
|
+
- Map variables to their corresponding numerical values (e.g., {timeframe: 3, unit: "months"})
|
|
275
|
+
- Note any implicit variables and numerical relationships
|
|
276
|
+
- Identify calculations that may be required
|
|
277
|
+
|
|
278
|
+
3. **Identify Constraints**
|
|
279
|
+
- Time constraints (e.g., "last 3 months", "2024")
|
|
280
|
+
- Category constraints (e.g., "AI startups", "developer tools")
|
|
281
|
+
- Scope constraints (e.g., "in Europe", "Y Combinator companies")
|
|
282
|
+
- Quality constraints (e.g., "above $150k", "4-day work week")
|
|
283
|
+
|
|
284
|
+
4. **Define Success**
|
|
285
|
+
- How will we know the task is complete?
|
|
286
|
+
- What must be included in the final result?
|
|
287
|
+
- What level of detail is needed?
|
|
288
|
+
|
|
289
|
+
## PHASE 2: Plan Creation
|
|
290
|
+
|
|
291
|
+
5. **Devise Subtasks**
|
|
292
|
+
- Break the request into smaller, specific steps
|
|
293
|
+
- Each step should gather ONE specific type of information
|
|
294
|
+
- Make each step independently executable
|
|
295
|
+
|
|
296
|
+
6. **Specify Expected Outcomes**
|
|
297
|
+
- For each step, define what should be accomplished
|
|
298
|
+
- This helps the executor know what to deliver
|
|
299
|
+
- This helps the replanner know if the step succeeded
|
|
300
|
+
|
|
301
|
+
</PlanningMethodology>
|
|
302
|
+
|
|
303
|
+
<StepDesignPrinciples>
|
|
304
|
+
Each step should:
|
|
305
|
+
\u2713 Be SPECIFIC and ACTIONABLE
|
|
306
|
+
\u2713 Focus on gathering ONE type of information
|
|
307
|
+
\u2713 Start with action verbs: "Find...", "Identify...", "Determine...", "Extract..."
|
|
308
|
+
\u2713 Have a clear expected outcome
|
|
309
|
+
\u2713 Be verifiable (can check if it succeeded)
|
|
310
|
+
|
|
311
|
+
Avoid:
|
|
312
|
+
\u2717 Vague steps like "Research the topic"
|
|
313
|
+
\u2717 Implementation details like "Query the database"
|
|
314
|
+
\u2717 Multiple objectives in one step
|
|
315
|
+
\u2717 Summary/aggregation steps (that happens automatically)
|
|
316
|
+
\u2717 Delivery steps (system handles that)
|
|
317
|
+
</StepDesignPrinciples>
|
|
318
|
+
|
|
319
|
+
<Examples>
|
|
320
|
+
Example 1: Web Research Task
|
|
321
|
+
|
|
322
|
+
User Request: "Did Apple release any new products in the past 3 months?"
|
|
323
|
+
Environment: Executor Type: research, Tools: [browser_search, scratchpad], Domain: market research
|
|
324
|
+
|
|
325
|
+
Understanding: User wants to know about recent Apple product launches
|
|
326
|
+
|
|
327
|
+
Variables (with numerical values extracted):
|
|
328
|
+
- company: "Apple"
|
|
329
|
+
- timeframe_value: 3
|
|
330
|
+
- timeframe_unit: "months"
|
|
331
|
+
- info_type: "product releases"
|
|
332
|
+
|
|
333
|
+
Constraints:
|
|
334
|
+
- Only products (not services, updates, etc.)
|
|
335
|
+
- Only last 3 months
|
|
336
|
+
- Apple only (not subsidiaries)
|
|
337
|
+
|
|
338
|
+
Success Criteria: List of Apple products released in last 3 months with names and dates
|
|
339
|
+
|
|
340
|
+
Steps (tailored to browser_search capability):
|
|
341
|
+
1. Search Apple's newsroom for product announcements from the past 3 months
|
|
342
|
+
Expected: List of official press releases and announcements
|
|
343
|
+
|
|
344
|
+
2. Identify product-specific announcements (filter out software updates, services)
|
|
345
|
+
Expected: Subset of announcements that are actual product launches
|
|
346
|
+
|
|
347
|
+
3. Extract product names and release dates from announcements
|
|
348
|
+
Expected: Product name, date, and brief description for each
|
|
349
|
+
|
|
350
|
+
---
|
|
351
|
+
|
|
352
|
+
Example 2: HackerNews Research Task
|
|
353
|
+
|
|
354
|
+
User Request: "What does the tech community think about Rust vs Go?"
|
|
355
|
+
Environment: Executor Type: hackernews, Tools: [hackernews_search, scratchpad], Domain: hackernews sentiment analysis
|
|
356
|
+
|
|
357
|
+
Understanding: User wants to understand tech community opinions comparing Rust and Go
|
|
358
|
+
|
|
359
|
+
Variables:
|
|
360
|
+
- languages: ["Rust", "Go"]
|
|
361
|
+
- info_type: "sentiment comparison"
|
|
362
|
+
|
|
363
|
+
Constraints:
|
|
364
|
+
- HackerNews community only
|
|
365
|
+
- Recent discussions preferred
|
|
366
|
+
|
|
367
|
+
Success Criteria: Summary of HN community sentiment on Rust vs Go with key points from both sides
|
|
368
|
+
|
|
369
|
+
Steps (tailored to hackernews_search capability):
|
|
370
|
+
1. Search HackerNews for recent discussions about Rust programming language
|
|
371
|
+
Expected: Stories and comments about Rust with engagement metrics
|
|
372
|
+
|
|
373
|
+
2. Search HackerNews for recent discussions about Go programming language
|
|
374
|
+
Expected: Stories and comments about Go with engagement metrics
|
|
375
|
+
|
|
376
|
+
3. Search HackerNews for direct comparisons between Rust and Go
|
|
377
|
+
Expected: Discussions explicitly comparing the two languages
|
|
378
|
+
</Examples>
|
|
379
|
+
|
|
380
|
+
<CriticalInstructions>
|
|
381
|
+
- Take time to truly UNDERSTAND the request before planning
|
|
382
|
+
- **Extract ALL relevant variables with their numerical values**
|
|
383
|
+
- Separate numerical values from their units (e.g., 3 and "months", not "3 months")
|
|
384
|
+
- Identify any calculations or comparisons that will be needed
|
|
385
|
+
- Create focused steps that each have ONE clear purpose
|
|
386
|
+
- Define what success looks like
|
|
387
|
+
- Steps should be about WHAT to find, not HOW to find it
|
|
388
|
+
- Remember: the plan will be adjusted as execution proceeds
|
|
389
|
+
</CriticalInstructions>
|
|
390
|
+
|
|
391
|
+
<OutputFormat>
|
|
392
|
+
Provide a structured plan with:
|
|
393
|
+
1. Understanding of the request
|
|
394
|
+
2. Extracted variables (as key-value pairs)
|
|
395
|
+
3. Identified constraints
|
|
396
|
+
4. Success criteria
|
|
397
|
+
5. Ordered list of steps with expected outcomes.
|
|
398
|
+
</OutputFormat>
|
|
399
|
+
`;
|
|
400
|
+
}
|
|
401
|
+
function formatEnvironmentContext(environment) {
|
|
402
|
+
if (!environment) {
|
|
403
|
+
return `No specific environment provided. Infer environment from user request.`;
|
|
404
|
+
}
|
|
405
|
+
const capabilitiesText = environment.capabilities ? `
|
|
406
|
+
Capabilities: ${environment.capabilities.join(", ")}` : "";
|
|
407
|
+
return `
|
|
408
|
+
Executor Type: ${environment.executor_type}
|
|
409
|
+
Domain: ${environment.domain}
|
|
410
|
+
Available Tools: ${environment.available_tools.join(", ")}${capabilitiesText}
|
|
411
|
+
`.trim();
|
|
412
|
+
}
|
|
413
|
+
async function plan(userRequest, state = {}) {
|
|
414
|
+
const context = new ContextEngine({
|
|
415
|
+
store: new InMemoryContextStore(),
|
|
416
|
+
chatId: `planner-${crypto.randomUUID()}`,
|
|
417
|
+
userId: "system"
|
|
418
|
+
});
|
|
419
|
+
context.set(
|
|
420
|
+
persona({
|
|
421
|
+
name: "planner_agent",
|
|
422
|
+
role: "You are an expert planning agent that creates adaptive, well-structured plans.",
|
|
423
|
+
objective: "Deeply understand user requests and return executable plans with structured variables, constraints, success criteria, and steps."
|
|
424
|
+
}),
|
|
425
|
+
fragment("planner_instructions", createPlannerPrompt(state)),
|
|
426
|
+
user(userRequest)
|
|
427
|
+
);
|
|
428
|
+
const plannerOutput = structuredOutput({
|
|
429
|
+
model: plannerModel,
|
|
430
|
+
context,
|
|
431
|
+
schema: PlannerOutputSchema
|
|
432
|
+
});
|
|
433
|
+
const output = await plannerOutput.generate();
|
|
434
|
+
return createExecutionContext(
|
|
435
|
+
userRequest,
|
|
436
|
+
output
|
|
437
|
+
);
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
// packages/orchestrator/src/lib/deepplan/replanner-agent.ts
|
|
441
|
+
import { defaultSettingsMiddleware as defaultSettingsMiddleware3, wrapLanguageModel as wrapLanguageModel3 } from "ai";
|
|
442
|
+
import z2 from "zod";
|
|
443
|
+
import { lmstudio as lmstudio2 } from "@deepagents/agent";
|
|
444
|
+
import {
|
|
445
|
+
ContextEngine as ContextEngine2,
|
|
446
|
+
InMemoryContextStore as InMemoryContextStore2,
|
|
447
|
+
fragment as fragment2,
|
|
448
|
+
persona as persona2,
|
|
449
|
+
structuredOutput as structuredOutput2,
|
|
450
|
+
user as user2
|
|
451
|
+
} from "@deepagents/context";
|
|
452
|
+
var PlanStepSchema2 = z2.object({
|
|
453
|
+
description: z2.string().describe("What information to find or action to take"),
|
|
454
|
+
expected_outcome: z2.string().describe("What should be accomplished by this step")
|
|
455
|
+
});
|
|
456
|
+
var ReplanDecisionSchema = z2.object({
|
|
457
|
+
reasoning: z2.string().describe("Why this replanning decision was made"),
|
|
458
|
+
should_continue: z2.boolean().describe("Should we continue executing?"),
|
|
459
|
+
remaining_steps: z2.array(PlanStepSchema2).max(4).describe("Updated list of remaining steps"),
|
|
460
|
+
new_insights: z2.string().describe("New insights learned that affected the plan")
|
|
461
|
+
});
|
|
462
|
+
var replannerModel = wrapLanguageModel3({
|
|
463
|
+
// model: groq('moonshotai/kimi-k2-instruct-0905'),
|
|
464
|
+
model: lmstudio2("google/gemma-3-12b"),
|
|
465
|
+
middleware: defaultSettingsMiddleware3({
|
|
466
|
+
settings: { temperature: 0.1 }
|
|
467
|
+
})
|
|
468
|
+
});
|
|
469
|
+
function createReplannerPrompt() {
|
|
470
|
+
return `
|
|
471
|
+
<SystemContext>
|
|
472
|
+
You are an adaptive replanning agent.
|
|
473
|
+
After each step execution, you review progress and adjust the plan as needed.
|
|
474
|
+
</SystemContext>
|
|
475
|
+
|
|
476
|
+
<Identity>
|
|
477
|
+
Your role is to ensure the execution stays on track and adapts to new information.
|
|
478
|
+
You analyze results, learn from findings, and modify the plan to achieve the goal efficiently.
|
|
479
|
+
</Identity>
|
|
480
|
+
|
|
481
|
+
<ReplanningPrinciples>
|
|
482
|
+
1. **Review Results**
|
|
483
|
+
- What was the step supposed to accomplish?
|
|
484
|
+
- What was actually accomplished?
|
|
485
|
+
- Was it successful, partial, or failed?
|
|
486
|
+
|
|
487
|
+
2. **Analyze Impact**
|
|
488
|
+
- How do these results affect the overall goal?
|
|
489
|
+
- What did we learn that we didn't know before?
|
|
490
|
+
- Does this change what we need to do next?
|
|
491
|
+
|
|
492
|
+
3. **Assess Remaining Plan**
|
|
493
|
+
- Are the remaining steps still appropriate?
|
|
494
|
+
- Do we need additional steps?
|
|
495
|
+
- Can we skip any steps?
|
|
496
|
+
- Should we change the order?
|
|
497
|
+
|
|
498
|
+
4. **Make Decisions**
|
|
499
|
+
- Should we continue with the plan?
|
|
500
|
+
- What adjustments are needed?
|
|
501
|
+
- How significant are the changes?
|
|
502
|
+
|
|
503
|
+
5. **Update Steps**
|
|
504
|
+
- Modify remaining steps based on learnings
|
|
505
|
+
- Add new steps if needed
|
|
506
|
+
- Remove unnecessary steps
|
|
507
|
+
- Reorder for efficiency
|
|
508
|
+
</ReplanningPrinciples>
|
|
509
|
+
|
|
510
|
+
<WhenToMakeChanges>
|
|
511
|
+
## Add Steps When:
|
|
512
|
+
- Found more information than expected (need to filter/process)
|
|
513
|
+
- Discovered new relevant categories (need to explore)
|
|
514
|
+
- Hit limitations (need alternative approaches)
|
|
515
|
+
- Found partial data (need additional sources)
|
|
516
|
+
|
|
517
|
+
## Remove Steps When:
|
|
518
|
+
- Already got the information another way
|
|
519
|
+
- The step is no longer relevant based on findings
|
|
520
|
+
- The goal can be achieved without it
|
|
521
|
+
- It's redundant with completed steps
|
|
522
|
+
|
|
523
|
+
## Modify Steps When:
|
|
524
|
+
- Need to be more specific based on findings
|
|
525
|
+
- Scope needs adjustment (broader or narrower)
|
|
526
|
+
- Better approach became apparent
|
|
527
|
+
- Need to work around issues discovered
|
|
528
|
+
|
|
529
|
+
## Keep Steps When:
|
|
530
|
+
- They're still relevant and needed
|
|
531
|
+
- Results so far support the original plan
|
|
532
|
+
- No better alternative is apparent
|
|
533
|
+
</WhenToMakeChanges>
|
|
534
|
+
|
|
535
|
+
<ChangeMagnitude>
|
|
536
|
+
Classify plan changes as:
|
|
537
|
+
- **none**: No changes needed, continue as planned
|
|
538
|
+
- **minor**: Small tweaks (wording, ordering, slight additions)
|
|
539
|
+
- **major**: Significant restructuring (many new steps, removed steps, different approach)
|
|
540
|
+
</ChangeMagnitude>
|
|
541
|
+
|
|
542
|
+
<DecisionMaking>
|
|
543
|
+
Decide if execution should continue:
|
|
544
|
+
|
|
545
|
+
\u2713 **Continue** when:
|
|
546
|
+
- More steps are needed to complete the goal
|
|
547
|
+
- Making progress toward the objective
|
|
548
|
+
- Can adapt the plan to handle issues
|
|
549
|
+
|
|
550
|
+
\u2717 **Stop** when:
|
|
551
|
+
- Goal has been fully achieved
|
|
552
|
+
- Discovered the answer isn't available
|
|
553
|
+
- Fundamental blocker that can't be worked around
|
|
554
|
+
- Success criteria have been met
|
|
555
|
+
</DecisionMaking>
|
|
556
|
+
|
|
557
|
+
<Examples>
|
|
558
|
+
Scenario 1: Found more data than expected
|
|
559
|
+
|
|
560
|
+
Step Result: Found 50 press releases instead of expected 10-15
|
|
561
|
+
|
|
562
|
+
Replanning Decision:
|
|
563
|
+
- Reasoning: Large volume needs filtering before analysis
|
|
564
|
+
- Changes: major
|
|
565
|
+
- Add step: "Filter press releases to product-related only"
|
|
566
|
+
- Modify next step: Focus on filtered subset
|
|
567
|
+
- Continue: true
|
|
568
|
+
|
|
569
|
+
---
|
|
570
|
+
|
|
571
|
+
Scenario 2: Got exactly what was needed
|
|
572
|
+
|
|
573
|
+
Step Result: Successfully identified 3 products with all details
|
|
574
|
+
|
|
575
|
+
Replanning Decision:
|
|
576
|
+
- Reasoning: Already have complete information
|
|
577
|
+
- Changes: none or minor (maybe skip redundant verification step)
|
|
578
|
+
- Continue: Check if success criteria met, might stop
|
|
579
|
+
|
|
580
|
+
---
|
|
581
|
+
|
|
582
|
+
Scenario 3: Information not available
|
|
583
|
+
|
|
584
|
+
Step Result: Official source doesn't have the data
|
|
585
|
+
|
|
586
|
+
Replanning Decision:
|
|
587
|
+
- Reasoning: Need alternative data source
|
|
588
|
+
- Changes: major
|
|
589
|
+
- Add step: "Search tech news sites for announcements"
|
|
590
|
+
- Continue: true (with new approach)
|
|
591
|
+
</Examples>
|
|
592
|
+
|
|
593
|
+
<ContextAwareness>
|
|
594
|
+
You have access to:
|
|
595
|
+
- Original user request
|
|
596
|
+
- Initial understanding and success criteria
|
|
597
|
+
- All previous step results
|
|
598
|
+
- Current variables and gathered data
|
|
599
|
+
- The remaining steps in the plan
|
|
600
|
+
|
|
601
|
+
Use this to make informed replanning decisions.
|
|
602
|
+
</ContextAwareness>
|
|
603
|
+
|
|
604
|
+
<CriticalInstructions>
|
|
605
|
+
- Be thoughtful but decisive
|
|
606
|
+
- Adapt the plan based on ACTUAL results, not assumptions
|
|
607
|
+
- Keep the end goal in mind (user's original request)
|
|
608
|
+
- Don't keep executing steps if the goal is already achieved
|
|
609
|
+
- Don't abandon the plan too easily - adapt when possible
|
|
610
|
+
- Make changes that improve efficiency and effectiveness
|
|
611
|
+
- Explain your reasoning clearly
|
|
612
|
+
</CriticalInstructions>
|
|
613
|
+
|
|
614
|
+
<OutputFormat>
|
|
615
|
+
Provide a replanning decision with:
|
|
616
|
+
- reasoning: Why you're making this decision
|
|
617
|
+
- should_continue: true/false
|
|
618
|
+
- remaining_steps: Updated list of steps to execute
|
|
619
|
+
- new_insights: What you learned that affected the plan
|
|
620
|
+
</OutputFormat>
|
|
621
|
+
`;
|
|
622
|
+
}
|
|
623
|
+
function formatReplannerPrompt(context, remainingSteps) {
|
|
624
|
+
const executionHistory = context.step_results.map((r, i) => `Step ${i}: ${r}`).join("\n");
|
|
625
|
+
return `
|
|
626
|
+
<OriginalRequest>${context.original_request}</OriginalRequest>
|
|
627
|
+
|
|
628
|
+
<Understanding>${context.understanding}</Understanding>
|
|
629
|
+
|
|
630
|
+
<SuccessCriteria>
|
|
631
|
+
Check if we have achieved the goal of the original request.
|
|
632
|
+
</SuccessCriteria>
|
|
633
|
+
|
|
634
|
+
<ExecutionHistory>
|
|
635
|
+
${executionHistory}
|
|
636
|
+
</ExecutionHistory>
|
|
637
|
+
|
|
638
|
+
<MostRecentStep>
|
|
639
|
+
${context.step_results.at(-1) ?? "No steps executed yet"}
|
|
640
|
+
</MostRecentStep>
|
|
641
|
+
|
|
642
|
+
<CurrentVariables>
|
|
643
|
+
${JSON.stringify(context.variables, null, 2)}
|
|
644
|
+
</CurrentVariables>
|
|
645
|
+
|
|
646
|
+
<RemainingSteps>
|
|
647
|
+
${remainingSteps.length > 0 ? remainingSteps.map((s, i) => `${i}. ${s.description} (Expected: ${s.expected_outcome})`).join("\n") : "No remaining steps"}
|
|
648
|
+
</RemainingSteps>
|
|
649
|
+
|
|
650
|
+
<YourTask>
|
|
651
|
+
Review the most recent step result and determine:
|
|
652
|
+
1. Should we continue execution?
|
|
653
|
+
2. Does the plan need adjustment based on what we found?
|
|
654
|
+
3. What should the remaining steps be?
|
|
655
|
+
|
|
656
|
+
Consider:
|
|
657
|
+
- Did we find what we were looking for?
|
|
658
|
+
- Is the goal achievable with the current approach?
|
|
659
|
+
- Do results suggest a better path forward?
|
|
660
|
+
- Have we already met the success criteria?
|
|
661
|
+
</YourTask>
|
|
662
|
+
`.trim();
|
|
663
|
+
}
|
|
664
|
+
async function replan(context) {
|
|
665
|
+
const remainingSteps = context.current_plan.slice(1);
|
|
666
|
+
const plannerContext = new ContextEngine2({
|
|
667
|
+
store: new InMemoryContextStore2(),
|
|
668
|
+
chatId: `replanner-${crypto.randomUUID()}`,
|
|
669
|
+
userId: "system"
|
|
670
|
+
});
|
|
671
|
+
plannerContext.set(
|
|
672
|
+
persona2({
|
|
673
|
+
name: "replanner_agent",
|
|
674
|
+
role: "You are an adaptive replanning agent.",
|
|
675
|
+
objective: "Review execution progress and adjust remaining steps so the plan reaches the original goal efficiently."
|
|
676
|
+
}),
|
|
677
|
+
fragment2("replanner_instructions", createReplannerPrompt()),
|
|
678
|
+
user2(formatReplannerPrompt(context, remainingSteps))
|
|
679
|
+
);
|
|
680
|
+
const replannerOutput = structuredOutput2({
|
|
681
|
+
model: replannerModel,
|
|
682
|
+
context: plannerContext,
|
|
683
|
+
schema: ReplanDecisionSchema
|
|
684
|
+
});
|
|
685
|
+
const output = await replannerOutput.generate();
|
|
686
|
+
const decision = output;
|
|
687
|
+
return {
|
|
688
|
+
...context,
|
|
689
|
+
current_plan: decision.remaining_steps,
|
|
690
|
+
is_complete: !decision.should_continue
|
|
691
|
+
};
|
|
692
|
+
}
|
|
693
|
+
|
|
694
|
+
// packages/orchestrator/src/lib/deepplan/synthesizer.ts
|
|
695
|
+
import { agent as agent2, execute, lmstudio as lmstudio3, user as user3 } from "@deepagents/agent";
|
|
696
|
+
var synthesizer = agent2({
|
|
697
|
+
name: "synthesizer_agent",
|
|
698
|
+
model: lmstudio3("google/gemma-3-12b"),
|
|
699
|
+
prompt: `
|
|
700
|
+
<SystemContext>
|
|
701
|
+
You are a synthesizer agent that compiles the results of executed plan steps into a final answer.
|
|
702
|
+
You ensure accuracy and coherence in the final output.
|
|
703
|
+
</SystemContext>
|
|
704
|
+
|
|
705
|
+
<Identity>
|
|
706
|
+
Your task is to take the individual step results and synthesize them into a coherent final response that addresses the original user request.
|
|
707
|
+
</Identity>
|
|
708
|
+
|
|
709
|
+
<ConstraintDetection>
|
|
710
|
+
**CRITICAL: Check the original request for output constraints FIRST**
|
|
711
|
+
</ConstraintDetection>
|
|
712
|
+
|
|
713
|
+
<SynthesisPrinciples>
|
|
714
|
+
1. **Verify Numerical Accuracy**
|
|
715
|
+
- Check all numerical values for consistency
|
|
716
|
+
- Ensure calculations are correct across steps
|
|
717
|
+
- Verify dates, counts, and measurements make sense
|
|
718
|
+
|
|
719
|
+
2. **Apply Commonsense Validation**
|
|
720
|
+
- Do the results make logical sense?
|
|
721
|
+
- Are there any contradictions or inconsistencies?
|
|
722
|
+
- Do temporal relationships align (e.g., dates in proper order)?
|
|
723
|
+
|
|
724
|
+
3. **Aggregate Intermediate Results**
|
|
725
|
+
- Combine findings from multiple steps coherently
|
|
726
|
+
- Preserve important numerical details
|
|
727
|
+
- Show clear connections between steps
|
|
728
|
+
|
|
729
|
+
4. **Show the Answer Clearly**
|
|
730
|
+
- Present the final answer in a structured format
|
|
731
|
+
- Highlight key numerical findings
|
|
732
|
+
- Make the conclusion explicit and unambiguous
|
|
733
|
+
</SynthesisPrinciples>
|
|
734
|
+
|
|
735
|
+
<Instructions>
|
|
736
|
+
1. **Read the original user request carefully** and identify any output constraints
|
|
737
|
+
2. Review all step results carefully
|
|
738
|
+
3. **Verify numerical consistency and commonsense**
|
|
739
|
+
4. If constraints exist: compile results according to constraints (minimal output)
|
|
740
|
+
5. If no constraints: synthesize insights into a comprehensive answer
|
|
741
|
+
6. **Show the answer clearly** with verified numbers and logical coherence
|
|
742
|
+
|
|
743
|
+
CRITICAL:
|
|
744
|
+
- Always prioritize explicit constraints over comprehensive analysis
|
|
745
|
+
- When in doubt about constraints, prefer minimal output
|
|
746
|
+
- Verify numerical accuracy before finalizing
|
|
747
|
+
- Check for commonsense and logical coherence
|
|
748
|
+
- The final answer should be well-structured and easy to understand
|
|
749
|
+
</Instructions>
|
|
750
|
+
`
|
|
751
|
+
});
|
|
752
|
+
async function synthesize(stepResults, originalRequest) {
|
|
753
|
+
const stepResultsText = stepResults.map((step, index) => `Step ${index + 1} Result:
|
|
754
|
+
${step}`).join("\n\n");
|
|
755
|
+
const prompt = `
|
|
756
|
+
Original User Request:
|
|
757
|
+
${originalRequest}
|
|
758
|
+
|
|
759
|
+
---
|
|
760
|
+
|
|
761
|
+
${stepResultsText}
|
|
762
|
+
`.trim();
|
|
763
|
+
return (await execute(synthesizer, [user3(prompt)], {})).text;
|
|
764
|
+
}
|
|
765
|
+
|
|
766
|
+
// packages/orchestrator/src/lib/deepplan/plan-and-solve.ts
|
|
767
|
+
async function runExecutor(agent3, context, step, state) {
|
|
768
|
+
const { text } = await generate(
|
|
769
|
+
agent3,
|
|
770
|
+
[user4(formatStepForExecutor(step, context))],
|
|
771
|
+
state
|
|
772
|
+
);
|
|
773
|
+
return {
|
|
774
|
+
...context,
|
|
775
|
+
variables: { ...context.variables },
|
|
776
|
+
step_results: [...context.step_results, text]
|
|
777
|
+
};
|
|
778
|
+
}
|
|
779
|
+
async function planAndSolve(options) {
|
|
780
|
+
let context = await plan(options.input);
|
|
781
|
+
const plans = [context.current_plan];
|
|
782
|
+
if (options.hooks?.onInitialPlan) {
|
|
783
|
+
const initialPlanResult = await options.hooks.onInitialPlan(context);
|
|
784
|
+
if (initialPlanResult) {
|
|
785
|
+
context = initialPlanResult;
|
|
786
|
+
}
|
|
787
|
+
}
|
|
788
|
+
if (context.is_complete) {
|
|
789
|
+
return synthesize(context.step_results, context.original_request);
|
|
790
|
+
}
|
|
791
|
+
while (context.current_plan.length > 0) {
|
|
792
|
+
const currentStep = context.current_plan[0];
|
|
793
|
+
context = await runExecutor(
|
|
794
|
+
options.executor,
|
|
795
|
+
context,
|
|
796
|
+
currentStep,
|
|
797
|
+
options.state
|
|
798
|
+
);
|
|
799
|
+
if (options.hooks?.beforeReplan) {
|
|
800
|
+
const beforeReplanResult = await options.hooks.beforeReplan(context);
|
|
801
|
+
if (beforeReplanResult) {
|
|
802
|
+
context = beforeReplanResult;
|
|
803
|
+
}
|
|
804
|
+
}
|
|
805
|
+
if (context.is_complete) {
|
|
806
|
+
break;
|
|
807
|
+
}
|
|
808
|
+
context = await replan(context);
|
|
809
|
+
plans.push(context.current_plan);
|
|
810
|
+
if (options.hooks?.afterReplan) {
|
|
811
|
+
const afterReplanResult = await options.hooks.afterReplan(context);
|
|
812
|
+
if (afterReplanResult) {
|
|
813
|
+
context = afterReplanResult;
|
|
814
|
+
}
|
|
815
|
+
}
|
|
816
|
+
if (context.is_complete) {
|
|
817
|
+
break;
|
|
818
|
+
}
|
|
819
|
+
}
|
|
820
|
+
options.state.plans = plans;
|
|
821
|
+
return synthesize(context.step_results, context.original_request);
|
|
822
|
+
}
|
|
823
|
+
export {
|
|
824
|
+
planAndSolve
|
|
825
|
+
};
|
|
826
|
+
//# sourceMappingURL=plan-and-solve.js.map
|