@modular-prompt/process 0.1.27 → 0.2.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/README.md +17 -2
- package/dist/workflows/agentic-workflow/agentic-workflow.d.ts +12 -8
- package/dist/workflows/agentic-workflow/agentic-workflow.d.ts.map +1 -1
- package/dist/workflows/agentic-workflow/agentic-workflow.js +182 -205
- package/dist/workflows/agentic-workflow/agentic-workflow.js.map +1 -1
- package/dist/workflows/agentic-workflow/index.d.ts +5 -2
- package/dist/workflows/agentic-workflow/index.d.ts.map +1 -1
- package/dist/workflows/agentic-workflow/index.js +5 -2
- package/dist/workflows/agentic-workflow/index.js.map +1 -1
- package/dist/workflows/agentic-workflow/process/builtin-tools.d.ts +24 -0
- package/dist/workflows/agentic-workflow/process/builtin-tools.d.ts.map +1 -0
- package/dist/workflows/agentic-workflow/process/builtin-tools.js +134 -0
- package/dist/workflows/agentic-workflow/process/builtin-tools.js.map +1 -0
- package/dist/workflows/agentic-workflow/process/format-helpers.d.ts +11 -0
- package/dist/workflows/agentic-workflow/process/format-helpers.d.ts.map +1 -0
- package/dist/workflows/agentic-workflow/process/format-helpers.js +18 -0
- package/dist/workflows/agentic-workflow/process/format-helpers.js.map +1 -0
- package/dist/workflows/agentic-workflow/process/index.d.ts +7 -0
- package/dist/workflows/agentic-workflow/process/index.d.ts.map +1 -0
- package/dist/workflows/agentic-workflow/process/index.js +7 -0
- package/dist/workflows/agentic-workflow/process/index.js.map +1 -0
- package/dist/workflows/agentic-workflow/process/query-with-tools.d.ts +37 -0
- package/dist/workflows/agentic-workflow/process/query-with-tools.d.ts.map +1 -0
- package/dist/workflows/agentic-workflow/process/query-with-tools.js +118 -0
- package/dist/workflows/agentic-workflow/process/query-with-tools.js.map +1 -0
- package/dist/workflows/agentic-workflow/task-types/execution-tasks.d.ts +35 -0
- package/dist/workflows/agentic-workflow/task-types/execution-tasks.d.ts.map +1 -0
- package/dist/workflows/agentic-workflow/task-types/execution-tasks.js +155 -0
- package/dist/workflows/agentic-workflow/task-types/execution-tasks.js.map +1 -0
- package/dist/workflows/agentic-workflow/task-types/index.d.ts +37 -0
- package/dist/workflows/agentic-workflow/task-types/index.d.ts.map +1 -0
- package/dist/workflows/agentic-workflow/task-types/index.js +95 -0
- package/dist/workflows/agentic-workflow/task-types/index.js.map +1 -0
- package/dist/workflows/agentic-workflow/task-types/output.d.ts +16 -0
- package/dist/workflows/agentic-workflow/task-types/output.d.ts.map +1 -0
- package/dist/workflows/agentic-workflow/task-types/output.js +31 -0
- package/dist/workflows/agentic-workflow/task-types/output.js.map +1 -0
- package/dist/workflows/agentic-workflow/task-types/planning.d.ts +19 -0
- package/dist/workflows/agentic-workflow/task-types/planning.d.ts.map +1 -0
- package/dist/workflows/agentic-workflow/task-types/planning.js +77 -0
- package/dist/workflows/agentic-workflow/task-types/planning.js.map +1 -0
- package/dist/workflows/agentic-workflow/types.d.ts +83 -37
- package/dist/workflows/agentic-workflow/types.d.ts.map +1 -1
- package/dist/workflows/agentic-workflow/types.js +27 -1
- package/dist/workflows/agentic-workflow/types.js.map +1 -1
- package/dist/workflows/concat-process-workflow.d.ts +3 -2
- package/dist/workflows/concat-process-workflow.d.ts.map +1 -1
- package/dist/workflows/concat-process-workflow.js +41 -5
- package/dist/workflows/concat-process-workflow.js.map +1 -1
- package/dist/workflows/default-workflow.d.ts +3 -2
- package/dist/workflows/default-workflow.d.ts.map +1 -1
- package/dist/workflows/default-workflow.js +14 -1
- package/dist/workflows/default-workflow.js.map +1 -1
- package/dist/workflows/dialogue-workflow.d.ts +3 -2
- package/dist/workflows/dialogue-workflow.d.ts.map +1 -1
- package/dist/workflows/dialogue-workflow.js +15 -3
- package/dist/workflows/dialogue-workflow.js.map +1 -1
- package/dist/workflows/driver-input.d.ts +16 -0
- package/dist/workflows/driver-input.d.ts.map +1 -0
- package/dist/workflows/driver-input.js +18 -0
- package/dist/workflows/driver-input.js.map +1 -0
- package/dist/workflows/index.d.ts +6 -3
- package/dist/workflows/index.d.ts.map +1 -1
- package/dist/workflows/index.js +5 -2
- package/dist/workflows/index.js.map +1 -1
- package/dist/workflows/self-prompting-workflow/self-prompting-workflow.d.ts +3 -2
- package/dist/workflows/self-prompting-workflow/self-prompting-workflow.d.ts.map +1 -1
- package/dist/workflows/self-prompting-workflow/self-prompting-workflow.js +4 -3
- package/dist/workflows/self-prompting-workflow/self-prompting-workflow.js.map +1 -1
- package/dist/workflows/stream-workflow.d.ts +3 -2
- package/dist/workflows/stream-workflow.d.ts.map +1 -1
- package/dist/workflows/stream-workflow.js +11 -3
- package/dist/workflows/stream-workflow.js.map +1 -1
- package/dist/workflows/summarize-workflow.d.ts +3 -2
- package/dist/workflows/summarize-workflow.d.ts.map +1 -1
- package/dist/workflows/summarize-workflow.js +11 -2
- package/dist/workflows/summarize-workflow.js.map +1 -1
- package/package.json +4 -3
- package/dist/workflows/agent-workflow.d.ts +0 -55
- package/dist/workflows/agent-workflow.d.ts.map +0 -1
- package/dist/workflows/agent-workflow.js +0 -337
- package/dist/workflows/agent-workflow.js.map +0 -1
- package/dist/workflows/agentic-workflow/modules/agentic.d.ts +0 -12
- package/dist/workflows/agentic-workflow/modules/agentic.d.ts.map +0 -1
- package/dist/workflows/agentic-workflow/modules/agentic.js +0 -22
- package/dist/workflows/agentic-workflow/modules/agentic.js.map +0 -1
- package/dist/workflows/agentic-workflow/modules/execution-freeform.d.ts +0 -15
- package/dist/workflows/agentic-workflow/modules/execution-freeform.d.ts.map +0 -1
- package/dist/workflows/agentic-workflow/modules/execution-freeform.js +0 -140
- package/dist/workflows/agentic-workflow/modules/execution-freeform.js.map +0 -1
- package/dist/workflows/agentic-workflow/modules/execution.d.ts +0 -11
- package/dist/workflows/agentic-workflow/modules/execution.d.ts.map +0 -1
- package/dist/workflows/agentic-workflow/modules/execution.js +0 -180
- package/dist/workflows/agentic-workflow/modules/execution.js.map +0 -1
- package/dist/workflows/agentic-workflow/modules/index.d.ts +0 -6
- package/dist/workflows/agentic-workflow/modules/index.d.ts.map +0 -1
- package/dist/workflows/agentic-workflow/modules/index.js +0 -7
- package/dist/workflows/agentic-workflow/modules/index.js.map +0 -1
- package/dist/workflows/agentic-workflow/modules/integration.d.ts +0 -11
- package/dist/workflows/agentic-workflow/modules/integration.d.ts.map +0 -1
- package/dist/workflows/agentic-workflow/modules/integration.js +0 -85
- package/dist/workflows/agentic-workflow/modules/integration.js.map +0 -1
- package/dist/workflows/agentic-workflow/modules/planning.d.ts +0 -11
- package/dist/workflows/agentic-workflow/modules/planning.d.ts.map +0 -1
- package/dist/workflows/agentic-workflow/modules/planning.js +0 -103
- package/dist/workflows/agentic-workflow/modules/planning.js.map +0 -1
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Task type registry and shared utilities
|
|
3
|
+
*/
|
|
4
|
+
import { config as planningConfig } from './planning.js';
|
|
5
|
+
import { config as outputConfig } from './output.js';
|
|
6
|
+
import { executionTaskConfigs } from './execution-tasks.js';
|
|
7
|
+
/**
|
|
8
|
+
* Task type registry.
|
|
9
|
+
* planning/output are special; execution tasks are auto-generated from EXECUTION_TASK_DEFS.
|
|
10
|
+
*/
|
|
11
|
+
const TASK_TYPE_REGISTRY = {
|
|
12
|
+
planning: planningConfig,
|
|
13
|
+
...executionTaskConfigs,
|
|
14
|
+
output: outputConfig,
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* Get task type configuration
|
|
18
|
+
*/
|
|
19
|
+
export function getTaskTypeConfig(taskType) {
|
|
20
|
+
return TASK_TYPE_REGISTRY[taskType];
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Convert execution log to MaterialElement array (previous task results)
|
|
24
|
+
*/
|
|
25
|
+
export function buildPreviousResultsMaterials(executionLog) {
|
|
26
|
+
return executionLog.map((log, index) => ({
|
|
27
|
+
type: 'material',
|
|
28
|
+
id: `task-result-${index}`,
|
|
29
|
+
title: `Task ${index + 1} result`,
|
|
30
|
+
content: log.result,
|
|
31
|
+
}));
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Build task list display for methodology section
|
|
35
|
+
*/
|
|
36
|
+
export function buildTaskListDisplay(ctx) {
|
|
37
|
+
if (!ctx.taskList || ctx.taskList.length === 0) {
|
|
38
|
+
return 'No tasks registered yet.';
|
|
39
|
+
}
|
|
40
|
+
const lines = [];
|
|
41
|
+
const currentIndex = ctx.currentTaskIndex ?? -1;
|
|
42
|
+
for (let i = 0; i < ctx.taskList.length; i++) {
|
|
43
|
+
const task = ctx.taskList[i];
|
|
44
|
+
let status;
|
|
45
|
+
if (i < currentIndex) {
|
|
46
|
+
status = '[completed]';
|
|
47
|
+
}
|
|
48
|
+
else if (i === currentIndex) {
|
|
49
|
+
status = '**[current]**';
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
status = '[pending]';
|
|
53
|
+
}
|
|
54
|
+
lines.push(`${i + 1}. (${task.taskType}): ${task.instruction} ${status}`);
|
|
55
|
+
}
|
|
56
|
+
return lines.join('\n');
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Common module shared by all task types.
|
|
60
|
+
* Provides workflow terms, methodology, and state information.
|
|
61
|
+
*/
|
|
62
|
+
export const taskCommon = {
|
|
63
|
+
terms: [
|
|
64
|
+
'- **Task**: A unit of work in the workflow. Each Task is executed by a separate AI instance.',
|
|
65
|
+
'- **Task Type**: Defines the role of a Task (e.g. think, toolCall, verify). The prompt is pre-configured for each type.',
|
|
66
|
+
'- **Focus**: The specific directive for the current Task — what to concentrate on and accomplish.',
|
|
67
|
+
],
|
|
68
|
+
methodology: [
|
|
69
|
+
'- We accomplish the Objective by executing Tasks sequentially.',
|
|
70
|
+
{
|
|
71
|
+
type: 'subsection',
|
|
72
|
+
title: 'Workflow Status / Current Task List',
|
|
73
|
+
items: [
|
|
74
|
+
(ctx) => buildTaskListDisplay(ctx),
|
|
75
|
+
],
|
|
76
|
+
},
|
|
77
|
+
],
|
|
78
|
+
};
|
|
79
|
+
/**
|
|
80
|
+
* Extract static text content from SectionContent.
|
|
81
|
+
* Only extracts strings, ignores DynamicContent and Elements.
|
|
82
|
+
*/
|
|
83
|
+
export function extractTextFromSection(section) {
|
|
84
|
+
if (!section)
|
|
85
|
+
return '';
|
|
86
|
+
const items = Array.isArray(section) ? section : [section];
|
|
87
|
+
const textParts = [];
|
|
88
|
+
for (const item of items) {
|
|
89
|
+
if (typeof item === 'string') {
|
|
90
|
+
textParts.push(item);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
return textParts.join('\n');
|
|
94
|
+
}
|
|
95
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/workflows/agentic-workflow/task-types/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAIH,OAAO,EAAE,MAAM,IAAI,cAAc,EAAE,MAAM,eAAe,CAAC;AACzD,OAAO,EAAE,MAAM,IAAI,YAAY,EAAE,MAAM,aAAa,CAAC;AACrD,OAAO,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AAY5D;;;GAGG;AACH,MAAM,kBAAkB,GAAqC;IAC3D,QAAQ,EAAE,cAAc;IACxB,GAAG,oBAAsD;IACzD,MAAM,EAAE,YAAY;CACe,CAAC;AAEtC;;GAEG;AACH,MAAM,UAAU,iBAAiB,CAAC,QAAkB;IAClD,OAAO,kBAAkB,CAAC,QAAQ,CAAC,CAAC;AACtC,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,6BAA6B,CAC3C,YAAuC;IAEvC,OAAO,YAAY,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,KAAK,EAAE,EAAE,CAAC,CAAC;QACvC,IAAI,EAAE,UAAmB;QACzB,EAAE,EAAE,eAAe,KAAK,EAAE;QAC1B,KAAK,EAAE,QAAQ,KAAK,GAAG,CAAC,SAAS;QACjC,OAAO,EAAE,GAAG,CAAC,MAAM;KACpB,CAAC,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oB,CAAC,GAAG,CAAC;aAC3D;SACF;KACF;CACF,CAAC;AAEF;;;GAGG;AACH,MAAM,UAAU,sBAAsB,CAAC,OAAwC;IAC7E,IAAI,CAAC,OAAO;QAAE,OAAO,EAAE,CAAC;IACxB,MAAM,KAAK,GAAG,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC;IAC3D,MAAM,SAAS,GAAa,EAAE,CAAC;IAC/B,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE,CAAC;YAC7B,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACvB,CAAC;IACH,CAAC;IACD,OAAO,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAC9B,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Output task type
|
|
3
|
+
*
|
|
4
|
+
* Uses the full userModule (passed via workflowBase) as the prompt.
|
|
5
|
+
* This module only adds:
|
|
6
|
+
* - An instruction to refer to the pre-computed task results in materials
|
|
7
|
+
* - The execution log as materials
|
|
8
|
+
*
|
|
9
|
+
* The model sees the original user prompt with task results injected,
|
|
10
|
+
* so it naturally produces the expected response.
|
|
11
|
+
*
|
|
12
|
+
* Tools: none
|
|
13
|
+
*/
|
|
14
|
+
import type { TaskTypeConfig } from './index.js';
|
|
15
|
+
export declare const config: TaskTypeConfig;
|
|
16
|
+
//# sourceMappingURL=output.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"output.d.ts","sourceRoot":"","sources":["../../../../src/workflows/agentic-workflow/task-types/output.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAIH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAgBjD,eAAO,MAAM,MAAM,EAAE,cAGpB,CAAC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Output task type
|
|
3
|
+
*
|
|
4
|
+
* Uses the full userModule (passed via workflowBase) as the prompt.
|
|
5
|
+
* This module only adds:
|
|
6
|
+
* - An instruction to refer to the pre-computed task results in materials
|
|
7
|
+
* - The execution log as materials
|
|
8
|
+
*
|
|
9
|
+
* The model sees the original user prompt with task results injected,
|
|
10
|
+
* so it naturally produces the expected response.
|
|
11
|
+
*
|
|
12
|
+
* Tools: none
|
|
13
|
+
*/
|
|
14
|
+
import { buildPreviousResultsMaterials } from './index.js';
|
|
15
|
+
const outputModule = {
|
|
16
|
+
instructions: [
|
|
17
|
+
'- Refer to the pre-computed results in materials to compose your response.',
|
|
18
|
+
],
|
|
19
|
+
materials: [
|
|
20
|
+
(ctx) => {
|
|
21
|
+
if (!ctx.executionLog?.length)
|
|
22
|
+
return null;
|
|
23
|
+
return buildPreviousResultsMaterials(ctx.executionLog);
|
|
24
|
+
},
|
|
25
|
+
],
|
|
26
|
+
};
|
|
27
|
+
export const config = {
|
|
28
|
+
module: outputModule,
|
|
29
|
+
builtinToolNames: [],
|
|
30
|
+
};
|
|
31
|
+
//# sourceMappingURL=output.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"output.js","sourceRoot":"","sources":["../../../../src/workflows/agentic-workflow/task-types/output.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAKH,OAAO,EAAE,6BAA6B,EAAE,MAAM,YAAY,CAAC;AAE3D,MAAM,YAAY,GAAyC;IACzD,YAAY,EAAE;QACZ,4EAA4E;KAC7E;IAED,SAAS,EAAE;QACT,CAAC,GAA2B,EAAE,EAAE;YAC9B,IAAI,CAAC,GAAG,CAAC,YAAY,EAAE,MAAM;gBAAE,OAAO,IAAI,CAAC;YAC3C,OAAO,6BAA6B,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC;QACzD,CAAC;KACF;CACF,CAAC;AAEF,MAAM,CAAC,MAAM,MAAM,GAAmB;IACpC,MAAM,EAAE,YAAY;IACpB,gBAAgB,EAAE,EAAE;CACrB,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Planning task type
|
|
3
|
+
*
|
|
4
|
+
* Analyzes the user prompt and extracts complexity to design a task sequence.
|
|
5
|
+
* The userModule is converted to a single formatted material ("Prompt to analyze")
|
|
6
|
+
* using distribute() + formatCompletionPrompt().
|
|
7
|
+
*
|
|
8
|
+
* Data side:
|
|
9
|
+
* - userModule compiled as "Prompt to analyze" material
|
|
10
|
+
* - ctx.inputs
|
|
11
|
+
*
|
|
12
|
+
* Output side:
|
|
13
|
+
* - cue: user message instructing to call __insert_tasks tool
|
|
14
|
+
*
|
|
15
|
+
* Tools: __insert_tasks
|
|
16
|
+
*/
|
|
17
|
+
import type { TaskTypeConfig } from './index.js';
|
|
18
|
+
export declare const config: TaskTypeConfig;
|
|
19
|
+
//# sourceMappingURL=planning.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"planning.d.ts","sourceRoot":"","sources":["../../../../src/workflows/agentic-workflow/task-types/planning.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAMH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAyDjD,eAAO,MAAM,MAAM,EAAE,cAGpB,CAAC"}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Planning task type
|
|
3
|
+
*
|
|
4
|
+
* Analyzes the user prompt and extracts complexity to design a task sequence.
|
|
5
|
+
* The userModule is converted to a single formatted material ("Prompt to analyze")
|
|
6
|
+
* using distribute() + formatCompletionPrompt().
|
|
7
|
+
*
|
|
8
|
+
* Data side:
|
|
9
|
+
* - userModule compiled as "Prompt to analyze" material
|
|
10
|
+
* - ctx.inputs
|
|
11
|
+
*
|
|
12
|
+
* Output side:
|
|
13
|
+
* - cue: user message instructing to call __insert_tasks tool
|
|
14
|
+
*
|
|
15
|
+
* Tools: __insert_tasks
|
|
16
|
+
*/
|
|
17
|
+
import { distribute } from '@modular-prompt/core';
|
|
18
|
+
import { formatCompletionPrompt } from '@modular-prompt/driver';
|
|
19
|
+
const planningModule = {
|
|
20
|
+
objective: [
|
|
21
|
+
'- Analyze the given prompt and extract complexity to design a task sequence.',
|
|
22
|
+
],
|
|
23
|
+
instructions: [
|
|
24
|
+
'- Analyze the prompt shown in "Prompt to analyze" and design the Tasks needed for execution.',
|
|
25
|
+
'- Call `__insert_tasks` once with a `tasks` array to register all Tasks.',
|
|
26
|
+
'- Each Task instruction should be concise: describe only what to focus on and what to do.',
|
|
27
|
+
'- Each Task receives all previous task results, so earlier results are available to later Tasks.',
|
|
28
|
+
'- Tools can be called from each Task, but tool results are received by the next Task.',
|
|
29
|
+
{
|
|
30
|
+
type: 'subsection',
|
|
31
|
+
title: 'Analysis Approach',
|
|
32
|
+
items: [
|
|
33
|
+
'1. **Inputs and outputs**: Understand what the final goal requires and what is available.',
|
|
34
|
+
'2. **Identify complexity**: Determine which parts of the prompt are complex and need decomposition. A simple prompt may need only one Task.',
|
|
35
|
+
'3. **Dependencies**: Identify what information is needed first and the correct processing order.',
|
|
36
|
+
'4. **Tool usage**: Identify where tool calls are required.',
|
|
37
|
+
],
|
|
38
|
+
},
|
|
39
|
+
],
|
|
40
|
+
materials: [
|
|
41
|
+
(ctx) => {
|
|
42
|
+
if (!ctx.userModule)
|
|
43
|
+
return null;
|
|
44
|
+
const compiled = distribute(ctx.userModule);
|
|
45
|
+
const text = formatCompletionPrompt(compiled, {
|
|
46
|
+
sectionDescriptions: {},
|
|
47
|
+
});
|
|
48
|
+
if (!text.trim())
|
|
49
|
+
return null;
|
|
50
|
+
return {
|
|
51
|
+
type: 'material',
|
|
52
|
+
id: 'user-prompt',
|
|
53
|
+
title: 'Prompt to analyze',
|
|
54
|
+
content: text,
|
|
55
|
+
};
|
|
56
|
+
},
|
|
57
|
+
],
|
|
58
|
+
inputs: [
|
|
59
|
+
(ctx) => {
|
|
60
|
+
if (!ctx.inputs)
|
|
61
|
+
return null;
|
|
62
|
+
return JSON.stringify(ctx.inputs, null, 2);
|
|
63
|
+
},
|
|
64
|
+
],
|
|
65
|
+
cue: [
|
|
66
|
+
{
|
|
67
|
+
type: 'message',
|
|
68
|
+
role: 'user',
|
|
69
|
+
content: 'Analyze the prompt and register tasks by calling `__insert_tasks`.',
|
|
70
|
+
},
|
|
71
|
+
],
|
|
72
|
+
};
|
|
73
|
+
export const config = {
|
|
74
|
+
module: planningModule,
|
|
75
|
+
builtinToolNames: ['__insert_tasks'],
|
|
76
|
+
};
|
|
77
|
+
//# sourceMappingURL=planning.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"planning.js","sourceRoot":"","sources":["../../../../src/workflows/agentic-workflow/task-types/planning.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAGH,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAClD,OAAO,EAAE,sBAAsB,EAAE,MAAM,wBAAwB,CAAC;AAIhE,MAAM,cAAc,GAAyC;IAC3D,SAAS,EAAE;QACT,8EAA8E;KAC/E;IACD,YAAY,EAAE;QACZ,8FAA8F;QAC9F,0EAA0E;QAC1E,2FAA2F;QAC3F,kGAAkG;QAClG,uFAAuF;QACvF;YACE,IAAI,EAAE,YAAqB;YAC3B,KAAK,EAAE,mBAAmB;YAC1B,KAAK,EAAE;gBACL,2FAA2F;gBAC3F,6IAA6I;gBAC7I,kGAAkG;gBAClG,4DAA4D;aAC7D;SACF;KACF;IAED,SAAS,EAAE;QACT,CAAC,GAA2B,EAAE,EAAE;YAC9B,IAAI,CAAC,GAAG,CAAC,UAAU;gBAAE,OAAO,IAAI,CAAC;YACjC,MAAM,QAAQ,GAAG,UAAU,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;YAC5C,MAAM,IAAI,GAAG,sBAAsB,CAAC,QAAQ,EAAE;gBAC5C,mBAAmB,EAAE,EAAE;aACxB,CAAC,CAAC;YACH,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE;gBAAE,OAAO,IAAI,CAAC;YAC9B,OAAO;gBACL,IAAI,EAAE,UAAmB;gBACzB,EAAE,EAAE,aAAa;gBACjB,KAAK,EAAE,mBAAmB;gBAC1B,OAAO,EAAE,IAAI;aACd,CAAC;QACJ,CAAC;KACF;IAED,MAAM,EAAE;QACN,CAAC,GAA2B,EAAE,EAAE;YAC9B,IAAI,CAAC,GAAG,CAAC,MAAM;gBAAE,OAAO,IAAI,CAAC;YAC7B,OAAO,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;QAC7C,CAAC;KACF;IAED,GAAG,EAAE;QACH;YACE,IAAI,EAAE,SAAkB;YACxB,IAAI,EAAE,MAAe;YACrB,OAAO,EAAE,oEAAoE;SAC9E;KACF;CACF,CAAC;AAEF,MAAM,CAAC,MAAM,MAAM,GAAmB;IACpC,MAAM,EAAE,cAAc;IACtB,gBAAgB,EAAE,CAAC,gBAAgB,CAAC;CACrC,CAAC"}
|
|
@@ -1,60 +1,106 @@
|
|
|
1
|
+
import type { ToolDefinition, QueryResult, ToolCall } from '@modular-prompt/driver';
|
|
2
|
+
import type { ResolvedModule } from '@modular-prompt/core';
|
|
3
|
+
import type { ModelRole } from '../driver-input.js';
|
|
1
4
|
/**
|
|
2
|
-
*
|
|
5
|
+
* Tool specification: definition for AI + handler for execution
|
|
3
6
|
*/
|
|
4
|
-
export
|
|
7
|
+
export interface ToolSpec {
|
|
8
|
+
definition: ToolDefinition;
|
|
9
|
+
handler: (args: Record<string, unknown>) => Promise<unknown>;
|
|
10
|
+
}
|
|
5
11
|
/**
|
|
6
|
-
*
|
|
12
|
+
* Tool call log entry (builtin tool execution record)
|
|
7
13
|
*/
|
|
8
|
-
export interface
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
constraints?: string[];
|
|
13
|
-
actions?: Array<{
|
|
14
|
-
tool: string;
|
|
15
|
-
params?: any;
|
|
16
|
-
}>;
|
|
14
|
+
export interface ToolCallLog {
|
|
15
|
+
name: string;
|
|
16
|
+
arguments: Record<string, unknown>;
|
|
17
|
+
result: unknown;
|
|
17
18
|
}
|
|
18
19
|
/**
|
|
19
|
-
*
|
|
20
|
+
* Built-in task types.
|
|
21
|
+
*
|
|
22
|
+
* Each type defines its own input contract:
|
|
23
|
+
* - What context data it receives (instructions vs data)
|
|
24
|
+
* - What tools are available
|
|
25
|
+
* - Default driver role
|
|
20
26
|
*/
|
|
21
|
-
export
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
+
export type TaskType = 'planning' | 'toolCall' | 'think' | 'verify' | 'extractContext' | 'recall' | 'determine' | 'output';
|
|
28
|
+
/**
|
|
29
|
+
* Default driver role for each task type.
|
|
30
|
+
* planning/output are hardcoded; execution tasks are derived from EXECUTION_TASK_DEFS.
|
|
31
|
+
*/
|
|
32
|
+
export declare const DEFAULT_DRIVER_ROLE: Record<TaskType, ModelRole>;
|
|
33
|
+
/**
|
|
34
|
+
* Default withXxx options for each task type
|
|
35
|
+
*/
|
|
36
|
+
export declare const DEFAULT_DATA_OPTIONS: Record<TaskType, {
|
|
37
|
+
withInputs: boolean;
|
|
38
|
+
withMessages: boolean;
|
|
39
|
+
withMaterials: boolean;
|
|
40
|
+
}>;
|
|
41
|
+
/**
|
|
42
|
+
* Agentic workflow task definition
|
|
43
|
+
*/
|
|
44
|
+
export interface AgenticTask {
|
|
45
|
+
/** What this task should accomplish */
|
|
46
|
+
instruction: string;
|
|
47
|
+
/** Task type determining prompt construction and input contract */
|
|
48
|
+
taskType: TaskType;
|
|
49
|
+
/** Driver role override (defaults per task type) */
|
|
50
|
+
driverRole?: ModelRole;
|
|
51
|
+
/** Include ctx.inputs in data */
|
|
52
|
+
withInputs?: boolean;
|
|
53
|
+
/** Include ctx.messages in data */
|
|
54
|
+
withMessages?: boolean;
|
|
55
|
+
/** Include ctx.materials in data */
|
|
56
|
+
withMaterials?: boolean;
|
|
27
57
|
}
|
|
28
58
|
/**
|
|
29
|
-
*
|
|
59
|
+
* Record of a single task execution
|
|
30
60
|
*/
|
|
31
|
-
export interface
|
|
32
|
-
|
|
61
|
+
export interface AgenticTaskExecutionLog {
|
|
62
|
+
taskType: TaskType;
|
|
63
|
+
result: string;
|
|
64
|
+
pendingToolCalls?: ToolCall[];
|
|
65
|
+
metadata?: {
|
|
66
|
+
usage?: QueryResult['usage'];
|
|
67
|
+
};
|
|
33
68
|
}
|
|
34
69
|
/**
|
|
35
|
-
* Context for agentic workflow
|
|
70
|
+
* Context for agentic workflow.
|
|
71
|
+
*
|
|
72
|
+
* Passed through the entire workflow lifecycle.
|
|
73
|
+
* Each task type selects what it needs from this context.
|
|
36
74
|
*/
|
|
37
75
|
export interface AgenticWorkflowContext {
|
|
76
|
+
/** Primary objective (passed as instruction to all tasks) */
|
|
38
77
|
objective: string;
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
78
|
+
/** Resolved user module (set by agenticProcess via resolve()) */
|
|
79
|
+
userModule?: ResolvedModule;
|
|
80
|
+
/** Structured input data */
|
|
81
|
+
inputs?: Record<string, unknown>;
|
|
82
|
+
/** Current task list */
|
|
83
|
+
taskList?: AgenticTask[];
|
|
84
|
+
/** Execution log of completed tasks */
|
|
85
|
+
executionLog?: AgenticTaskExecutionLog[];
|
|
86
|
+
/** Index of the currently executing task */
|
|
87
|
+
currentTaskIndex?: number;
|
|
88
|
+
/** Persisted state string from previous task execution */
|
|
89
|
+
state?: string;
|
|
49
90
|
}
|
|
50
91
|
/**
|
|
51
92
|
* Options for agentic workflow
|
|
52
93
|
*/
|
|
53
94
|
export interface AgenticWorkflowOptions {
|
|
54
|
-
|
|
55
|
-
|
|
95
|
+
/** Maximum number of tasks (default: 10) */
|
|
96
|
+
maxTasks?: number;
|
|
97
|
+
/** External tools available to tasks */
|
|
98
|
+
tools?: ToolSpec[];
|
|
99
|
+
/** Maximum tool call iterations per task (default: 10) */
|
|
100
|
+
maxToolCalls?: number;
|
|
101
|
+
/** Skip planning and use provided taskList (default: true) */
|
|
56
102
|
enablePlanning?: boolean;
|
|
57
|
-
|
|
58
|
-
|
|
103
|
+
/** Include intermediate task results wrapped in <think> tags before the final output (default: false) */
|
|
104
|
+
includeThinking?: boolean;
|
|
59
105
|
}
|
|
60
106
|
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/workflows/agentic-workflow/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/workflows/agentic-workflow/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AACpF,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAC3D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAMpD;;GAEG;AACH,MAAM,WAAW,QAAQ;IACvB,UAAU,EAAE,cAAc,CAAC;IAC3B,OAAO,EAAE,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;CAC9D;AAED;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACnC,MAAM,EAAE,OAAO,CAAC;CACjB;AAMD;;;;;;;GAOG;AACH,MAAM,MAAM,QAAQ,GAChB,UAAU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IACvC,YAAY,CAAC,EAAE,uBAAuB,EAAE,CAAC;IACzC,4CAA4C;IAC5C,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,0DAA0D;IAC1D,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAMD;;GAEG;AACH,MAAM,WAAW,sBAAsB;IACrC,4CAA4C;IAC5C,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,wCAAwC;IACxC,KAAK,CAAC,EAAE,QAAQ,EAAE,CAAC;IACnB,0DAA0D;IAC1D,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,8DAA8D;IAC9D,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,yGAAyG;IACzG,eAAe,CAAC,EAAE,OAAO,CAAC;CAC3B"}
|
|
@@ -1,2 +1,28 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Default driver role for each task type.
|
|
3
|
+
* planning/output are hardcoded; execution tasks are derived from EXECUTION_TASK_DEFS.
|
|
4
|
+
*/
|
|
5
|
+
export const DEFAULT_DRIVER_ROLE = {
|
|
6
|
+
planning: 'plan',
|
|
7
|
+
toolCall: 'instruct',
|
|
8
|
+
think: 'instruct',
|
|
9
|
+
verify: 'instruct',
|
|
10
|
+
extractContext: 'thinking',
|
|
11
|
+
recall: 'instruct',
|
|
12
|
+
determine: 'instruct',
|
|
13
|
+
output: 'chat',
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* Default withXxx options for each task type
|
|
17
|
+
*/
|
|
18
|
+
export const DEFAULT_DATA_OPTIONS = {
|
|
19
|
+
planning: { withInputs: true, withMessages: false, withMaterials: true },
|
|
20
|
+
toolCall: { withInputs: false, withMessages: false, withMaterials: false },
|
|
21
|
+
think: { withInputs: false, withMessages: false, withMaterials: false },
|
|
22
|
+
verify: { withInputs: false, withMessages: false, withMaterials: false },
|
|
23
|
+
extractContext: { withInputs: true, withMessages: true, withMaterials: true },
|
|
24
|
+
recall: { withInputs: false, withMessages: false, withMaterials: false },
|
|
25
|
+
determine: { withInputs: true, withMessages: true, withMaterials: true },
|
|
26
|
+
output: { withInputs: false, withMessages: false, withMaterials: false },
|
|
27
|
+
};
|
|
2
28
|
//# sourceMappingURL=types.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/workflows/agentic-workflow/types.ts"],"names":[],"mappings":""}
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/workflows/agentic-workflow/types.ts"],"names":[],"mappings":"AA+CA;;;GAGG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAgC;IAC9D,QAAQ,EAAE,MAAM;IAChB,QAAQ,EAAE,UAAU;IACpB,KAAK,EAAE,UAAU;IACjB,MAAM,EAAE,UAAU;IAClB,cAAc,EAAE,UAAU;IAC1B,MAAM,EAAE,UAAU;IAClB,SAAS,EAAE,UAAU;IACrB,MAAM,EAAE,MAAM;CACf,CAAC;AAEF;;GAEG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAA6F;IAC5H,QAAQ,EAAE,EAAE,UAAU,EAAE,IAAI,EAAE,YAAY,EAAE,KAAK,EAAE,aAAa,EAAE,IAAI,EAAE;IACxE,QAAQ,EAAE,EAAE,UAAU,EAAE,KAAK,EAAE,YAAY,EAAE,KAAK,EAAE,aAAa,EAAE,KAAK,EAAE;IAC1E,KAAK,EAAE,EAAE,UAAU,EAAE,KAAK,EAAE,YAAY,EAAE,KAAK,EAAE,aAAa,EAAE,KAAK,EAAE;IACvE,MAAM,EAAE,EAAE,UAAU,EAAE,KAAK,EAAE,YAAY,EAAE,KAAK,EAAE,aAAa,EAAE,KAAK,EAAE;IACxE,cAAc,EAAE,EAAE,UAAU,EAAE,IAAI,EAAE,YAAY,EAAE,IAAI,EAAE,aAAa,EAAE,IAAI,EAAE;IAC7E,MAAM,EAAE,EAAE,UAAU,EAAE,KAAK,EAAE,YAAY,EAAE,KAAK,EAAE,aAAa,EAAE,KAAK,EAAE;IACxE,SAAS,EAAE,EAAE,UAAU,EAAE,IAAI,EAAE,YAAY,EAAE,IAAI,EAAE,aAAa,EAAE,IAAI,EAAE;IACxE,MAAM,EAAE,EAAE,UAAU,EAAE,KAAK,EAAE,YAAY,EAAE,KAAK,EAAE,aAAa,EAAE,KAAK,EAAE;CACzE,CAAC"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { PromptModule } from '@modular-prompt/core';
|
|
2
|
-
import { type
|
|
2
|
+
import { type WorkflowResult } from './types.js';
|
|
3
|
+
import { type DriverInput } from './driver-input.js';
|
|
3
4
|
/**
|
|
4
5
|
* Context for concat processing workflow
|
|
5
6
|
*/
|
|
@@ -25,5 +26,5 @@ export interface ConcatProcessOptions {
|
|
|
25
26
|
* Concat processing workflow - processes chunks independently and concatenates results
|
|
26
27
|
* Unlike stream processing which maintains state, concat treats each chunk independently
|
|
27
28
|
*/
|
|
28
|
-
export declare function concatProcess(driver:
|
|
29
|
+
export declare function concatProcess(driver: DriverInput, module: PromptModule<ConcatProcessContext>, context: ConcatProcessContext, options?: ConcatProcessOptions): Promise<WorkflowResult<ConcatProcessContext>>;
|
|
29
30
|
//# sourceMappingURL=concat-process-workflow.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"concat-process-workflow.d.ts","sourceRoot":"","sources":["../../src/workflows/concat-process-workflow.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;
|
|
1
|
+
{"version":3,"file":"concat-process-workflow.d.ts","sourceRoot":"","sources":["../../src/workflows/concat-process-workflow.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAEzD,OAAO,EAA0B,KAAK,cAAc,EAAE,MAAM,YAAY,CAAC;AACzE,OAAO,EAAE,KAAK,WAAW,EAAiB,MAAM,mBAAmB,CAAC;AAKpE;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACnC,MAAM,EAAE,KAAK,CAAC;QACZ,OAAO,EAAE,MAAM,CAAC;QAChB,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;KAChC,CAAC,CAAC;IACH,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB;AAED;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACnC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AA6BD;;;GAGG;AACH,wBAAsB,aAAa,CACjC,MAAM,EAAE,WAAW,EACnB,MAAM,EAAE,YAAY,CAAC,oBAAoB,CAAC,EAC1C,OAAO,EAAE,oBAAoB,EAC7B,OAAO,GAAE,oBAAyB,GACjC,OAAO,CAAC,cAAc,CAAC,oBAAoB,CAAC,CAAC,CAoJ/C"}
|
|
@@ -1,10 +1,41 @@
|
|
|
1
|
-
import { compile } from '@modular-prompt/core';
|
|
1
|
+
import { compile, merge } from '@modular-prompt/core';
|
|
2
|
+
import { Logger } from '@modular-prompt/utils';
|
|
2
3
|
import { WorkflowExecutionError } from './types.js';
|
|
4
|
+
import { resolveDriver } from './driver-input.js';
|
|
5
|
+
const logger = new Logger({ prefix: 'process', context: 'concat' });
|
|
6
|
+
/**
|
|
7
|
+
* Base module for concat processing
|
|
8
|
+
*/
|
|
9
|
+
const concatProcessing = {
|
|
10
|
+
objective: [
|
|
11
|
+
'The assistant processes each provided chunk independently and produces output for it.',
|
|
12
|
+
'Each chunk is a self-contained unit - process it without depending on other chunks.',
|
|
13
|
+
],
|
|
14
|
+
methodology: [
|
|
15
|
+
'Read the provided Input Chunk(s) carefully.',
|
|
16
|
+
'Apply the specified processing to each chunk independently.',
|
|
17
|
+
'Output the processing result directly.',
|
|
18
|
+
],
|
|
19
|
+
materials: [
|
|
20
|
+
(ctx) => {
|
|
21
|
+
if (!ctx.chunks || ctx.chunks.length === 0)
|
|
22
|
+
return null;
|
|
23
|
+
return ctx.chunks.map((chunk, index) => ({
|
|
24
|
+
type: 'chunk',
|
|
25
|
+
content: chunk.content,
|
|
26
|
+
partOf: chunk.partOf || 'input',
|
|
27
|
+
index,
|
|
28
|
+
usage: chunk.usage
|
|
29
|
+
}));
|
|
30
|
+
}
|
|
31
|
+
],
|
|
32
|
+
};
|
|
3
33
|
/**
|
|
4
34
|
* Concat processing workflow - processes chunks independently and concatenates results
|
|
5
35
|
* Unlike stream processing which maintains state, concat treats each chunk independently
|
|
6
36
|
*/
|
|
7
37
|
export async function concatProcess(driver, module, context, options = {}) {
|
|
38
|
+
logger.info('[start] concat workflow');
|
|
8
39
|
const { batchSize = 1, separator = '\n', parallel = false } = options;
|
|
9
40
|
if (!context.chunks || context.chunks.length === 0) {
|
|
10
41
|
throw new Error('No chunks provided for processing');
|
|
@@ -22,9 +53,11 @@ export async function concatProcess(driver, module, context, options = {}) {
|
|
|
22
53
|
chunks: [chunk],
|
|
23
54
|
processedCount: startIndex + index
|
|
24
55
|
};
|
|
25
|
-
const prompt = compile(module, chunkContext);
|
|
56
|
+
const prompt = compile(merge(concatProcessing, module), chunkContext);
|
|
57
|
+
logger.verbose('[prompt]', JSON.stringify(prompt));
|
|
26
58
|
try {
|
|
27
|
-
const result = await driver.query(prompt);
|
|
59
|
+
const result = await resolveDriver(driver, 'default').query(prompt);
|
|
60
|
+
logger.verbose('[output]', result.content);
|
|
28
61
|
// Check finish reason for dynamic failures
|
|
29
62
|
if (result.finishReason && result.finishReason !== 'stop') {
|
|
30
63
|
throw new WorkflowExecutionError(`Query failed with reason: ${result.finishReason}`, {
|
|
@@ -67,9 +100,11 @@ export async function concatProcess(driver, module, context, options = {}) {
|
|
|
67
100
|
results: results.length > 0 ? results : undefined,
|
|
68
101
|
processedCount: startIndex + i
|
|
69
102
|
};
|
|
70
|
-
const prompt = compile(module, batchContext);
|
|
103
|
+
const prompt = compile(merge(concatProcessing, module), batchContext);
|
|
104
|
+
logger.verbose('[prompt]', JSON.stringify(prompt));
|
|
71
105
|
try {
|
|
72
|
-
const queryResult = await driver.query(prompt);
|
|
106
|
+
const queryResult = await resolveDriver(driver, 'default').query(prompt);
|
|
107
|
+
logger.verbose('[output]', queryResult.content);
|
|
73
108
|
// Check finish reason for dynamic failures
|
|
74
109
|
if (queryResult.finishReason && queryResult.finishReason !== 'stop') {
|
|
75
110
|
throw new WorkflowExecutionError(`Query failed with reason: ${queryResult.finishReason}`, {
|
|
@@ -108,6 +143,7 @@ export async function concatProcess(driver, module, context, options = {}) {
|
|
|
108
143
|
results,
|
|
109
144
|
processedCount
|
|
110
145
|
};
|
|
146
|
+
logger.info('[end]');
|
|
111
147
|
return {
|
|
112
148
|
output,
|
|
113
149
|
context: finalContext,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"concat-process-workflow.js","sourceRoot":"","sources":["../../src/workflows/concat-process-workflow.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;
|
|
1
|
+
{"version":3,"file":"concat-process-workflow.js","sourceRoot":"","sources":["../../src/workflows/concat-process-workflow.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,sBAAsB,CAAC;AAEtD,OAAO,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAC/C,OAAO,EAAE,sBAAsB,EAAuB,MAAM,YAAY,CAAC;AACzE,OAAO,EAAoB,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAEpE,MAAM,MAAM,GAAG,IAAI,MAAM,CAAC,EAAE,MAAM,EAAE,SAAS,EAAE,OAAO,EAAE,QAAQ,EAAE,CAAC,CAAC;AA0BpE;;GAEG;AACH,MAAM,gBAAgB,GAAuC;IAC3D,SAAS,EAAE;QACT,uF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OAAO,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,SAAS;iBACxE,CAAC,CAAC;YACL,CAAC;QACH,CAAC;IACH,CAAC;IAED,sBAAsB;IACtB,MAAM,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;IAEvC,MAAM,YAAY,GAAyB;QACzC,GAAG,OAAO;QACV,OAAO;QACP,cAAc;KACf,CAAC;IAEF,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IAErB,OAAO;QACL,MAAM;QACN,OAAO,EAAE,YAAY;QACrB,QAAQ,EAAE;YACR,eAAe,EAAE,cAAc;YAC/B,YAAY,EAAE,OAAO,CAAC,MAAM;YAC5B,QAAQ;SACT;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { PromptModule } from '@modular-prompt/core';
|
|
2
2
|
import type { QueryOptions } from '@modular-prompt/driver';
|
|
3
|
-
import { type
|
|
3
|
+
import { type WorkflowResult } from './types.js';
|
|
4
|
+
import { type DriverInput } from './driver-input.js';
|
|
4
5
|
/**
|
|
5
6
|
* Options for default workflow
|
|
6
7
|
*/
|
|
@@ -11,5 +12,5 @@ export interface DefaultProcessOptions {
|
|
|
11
12
|
* Default workflow - compiles a module with context and queries the driver.
|
|
12
13
|
* This is the simplest process, wrapping compile + driver.query().
|
|
13
14
|
*/
|
|
14
|
-
export declare function defaultProcess<TContext extends Record<string, any>>(driver:
|
|
15
|
+
export declare function defaultProcess<TContext extends Record<string, any>>(driver: DriverInput, module: PromptModule<TContext>, context: TContext, options?: DefaultProcessOptions): Promise<WorkflowResult<TContext>>;
|
|
15
16
|
//# sourceMappingURL=default-workflow.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"default-workflow.d.ts","sourceRoot":"","sources":["../../src/workflows/default-workflow.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACzD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;
|
|
1
|
+
{"version":3,"file":"default-workflow.d.ts","sourceRoot":"","sources":["../../src/workflows/default-workflow.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACzD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAE3D,OAAO,EAA0B,KAAK,cAAc,EAAE,MAAM,YAAY,CAAC;AACzE,OAAO,EAAE,KAAK,WAAW,EAAiB,MAAM,mBAAmB,CAAC;AAIpE;;GAEG;AACH,MAAM,WAAW,qBAAqB;IACpC,YAAY,CAAC,EAAE,OAAO,CAAC,YAAY,CAAC,CAAC;CACtC;AAED;;;GAGG;AACH,wBAAsB,cAAc,CAAC,QAAQ,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EACvE,MAAM,EAAE,WAAW,EACnB,MAAM,EAAE,YAAY,CAAC,QAAQ,CAAC,EAC9B,OAAO,EAAE,QAAQ,EACjB,OAAO,GAAE,qBAA0B,GAClC,OAAO,CAAC,cAAc,CAAC,QAAQ,CAAC,CAAC,CAiCnC"}
|
|
@@ -1,13 +1,26 @@
|
|
|
1
1
|
import { compile } from '@modular-prompt/core';
|
|
2
|
+
import { Logger } from '@modular-prompt/utils';
|
|
2
3
|
import { WorkflowExecutionError } from './types.js';
|
|
4
|
+
import { resolveDriver } from './driver-input.js';
|
|
5
|
+
const logger = new Logger({ prefix: 'process', context: 'default' });
|
|
3
6
|
/**
|
|
4
7
|
* Default workflow - compiles a module with context and queries the driver.
|
|
5
8
|
* This is the simplest process, wrapping compile + driver.query().
|
|
6
9
|
*/
|
|
7
10
|
export async function defaultProcess(driver, module, context, options = {}) {
|
|
8
11
|
try {
|
|
12
|
+
logger.info('[start] default workflow');
|
|
9
13
|
const compiled = compile(module, context);
|
|
10
|
-
const
|
|
14
|
+
const toolNames = options.queryOptions?.tools?.map(t => t.name) ?? [];
|
|
15
|
+
logger.verbose('[prompt]', JSON.stringify(compiled), toolNames.length > 0 ? `tools: [${toolNames.join(', ')}]` : '');
|
|
16
|
+
const result = await resolveDriver(driver, 'default').query(compiled, options.queryOptions);
|
|
17
|
+
logger.verbose('[output]', result.content);
|
|
18
|
+
if (result.toolCalls?.length) {
|
|
19
|
+
for (const tc of result.toolCalls) {
|
|
20
|
+
logger.debug('[tool:call]', tc.name, JSON.stringify(tc.arguments));
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
logger.info('[end]');
|
|
11
24
|
return {
|
|
12
25
|
output: result.content,
|
|
13
26
|
context,
|