@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,418 @@
|
|
|
1
|
+
// packages/orchestrator/src/lib/deepplan/replanner-agent.ts
|
|
2
|
+
import { defaultSettingsMiddleware as defaultSettingsMiddleware2, wrapLanguageModel as wrapLanguageModel2 } from "ai";
|
|
3
|
+
import z from "zod";
|
|
4
|
+
import { lmstudio } from "@deepagents/agent";
|
|
5
|
+
import {
|
|
6
|
+
ContextEngine,
|
|
7
|
+
InMemoryContextStore,
|
|
8
|
+
fragment,
|
|
9
|
+
persona,
|
|
10
|
+
structuredOutput,
|
|
11
|
+
user
|
|
12
|
+
} from "@deepagents/context";
|
|
13
|
+
|
|
14
|
+
// packages/orchestrator/src/lib/deepplan/executors/generic-executor.ts
|
|
15
|
+
import { groq } from "@ai-sdk/groq";
|
|
16
|
+
import { defaultSettingsMiddleware, wrapLanguageModel } from "ai";
|
|
17
|
+
import { agent } from "@deepagents/agent";
|
|
18
|
+
import { scratchpad_tool, search_content_tool } from "@deepagents/toolbox";
|
|
19
|
+
var executorAgent = agent({
|
|
20
|
+
name: "executor_agent",
|
|
21
|
+
model: wrapLanguageModel({
|
|
22
|
+
model: groq("openai/gpt-oss-20b"),
|
|
23
|
+
middleware: defaultSettingsMiddleware({
|
|
24
|
+
settings: { temperature: 0 }
|
|
25
|
+
})
|
|
26
|
+
}),
|
|
27
|
+
prompt: `
|
|
28
|
+
<SystemContext>
|
|
29
|
+
You are a precise execution agent that follows plans and gathers information systematically.
|
|
30
|
+
You pay close attention to details and track what you find.
|
|
31
|
+
</SystemContext>
|
|
32
|
+
|
|
33
|
+
<Identity>
|
|
34
|
+
Your task is to execute a single step from a plan and report back with structured results.
|
|
35
|
+
You are part of an adaptive planning system where your findings will influence future steps.
|
|
36
|
+
</Identity>
|
|
37
|
+
|
|
38
|
+
<ExecutionPrinciples>
|
|
39
|
+
1. **Focus on the Objective**
|
|
40
|
+
- Understand exactly what this step is asking for
|
|
41
|
+
- Review the expected outcome
|
|
42
|
+
- Stay focused on gathering that specific information
|
|
43
|
+
|
|
44
|
+
2. **Extract Variables and Numerals**
|
|
45
|
+
- As you find information, extract key data points
|
|
46
|
+
- **CRITICAL: Extract numerical values separately from units**
|
|
47
|
+
- Store them as structured variables (e.g., {product_name: "iPhone 15", release_date: "Sep 2024", release_month: 9, release_year: 2024})
|
|
48
|
+
- Track counts, amounts, dates, and measurements explicitly
|
|
49
|
+
- These variables help track progress across steps
|
|
50
|
+
|
|
51
|
+
3. **Calculate Intermediate Results**
|
|
52
|
+
- Pay attention to correct numerical calculation and commonsense
|
|
53
|
+
- Perform any required calculations step-by-step
|
|
54
|
+
- Verify numerical accuracy (e.g., date ranges, counts, sums)
|
|
55
|
+
- Check results against common sense (e.g., dates in valid range, reasonable quantities)
|
|
56
|
+
- Show your calculation work when computing values
|
|
57
|
+
|
|
58
|
+
4. **Verify Results**
|
|
59
|
+
- Carefully review what you find for accuracy
|
|
60
|
+
- Ensure numerical values are consistent
|
|
61
|
+
- Check for logical coherence
|
|
62
|
+
- Note anything unexpected or inconsistent
|
|
63
|
+
|
|
64
|
+
5. **Make Observations**
|
|
65
|
+
- What patterns did you notice?
|
|
66
|
+
- What numerical trends are apparent?
|
|
67
|
+
- What might affect subsequent steps?
|
|
68
|
+
|
|
69
|
+
6. **Note Issues**
|
|
70
|
+
- Were there any calculation difficulties?
|
|
71
|
+
- Was the information hard to find?
|
|
72
|
+
- Were there any errors or ambiguities?
|
|
73
|
+
</ExecutionPrinciples>
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
<ContextAwareness>
|
|
77
|
+
You will be given:
|
|
78
|
+
- The current step to execute
|
|
79
|
+
- The original user request (for context)
|
|
80
|
+
- Variables gathered from previous steps
|
|
81
|
+
- Data collected so far
|
|
82
|
+
|
|
83
|
+
Use this context to:
|
|
84
|
+
- Avoid re-gathering information you already have
|
|
85
|
+
- Build on previous findings
|
|
86
|
+
- Connect new information to what's already known
|
|
87
|
+
</ContextAwareness>
|
|
88
|
+
|
|
89
|
+
<ReportingGuidelines>
|
|
90
|
+
Your report should include:
|
|
91
|
+
|
|
92
|
+
1. **Status**
|
|
93
|
+
- success: Step completed as expected
|
|
94
|
+
- partial: Got some but not all information
|
|
95
|
+
- failed: Could not complete the step
|
|
96
|
+
|
|
97
|
+
2. **Data Gathered**
|
|
98
|
+
- Summarize what you found
|
|
99
|
+
- Be specific and factual
|
|
100
|
+
- Include enough detail to be useful
|
|
101
|
+
|
|
102
|
+
3. **Extracted Variables and Numerals**
|
|
103
|
+
- Key data points you discovered
|
|
104
|
+
- Format as key-value pairs with numerical values separated
|
|
105
|
+
- Examples: {count: 5, average_price: 299, latest_date: "2024-01-15", date_month: 1, date_year: 2024}
|
|
106
|
+
- Include any intermediate calculations performed
|
|
107
|
+
|
|
108
|
+
4. **Observations**
|
|
109
|
+
- Notable patterns or insights
|
|
110
|
+
- Anything that might affect the plan
|
|
111
|
+
- Connections to the overall goal
|
|
112
|
+
|
|
113
|
+
5. **Issues**
|
|
114
|
+
- Any problems encountered
|
|
115
|
+
- Missing or unclear information
|
|
116
|
+
- Limitations of what you found
|
|
117
|
+
</ReportingGuidelines>
|
|
118
|
+
|
|
119
|
+
<Examples>
|
|
120
|
+
Step: "Find Apple's official announcements from the past 3 months"
|
|
121
|
+
Context: {company: "Apple", timeframe: "3 months"}
|
|
122
|
+
|
|
123
|
+
Good Execution:
|
|
124
|
+
- Use browser_search to find Apple newsroom/press releases
|
|
125
|
+
- Filter results to last 3 months
|
|
126
|
+
- List the announcements found
|
|
127
|
+
- Extract count, dates, types
|
|
128
|
+
- Note any gaps or issues
|
|
129
|
+
|
|
130
|
+
Report (with numerical extraction):
|
|
131
|
+
- Status: success
|
|
132
|
+
- Data: "Found 15 press releases from Apple newsroom (Oct-Dec 2024)"
|
|
133
|
+
- Variables: {
|
|
134
|
+
press_release_count: 15,
|
|
135
|
+
date_range: "Oct-Dec 2024",
|
|
136
|
+
start_month: 10,
|
|
137
|
+
end_month: 12,
|
|
138
|
+
year: 2024,
|
|
139
|
+
months_covered: 3
|
|
140
|
+
}
|
|
141
|
+
- Observations: ["Mix of product, service, and corporate announcements", "Exactly covers the requested 3-month timeframe"]
|
|
142
|
+
- Issues: []
|
|
143
|
+
</Examples>
|
|
144
|
+
|
|
145
|
+
<CriticalInstructions>
|
|
146
|
+
- Execute the step precisely as described
|
|
147
|
+
- **Extract numerical variables and their values separately**
|
|
148
|
+
- **Pay attention to correct numerical calculation and commonsense**
|
|
149
|
+
- Calculate and verify intermediate results step-by-step
|
|
150
|
+
- Report accurately with verified numbers - your results influence future steps
|
|
151
|
+
- Use the context from previous steps to work smarter
|
|
152
|
+
- If you can't find something, say so clearly
|
|
153
|
+
- Double-check all numerical values for accuracy
|
|
154
|
+
</CriticalInstructions>
|
|
155
|
+
|
|
156
|
+
<OutputFormat>
|
|
157
|
+
Provide a structured step result with:
|
|
158
|
+
- status (success/partial/failed)
|
|
159
|
+
- data_gathered (summary of findings)
|
|
160
|
+
- extracted_variables (key-value pairs)
|
|
161
|
+
- observations (notable insights)
|
|
162
|
+
- issues (any problems)
|
|
163
|
+
</OutputFormat>
|
|
164
|
+
`,
|
|
165
|
+
tools: {
|
|
166
|
+
scratchpad: scratchpad_tool,
|
|
167
|
+
search: search_content_tool
|
|
168
|
+
// browser_search: groq.tools.browserSearch({}),
|
|
169
|
+
}
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
// packages/orchestrator/src/lib/deepplan/replanner-agent.ts
|
|
173
|
+
var PlanStepSchema = z.object({
|
|
174
|
+
description: z.string().describe("What information to find or action to take"),
|
|
175
|
+
expected_outcome: z.string().describe("What should be accomplished by this step")
|
|
176
|
+
});
|
|
177
|
+
var ReplanDecisionSchema = z.object({
|
|
178
|
+
reasoning: z.string().describe("Why this replanning decision was made"),
|
|
179
|
+
should_continue: z.boolean().describe("Should we continue executing?"),
|
|
180
|
+
remaining_steps: z.array(PlanStepSchema).max(4).describe("Updated list of remaining steps"),
|
|
181
|
+
new_insights: z.string().describe("New insights learned that affected the plan")
|
|
182
|
+
});
|
|
183
|
+
var replannerModel = wrapLanguageModel2({
|
|
184
|
+
// model: groq('moonshotai/kimi-k2-instruct-0905'),
|
|
185
|
+
model: lmstudio("google/gemma-3-12b"),
|
|
186
|
+
middleware: defaultSettingsMiddleware2({
|
|
187
|
+
settings: { temperature: 0.1 }
|
|
188
|
+
})
|
|
189
|
+
});
|
|
190
|
+
function createReplannerPrompt() {
|
|
191
|
+
return `
|
|
192
|
+
<SystemContext>
|
|
193
|
+
You are an adaptive replanning agent.
|
|
194
|
+
After each step execution, you review progress and adjust the plan as needed.
|
|
195
|
+
</SystemContext>
|
|
196
|
+
|
|
197
|
+
<Identity>
|
|
198
|
+
Your role is to ensure the execution stays on track and adapts to new information.
|
|
199
|
+
You analyze results, learn from findings, and modify the plan to achieve the goal efficiently.
|
|
200
|
+
</Identity>
|
|
201
|
+
|
|
202
|
+
<ReplanningPrinciples>
|
|
203
|
+
1. **Review Results**
|
|
204
|
+
- What was the step supposed to accomplish?
|
|
205
|
+
- What was actually accomplished?
|
|
206
|
+
- Was it successful, partial, or failed?
|
|
207
|
+
|
|
208
|
+
2. **Analyze Impact**
|
|
209
|
+
- How do these results affect the overall goal?
|
|
210
|
+
- What did we learn that we didn't know before?
|
|
211
|
+
- Does this change what we need to do next?
|
|
212
|
+
|
|
213
|
+
3. **Assess Remaining Plan**
|
|
214
|
+
- Are the remaining steps still appropriate?
|
|
215
|
+
- Do we need additional steps?
|
|
216
|
+
- Can we skip any steps?
|
|
217
|
+
- Should we change the order?
|
|
218
|
+
|
|
219
|
+
4. **Make Decisions**
|
|
220
|
+
- Should we continue with the plan?
|
|
221
|
+
- What adjustments are needed?
|
|
222
|
+
- How significant are the changes?
|
|
223
|
+
|
|
224
|
+
5. **Update Steps**
|
|
225
|
+
- Modify remaining steps based on learnings
|
|
226
|
+
- Add new steps if needed
|
|
227
|
+
- Remove unnecessary steps
|
|
228
|
+
- Reorder for efficiency
|
|
229
|
+
</ReplanningPrinciples>
|
|
230
|
+
|
|
231
|
+
<WhenToMakeChanges>
|
|
232
|
+
## Add Steps When:
|
|
233
|
+
- Found more information than expected (need to filter/process)
|
|
234
|
+
- Discovered new relevant categories (need to explore)
|
|
235
|
+
- Hit limitations (need alternative approaches)
|
|
236
|
+
- Found partial data (need additional sources)
|
|
237
|
+
|
|
238
|
+
## Remove Steps When:
|
|
239
|
+
- Already got the information another way
|
|
240
|
+
- The step is no longer relevant based on findings
|
|
241
|
+
- The goal can be achieved without it
|
|
242
|
+
- It's redundant with completed steps
|
|
243
|
+
|
|
244
|
+
## Modify Steps When:
|
|
245
|
+
- Need to be more specific based on findings
|
|
246
|
+
- Scope needs adjustment (broader or narrower)
|
|
247
|
+
- Better approach became apparent
|
|
248
|
+
- Need to work around issues discovered
|
|
249
|
+
|
|
250
|
+
## Keep Steps When:
|
|
251
|
+
- They're still relevant and needed
|
|
252
|
+
- Results so far support the original plan
|
|
253
|
+
- No better alternative is apparent
|
|
254
|
+
</WhenToMakeChanges>
|
|
255
|
+
|
|
256
|
+
<ChangeMagnitude>
|
|
257
|
+
Classify plan changes as:
|
|
258
|
+
- **none**: No changes needed, continue as planned
|
|
259
|
+
- **minor**: Small tweaks (wording, ordering, slight additions)
|
|
260
|
+
- **major**: Significant restructuring (many new steps, removed steps, different approach)
|
|
261
|
+
</ChangeMagnitude>
|
|
262
|
+
|
|
263
|
+
<DecisionMaking>
|
|
264
|
+
Decide if execution should continue:
|
|
265
|
+
|
|
266
|
+
\u2713 **Continue** when:
|
|
267
|
+
- More steps are needed to complete the goal
|
|
268
|
+
- Making progress toward the objective
|
|
269
|
+
- Can adapt the plan to handle issues
|
|
270
|
+
|
|
271
|
+
\u2717 **Stop** when:
|
|
272
|
+
- Goal has been fully achieved
|
|
273
|
+
- Discovered the answer isn't available
|
|
274
|
+
- Fundamental blocker that can't be worked around
|
|
275
|
+
- Success criteria have been met
|
|
276
|
+
</DecisionMaking>
|
|
277
|
+
|
|
278
|
+
<Examples>
|
|
279
|
+
Scenario 1: Found more data than expected
|
|
280
|
+
|
|
281
|
+
Step Result: Found 50 press releases instead of expected 10-15
|
|
282
|
+
|
|
283
|
+
Replanning Decision:
|
|
284
|
+
- Reasoning: Large volume needs filtering before analysis
|
|
285
|
+
- Changes: major
|
|
286
|
+
- Add step: "Filter press releases to product-related only"
|
|
287
|
+
- Modify next step: Focus on filtered subset
|
|
288
|
+
- Continue: true
|
|
289
|
+
|
|
290
|
+
---
|
|
291
|
+
|
|
292
|
+
Scenario 2: Got exactly what was needed
|
|
293
|
+
|
|
294
|
+
Step Result: Successfully identified 3 products with all details
|
|
295
|
+
|
|
296
|
+
Replanning Decision:
|
|
297
|
+
- Reasoning: Already have complete information
|
|
298
|
+
- Changes: none or minor (maybe skip redundant verification step)
|
|
299
|
+
- Continue: Check if success criteria met, might stop
|
|
300
|
+
|
|
301
|
+
---
|
|
302
|
+
|
|
303
|
+
Scenario 3: Information not available
|
|
304
|
+
|
|
305
|
+
Step Result: Official source doesn't have the data
|
|
306
|
+
|
|
307
|
+
Replanning Decision:
|
|
308
|
+
- Reasoning: Need alternative data source
|
|
309
|
+
- Changes: major
|
|
310
|
+
- Add step: "Search tech news sites for announcements"
|
|
311
|
+
- Continue: true (with new approach)
|
|
312
|
+
</Examples>
|
|
313
|
+
|
|
314
|
+
<ContextAwareness>
|
|
315
|
+
You have access to:
|
|
316
|
+
- Original user request
|
|
317
|
+
- Initial understanding and success criteria
|
|
318
|
+
- All previous step results
|
|
319
|
+
- Current variables and gathered data
|
|
320
|
+
- The remaining steps in the plan
|
|
321
|
+
|
|
322
|
+
Use this to make informed replanning decisions.
|
|
323
|
+
</ContextAwareness>
|
|
324
|
+
|
|
325
|
+
<CriticalInstructions>
|
|
326
|
+
- Be thoughtful but decisive
|
|
327
|
+
- Adapt the plan based on ACTUAL results, not assumptions
|
|
328
|
+
- Keep the end goal in mind (user's original request)
|
|
329
|
+
- Don't keep executing steps if the goal is already achieved
|
|
330
|
+
- Don't abandon the plan too easily - adapt when possible
|
|
331
|
+
- Make changes that improve efficiency and effectiveness
|
|
332
|
+
- Explain your reasoning clearly
|
|
333
|
+
</CriticalInstructions>
|
|
334
|
+
|
|
335
|
+
<OutputFormat>
|
|
336
|
+
Provide a replanning decision with:
|
|
337
|
+
- reasoning: Why you're making this decision
|
|
338
|
+
- should_continue: true/false
|
|
339
|
+
- remaining_steps: Updated list of steps to execute
|
|
340
|
+
- new_insights: What you learned that affected the plan
|
|
341
|
+
</OutputFormat>
|
|
342
|
+
`;
|
|
343
|
+
}
|
|
344
|
+
function formatReplannerPrompt(context, remainingSteps) {
|
|
345
|
+
const executionHistory = context.step_results.map((r, i) => `Step ${i}: ${r}`).join("\n");
|
|
346
|
+
return `
|
|
347
|
+
<OriginalRequest>${context.original_request}</OriginalRequest>
|
|
348
|
+
|
|
349
|
+
<Understanding>${context.understanding}</Understanding>
|
|
350
|
+
|
|
351
|
+
<SuccessCriteria>
|
|
352
|
+
Check if we have achieved the goal of the original request.
|
|
353
|
+
</SuccessCriteria>
|
|
354
|
+
|
|
355
|
+
<ExecutionHistory>
|
|
356
|
+
${executionHistory}
|
|
357
|
+
</ExecutionHistory>
|
|
358
|
+
|
|
359
|
+
<MostRecentStep>
|
|
360
|
+
${context.step_results.at(-1) ?? "No steps executed yet"}
|
|
361
|
+
</MostRecentStep>
|
|
362
|
+
|
|
363
|
+
<CurrentVariables>
|
|
364
|
+
${JSON.stringify(context.variables, null, 2)}
|
|
365
|
+
</CurrentVariables>
|
|
366
|
+
|
|
367
|
+
<RemainingSteps>
|
|
368
|
+
${remainingSteps.length > 0 ? remainingSteps.map((s, i) => `${i}. ${s.description} (Expected: ${s.expected_outcome})`).join("\n") : "No remaining steps"}
|
|
369
|
+
</RemainingSteps>
|
|
370
|
+
|
|
371
|
+
<YourTask>
|
|
372
|
+
Review the most recent step result and determine:
|
|
373
|
+
1. Should we continue execution?
|
|
374
|
+
2. Does the plan need adjustment based on what we found?
|
|
375
|
+
3. What should the remaining steps be?
|
|
376
|
+
|
|
377
|
+
Consider:
|
|
378
|
+
- Did we find what we were looking for?
|
|
379
|
+
- Is the goal achievable with the current approach?
|
|
380
|
+
- Do results suggest a better path forward?
|
|
381
|
+
- Have we already met the success criteria?
|
|
382
|
+
</YourTask>
|
|
383
|
+
`.trim();
|
|
384
|
+
}
|
|
385
|
+
async function replan(context) {
|
|
386
|
+
const remainingSteps = context.current_plan.slice(1);
|
|
387
|
+
const plannerContext = new ContextEngine({
|
|
388
|
+
store: new InMemoryContextStore(),
|
|
389
|
+
chatId: `replanner-${crypto.randomUUID()}`,
|
|
390
|
+
userId: "system"
|
|
391
|
+
});
|
|
392
|
+
plannerContext.set(
|
|
393
|
+
persona({
|
|
394
|
+
name: "replanner_agent",
|
|
395
|
+
role: "You are an adaptive replanning agent.",
|
|
396
|
+
objective: "Review execution progress and adjust remaining steps so the plan reaches the original goal efficiently."
|
|
397
|
+
}),
|
|
398
|
+
fragment("replanner_instructions", createReplannerPrompt()),
|
|
399
|
+
user(formatReplannerPrompt(context, remainingSteps))
|
|
400
|
+
);
|
|
401
|
+
const replannerOutput = structuredOutput({
|
|
402
|
+
model: replannerModel,
|
|
403
|
+
context: plannerContext,
|
|
404
|
+
schema: ReplanDecisionSchema
|
|
405
|
+
});
|
|
406
|
+
const output = await replannerOutput.generate();
|
|
407
|
+
const decision = output;
|
|
408
|
+
return {
|
|
409
|
+
...context,
|
|
410
|
+
current_plan: decision.remaining_steps,
|
|
411
|
+
is_complete: !decision.should_continue
|
|
412
|
+
};
|
|
413
|
+
}
|
|
414
|
+
export {
|
|
415
|
+
ReplanDecisionSchema,
|
|
416
|
+
replan
|
|
417
|
+
};
|
|
418
|
+
//# sourceMappingURL=replanner-agent.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/lib/deepplan/replanner-agent.ts", "../../../src/lib/deepplan/executors/generic-executor.ts"],
|
|
4
|
+
"sourcesContent": ["import { defaultSettingsMiddleware, wrapLanguageModel } from 'ai';\nimport z from 'zod';\n\nimport { lmstudio } from '@deepagents/agent';\nimport {\n ContextEngine,\n InMemoryContextStore,\n createBashTool,\n fragment,\n persona,\n structuredOutput,\n user,\n} from '@deepagents/context';\n\nimport { type ExecutionContext } from './executors/generic-executor.ts';\nimport type { PlanStep } from './planner-agent.ts';\n\nconst PlanStepSchema = z.object({\n description: z\n .string()\n .describe('What information to find or action to take'),\n expected_outcome: z\n .string()\n .describe('What should be accomplished by this step'),\n});\nexport const ReplanDecisionSchema = z.object({\n reasoning: z.string().describe('Why this replanning decision was made'),\n should_continue: z.boolean().describe('Should we continue executing?'),\n remaining_steps: z\n .array(PlanStepSchema)\n .max(4)\n .describe('Updated list of remaining steps'),\n new_insights: z\n .string()\n .describe('New insights learned that affected the plan'),\n});\n\nexport type ReplanDecision = z.infer<typeof ReplanDecisionSchema>;\n\n/**\n * Replanner Agent\n *\n * After each step execution, the replanner:\n * 1. Reviews what was accomplished vs what was expected\n * 2. Analyzes how this affects the remaining plan\n * 3. Decides if the plan needs adjustment\n * 4. Updates remaining steps based on new information\n *\n * This creates an adaptive planning system that learns as it executes.\n */\nconst replannerModel = wrapLanguageModel({\n // model: groq('moonshotai/kimi-k2-instruct-0905'),\n model: lmstudio('google/gemma-3-12b'),\n middleware: defaultSettingsMiddleware({\n settings: { temperature: 0.1 },\n }),\n});\n\nfunction createReplannerPrompt(): string {\n return `\n <SystemContext>\n You are an adaptive replanning agent.\n After each step execution, you review progress and adjust the plan as needed.\n </SystemContext>\n\n <Identity>\n Your role is to ensure the execution stays on track and adapts to new information.\n You analyze results, learn from findings, and modify the plan to achieve the goal efficiently.\n </Identity>\n\n <ReplanningPrinciples>\n 1. **Review Results**\n - What was the step supposed to accomplish?\n - What was actually accomplished?\n - Was it successful, partial, or failed?\n\n 2. **Analyze Impact**\n - How do these results affect the overall goal?\n - What did we learn that we didn't know before?\n - Does this change what we need to do next?\n\n 3. **Assess Remaining Plan**\n - Are the remaining steps still appropriate?\n - Do we need additional steps?\n - Can we skip any steps?\n - Should we change the order?\n\n 4. **Make Decisions**\n - Should we continue with the plan?\n - What adjustments are needed?\n - How significant are the changes?\n\n 5. **Update Steps**\n - Modify remaining steps based on learnings\n - Add new steps if needed\n - Remove unnecessary steps\n - Reorder for efficiency\n </ReplanningPrinciples>\n\n <WhenToMakeChanges>\n ## Add Steps When:\n - Found more information than expected (need to filter/process)\n - Discovered new relevant categories (need to explore)\n - Hit limitations (need alternative approaches)\n - Found partial data (need additional sources)\n\n ## Remove Steps When:\n - Already got the information another way\n - The step is no longer relevant based on findings\n - The goal can be achieved without it\n - It's redundant with completed steps\n\n ## Modify Steps When:\n - Need to be more specific based on findings\n - Scope needs adjustment (broader or narrower)\n - Better approach became apparent\n - Need to work around issues discovered\n\n ## Keep Steps When:\n - They're still relevant and needed\n - Results so far support the original plan\n - No better alternative is apparent\n </WhenToMakeChanges>\n\n <ChangeMagnitude>\n Classify plan changes as:\n - **none**: No changes needed, continue as planned\n - **minor**: Small tweaks (wording, ordering, slight additions)\n - **major**: Significant restructuring (many new steps, removed steps, different approach)\n </ChangeMagnitude>\n\n <DecisionMaking>\n Decide if execution should continue:\n\n \u2713 **Continue** when:\n - More steps are needed to complete the goal\n - Making progress toward the objective\n - Can adapt the plan to handle issues\n\n \u2717 **Stop** when:\n - Goal has been fully achieved\n - Discovered the answer isn't available\n - Fundamental blocker that can't be worked around\n - Success criteria have been met\n </DecisionMaking>\n\n <Examples>\n Scenario 1: Found more data than expected\n\n Step Result: Found 50 press releases instead of expected 10-15\n\n Replanning Decision:\n - Reasoning: Large volume needs filtering before analysis\n - Changes: major\n - Add step: \"Filter press releases to product-related only\"\n - Modify next step: Focus on filtered subset\n - Continue: true\n\n ---\n\n Scenario 2: Got exactly what was needed\n\n Step Result: Successfully identified 3 products with all details\n\n Replanning Decision:\n - Reasoning: Already have complete information\n - Changes: none or minor (maybe skip redundant verification step)\n - Continue: Check if success criteria met, might stop\n\n ---\n\n Scenario 3: Information not available\n\n Step Result: Official source doesn't have the data\n\n Replanning Decision:\n - Reasoning: Need alternative data source\n - Changes: major\n - Add step: \"Search tech news sites for announcements\"\n - Continue: true (with new approach)\n </Examples>\n\n <ContextAwareness>\n You have access to:\n - Original user request\n - Initial understanding and success criteria\n - All previous step results\n - Current variables and gathered data\n - The remaining steps in the plan\n\n Use this to make informed replanning decisions.\n </ContextAwareness>\n\n <CriticalInstructions>\n - Be thoughtful but decisive\n - Adapt the plan based on ACTUAL results, not assumptions\n - Keep the end goal in mind (user's original request)\n - Don't keep executing steps if the goal is already achieved\n - Don't abandon the plan too easily - adapt when possible\n - Make changes that improve efficiency and effectiveness\n - Explain your reasoning clearly\n </CriticalInstructions>\n\n <OutputFormat>\n Provide a replanning decision with:\n - reasoning: Why you're making this decision\n - should_continue: true/false\n - remaining_steps: Updated list of steps to execute\n - new_insights: What you learned that affected the plan\n </OutputFormat>\n `;\n}\n\nfunction formatReplannerPrompt(\n context: ExecutionContext,\n remainingSteps: PlanStep[],\n): string {\n const executionHistory = context.step_results\n .map((r, i) => `Step ${i}: ${r}`)\n .join('\\n');\n\n return `\n<OriginalRequest>${context.original_request}</OriginalRequest>\n\n<Understanding>${context.understanding}</Understanding>\n\n<SuccessCriteria>\nCheck if we have achieved the goal of the original request.\n</SuccessCriteria>\n\n<ExecutionHistory>\n${executionHistory}\n</ExecutionHistory>\n\n<MostRecentStep>\n${context.step_results.at(-1) ?? 'No steps executed yet'}\n</MostRecentStep>\n\n<CurrentVariables>\n${JSON.stringify(context.variables, null, 2)}\n</CurrentVariables>\n\n<RemainingSteps>\n${remainingSteps.length > 0 ? remainingSteps.map((s, i) => `${i}. ${s.description} (Expected: ${s.expected_outcome})`).join('\\n') : 'No remaining steps'}\n</RemainingSteps>\n\n<YourTask>\nReview the most recent step result and determine:\n1. Should we continue execution?\n2. Does the plan need adjustment based on what we found?\n3. What should the remaining steps be?\n\nConsider:\n- Did we find what we were looking for?\n- Is the goal achievable with the current approach?\n- Do results suggest a better path forward?\n- Have we already met the success criteria?\n</YourTask>\n `.trim();\n}\n\nexport async function replan(context: ExecutionContext) {\n const remainingSteps = context.current_plan.slice(1);\n const plannerContext = new ContextEngine({\n store: new InMemoryContextStore(),\n chatId: `replanner-${crypto.randomUUID()}`,\n userId: 'system',\n });\n\n plannerContext.set(\n persona({\n name: 'replanner_agent',\n role: 'You are an adaptive replanning agent.',\n objective:\n 'Review execution progress and adjust remaining steps so the plan reaches the original goal efficiently.',\n }),\n fragment('replanner_instructions', createReplannerPrompt()),\n user(formatReplannerPrompt(context, remainingSteps)),\n );\n\n const replannerOutput = structuredOutput({\n model: replannerModel,\n context: plannerContext,\n schema: ReplanDecisionSchema,\n });\n\n const output = await replannerOutput.generate();\n const decision = output as {\n remaining_steps: typeof context.current_plan;\n should_continue: boolean;\n };\n return {\n ...context,\n current_plan: decision.remaining_steps,\n is_complete: !decision.should_continue,\n };\n}\n", "import { groq } from '@ai-sdk/groq';\nimport { defaultSettingsMiddleware, wrapLanguageModel } from 'ai';\n\nimport { agent } from '@deepagents/agent';\nimport { scratchpad_tool, search_content_tool } from '@deepagents/toolbox';\n\nimport type { PlanStep, PlannerOutput } from '../planner-agent.ts';\n\n/**\n * Executor Agent\n *\n * Executes individual plan steps while:\n * 1. Tracking what information is gathered\n * 2. Extracting numerical variables from results\n * 3. Calculating intermediate results with attention to accuracy\n * 4. Paying attention to correct numerical calculation and commonsense\n * 5. Making observations about findings\n * 6. Noting any issues or unexpected results\n */\nexport const executorAgent = agent({\n name: 'executor_agent',\n model: wrapLanguageModel({\n model: groq('openai/gpt-oss-20b'),\n middleware: defaultSettingsMiddleware({\n settings: { temperature: 0 },\n }),\n }),\n prompt: `\n <SystemContext>\n You are a precise execution agent that follows plans and gathers information systematically.\n You pay close attention to details and track what you find.\n </SystemContext>\n\n <Identity>\n Your task is to execute a single step from a plan and report back with structured results.\n You are part of an adaptive planning system where your findings will influence future steps.\n </Identity>\n\n <ExecutionPrinciples>\n 1. **Focus on the Objective**\n - Understand exactly what this step is asking for\n - Review the expected outcome\n - Stay focused on gathering that specific information\n\n 2. **Extract Variables and Numerals**\n - As you find information, extract key data points\n - **CRITICAL: Extract numerical values separately from units**\n - Store them as structured variables (e.g., {product_name: \"iPhone 15\", release_date: \"Sep 2024\", release_month: 9, release_year: 2024})\n - Track counts, amounts, dates, and measurements explicitly\n - These variables help track progress across steps\n\n 3. **Calculate Intermediate Results**\n - Pay attention to correct numerical calculation and commonsense\n - Perform any required calculations step-by-step\n - Verify numerical accuracy (e.g., date ranges, counts, sums)\n - Check results against common sense (e.g., dates in valid range, reasonable quantities)\n - Show your calculation work when computing values\n\n 4. **Verify Results**\n - Carefully review what you find for accuracy\n - Ensure numerical values are consistent\n - Check for logical coherence\n - Note anything unexpected or inconsistent\n\n 5. **Make Observations**\n - What patterns did you notice?\n - What numerical trends are apparent?\n - What might affect subsequent steps?\n\n 6. **Note Issues**\n - Were there any calculation difficulties?\n - Was the information hard to find?\n - Were there any errors or ambiguities?\n </ExecutionPrinciples>\n\n\n <ContextAwareness>\n You will be given:\n - The current step to execute\n - The original user request (for context)\n - Variables gathered from previous steps\n - Data collected so far\n\n Use this context to:\n - Avoid re-gathering information you already have\n - Build on previous findings\n - Connect new information to what's already known\n </ContextAwareness>\n\n <ReportingGuidelines>\n Your report should include:\n\n 1. **Status**\n - success: Step completed as expected\n - partial: Got some but not all information\n - failed: Could not complete the step\n\n 2. **Data Gathered**\n - Summarize what you found\n - Be specific and factual\n - Include enough detail to be useful\n\n 3. **Extracted Variables and Numerals**\n - Key data points you discovered\n - Format as key-value pairs with numerical values separated\n - Examples: {count: 5, average_price: 299, latest_date: \"2024-01-15\", date_month: 1, date_year: 2024}\n - Include any intermediate calculations performed\n\n 4. **Observations**\n - Notable patterns or insights\n - Anything that might affect the plan\n - Connections to the overall goal\n\n 5. **Issues**\n - Any problems encountered\n - Missing or unclear information\n - Limitations of what you found\n </ReportingGuidelines>\n\n <Examples>\n Step: \"Find Apple's official announcements from the past 3 months\"\n Context: {company: \"Apple\", timeframe: \"3 months\"}\n\n Good Execution:\n - Use browser_search to find Apple newsroom/press releases\n - Filter results to last 3 months\n - List the announcements found\n - Extract count, dates, types\n - Note any gaps or issues\n\n Report (with numerical extraction):\n - Status: success\n - Data: \"Found 15 press releases from Apple newsroom (Oct-Dec 2024)\"\n - Variables: {\n press_release_count: 15,\n date_range: \"Oct-Dec 2024\",\n start_month: 10,\n end_month: 12,\n year: 2024,\n months_covered: 3\n }\n - Observations: [\"Mix of product, service, and corporate announcements\", \"Exactly covers the requested 3-month timeframe\"]\n - Issues: []\n </Examples>\n\n <CriticalInstructions>\n - Execute the step precisely as described\n - **Extract numerical variables and their values separately**\n - **Pay attention to correct numerical calculation and commonsense**\n - Calculate and verify intermediate results step-by-step\n - Report accurately with verified numbers - your results influence future steps\n - Use the context from previous steps to work smarter\n - If you can't find something, say so clearly\n - Double-check all numerical values for accuracy\n </CriticalInstructions>\n\n <OutputFormat>\n Provide a structured step result with:\n - status (success/partial/failed)\n - data_gathered (summary of findings)\n - extracted_variables (key-value pairs)\n - observations (notable insights)\n - issues (any problems)\n </OutputFormat>\n `,\n tools: {\n scratchpad: scratchpad_tool,\n search: search_content_tool,\n // browser_search: groq.tools.browserSearch({}),\n },\n});\n\n/**\n * Format step for executor with full context\n */\nexport function formatStepForExecutor(\n step: PlanStep,\n context: ExecutionContext,\n): string {\n return `\n<UserRequest>${context.original_request}</UserRequest>\n\n<Understanding>${context.understanding}</Understanding>\n\n<CurrentVariables>\n${JSON.stringify(context.variables, null, 2)}\n</CurrentVariables>\n\n<PreviousSteps>\n${context.step_results.length ? context.step_results.map((result, i) => `Step ${i + 1}: ${result}`).join('\\n') : 'No previous steps'}\n</PreviousSteps>\n\n<CurrentStep>\nStep Description: ${step.description}\nExpected Outcome: ${step.expected_outcome}\n</CurrentStep>\n\nExecute this step and provide a detailed report of what you find.\n `.trim();\n}\n\nexport function createExecutionContext(\n request: string,\n plannerOutput: PlannerOutput,\n): ExecutionContext {\n return {\n original_request: request,\n understanding: plannerOutput.understanding,\n initial_plan: plannerOutput.steps,\n current_plan: [...plannerOutput.steps],\n variables: { ...plannerOutput.variables },\n step_results: [],\n is_complete: false,\n };\n}\n\nexport interface ExecutionContext {\n // Request information\n original_request: string;\n understanding: string;\n\n // Planning state\n initial_plan: PlanStep[];\n current_plan: PlanStep[];\n\n // Data collected\n variables: Record<string, string | number | boolean>;\n\n // Execution history\n step_results: string[];\n\n // Status\n is_complete: boolean;\n success_criteria_met?: boolean;\n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AQ,aAAa,MAAM,CAAC;AACnD,QAAM,iBAAiB,IAAI,cAAc;AAAA,IACvC,OAAO,IAAI,qBAAqB;AAAA,IAChC,QAAQ,aAAa,OAAO,WAAW,CAAC;AAAA,IACxC,QAAQ;AAAA,EACV,CAAC;AAED,iBAAe;AAAA,IACb,QAAQ;AAAA,MACN,MAAM;AAAA,MACN,MAAM;AAAA,MACN,WACE;AAAA,IACJ,CAAC;AAAA,IACD,SAAS,0BAA0B,sBAAsB,CAAC;AAAA,IAC1D,KAAK,sBAAsB,SAAS,cAAc,CAAC;AAAA,EACrD;AAEA,QAAM,kBAAkB,iBAAiB;AAAA,IACvC,OAAO;AAAA,IACP,SAAS;AAAA,IACT,QAAQ;AAAA,EACV,CAAC;AAED,QAAM,SAAS,MAAM,gBAAgB,SAAS;AAC9C,QAAM,WAAW;AAIjB,SAAO;AAAA,IACL,GAAG;AAAA,IACH,cAAc,SAAS;AAAA,IACvB,aAAa,CAAC,SAAS;AAAA,EACzB;AACF;",
|
|
6
|
+
"names": ["defaultSettingsMiddleware", "wrapLanguageModel", "wrapLanguageModel", "defaultSettingsMiddleware"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
// packages/orchestrator/src/lib/deepplan/synthesizer.ts
|
|
2
|
+
import { agent, execute, lmstudio, user } from "@deepagents/agent";
|
|
3
|
+
var synthesizer = agent({
|
|
4
|
+
name: "synthesizer_agent",
|
|
5
|
+
model: lmstudio("google/gemma-3-12b"),
|
|
6
|
+
prompt: `
|
|
7
|
+
<SystemContext>
|
|
8
|
+
You are a synthesizer agent that compiles the results of executed plan steps into a final answer.
|
|
9
|
+
You ensure accuracy and coherence in the final output.
|
|
10
|
+
</SystemContext>
|
|
11
|
+
|
|
12
|
+
<Identity>
|
|
13
|
+
Your task is to take the individual step results and synthesize them into a coherent final response that addresses the original user request.
|
|
14
|
+
</Identity>
|
|
15
|
+
|
|
16
|
+
<ConstraintDetection>
|
|
17
|
+
**CRITICAL: Check the original request for output constraints FIRST**
|
|
18
|
+
</ConstraintDetection>
|
|
19
|
+
|
|
20
|
+
<SynthesisPrinciples>
|
|
21
|
+
1. **Verify Numerical Accuracy**
|
|
22
|
+
- Check all numerical values for consistency
|
|
23
|
+
- Ensure calculations are correct across steps
|
|
24
|
+
- Verify dates, counts, and measurements make sense
|
|
25
|
+
|
|
26
|
+
2. **Apply Commonsense Validation**
|
|
27
|
+
- Do the results make logical sense?
|
|
28
|
+
- Are there any contradictions or inconsistencies?
|
|
29
|
+
- Do temporal relationships align (e.g., dates in proper order)?
|
|
30
|
+
|
|
31
|
+
3. **Aggregate Intermediate Results**
|
|
32
|
+
- Combine findings from multiple steps coherently
|
|
33
|
+
- Preserve important numerical details
|
|
34
|
+
- Show clear connections between steps
|
|
35
|
+
|
|
36
|
+
4. **Show the Answer Clearly**
|
|
37
|
+
- Present the final answer in a structured format
|
|
38
|
+
- Highlight key numerical findings
|
|
39
|
+
- Make the conclusion explicit and unambiguous
|
|
40
|
+
</SynthesisPrinciples>
|
|
41
|
+
|
|
42
|
+
<Instructions>
|
|
43
|
+
1. **Read the original user request carefully** and identify any output constraints
|
|
44
|
+
2. Review all step results carefully
|
|
45
|
+
3. **Verify numerical consistency and commonsense**
|
|
46
|
+
4. If constraints exist: compile results according to constraints (minimal output)
|
|
47
|
+
5. If no constraints: synthesize insights into a comprehensive answer
|
|
48
|
+
6. **Show the answer clearly** with verified numbers and logical coherence
|
|
49
|
+
|
|
50
|
+
CRITICAL:
|
|
51
|
+
- Always prioritize explicit constraints over comprehensive analysis
|
|
52
|
+
- When in doubt about constraints, prefer minimal output
|
|
53
|
+
- Verify numerical accuracy before finalizing
|
|
54
|
+
- Check for commonsense and logical coherence
|
|
55
|
+
- The final answer should be well-structured and easy to understand
|
|
56
|
+
</Instructions>
|
|
57
|
+
`
|
|
58
|
+
});
|
|
59
|
+
async function synthesize(stepResults, originalRequest) {
|
|
60
|
+
const stepResultsText = stepResults.map((step, index) => `Step ${index + 1} Result:
|
|
61
|
+
${step}`).join("\n\n");
|
|
62
|
+
const prompt = `
|
|
63
|
+
Original User Request:
|
|
64
|
+
${originalRequest}
|
|
65
|
+
|
|
66
|
+
---
|
|
67
|
+
|
|
68
|
+
${stepResultsText}
|
|
69
|
+
`.trim();
|
|
70
|
+
return (await execute(synthesizer, [user(prompt)], {})).text;
|
|
71
|
+
}
|
|
72
|
+
export {
|
|
73
|
+
synthesize
|
|
74
|
+
};
|
|
75
|
+
//# sourceMappingURL=synthesizer.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/lib/deepplan/synthesizer.ts"],
|
|
4
|
+
"sourcesContent": ["import { agent, execute, lmstudio, user } from '@deepagents/agent';\n\n/**\n * Synthesizer agent that compiles step results into a final answer\n * Applies numerical accuracy and commonsense validation\n */\nconst synthesizer = agent({\n name: 'synthesizer_agent',\n model: lmstudio('google/gemma-3-12b'),\n prompt: `\n\t\t<SystemContext>\n\t\t\tYou are a synthesizer agent that compiles the results of executed plan steps into a final answer.\n\t\t\tYou ensure accuracy and coherence in the final output.\n\t\t</SystemContext>\n\n\t\t<Identity>\n\t\t\tYour task is to take the individual step results and synthesize them into a coherent final response that addresses the original user request.\n\t\t</Identity>\n\n\t\t<ConstraintDetection>\n\t\t\t**CRITICAL: Check the original request for output constraints FIRST**\n\t\t</ConstraintDetection>\n\n\t\t<SynthesisPrinciples>\n\t\t\t1. **Verify Numerical Accuracy**\n\t\t\t\t - Check all numerical values for consistency\n\t\t\t\t - Ensure calculations are correct across steps\n\t\t\t\t - Verify dates, counts, and measurements make sense\n\n\t\t\t2. **Apply Commonsense Validation**\n\t\t\t\t - Do the results make logical sense?\n\t\t\t\t - Are there any contradictions or inconsistencies?\n\t\t\t\t - Do temporal relationships align (e.g., dates in proper order)?\n\n\t\t\t3. **Aggregate Intermediate Results**\n\t\t\t\t - Combine findings from multiple steps coherently\n\t\t\t\t - Preserve important numerical details\n\t\t\t\t - Show clear connections between steps\n\n\t\t\t4. **Show the Answer Clearly**\n\t\t\t\t - Present the final answer in a structured format\n\t\t\t\t - Highlight key numerical findings\n\t\t\t\t - Make the conclusion explicit and unambiguous\n\t\t</SynthesisPrinciples>\n\n\t\t<Instructions>\n\t\t\t1. **Read the original user request carefully** and identify any output constraints\n\t\t\t2. Review all step results carefully\n\t\t\t3. **Verify numerical consistency and commonsense**\n\t\t\t4. If constraints exist: compile results according to constraints (minimal output)\n\t\t\t5. If no constraints: synthesize insights into a comprehensive answer\n\t\t\t6. **Show the answer clearly** with verified numbers and logical coherence\n\n\t\t\tCRITICAL:\n\t\t\t- Always prioritize explicit constraints over comprehensive analysis\n\t\t\t- When in doubt about constraints, prefer minimal output\n\t\t\t- Verify numerical accuracy before finalizing\n\t\t\t- Check for commonsense and logical coherence\n\t\t\t- The final answer should be well-structured and easy to understand\n\t\t</Instructions>\n\t`,\n});\n\nexport async function synthesize(\n stepResults: string[],\n originalRequest: string,\n) {\n const stepResultsText = stepResults\n .map((step, index) => `Step ${index + 1} Result:\\n${step}`)\n .join('\\n\\n');\n\n const prompt = `\nOriginal User Request:\n${originalRequest}\n\n---\n\n${stepResultsText}\n `.trim();\n\n return (await execute(synthesizer, [user(prompt)], {})).text;\n}\n"],
|
|
5
|
+
"mappings": ";AAAA,SAAS,OAAO,SAAS,UAAU,YAAY;AAM/C,IAAM,cAAc,MAAM;AAAA,EACxB,MAAM;AAAA,EACN,OAAO,SAAS,oBAAoB;AAAA,EACpC,QAAQ;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;AAoDV,CAAC;AAED,eAAsB,WACpB,aACA,iBACA;AACA,QAAM,kBAAkB,YACrB,IAAI,CAAC,MAAM,UAAU,QAAQ,QAAQ,CAAC;AAAA,EAAa,IAAI,EAAE,EACzD,KAAK,MAAM;AAEd,QAAM,SAAS;AAAA;AAAA,EAEf,eAAe;AAAA;AAAA;AAAA;AAAA,EAIf,eAAe;AAAA,IACb,KAAK;AAEP,UAAQ,MAAM,QAAQ,aAAa,CAAC,KAAK,MAAM,CAAC,GAAG,CAAC,CAAC,GAAG;AAC1D;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|