@o-lang/olang 1.0.1 → 1.0.2
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/package.json +16 -5
- package/src/parser.js +45 -4
- package/src/runtime.js +18 -12
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@o-lang/olang",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"author": "Olalekan Ogundipe <info@workfily.com>",
|
|
5
5
|
"description": "O-Lang: A governance language for user-directed, rule-enforced agent workflows",
|
|
6
6
|
"main": "./src/index.js",
|
|
@@ -18,11 +18,22 @@
|
|
|
18
18
|
"commander": "^12.0.0",
|
|
19
19
|
"dotenv": "^17.2.3"
|
|
20
20
|
},
|
|
21
|
-
"keywords": [
|
|
21
|
+
"keywords": [
|
|
22
|
+
"agent",
|
|
23
|
+
"governance",
|
|
24
|
+
"workflow",
|
|
25
|
+
"llm",
|
|
26
|
+
"automation",
|
|
27
|
+
"olang",
|
|
28
|
+
"ai"
|
|
29
|
+
],
|
|
22
30
|
"license": "MIT",
|
|
23
31
|
"repository": {
|
|
24
32
|
"type": "git",
|
|
25
|
-
"url": "https://github.com/O-Lang-Central/olang-kernel.git"
|
|
33
|
+
"url": "git+https://github.com/O-Lang-Central/olang-kernel.git"
|
|
26
34
|
},
|
|
27
|
-
"homepage": "https://github.com/O-Lang-Central/olang-kernel"
|
|
28
|
-
|
|
35
|
+
"homepage": "https://github.com/O-Lang-Central/olang-kernel",
|
|
36
|
+
"publishConfig": {
|
|
37
|
+
"access": "public"
|
|
38
|
+
}
|
|
39
|
+
}
|
package/src/parser.js
CHANGED
|
@@ -33,7 +33,7 @@ function parse(code) {
|
|
|
33
33
|
stepNumber: parseInt(stepMatch[1], 10),
|
|
34
34
|
actionRaw: stepMatch[2].trim(),
|
|
35
35
|
saveAs: null,
|
|
36
|
-
constraints: {}
|
|
36
|
+
constraints: {}
|
|
37
37
|
});
|
|
38
38
|
i++;
|
|
39
39
|
continue;
|
|
@@ -47,7 +47,7 @@ function parse(code) {
|
|
|
47
47
|
continue;
|
|
48
48
|
}
|
|
49
49
|
|
|
50
|
-
// Constraint
|
|
50
|
+
// Constraint
|
|
51
51
|
const constraintMatch = line.match(/^Constraint:\s*(.+)$/i);
|
|
52
52
|
if (constraintMatch && workflow.steps.length > 0) {
|
|
53
53
|
const lastStep = workflow.steps[workflow.steps.length - 1];
|
|
@@ -88,7 +88,7 @@ function parse(code) {
|
|
|
88
88
|
body.push(lines[i]);
|
|
89
89
|
i++;
|
|
90
90
|
}
|
|
91
|
-
if (i < lines.length) i++;
|
|
91
|
+
if (i < lines.length) i++;
|
|
92
92
|
workflow.steps.push({ type: 'if', condition, body: parseBlock(body) });
|
|
93
93
|
continue;
|
|
94
94
|
}
|
|
@@ -199,6 +199,32 @@ function parse(code) {
|
|
|
199
199
|
continue;
|
|
200
200
|
}
|
|
201
201
|
|
|
202
|
+
// --- New: Use <Tool> ---
|
|
203
|
+
const useMatch = line.match(/^Use\s+(.+)$/i);
|
|
204
|
+
if (useMatch) {
|
|
205
|
+
workflow.steps.push({
|
|
206
|
+
type: 'use',
|
|
207
|
+
tool: useMatch[1].trim(),
|
|
208
|
+
saveAs: null,
|
|
209
|
+
constraints: {}
|
|
210
|
+
});
|
|
211
|
+
i++;
|
|
212
|
+
continue;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
// --- New: Ask <Target> ---
|
|
216
|
+
const askMatch = line.match(/^Ask\s+(.+)$/i);
|
|
217
|
+
if (askMatch) {
|
|
218
|
+
workflow.steps.push({
|
|
219
|
+
type: 'ask',
|
|
220
|
+
target: askMatch[1].trim(),
|
|
221
|
+
saveAs: null,
|
|
222
|
+
constraints: {}
|
|
223
|
+
});
|
|
224
|
+
i++;
|
|
225
|
+
continue;
|
|
226
|
+
}
|
|
227
|
+
|
|
202
228
|
i++;
|
|
203
229
|
}
|
|
204
230
|
|
|
@@ -221,25 +247,40 @@ function parseBlock(lines) {
|
|
|
221
247
|
steps.push(current);
|
|
222
248
|
continue;
|
|
223
249
|
}
|
|
250
|
+
|
|
224
251
|
const saveMatch = line.match(/^Save as\s+(.+)$/i);
|
|
225
252
|
if (saveMatch && current) {
|
|
226
253
|
current.saveAs = saveMatch[1].trim();
|
|
227
254
|
}
|
|
255
|
+
|
|
228
256
|
const debriefMatch = line.match(/^Debrief\s+(\w+)\s+with\s+"(.+)"$/i);
|
|
229
257
|
if (debriefMatch) {
|
|
230
258
|
steps.push({ type: 'debrief', agent: debriefMatch[1], message: debriefMatch[2] });
|
|
231
259
|
}
|
|
260
|
+
|
|
232
261
|
const evolveMatch = line.match(/^Evolve\s+(\w+)\s+using\s+feedback:\s+"(.+)"$/i);
|
|
233
262
|
if (evolveMatch) {
|
|
234
263
|
steps.push({ type: 'evolve', agent: evolveMatch[1], feedback: evolveMatch[2] });
|
|
235
264
|
}
|
|
265
|
+
|
|
236
266
|
const promptMatch = line.match(/^Prompt user to\s+"(.+)"$/i);
|
|
237
267
|
if (promptMatch) {
|
|
238
268
|
steps.push({ type: 'prompt', question: promptMatch[1], saveAs: null });
|
|
239
269
|
}
|
|
270
|
+
|
|
271
|
+
// New: Use <Tool>
|
|
272
|
+
const useMatch = line.match(/^Use\s+(.+)$/i);
|
|
273
|
+
if (useMatch) {
|
|
274
|
+
steps.push({ type: 'use', tool: useMatch[1].trim(), saveAs: null, constraints: {} });
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
// New: Ask <Target>
|
|
278
|
+
const askMatch = line.match(/^Ask\s+(.+)$/i);
|
|
279
|
+
if (askMatch) {
|
|
280
|
+
steps.push({ type: 'ask', target: askMatch[1].trim(), saveAs: null, constraints: {} });
|
|
281
|
+
}
|
|
240
282
|
}
|
|
241
283
|
return steps;
|
|
242
284
|
}
|
|
243
285
|
|
|
244
286
|
module.exports = { parse };
|
|
245
|
-
|
package/src/runtime.js
CHANGED
|
@@ -35,7 +35,6 @@ class RuntimeAPI {
|
|
|
35
35
|
return path.split('.').reduce((o, k) => (o && o[k] !== undefined) ? o[k] : undefined, obj);
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
-
// 🔍 Find the last "Ask ... Save as ..." step that can be evolved
|
|
39
38
|
findLastSummaryStep() {
|
|
40
39
|
for (let i = this.workflowSteps.length - 1; i >= 0; i--) {
|
|
41
40
|
const step = this.workflowSteps[i];
|
|
@@ -58,6 +57,20 @@ class RuntimeAPI {
|
|
|
58
57
|
break;
|
|
59
58
|
}
|
|
60
59
|
|
|
60
|
+
case 'use': {
|
|
61
|
+
// "Use <Tool>" step
|
|
62
|
+
const res = await agentResolver(`Use ${step.tool}`, this.context);
|
|
63
|
+
if (step.saveAs) this.context[step.saveAs] = res;
|
|
64
|
+
break;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
case 'ask': {
|
|
68
|
+
// "Ask <Target>" step
|
|
69
|
+
const res = await agentResolver(`Ask ${step.target}`, this.context);
|
|
70
|
+
if (step.saveAs) this.context[step.saveAs] = res;
|
|
71
|
+
break;
|
|
72
|
+
}
|
|
73
|
+
|
|
61
74
|
case 'if': {
|
|
62
75
|
if (this.evaluateCondition(step.condition, this.context)) {
|
|
63
76
|
for (const s of step.body) await this.executeStep(s, agentResolver);
|
|
@@ -86,7 +99,6 @@ class RuntimeAPI {
|
|
|
86
99
|
}
|
|
87
100
|
|
|
88
101
|
case 'evolve': {
|
|
89
|
-
// ✅ Runtime-enforced bounded evolution
|
|
90
102
|
const maxGen = step.constraints?.max_generations || 1;
|
|
91
103
|
if (maxGen < 1) {
|
|
92
104
|
this.context['improved_summary'] = this.context['summary'] || '';
|
|
@@ -100,34 +112,28 @@ class RuntimeAPI {
|
|
|
100
112
|
return;
|
|
101
113
|
}
|
|
102
114
|
|
|
103
|
-
const varName = summaryStep.saveAs;
|
|
115
|
+
const varName = summaryStep.saveAs;
|
|
104
116
|
let currentOutput = this.context[varName] || '';
|
|
105
117
|
|
|
106
|
-
// Run up to max_generations attempts
|
|
107
118
|
for (let attempt = 0; attempt < maxGen; attempt++) {
|
|
108
|
-
// Rebuild the original action with current context (re-interpolates {doc.text}, etc.)
|
|
109
119
|
let revisedAction = summaryStep.actionRaw.replace(/\{([^\}]+)\}/g, (_, path) => {
|
|
110
120
|
const val = this.getNested(this.context, path.trim());
|
|
111
121
|
return val !== undefined ? String(val) : `{${path}}`;
|
|
112
122
|
});
|
|
113
123
|
|
|
114
|
-
// Append improvement feedback on every attempt (including first)
|
|
115
124
|
if (step.feedback) {
|
|
116
|
-
revisedAction = revisedAction.replace(/(")
|
|
125
|
+
revisedAction = revisedAction.replace(/(")$/, `\n\n[IMPROVEMENT FEEDBACK: ${step.feedback}]$1`);
|
|
117
126
|
}
|
|
118
127
|
|
|
119
|
-
// Delegate ONLY the "Ask ..." action to the resolver
|
|
120
128
|
currentOutput = await agentResolver(revisedAction, this.context);
|
|
121
|
-
this.context[varName] = currentOutput;
|
|
129
|
+
this.context[varName] = currentOutput;
|
|
122
130
|
|
|
123
|
-
// Optional: emit debrief for observability
|
|
124
131
|
this.emit('debrief', {
|
|
125
132
|
agent: step.agent || 'Evolver',
|
|
126
133
|
message: `Evolve attempt ${attempt + 1}/${maxGen}: ${currentOutput.substring(0, 80)}...`
|
|
127
134
|
});
|
|
128
135
|
}
|
|
129
136
|
|
|
130
|
-
// ✅ Always expose final result as 'improved_summary' for downstream use
|
|
131
137
|
this.context['improved_summary'] = currentOutput;
|
|
132
138
|
break;
|
|
133
139
|
}
|
|
@@ -167,7 +173,7 @@ class RuntimeAPI {
|
|
|
167
173
|
|
|
168
174
|
async executeWorkflow(workflow, inputs, agentResolver) {
|
|
169
175
|
this.context = { ...inputs };
|
|
170
|
-
this.workflowSteps = workflow.steps;
|
|
176
|
+
this.workflowSteps = workflow.steps;
|
|
171
177
|
|
|
172
178
|
for (const step of workflow.steps) {
|
|
173
179
|
await this.executeStep(step, agentResolver);
|