@siftd/connect-agent 0.2.53 → 0.2.54
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/orchestrator.js +38 -6
- package/package.json +1 -1
package/dist/orchestrator.js
CHANGED
|
@@ -734,8 +734,8 @@ export class MasterOrchestrator {
|
|
|
734
734
|
}
|
|
735
735
|
hasCalendarMutation(message) {
|
|
736
736
|
const lower = this.stripTodoSnapshot(message).toLowerCase();
|
|
737
|
-
const target = /(^|\s)\/cal\b|\/calendar\b|\bcalendar\b|\bcal\b/.test(lower);
|
|
738
|
-
const action = /\b(add|create|schedule|book|move|reschedule|update|change|cancel|delete|remove)\b/.test(lower);
|
|
737
|
+
const target = /(^|\s)\/cal\b|\/calendar\b|\bcalendar\b|\bcal\b|\bschedule\b|\bagenda\b/.test(lower);
|
|
738
|
+
const action = /\b(add|create|schedule|book|move|reschedule|update|change|cancel|delete|remove|set|put|place|remind)\b/.test(lower);
|
|
739
739
|
const query = /\b(what|show|list|open|view|see)\b/.test(lower);
|
|
740
740
|
return target && action && !query;
|
|
741
741
|
}
|
|
@@ -1422,9 +1422,9 @@ ${hubContextStr}
|
|
|
1422
1422
|
const toolsBase = this.getToolDefinitions();
|
|
1423
1423
|
const last = messages[messages.length - 1];
|
|
1424
1424
|
const lastContent = last && last.role === 'user' && typeof last.content === 'string' ? last.content : '';
|
|
1425
|
-
const
|
|
1426
|
-
|
|
1427
|
-
|
|
1425
|
+
const requiredTodo = lastContent ? this.hasTodoMutation(lastContent) : false;
|
|
1426
|
+
const requiredCal = lastContent ? this.hasCalendarMutation(lastContent) : false;
|
|
1427
|
+
const restrictWorkers = requiredTodo || requiredCal;
|
|
1428
1428
|
const wantsTodoOrCal = restrictWorkers;
|
|
1429
1429
|
const todoCalTools = new Set(['calendar_upsert_events', 'todo_upsert_items']);
|
|
1430
1430
|
const blockedTools = new Set([
|
|
@@ -1444,6 +1444,7 @@ ${hubContextStr}
|
|
|
1444
1444
|
const requestTimeoutMs = 60000;
|
|
1445
1445
|
const forcedToolChoice = this.getToolChoice(currentMessages);
|
|
1446
1446
|
let retriedForcedTool = false;
|
|
1447
|
+
let retriedTodoCal = false;
|
|
1447
1448
|
while (iterations < maxIterations) {
|
|
1448
1449
|
iterations++;
|
|
1449
1450
|
const toolChoice = forcedToolChoice ?? this.getToolChoice(currentMessages);
|
|
@@ -1492,13 +1493,44 @@ ${hubContextStr}
|
|
|
1492
1493
|
];
|
|
1493
1494
|
continue;
|
|
1494
1495
|
}
|
|
1496
|
+
if (wantsTodoOrCal && !retriedTodoCal && (requiredTodo || requiredCal)) {
|
|
1497
|
+
retriedTodoCal = true;
|
|
1498
|
+
const required = [
|
|
1499
|
+
requiredTodo ? 'todo_upsert_items' : null,
|
|
1500
|
+
requiredCal ? 'calendar_upsert_events' : null
|
|
1501
|
+
].filter(Boolean).join(' and ');
|
|
1502
|
+
const followup = `You must call ${required} now. Do not spawn workers or call any other tools.`;
|
|
1503
|
+
currentMessages = [
|
|
1504
|
+
...currentMessages,
|
|
1505
|
+
{ role: 'assistant', content: response.content },
|
|
1506
|
+
{ role: 'user', content: followup }
|
|
1507
|
+
];
|
|
1508
|
+
continue;
|
|
1509
|
+
}
|
|
1495
1510
|
return this.extractText(response.content);
|
|
1496
1511
|
}
|
|
1497
1512
|
const toolUseBlocks = response.content.filter((block) => block.type === 'tool_use');
|
|
1498
1513
|
const toolNames = toolUseBlocks.map((block) => block.name);
|
|
1499
1514
|
// Process tool calls
|
|
1500
1515
|
const toolResults = await this.processToolCalls(response.content, sendMessage);
|
|
1501
|
-
|
|
1516
|
+
const missingTodo = requiredTodo && !toolNames.includes('todo_upsert_items');
|
|
1517
|
+
const missingCal = requiredCal && !toolNames.includes('calendar_upsert_events');
|
|
1518
|
+
if (wantsTodoOrCal && (missingTodo || missingCal) && !retriedTodoCal) {
|
|
1519
|
+
retriedTodoCal = true;
|
|
1520
|
+
const required = [
|
|
1521
|
+
missingTodo ? 'todo_upsert_items' : null,
|
|
1522
|
+
missingCal ? 'calendar_upsert_events' : null
|
|
1523
|
+
].filter(Boolean).join(' and ');
|
|
1524
|
+
const followup = `You must call ${required} now. Do not repeat tools already called. Do not spawn workers.`;
|
|
1525
|
+
currentMessages = [
|
|
1526
|
+
...currentMessages,
|
|
1527
|
+
{ role: 'assistant', content: response.content },
|
|
1528
|
+
{ role: 'user', content: toolResults },
|
|
1529
|
+
{ role: 'user', content: followup }
|
|
1530
|
+
];
|
|
1531
|
+
continue;
|
|
1532
|
+
}
|
|
1533
|
+
if (wantsTodoOrCal && !missingTodo && !missingCal) {
|
|
1502
1534
|
const updates = [];
|
|
1503
1535
|
if (toolNames.includes('todo_upsert_items'))
|
|
1504
1536
|
updates.push('Updated /todo.');
|