@lowire/loop 0.0.11 → 0.0.12
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/lib/loop.d.ts +2 -3
- package/lib/loop.js +15 -17
- package/lib/types.d.ts +1 -1
- package/package.json +1 -1
package/lib/loop.d.ts
CHANGED
|
@@ -45,7 +45,6 @@ export type LoopOptions = types.CompletionOptions & LoopEvents & {
|
|
|
45
45
|
tools?: types.Tool[];
|
|
46
46
|
callTool?: types.ToolCallback;
|
|
47
47
|
maxTurns?: number;
|
|
48
|
-
resultSchema?: types.Schema;
|
|
49
48
|
cache?: {
|
|
50
49
|
messages: types.ReplayCache;
|
|
51
50
|
secrets: Record<string, string>;
|
|
@@ -57,10 +56,10 @@ export declare class Loop {
|
|
|
57
56
|
private _loopOptions;
|
|
58
57
|
private _cacheOutput;
|
|
59
58
|
constructor(loopName: 'openai' | 'github' | 'anthropic' | 'google', options: LoopOptions);
|
|
60
|
-
run
|
|
59
|
+
run(task: string, runOptions?: Omit<LoopOptions, 'model'> & {
|
|
61
60
|
model?: string;
|
|
62
61
|
}): Promise<{
|
|
63
|
-
result?:
|
|
62
|
+
result?: types.ToolResult;
|
|
64
63
|
status: 'ok' | 'break';
|
|
65
64
|
usage: types.Usage;
|
|
66
65
|
turns: number;
|
package/lib/loop.js
CHANGED
|
@@ -29,12 +29,7 @@ class Loop {
|
|
|
29
29
|
}
|
|
30
30
|
async run(task, runOptions = {}) {
|
|
31
31
|
const options = { ...this._loopOptions, ...runOptions };
|
|
32
|
-
const allTools = [...options.tools || []];
|
|
33
|
-
allTools.push({
|
|
34
|
-
name: 'report_result',
|
|
35
|
-
description: 'Report the result of the task.',
|
|
36
|
-
inputSchema: options.resultSchema ?? defaultResultSchema,
|
|
37
|
-
});
|
|
32
|
+
const allTools = [...(options.tools || []).map(wrapToolWithIsDone)];
|
|
38
33
|
const conversation = {
|
|
39
34
|
systemPrompt,
|
|
40
35
|
messages: [
|
|
@@ -84,8 +79,6 @@ class Loop {
|
|
|
84
79
|
for (const toolCall of toolCalls) {
|
|
85
80
|
const { name, arguments: args } = toolCall;
|
|
86
81
|
debug?.('lowire:loop')('Call tool', name, JSON.stringify(args, null, 2));
|
|
87
|
-
if (name === 'report_result')
|
|
88
|
-
return { result: args, status: 'ok', usage: totalUsage, turns };
|
|
89
82
|
const status = await options.onBeforeToolCall?.({ assistantMessage, toolCall });
|
|
90
83
|
if (status === 'break')
|
|
91
84
|
return { status: 'break', usage: totalUsage, turns };
|
|
@@ -121,6 +114,8 @@ class Loop {
|
|
|
121
114
|
continue;
|
|
122
115
|
}
|
|
123
116
|
toolCall.result = result;
|
|
117
|
+
if (args._is_done)
|
|
118
|
+
return { result, status: 'ok', usage: totalUsage, turns };
|
|
124
119
|
}
|
|
125
120
|
catch (error) {
|
|
126
121
|
const errorMessage = `Error while executing tool "${name}": ${error instanceof Error ? error.message : String(error)}\n\nPlease try to recover and complete the task.`;
|
|
@@ -153,15 +148,18 @@ class Loop {
|
|
|
153
148
|
}
|
|
154
149
|
}
|
|
155
150
|
exports.Loop = Loop;
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
properties
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
151
|
+
function wrapToolWithIsDone(tool) {
|
|
152
|
+
const inputSchema = { ...tool.inputSchema };
|
|
153
|
+
inputSchema.properties = {
|
|
154
|
+
...inputSchema.properties,
|
|
155
|
+
_is_done: { type: 'boolean', description: 'Whether the task is complete. If false, agentic loop will continue to perform the task.' },
|
|
156
|
+
};
|
|
157
|
+
inputSchema.required = [...(inputSchema.required || []), '_is_done'];
|
|
158
|
+
return {
|
|
159
|
+
...tool,
|
|
160
|
+
inputSchema,
|
|
161
|
+
};
|
|
162
|
+
}
|
|
165
163
|
const systemPrompt = `
|
|
166
164
|
You are an autonomous agent designed to complete tasks by interacting with tools. Perform the user task.
|
|
167
165
|
`;
|
package/lib/types.d.ts
CHANGED