@lowire/loop 0.0.6 → 0.0.8

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 CHANGED
@@ -23,6 +23,12 @@ export type LoopOptions = types.CompletionOptions & {
23
23
  messages: types.ReplayCache;
24
24
  secrets: Record<string, string>;
25
25
  };
26
+ beforeTurn?: (params: {
27
+ turn: number;
28
+ conversation: types.Conversation;
29
+ summarizedConversation?: types.Conversation;
30
+ usage: types.Usage;
31
+ }) => 'break' | 'continue' | void;
26
32
  summarize?: boolean;
27
33
  };
28
34
  export declare class Loop {
@@ -32,7 +38,11 @@ export declare class Loop {
32
38
  constructor(loopName: 'openai' | 'github' | 'anthropic' | 'google', options: LoopOptions);
33
39
  run<T>(task: string, runOptions?: Omit<LoopOptions, 'model'> & {
34
40
  model?: string;
35
- }): Promise<T>;
41
+ }): Promise<{
42
+ result?: T;
43
+ status: 'ok' | 'break';
44
+ usage: types.Usage;
45
+ }>;
36
46
  private _summarizeConversation;
37
47
  cache(): types.ReplayCache;
38
48
  }
package/lib/loop.js CHANGED
@@ -54,11 +54,14 @@ class Loop {
54
54
  secrets: options.cache.secrets
55
55
  } : undefined;
56
56
  const summarizedConversation = options.summarize ? this._summarizeConversation(task, conversation, options) : conversation;
57
+ const status = options.beforeTurn?.({ turn, conversation, summarizedConversation, usage: totalUsage });
58
+ if (status === 'break')
59
+ return { status: 'break', usage: totalUsage };
57
60
  debug?.('lowire:loop')(`Request`, JSON.stringify({ ...summarizedConversation, tools: `${summarizedConversation.tools.length} tools` }, null, 2));
58
61
  const { result: assistantMessage, usage } = await (0, cache_1.cachedComplete)(this._provider, summarizedConversation, caches, options);
59
- const text = assistantMessage.content.filter(part => part.type === 'text').map(part => part.text).join('\n');
62
+ const intent = assistantMessage.content.filter(part => part.type === 'text').map(part => part.text).join('\n');
60
63
  debug?.('lowire:loop')('Usage', `input: ${usage.input}, output: ${usage.output}`);
61
- debug?.('lowire:loop')('Assistant', text, JSON.stringify(assistantMessage.content, null, 2));
64
+ debug?.('lowire:loop')('Assistant', intent, JSON.stringify(assistantMessage.content, null, 2));
62
65
  totalUsage.input += usage.input;
63
66
  totalUsage.output += usage.output;
64
67
  conversation.messages.push(assistantMessage);
@@ -71,13 +74,14 @@ class Loop {
71
74
  const { name, arguments: args } = toolCall;
72
75
  debug?.('lowire:loop')('Call tool', name, JSON.stringify(args, null, 2));
73
76
  if (name === 'report_result')
74
- return args;
77
+ return { result: args, status: 'ok', usage: totalUsage };
75
78
  try {
76
79
  const result = await options.callTool({
77
80
  name,
78
81
  arguments: {
79
82
  ...args,
80
83
  _meta: {
84
+ 'dev.lowire/intent': intent,
81
85
  'dev.lowire/history': true,
82
86
  'dev.lowire/state': true,
83
87
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lowire/loop",
3
- "version": "0.0.6",
3
+ "version": "0.0.8",
4
4
  "description": "Small agentic loop",
5
5
  "repository": {
6
6
  "type": "git",