confused-ai-core 0.1.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/FEATURES.md +169 -0
- package/package.json +119 -0
- package/src/agent.ts +187 -0
- package/src/agentic/index.ts +87 -0
- package/src/agentic/runner.ts +386 -0
- package/src/agentic/types.ts +91 -0
- package/src/artifacts/artifact.ts +417 -0
- package/src/artifacts/index.ts +42 -0
- package/src/artifacts/media.ts +304 -0
- package/src/cli/index.ts +122 -0
- package/src/core/base-agent.ts +151 -0
- package/src/core/context-builder.ts +106 -0
- package/src/core/index.ts +8 -0
- package/src/core/schemas.ts +17 -0
- package/src/core/types.ts +158 -0
- package/src/create-agent.ts +309 -0
- package/src/debug-logger.ts +188 -0
- package/src/dx/agent.ts +88 -0
- package/src/dx/define-agent.ts +183 -0
- package/src/dx/dev-logger.ts +57 -0
- package/src/dx/index.ts +11 -0
- package/src/errors.ts +175 -0
- package/src/execution/engine.ts +522 -0
- package/src/execution/graph-builder.ts +362 -0
- package/src/execution/index.ts +8 -0
- package/src/execution/types.ts +257 -0
- package/src/execution/worker-pool.ts +308 -0
- package/src/extensions/index.ts +123 -0
- package/src/guardrails/allowlist.ts +155 -0
- package/src/guardrails/index.ts +17 -0
- package/src/guardrails/types.ts +159 -0
- package/src/guardrails/validator.ts +265 -0
- package/src/index.ts +74 -0
- package/src/knowledge/index.ts +5 -0
- package/src/knowledge/types.ts +52 -0
- package/src/learning/in-memory-store.ts +72 -0
- package/src/learning/index.ts +6 -0
- package/src/learning/types.ts +42 -0
- package/src/llm/cache.ts +300 -0
- package/src/llm/index.ts +22 -0
- package/src/llm/model-resolver.ts +81 -0
- package/src/llm/openai-provider.ts +313 -0
- package/src/llm/openrouter-provider.ts +29 -0
- package/src/llm/types.ts +131 -0
- package/src/memory/in-memory-store.ts +255 -0
- package/src/memory/index.ts +7 -0
- package/src/memory/types.ts +193 -0
- package/src/memory/vector-store.ts +251 -0
- package/src/observability/console-logger.ts +123 -0
- package/src/observability/index.ts +12 -0
- package/src/observability/metrics.ts +85 -0
- package/src/observability/otlp-exporter.ts +417 -0
- package/src/observability/tracer.ts +105 -0
- package/src/observability/types.ts +341 -0
- package/src/orchestration/agent-adapter.ts +33 -0
- package/src/orchestration/index.ts +34 -0
- package/src/orchestration/load-balancer.ts +151 -0
- package/src/orchestration/mcp-types.ts +59 -0
- package/src/orchestration/message-bus.ts +192 -0
- package/src/orchestration/orchestrator.ts +349 -0
- package/src/orchestration/pipeline.ts +66 -0
- package/src/orchestration/supervisor.ts +107 -0
- package/src/orchestration/swarm.ts +1099 -0
- package/src/orchestration/toolkit.ts +47 -0
- package/src/orchestration/types.ts +339 -0
- package/src/planner/classical-planner.ts +383 -0
- package/src/planner/index.ts +8 -0
- package/src/planner/llm-planner.ts +353 -0
- package/src/planner/types.ts +227 -0
- package/src/planner/validator.ts +297 -0
- package/src/production/circuit-breaker.ts +290 -0
- package/src/production/graceful-shutdown.ts +251 -0
- package/src/production/health.ts +333 -0
- package/src/production/index.ts +57 -0
- package/src/production/latency-eval.ts +62 -0
- package/src/production/rate-limiter.ts +287 -0
- package/src/production/resumable-stream.ts +289 -0
- package/src/production/types.ts +81 -0
- package/src/sdk/index.ts +374 -0
- package/src/session/db-driver.ts +50 -0
- package/src/session/in-memory-store.ts +235 -0
- package/src/session/index.ts +12 -0
- package/src/session/sql-store.ts +315 -0
- package/src/session/sqlite-store.ts +61 -0
- package/src/session/types.ts +153 -0
- package/src/tools/base-tool.ts +223 -0
- package/src/tools/browser-tool.ts +123 -0
- package/src/tools/calculator-tool.ts +265 -0
- package/src/tools/file-tools.ts +394 -0
- package/src/tools/github-tool.ts +432 -0
- package/src/tools/hackernews-tool.ts +187 -0
- package/src/tools/http-tool.ts +118 -0
- package/src/tools/index.ts +99 -0
- package/src/tools/jira-tool.ts +373 -0
- package/src/tools/notion-tool.ts +322 -0
- package/src/tools/openai-tool.ts +236 -0
- package/src/tools/registry.ts +131 -0
- package/src/tools/serpapi-tool.ts +234 -0
- package/src/tools/shell-tool.ts +118 -0
- package/src/tools/slack-tool.ts +327 -0
- package/src/tools/telegram-tool.ts +127 -0
- package/src/tools/types.ts +229 -0
- package/src/tools/websearch-tool.ts +335 -0
- package/src/tools/wikipedia-tool.ts +177 -0
- package/src/tools/yfinance-tool.ts +33 -0
- package/src/voice/index.ts +17 -0
- package/src/voice/voice-provider.ts +228 -0
- package/tests/artifact.test.ts +241 -0
- package/tests/circuit-breaker.test.ts +171 -0
- package/tests/health.test.ts +192 -0
- package/tests/llm-cache.test.ts +186 -0
- package/tests/rate-limiter.test.ts +161 -0
- package/tsconfig.json +29 -0
- package/vitest.config.ts +47 -0
|
@@ -0,0 +1,353 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* LLM-based planner implementation
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import {
|
|
6
|
+
Planner,
|
|
7
|
+
Plan,
|
|
8
|
+
PlanContext,
|
|
9
|
+
PlanFeedback,
|
|
10
|
+
ValidationResult,
|
|
11
|
+
Task,
|
|
12
|
+
TaskPriority,
|
|
13
|
+
LLMPlannerConfig,
|
|
14
|
+
} from './types.js';
|
|
15
|
+
import type { EntityId } from '../core/types.js';
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* LLM provider interface for planning
|
|
19
|
+
*/
|
|
20
|
+
interface LLMProvider {
|
|
21
|
+
generateText(prompt: string, options?: { temperature?: number; maxTokens?: number }): Promise<string>;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* LLM-based planner that uses language models for task decomposition
|
|
26
|
+
*/
|
|
27
|
+
export class LLMPlanner implements Planner {
|
|
28
|
+
private config: Required<LLMPlannerConfig>;
|
|
29
|
+
private llmProvider: LLMProvider;
|
|
30
|
+
|
|
31
|
+
constructor(config: LLMPlannerConfig, llmProvider: LLMProvider) {
|
|
32
|
+
this.config = {
|
|
33
|
+
maxIterations: config.maxIterations ?? 10,
|
|
34
|
+
timeoutMs: config.timeoutMs ?? 60000,
|
|
35
|
+
allowParallelExecution: config.allowParallelExecution ?? true,
|
|
36
|
+
retryPolicy: config.retryPolicy ?? {
|
|
37
|
+
maxRetries: 3,
|
|
38
|
+
backoffMs: 1000,
|
|
39
|
+
maxBackoffMs: 30000,
|
|
40
|
+
exponentialBase: 2,
|
|
41
|
+
},
|
|
42
|
+
model: config.model,
|
|
43
|
+
temperature: config.temperature ?? 0.7,
|
|
44
|
+
maxTokens: config.maxTokens ?? 2000,
|
|
45
|
+
systemPrompt: config.systemPrompt ?? this.getDefaultSystemPrompt(),
|
|
46
|
+
};
|
|
47
|
+
this.llmProvider = llmProvider;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
async plan(goal: string, context?: PlanContext): Promise<Plan> {
|
|
51
|
+
const planId = this.generateId();
|
|
52
|
+
|
|
53
|
+
// Build the planning prompt
|
|
54
|
+
const prompt = this.buildPlanningPrompt(goal, context);
|
|
55
|
+
|
|
56
|
+
// Generate plan from LLM
|
|
57
|
+
const response = await this.llmProvider.generateText(prompt, {
|
|
58
|
+
temperature: this.config.temperature,
|
|
59
|
+
maxTokens: this.config.maxTokens,
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
// Parse tasks from LLM response
|
|
63
|
+
const tasks = this.parseTasksFromResponse(response, context);
|
|
64
|
+
|
|
65
|
+
// Build dependencies
|
|
66
|
+
this.buildDependencies(tasks);
|
|
67
|
+
|
|
68
|
+
const plan: Plan = {
|
|
69
|
+
id: planId,
|
|
70
|
+
goal,
|
|
71
|
+
tasks,
|
|
72
|
+
createdAt: new Date(),
|
|
73
|
+
metadata: {
|
|
74
|
+
plannerType: 'llm',
|
|
75
|
+
estimatedTotalDurationMs: this.calculateTotalDuration(tasks),
|
|
76
|
+
confidence: this.estimateConfidence(tasks, response),
|
|
77
|
+
context: context?.metadata,
|
|
78
|
+
},
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
return plan;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
async refine(plan: Plan, feedback: PlanFeedback): Promise<Plan> {
|
|
85
|
+
const prompt = this.buildRefinementPrompt(plan, feedback);
|
|
86
|
+
|
|
87
|
+
const response = await this.llmProvider.generateText(prompt, {
|
|
88
|
+
temperature: this.config.temperature,
|
|
89
|
+
maxTokens: this.config.maxTokens,
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
const refinedTasks = this.parseTasksFromResponse(response);
|
|
93
|
+
|
|
94
|
+
// Build dependencies
|
|
95
|
+
this.buildDependencies(refinedTasks);
|
|
96
|
+
|
|
97
|
+
return {
|
|
98
|
+
...plan,
|
|
99
|
+
tasks: refinedTasks,
|
|
100
|
+
metadata: {
|
|
101
|
+
...plan.metadata,
|
|
102
|
+
confidence: (plan.metadata.confidence ?? 0.5) * 0.9,
|
|
103
|
+
},
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
validate(plan: Plan): ValidationResult {
|
|
108
|
+
const errors: ValidationResult['errors'] = [];
|
|
109
|
+
|
|
110
|
+
// Check for circular dependencies
|
|
111
|
+
const visited = new Set<EntityId>();
|
|
112
|
+
const recursionStack = new Set<EntityId>();
|
|
113
|
+
|
|
114
|
+
const hasCycle = (taskId: EntityId, taskMap: Map<EntityId, Task>): boolean => {
|
|
115
|
+
visited.add(taskId);
|
|
116
|
+
recursionStack.add(taskId);
|
|
117
|
+
|
|
118
|
+
const task = taskMap.get(taskId);
|
|
119
|
+
if (task) {
|
|
120
|
+
for (const depId of task.dependencies) {
|
|
121
|
+
if (!visited.has(depId)) {
|
|
122
|
+
if (hasCycle(depId, taskMap)) {
|
|
123
|
+
return true;
|
|
124
|
+
}
|
|
125
|
+
} else if (recursionStack.has(depId)) {
|
|
126
|
+
return true;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
recursionStack.delete(taskId);
|
|
132
|
+
return false;
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
const taskMap = new Map(plan.tasks.map(t => [t.id, t]));
|
|
136
|
+
|
|
137
|
+
for (const task of plan.tasks) {
|
|
138
|
+
if (!visited.has(task.id)) {
|
|
139
|
+
if (hasCycle(task.id, taskMap)) {
|
|
140
|
+
errors.push({
|
|
141
|
+
taskId: task.id,
|
|
142
|
+
message: 'Circular dependency detected',
|
|
143
|
+
severity: 'error',
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
// Check for missing dependencies
|
|
149
|
+
for (const depId of task.dependencies) {
|
|
150
|
+
if (!taskMap.has(depId)) {
|
|
151
|
+
errors.push({
|
|
152
|
+
taskId: task.id,
|
|
153
|
+
message: `Missing dependency: ${depId}`,
|
|
154
|
+
severity: 'error',
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
// Validate task structure
|
|
160
|
+
if (!task.name || task.name.trim().length === 0) {
|
|
161
|
+
errors.push({
|
|
162
|
+
taskId: task.id,
|
|
163
|
+
message: 'Task name is required',
|
|
164
|
+
severity: 'error',
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
return {
|
|
170
|
+
valid: errors.length === 0,
|
|
171
|
+
errors,
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* Build the planning prompt for the LLM
|
|
177
|
+
*/
|
|
178
|
+
private buildPlanningPrompt(goal: string, context?: PlanContext): string {
|
|
179
|
+
const availableTools = context?.availableTools?.join(', ') ?? 'None specified';
|
|
180
|
+
const constraints = context?.constraints?.join('\n') ?? 'None specified';
|
|
181
|
+
const memory = context?.memory?.join('\n') ?? 'None available';
|
|
182
|
+
|
|
183
|
+
return `${this.config.systemPrompt}
|
|
184
|
+
|
|
185
|
+
Goal: ${goal}
|
|
186
|
+
|
|
187
|
+
Available Tools: ${availableTools}
|
|
188
|
+
|
|
189
|
+
Constraints:
|
|
190
|
+
${constraints}
|
|
191
|
+
|
|
192
|
+
Relevant Context from Memory:
|
|
193
|
+
${memory}
|
|
194
|
+
|
|
195
|
+
Please break down this goal into a sequence of tasks. For each task, provide:
|
|
196
|
+
1. Task name (short, descriptive)
|
|
197
|
+
2. Task description (detailed)
|
|
198
|
+
3. Priority (CRITICAL, HIGH, MEDIUM, LOW)
|
|
199
|
+
4. Estimated duration in milliseconds (optional)
|
|
200
|
+
|
|
201
|
+
Format your response as JSON:
|
|
202
|
+
{
|
|
203
|
+
"tasks": [
|
|
204
|
+
{
|
|
205
|
+
"name": "Task Name",
|
|
206
|
+
"description": "Detailed description of what this task does",
|
|
207
|
+
"priority": "HIGH",
|
|
208
|
+
"estimatedDurationMs": 5000
|
|
209
|
+
}
|
|
210
|
+
]
|
|
211
|
+
}`;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
/**
|
|
215
|
+
* Build the refinement prompt
|
|
216
|
+
*/
|
|
217
|
+
private buildRefinementPrompt(plan: Plan, feedback: PlanFeedback): string {
|
|
218
|
+
const tasksJson = JSON.stringify(plan.tasks, null, 2);
|
|
219
|
+
|
|
220
|
+
return `${this.config.systemPrompt}
|
|
221
|
+
|
|
222
|
+
The following plan failed during execution:
|
|
223
|
+
|
|
224
|
+
Goal: ${plan.goal}
|
|
225
|
+
|
|
226
|
+
Current Tasks:
|
|
227
|
+
${tasksJson}
|
|
228
|
+
|
|
229
|
+
Failed Task: ${feedback.failedTaskId ?? 'Unknown'}
|
|
230
|
+
Error: ${feedback.error ?? 'Unknown error'}
|
|
231
|
+
|
|
232
|
+
Suggestions for improvement:
|
|
233
|
+
${feedback.suggestions?.join('\n') ?? 'None provided'}
|
|
234
|
+
|
|
235
|
+
Please provide a refined plan that addresses these issues. Return the complete updated task list in the same JSON format.`;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
/**
|
|
239
|
+
* Parse tasks from LLM response
|
|
240
|
+
*/
|
|
241
|
+
private parseTasksFromResponse(response: string, context?: PlanContext): Task[] {
|
|
242
|
+
try {
|
|
243
|
+
// Try to extract JSON from the response
|
|
244
|
+
const jsonMatch = response.match(/\{[\s\S]*\}/);
|
|
245
|
+
if (!jsonMatch) {
|
|
246
|
+
throw new Error('No JSON found in response');
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
const parsed = JSON.parse(jsonMatch[0]);
|
|
250
|
+
const taskData = parsed.tasks ?? parsed;
|
|
251
|
+
|
|
252
|
+
if (!Array.isArray(taskData)) {
|
|
253
|
+
throw new Error('Expected tasks array in response');
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
return taskData.map((data: Record<string, unknown>, index: number) => ({
|
|
257
|
+
id: this.generateId(),
|
|
258
|
+
name: String(data.name ?? `Task ${index + 1}`),
|
|
259
|
+
description: String(data.description ?? ''),
|
|
260
|
+
dependencies: Array.isArray(data.dependencies) ? data.dependencies : [],
|
|
261
|
+
estimatedDurationMs: typeof data.estimatedDurationMs === 'number'
|
|
262
|
+
? data.estimatedDurationMs
|
|
263
|
+
: undefined,
|
|
264
|
+
priority: this.parsePriority(data.priority),
|
|
265
|
+
metadata: {
|
|
266
|
+
toolIds: context?.availableTools,
|
|
267
|
+
...((data.metadata as Record<string, unknown>) ?? {}),
|
|
268
|
+
},
|
|
269
|
+
}));
|
|
270
|
+
} catch (error) {
|
|
271
|
+
// Fallback: create a single task with the raw response
|
|
272
|
+
return [{
|
|
273
|
+
id: this.generateId(),
|
|
274
|
+
name: 'Execute Plan',
|
|
275
|
+
description: response,
|
|
276
|
+
dependencies: [],
|
|
277
|
+
priority: TaskPriority.MEDIUM,
|
|
278
|
+
metadata: {},
|
|
279
|
+
}];
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
/**
|
|
284
|
+
* Parse priority from string
|
|
285
|
+
*/
|
|
286
|
+
private parsePriority(priority: unknown): TaskPriority {
|
|
287
|
+
const priorityMap: Record<string, TaskPriority> = {
|
|
288
|
+
'CRITICAL': TaskPriority.CRITICAL,
|
|
289
|
+
'HIGH': TaskPriority.HIGH,
|
|
290
|
+
'MEDIUM': TaskPriority.MEDIUM,
|
|
291
|
+
'LOW': TaskPriority.LOW,
|
|
292
|
+
};
|
|
293
|
+
|
|
294
|
+
return priorityMap[String(priority).toUpperCase()] ?? TaskPriority.MEDIUM;
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
/**
|
|
298
|
+
* Build task dependencies
|
|
299
|
+
*/
|
|
300
|
+
private buildDependencies(tasks: Task[]): void {
|
|
301
|
+
// Simple sequential dependency for tasks without explicit dependencies
|
|
302
|
+
for (let i = 1; i < tasks.length; i++) {
|
|
303
|
+
const task = tasks[i];
|
|
304
|
+
if (task.dependencies.length === 0) {
|
|
305
|
+
Object.assign(task, {
|
|
306
|
+
dependencies: [tasks[i - 1].id],
|
|
307
|
+
});
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
/**
|
|
313
|
+
* Calculate total plan duration
|
|
314
|
+
*/
|
|
315
|
+
private calculateTotalDuration(tasks: Task[]): number {
|
|
316
|
+
return tasks.reduce((sum, task) => sum + (task.estimatedDurationMs ?? 5000), 0);
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
/**
|
|
320
|
+
* Estimate confidence based on response quality
|
|
321
|
+
*/
|
|
322
|
+
private estimateConfidence(tasks: Task[], response: string): number {
|
|
323
|
+
// Simple heuristic based on task count and response length
|
|
324
|
+
const baseConfidence = 0.7;
|
|
325
|
+
const taskBonus = Math.min(tasks.length * 0.05, 0.2);
|
|
326
|
+
const lengthBonus = response.length > 500 ? 0.1 : 0;
|
|
327
|
+
|
|
328
|
+
return Math.min(baseConfidence + taskBonus + lengthBonus, 1.0);
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
/**
|
|
332
|
+
* Generate a unique ID
|
|
333
|
+
*/
|
|
334
|
+
private generateId(): EntityId {
|
|
335
|
+
return `llm-task-${Date.now()}-${Math.random().toString(36).substring(2, 11)}`;
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
/**
|
|
339
|
+
* Get the default system prompt
|
|
340
|
+
*/
|
|
341
|
+
private getDefaultSystemPrompt(): string {
|
|
342
|
+
return `You are an expert task planner. Your role is to break down complex goals into manageable, sequential tasks.
|
|
343
|
+
|
|
344
|
+
Guidelines:
|
|
345
|
+
- Create clear, actionable tasks
|
|
346
|
+
- Consider dependencies between tasks
|
|
347
|
+
- Assign appropriate priorities
|
|
348
|
+
- Estimate realistic durations
|
|
349
|
+
- Use available tools effectively
|
|
350
|
+
|
|
351
|
+
Respond with valid JSON only.`;
|
|
352
|
+
}
|
|
353
|
+
}
|
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Planner types and interfaces
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import type { EntityId } from '../core/types.js';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Task definition in a plan
|
|
9
|
+
*/
|
|
10
|
+
export interface Task {
|
|
11
|
+
readonly id: EntityId;
|
|
12
|
+
readonly name: string;
|
|
13
|
+
readonly description: string;
|
|
14
|
+
readonly dependencies: EntityId[];
|
|
15
|
+
readonly estimatedDurationMs?: number;
|
|
16
|
+
readonly priority: TaskPriority;
|
|
17
|
+
readonly metadata: TaskMetadata;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Task priority levels
|
|
22
|
+
*/
|
|
23
|
+
export enum TaskPriority {
|
|
24
|
+
CRITICAL = 0,
|
|
25
|
+
HIGH = 1,
|
|
26
|
+
MEDIUM = 2,
|
|
27
|
+
LOW = 3,
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Task metadata
|
|
32
|
+
*/
|
|
33
|
+
export interface TaskMetadata {
|
|
34
|
+
readonly toolIds?: EntityId[];
|
|
35
|
+
readonly requiredMemory?: string[];
|
|
36
|
+
readonly outputKey?: string;
|
|
37
|
+
readonly maxRetries?: number;
|
|
38
|
+
readonly timeoutMs?: number;
|
|
39
|
+
readonly custom?: Record<string, unknown>;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Task execution status
|
|
44
|
+
*/
|
|
45
|
+
export enum TaskStatus {
|
|
46
|
+
PENDING = 'pending',
|
|
47
|
+
RUNNING = 'running',
|
|
48
|
+
COMPLETED = 'completed',
|
|
49
|
+
FAILED = 'failed',
|
|
50
|
+
CANCELLED = 'cancelled',
|
|
51
|
+
SKIPPED = 'skipped',
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Task result
|
|
56
|
+
*/
|
|
57
|
+
export interface TaskResult {
|
|
58
|
+
readonly taskId: EntityId;
|
|
59
|
+
readonly status: TaskStatus;
|
|
60
|
+
readonly output?: unknown;
|
|
61
|
+
readonly error?: TaskError;
|
|
62
|
+
readonly executionTimeMs: number;
|
|
63
|
+
readonly startedAt: Date;
|
|
64
|
+
readonly completedAt?: Date;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Task error details
|
|
69
|
+
*/
|
|
70
|
+
export interface TaskError {
|
|
71
|
+
readonly code: string;
|
|
72
|
+
readonly message: string;
|
|
73
|
+
readonly stack?: string;
|
|
74
|
+
readonly retryable: boolean;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* A plan consisting of tasks with dependencies
|
|
79
|
+
*/
|
|
80
|
+
export interface Plan {
|
|
81
|
+
readonly id: EntityId;
|
|
82
|
+
readonly goal: string;
|
|
83
|
+
readonly tasks: Task[];
|
|
84
|
+
readonly createdAt: Date;
|
|
85
|
+
readonly metadata: PlanMetadata;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Plan metadata
|
|
90
|
+
*/
|
|
91
|
+
export interface PlanMetadata {
|
|
92
|
+
readonly plannerType: string;
|
|
93
|
+
readonly estimatedTotalDurationMs?: number;
|
|
94
|
+
readonly confidence?: number;
|
|
95
|
+
readonly context?: Record<string, unknown>;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Plan execution result
|
|
100
|
+
*/
|
|
101
|
+
export interface PlanExecutionResult {
|
|
102
|
+
readonly planId: EntityId;
|
|
103
|
+
readonly status: PlanExecutionStatus;
|
|
104
|
+
readonly taskResults: Map<EntityId, TaskResult>;
|
|
105
|
+
readonly startedAt: Date;
|
|
106
|
+
readonly completedAt?: Date;
|
|
107
|
+
readonly totalExecutionTimeMs: number;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Plan execution status
|
|
112
|
+
*/
|
|
113
|
+
export enum PlanExecutionStatus {
|
|
114
|
+
PENDING = 'pending',
|
|
115
|
+
RUNNING = 'running',
|
|
116
|
+
COMPLETED = 'completed',
|
|
117
|
+
PARTIAL = 'partial',
|
|
118
|
+
FAILED = 'failed',
|
|
119
|
+
CANCELLED = 'cancelled',
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Planner configuration
|
|
124
|
+
*/
|
|
125
|
+
export interface PlannerConfig {
|
|
126
|
+
readonly maxIterations?: number;
|
|
127
|
+
readonly timeoutMs?: number;
|
|
128
|
+
readonly allowParallelExecution?: boolean;
|
|
129
|
+
readonly retryPolicy?: RetryPolicy;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* Retry policy for tasks
|
|
134
|
+
*/
|
|
135
|
+
export interface RetryPolicy {
|
|
136
|
+
readonly maxRetries: number;
|
|
137
|
+
readonly backoffMs: number;
|
|
138
|
+
readonly maxBackoffMs: number;
|
|
139
|
+
readonly exponentialBase: number;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* Abstract planner interface
|
|
144
|
+
*/
|
|
145
|
+
export interface Planner {
|
|
146
|
+
/**
|
|
147
|
+
* Create a plan from a goal
|
|
148
|
+
*/
|
|
149
|
+
plan(goal: string, context?: PlanContext): Promise<Plan>;
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* Refine an existing plan based on feedback
|
|
153
|
+
*/
|
|
154
|
+
refine(plan: Plan, feedback: PlanFeedback): Promise<Plan>;
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* Validate if a plan is executable
|
|
158
|
+
*/
|
|
159
|
+
validate(plan: Plan): ValidationResult;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* Context for planning
|
|
164
|
+
*/
|
|
165
|
+
export interface PlanContext {
|
|
166
|
+
readonly availableTools?: string[];
|
|
167
|
+
readonly memory?: string[];
|
|
168
|
+
readonly constraints?: string[];
|
|
169
|
+
readonly previousPlans?: Plan[];
|
|
170
|
+
readonly metadata?: Record<string, unknown>;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* Feedback for plan refinement
|
|
175
|
+
*/
|
|
176
|
+
export interface PlanFeedback {
|
|
177
|
+
readonly failedTaskId?: EntityId;
|
|
178
|
+
readonly error?: string;
|
|
179
|
+
readonly suggestions?: string[];
|
|
180
|
+
readonly additionalContext?: Record<string, unknown>;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* Validation result
|
|
185
|
+
*/
|
|
186
|
+
export interface ValidationResult {
|
|
187
|
+
readonly valid: boolean;
|
|
188
|
+
readonly errors: ValidationError[];
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
/**
|
|
192
|
+
* Validation error
|
|
193
|
+
*/
|
|
194
|
+
export interface ValidationError {
|
|
195
|
+
readonly taskId?: EntityId;
|
|
196
|
+
readonly message: string;
|
|
197
|
+
readonly severity: 'error' | 'warning';
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
/**
|
|
201
|
+
* LLM-based planner configuration
|
|
202
|
+
*/
|
|
203
|
+
export interface LLMPlannerConfig extends PlannerConfig {
|
|
204
|
+
readonly model: string;
|
|
205
|
+
readonly temperature?: number;
|
|
206
|
+
readonly maxTokens?: number;
|
|
207
|
+
readonly systemPrompt?: string;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
/**
|
|
211
|
+
* Classical planner configuration
|
|
212
|
+
*/
|
|
213
|
+
export interface ClassicalPlannerConfig extends PlannerConfig {
|
|
214
|
+
readonly algorithm: PlanningAlgorithm;
|
|
215
|
+
readonly heuristic?: string;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
/**
|
|
219
|
+
* Planning algorithms
|
|
220
|
+
*/
|
|
221
|
+
export enum PlanningAlgorithm {
|
|
222
|
+
A_STAR = 'a_star',
|
|
223
|
+
BFS = 'bfs',
|
|
224
|
+
DFS = 'dfs',
|
|
225
|
+
GREEDY = 'greedy',
|
|
226
|
+
HIERARCHICAL = 'hierarchical',
|
|
227
|
+
}
|