@limo-labs/deity 0.2.1 → 0.2.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/dist/index.cjs CHANGED
@@ -2876,6 +2876,7 @@ var DEFAULT_LLM_LOOP_CONFIG = {
2876
2876
  // 2 minutes
2877
2877
  verbose: false
2878
2878
  };
2879
+ var DEADLINE_PROMPT = `\u26A0\uFE0F DEADLINE REACHED: You have reached the maximum allowed rounds or time limit. You MUST immediately provide your final answer based on the information gathered so far. Do NOT call any more tools. Respond with your best final output NOW.`;
2879
2880
  async function executeLLMLoop(adapter, initialMessages, tools, config, ctx, loopConfig = {}, validator) {
2880
2881
  const cfg = { ...DEFAULT_LLM_LOOP_CONFIG, ...loopConfig };
2881
2882
  const messagesWithMemory = await injectRelevantMemories(
@@ -2889,6 +2890,7 @@ async function executeLLMLoop(adapter, initialMessages, tools, config, ctx, loop
2889
2890
  let toolCallsExecuted = 0;
2890
2891
  let response;
2891
2892
  let toolCallsThisRound = [];
2893
+ const startTime = Date.now();
2892
2894
  while (rounds < cfg.maxToolRounds) {
2893
2895
  rounds++;
2894
2896
  toolCallsThisRound = [];
@@ -2936,10 +2938,6 @@ async function executeLLMLoop(adapter, initialMessages, tools, config, ctx, loop
2936
2938
  }
2937
2939
  break;
2938
2940
  }
2939
- if (rounds >= cfg.maxToolRounds) {
2940
- errors.push(`Maximum tool rounds (${cfg.maxToolRounds}) exceeded`);
2941
- break;
2942
- }
2943
2941
  for (const toolCall of response.toolCalls) {
2944
2942
  const alreadyExecuted = toolCall._alreadyExecuted;
2945
2943
  if (alreadyExecuted) {
@@ -3007,6 +3005,23 @@ async function executeLLMLoop(adapter, initialMessages, tools, config, ctx, loop
3007
3005
  if (allPreExecuted) {
3008
3006
  break;
3009
3007
  }
3008
+ const isTimeout = cfg.timeout > 0 && Date.now() - startTime >= cfg.timeout;
3009
+ const isLastRound = rounds >= cfg.maxToolRounds;
3010
+ if (isTimeout || isLastRound) {
3011
+ messages.push({
3012
+ role: "user",
3013
+ content: DEADLINE_PROMPT
3014
+ });
3015
+ try {
3016
+ response = await adapter.generate(messages, void 0, config, ctx);
3017
+ messages.push({ role: "assistant", content: response.content });
3018
+ } catch (_error) {
3019
+ }
3020
+ errors.push(
3021
+ isTimeout ? `Timeout reached (${cfg.timeout}ms)` : `Maximum tool rounds (${cfg.maxToolRounds}) reached`
3022
+ );
3023
+ break;
3024
+ }
3010
3025
  }
3011
3026
  return {
3012
3027
  response,
@@ -3246,6 +3261,17 @@ async function executeWithRetry(component, ctx, executeFn) {
3246
3261
  }
3247
3262
  const shouldRetry = retryConfig.shouldRetry ? retryConfig.shouldRetry(attempts, output, ctx) : attempts < retryConfig.maxAttempts;
3248
3263
  if (!shouldRetry) {
3264
+ const lastOutput = outputHistory[outputHistory.length - 1];
3265
+ if (lastOutput !== void 0) {
3266
+ return {
3267
+ output: lastOutput,
3268
+ success: true,
3269
+ attempts,
3270
+ errors: validation.errors ?? ["Validation failed (used best-effort output)"],
3271
+ validationHistory,
3272
+ outputHistory
3273
+ };
3274
+ }
3249
3275
  return {
3250
3276
  success: false,
3251
3277
  attempts,
@@ -4344,7 +4370,7 @@ zod.z.object({
4344
4370
  sessionId: zod.z.string().min(1, "Session ID cannot be empty"),
4345
4371
  workflowName: zod.z.string().min(1, "Workflow name cannot be empty"),
4346
4372
  pausedAt: zod.z.string().datetime("Must be ISO 8601 datetime"),
4347
- version: zod.z.string().regex(/^\d+\.\d+\.\d+$/, "Must be semver format (e.g., 4.0.0)"),
4373
+ version: zod.z.string().regex(/^\d+\.\d+\.\d+$/, "Must be semver format (e.g., 1.0.0)"),
4348
4374
  state: PausedSessionStateSchema,
4349
4375
  metadata: PausedSessionMetadataSchema
4350
4376
  });
@@ -4360,7 +4386,7 @@ var SessionSerializer = class {
4360
4386
  metadata;
4361
4387
  constructor() {
4362
4388
  this.metadata = {
4363
- version: "4.0.0",
4389
+ version: "1.0.0",
4364
4390
  timestamp: /* @__PURE__ */ new Date(),
4365
4391
  specialFields: []
4366
4392
  };
@@ -5252,6 +5278,7 @@ function createLoopNode(child, maxIterations) {
5252
5278
 
5253
5279
  exports.Agent = Agent;
5254
5280
  exports.Conditional = Conditional;
5281
+ exports.DEADLINE_PROMPT = DEADLINE_PROMPT;
5255
5282
  exports.DEBUG_ENABLED = DEBUG_ENABLED;
5256
5283
  exports.DebugLogger = DebugLogger;
5257
5284
  exports.ForEach = ForEach;