@deepagents/context 0.28.0 → 0.29.1
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/browser.js +75 -45
- package/dist/browser.js.map +3 -3
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +224 -82
- package/dist/index.js.map +4 -4
- package/dist/lib/chat.d.ts +1 -1
- package/dist/lib/chat.d.ts.map +1 -1
- package/dist/lib/engine.d.ts.map +1 -1
- package/dist/lib/fragments/message/user.d.ts +59 -22
- package/dist/lib/fragments/message/user.d.ts.map +1 -1
- package/dist/lib/fragments/reasoning.d.ts +17 -0
- package/dist/lib/fragments/reasoning.d.ts.map +1 -0
- package/package.json +4 -4
- package/dist/example-error-recovery.d.ts +0 -2
- package/dist/example-error-recovery.d.ts.map +0 -1
package/dist/index.d.ts
CHANGED
|
@@ -8,6 +8,7 @@ export * from './lib/estimate.ts';
|
|
|
8
8
|
export * from './lib/fragments.ts';
|
|
9
9
|
export * from './lib/fragments/domain.ts';
|
|
10
10
|
export * from './lib/fragments/message/user.ts';
|
|
11
|
+
export * from './lib/fragments/reasoning.ts';
|
|
11
12
|
export * from './lib/fragments/user.ts';
|
|
12
13
|
export * from './lib/guardrail.ts';
|
|
13
14
|
export * from './lib/guardrails/error-recovery.guardrail.ts';
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,eAAe,CAAC;AAC9B,cAAc,sBAAsB,CAAC;AACrC,cAAc,iCAAiC,CAAC;AAChD,cAAc,qCAAqC,CAAC;AACpD,cAAc,iBAAiB,CAAC;AAChC,cAAc,mBAAmB,CAAC;AAClC,cAAc,oBAAoB,CAAC;AACnC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,iCAAiC,CAAC;AAChD,cAAc,yBAAyB,CAAC;AACxC,cAAc,oBAAoB,CAAC;AACnC,cAAc,8CAA8C,CAAC;AAC7D,cAAc,2BAA2B,CAAC;AAC1C,cAAc,iBAAiB,CAAC;AAChC,cAAc,sCAAsC,CAAC;AACrD,cAAc,wBAAwB,CAAC;AACvC,cAAc,uBAAuB,CAAC;AACtC,cAAc,yBAAyB,CAAC;AACxC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,+BAA+B,CAAC;AAC9C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,gCAAgC,CAAC;AAC/C,cAAc,sBAAsB,CAAC;AACrC,cAAc,wBAAwB,CAAC;AACvC,cAAc,gCAAgC,CAAC;AAC/C,cAAc,qCAAqC,CAAC;AACpD,cAAc,gCAAgC,CAAC;AAC/C,cAAc,8BAA8B,CAAC;AAC7C,cAAc,gBAAgB,CAAC;AAC/B,cAAc,oBAAoB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,eAAe,CAAC;AAC9B,cAAc,sBAAsB,CAAC;AACrC,cAAc,iCAAiC,CAAC;AAChD,cAAc,qCAAqC,CAAC;AACpD,cAAc,iBAAiB,CAAC;AAChC,cAAc,mBAAmB,CAAC;AAClC,cAAc,oBAAoB,CAAC;AACnC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,iCAAiC,CAAC;AAChD,cAAc,8BAA8B,CAAC;AAC7C,cAAc,yBAAyB,CAAC;AACxC,cAAc,oBAAoB,CAAC;AACnC,cAAc,8CAA8C,CAAC;AAC7D,cAAc,2BAA2B,CAAC;AAC1C,cAAc,iBAAiB,CAAC;AAChC,cAAc,sCAAsC,CAAC;AACrD,cAAc,wBAAwB,CAAC;AACvC,cAAc,uBAAuB,CAAC;AACtC,cAAc,yBAAyB,CAAC;AACxC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,+BAA+B,CAAC;AAC9C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,gCAAgC,CAAC;AAC/C,cAAc,sBAAsB,CAAC;AACrC,cAAc,wBAAwB,CAAC;AACvC,cAAc,gCAAgC,CAAC;AAC/C,cAAc,qCAAqC,CAAC;AACpD,cAAc,gCAAgC,CAAC;AAC/C,cAAc,8BAA8B,CAAC;AAC7C,cAAc,gBAAgB,CAAC;AAC/B,cAAc,oBAAoB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -591,6 +591,33 @@ async function estimate(modelId, renderer, ...fragments) {
|
|
|
591
591
|
|
|
592
592
|
// packages/context/src/lib/fragments/message/user.ts
|
|
593
593
|
import { generateId as generateId3, isTextUIPart } from "ai";
|
|
594
|
+
function everyNTurns(n) {
|
|
595
|
+
return (turn) => turn % n === 0;
|
|
596
|
+
}
|
|
597
|
+
function once() {
|
|
598
|
+
return (turn) => turn === 1;
|
|
599
|
+
}
|
|
600
|
+
function firstN(n) {
|
|
601
|
+
return (turn) => turn <= n;
|
|
602
|
+
}
|
|
603
|
+
function afterTurn(n) {
|
|
604
|
+
return (turn) => turn > n;
|
|
605
|
+
}
|
|
606
|
+
function and(...predicates) {
|
|
607
|
+
return (turn) => predicates.every((p) => p(turn));
|
|
608
|
+
}
|
|
609
|
+
function or(...predicates) {
|
|
610
|
+
return (turn) => predicates.some((p) => p(turn));
|
|
611
|
+
}
|
|
612
|
+
function not(predicate) {
|
|
613
|
+
return (turn) => !predicate(turn);
|
|
614
|
+
}
|
|
615
|
+
function isConditionalReminder(fragment2) {
|
|
616
|
+
return fragment2.name === "reminder" && !!fragment2.metadata?.reminder;
|
|
617
|
+
}
|
|
618
|
+
function getConditionalReminder(fragment2) {
|
|
619
|
+
return fragment2.metadata.reminder;
|
|
620
|
+
}
|
|
594
621
|
var SYSTEM_REMINDER_OPEN_TAG = "<system-reminder>";
|
|
595
622
|
var SYSTEM_REMINDER_CLOSE_TAG = "</system-reminder>";
|
|
596
623
|
function getReminderRanges(metadata) {
|
|
@@ -725,66 +752,61 @@ function applyPartReminder(message2, value) {
|
|
|
725
752
|
mode: "part"
|
|
726
753
|
};
|
|
727
754
|
}
|
|
728
|
-
function
|
|
729
|
-
return
|
|
755
|
+
function resolveReminderText(item, ctx) {
|
|
756
|
+
return typeof item.text === "function" ? item.text(ctx) : item.text;
|
|
730
757
|
}
|
|
731
|
-
function
|
|
732
|
-
|
|
733
|
-
if (
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
return
|
|
758
|
+
function applyReminderToMessage(message2, item, ctx) {
|
|
759
|
+
const resolvedText = resolveReminderText(item, ctx);
|
|
760
|
+
if (resolvedText.trim().length === 0) {
|
|
761
|
+
return null;
|
|
762
|
+
}
|
|
763
|
+
return item.asPart ? applyPartReminder(message2, resolvedText) : applyInlineReminder(message2, resolvedText);
|
|
764
|
+
}
|
|
765
|
+
function mergeReminderMetadata(message2, addedReminders) {
|
|
766
|
+
if (addedReminders.length === 0) return;
|
|
767
|
+
const metadata = isRecord(message2.metadata) ? { ...message2.metadata } : {};
|
|
768
|
+
const existing = Array.isArray(metadata.reminders) ? metadata.reminders : [];
|
|
769
|
+
metadata.reminders = [...existing, ...addedReminders];
|
|
770
|
+
message2.metadata = metadata;
|
|
740
771
|
}
|
|
741
772
|
function reminder(text, options) {
|
|
742
773
|
if (typeof text === "string") {
|
|
743
774
|
assertReminderText(text);
|
|
744
775
|
}
|
|
776
|
+
if (options && "when" in options && options.when) {
|
|
777
|
+
return {
|
|
778
|
+
name: "reminder",
|
|
779
|
+
metadata: {
|
|
780
|
+
reminder: {
|
|
781
|
+
text,
|
|
782
|
+
when: options.when,
|
|
783
|
+
asPart: options.asPart ?? false
|
|
784
|
+
}
|
|
785
|
+
}
|
|
786
|
+
};
|
|
787
|
+
}
|
|
745
788
|
return {
|
|
746
789
|
text,
|
|
747
|
-
asPart: options?.asPart ?? false
|
|
748
|
-
...options?.everyNTurns !== void 0 && {
|
|
749
|
-
everyNTurns: options.everyNTurns
|
|
750
|
-
},
|
|
751
|
-
...options?.once !== void 0 && { once: options.once },
|
|
752
|
-
...options?.firstN !== void 0 && { firstN: options.firstN },
|
|
753
|
-
...options?.afterTurn !== void 0 && { afterTurn: options.afterTurn },
|
|
754
|
-
...options?.when !== void 0 && { when: options.when }
|
|
790
|
+
asPart: options?.asPart ?? false
|
|
755
791
|
};
|
|
756
792
|
}
|
|
757
|
-
function resolveReminderText(item, ctx) {
|
|
758
|
-
return typeof item.text === "function" ? item.text(ctx) : item.text;
|
|
759
|
-
}
|
|
760
793
|
function user(content, ...reminders) {
|
|
761
794
|
const message2 = typeof content === "string" ? {
|
|
762
795
|
id: generateId3(),
|
|
763
796
|
role: "user",
|
|
764
797
|
parts: [{ type: "text", text: content }]
|
|
765
798
|
} : { ...content, role: "user", parts: [...content.parts] };
|
|
766
|
-
|
|
767
|
-
const scheduledReminders = reminders.filter((r) => hasSchedule(r));
|
|
768
|
-
if (immediateReminders.length > 0) {
|
|
769
|
-
const addedReminders = [];
|
|
799
|
+
if (reminders.length > 0) {
|
|
770
800
|
const plainText = extractPlainText(message2);
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
}
|
|
776
|
-
addedReminders.push(
|
|
777
|
-
item.asPart ? applyPartReminder(message2, resolvedText) : applyInlineReminder(message2, resolvedText)
|
|
778
|
-
);
|
|
779
|
-
}
|
|
780
|
-
if (addedReminders.length > 0) {
|
|
781
|
-
const metadata = isRecord(message2.metadata) ? { ...message2.metadata } : {};
|
|
782
|
-
const existingReminders = Array.isArray(metadata.reminders) ? metadata.reminders : [];
|
|
783
|
-
metadata.reminders = [...existingReminders, ...addedReminders];
|
|
784
|
-
message2.metadata = metadata;
|
|
801
|
+
const addedReminders = [];
|
|
802
|
+
for (const item of reminders) {
|
|
803
|
+
const meta = applyReminderToMessage(message2, item, {
|
|
804
|
+
content: plainText
|
|
805
|
+
});
|
|
806
|
+
if (meta) addedReminders.push(meta);
|
|
785
807
|
}
|
|
808
|
+
mergeReminderMetadata(message2, addedReminders);
|
|
786
809
|
}
|
|
787
|
-
const fragmentMetadata = scheduledReminders.length > 0 ? { scheduledReminders } : void 0;
|
|
788
810
|
return {
|
|
789
811
|
id: message2.id,
|
|
790
812
|
name: "user",
|
|
@@ -797,8 +819,7 @@ function user(content, ...reminders) {
|
|
|
797
819
|
encode() {
|
|
798
820
|
return message2;
|
|
799
821
|
}
|
|
800
|
-
}
|
|
801
|
-
metadata: fragmentMetadata
|
|
822
|
+
}
|
|
802
823
|
};
|
|
803
824
|
}
|
|
804
825
|
|
|
@@ -1700,6 +1721,9 @@ var ContextEngine = class {
|
|
|
1700
1721
|
#initialized = false;
|
|
1701
1722
|
/** Initial metadata to merge on first initialization */
|
|
1702
1723
|
#initialMetadata;
|
|
1724
|
+
get #renderableFragments() {
|
|
1725
|
+
return this.#fragments.filter((f) => !isConditionalReminder(f));
|
|
1726
|
+
}
|
|
1703
1727
|
constructor(options) {
|
|
1704
1728
|
if (!options.chatId) {
|
|
1705
1729
|
throw new Error("chatId is required");
|
|
@@ -1866,7 +1890,7 @@ var ContextEngine = class {
|
|
|
1866
1890
|
* @internal Use resolve() instead for public API.
|
|
1867
1891
|
*/
|
|
1868
1892
|
render(renderer) {
|
|
1869
|
-
return renderer.render(this.#
|
|
1893
|
+
return renderer.render(this.#renderableFragments);
|
|
1870
1894
|
}
|
|
1871
1895
|
/**
|
|
1872
1896
|
* Resolve context into AI SDK-ready format.
|
|
@@ -1887,7 +1911,7 @@ var ContextEngine = class {
|
|
|
1887
1911
|
*/
|
|
1888
1912
|
async resolve(options) {
|
|
1889
1913
|
await this.#ensureInitialized();
|
|
1890
|
-
const systemPrompt = options.renderer.render(this.#
|
|
1914
|
+
const systemPrompt = options.renderer.render(this.#renderableFragments);
|
|
1891
1915
|
const messages = [];
|
|
1892
1916
|
if (this.#branch?.headMessageId) {
|
|
1893
1917
|
const chain = await this.#store.getMessageChain(
|
|
@@ -1903,46 +1927,43 @@ var ContextEngine = class {
|
|
|
1903
1927
|
this.#pendingMessages[i] = await this.#resolveLazyFragment(fragment2);
|
|
1904
1928
|
}
|
|
1905
1929
|
}
|
|
1906
|
-
const turn = await this.getTurnCount();
|
|
1907
1930
|
for (const fragment2 of this.#pendingMessages) {
|
|
1908
1931
|
if (!fragment2.codec) {
|
|
1909
1932
|
throw new Error(
|
|
1910
1933
|
`Fragment "${fragment2.name}" is missing codec. Lazy fragments must be resolved before encode.`
|
|
1911
1934
|
);
|
|
1912
1935
|
}
|
|
1913
|
-
|
|
1914
|
-
|
|
1915
|
-
|
|
1936
|
+
messages.push(fragment2.codec.encode());
|
|
1937
|
+
}
|
|
1938
|
+
const conditionalReminders = this.#fragments.filter(isConditionalReminder);
|
|
1939
|
+
if (conditionalReminders.length > 0) {
|
|
1940
|
+
const turn = await this.getTurnCount();
|
|
1941
|
+
let lastUserIndex = -1;
|
|
1942
|
+
for (let i = messages.length - 1; i >= 0; i--) {
|
|
1943
|
+
if (messages[i].role === "user") {
|
|
1944
|
+
lastUserIndex = i;
|
|
1945
|
+
break;
|
|
1946
|
+
}
|
|
1947
|
+
}
|
|
1948
|
+
if (lastUserIndex >= 0) {
|
|
1949
|
+
const original = messages[lastUserIndex];
|
|
1916
1950
|
const message2 = {
|
|
1917
1951
|
...original,
|
|
1918
1952
|
parts: [...original.parts]
|
|
1919
1953
|
};
|
|
1920
1954
|
const plainText = message2.parts.filter(isTextUIPart2).map((p) => p.text).join(" ");
|
|
1921
1955
|
const addedReminders = [];
|
|
1922
|
-
for (const
|
|
1923
|
-
|
|
1924
|
-
|
|
1925
|
-
|
|
1926
|
-
const resolvedText = resolveReminderText(item, {
|
|
1956
|
+
for (const fragment2 of conditionalReminders) {
|
|
1957
|
+
const config = getConditionalReminder(fragment2);
|
|
1958
|
+
if (!config.when(turn)) continue;
|
|
1959
|
+
const meta = applyReminderToMessage(message2, config, {
|
|
1927
1960
|
content: plainText,
|
|
1928
1961
|
turn
|
|
1929
1962
|
});
|
|
1930
|
-
if (
|
|
1931
|
-
continue;
|
|
1932
|
-
}
|
|
1933
|
-
addedReminders.push(
|
|
1934
|
-
item.asPart ? applyPartReminder(message2, resolvedText) : applyInlineReminder(message2, resolvedText)
|
|
1935
|
-
);
|
|
1936
|
-
}
|
|
1937
|
-
if (addedReminders.length > 0) {
|
|
1938
|
-
const metadata = typeof message2.metadata === "object" && message2.metadata !== null && !Array.isArray(message2.metadata) ? { ...message2.metadata } : {};
|
|
1939
|
-
const existingReminders = Array.isArray(metadata.reminders) ? metadata.reminders : [];
|
|
1940
|
-
metadata.reminders = [...existingReminders, ...addedReminders];
|
|
1941
|
-
message2.metadata = metadata;
|
|
1963
|
+
if (meta) addedReminders.push(meta);
|
|
1942
1964
|
}
|
|
1943
|
-
|
|
1944
|
-
|
|
1945
|
-
messages.push(fragment2.codec.encode());
|
|
1965
|
+
mergeReminderMetadata(message2, addedReminders);
|
|
1966
|
+
messages[lastUserIndex] = message2;
|
|
1946
1967
|
}
|
|
1947
1968
|
}
|
|
1948
1969
|
return {
|
|
@@ -2079,7 +2100,7 @@ var ContextEngine = class {
|
|
|
2079
2100
|
}
|
|
2080
2101
|
const tokenizer = registry.getTokenizer(modelId);
|
|
2081
2102
|
const fragmentEstimates = [];
|
|
2082
|
-
for (const fragment2 of this.#
|
|
2103
|
+
for (const fragment2 of this.#renderableFragments) {
|
|
2083
2104
|
const rendered = renderer.render([fragment2]);
|
|
2084
2105
|
const tokens = tokenizer.count(rendered);
|
|
2085
2106
|
const cost = tokens / 1e6 * model.cost.input;
|
|
@@ -2412,7 +2433,7 @@ var ContextEngine = class {
|
|
|
2412
2433
|
await this.#ensureInitialized();
|
|
2413
2434
|
const { renderer } = options;
|
|
2414
2435
|
const estimateResult = await this.estimate(options.modelId, { renderer });
|
|
2415
|
-
const rendered = renderer.render(this.#
|
|
2436
|
+
const rendered = renderer.render(this.#renderableFragments);
|
|
2416
2437
|
const persistedMessages = [];
|
|
2417
2438
|
if (this.#branch?.headMessageId) {
|
|
2418
2439
|
const chain = await this.#store.getMessageChain(
|
|
@@ -3426,25 +3447,29 @@ async function chat(agent2, messages, options) {
|
|
|
3426
3447
|
} else {
|
|
3427
3448
|
context.set(lastFragment);
|
|
3428
3449
|
await context.save();
|
|
3429
|
-
assistantMsgId =
|
|
3450
|
+
assistantMsgId = generateId4();
|
|
3430
3451
|
}
|
|
3431
3452
|
const uiMessages = messages.map(chatMessageToUIMessage);
|
|
3432
|
-
let
|
|
3453
|
+
let title = null;
|
|
3433
3454
|
if (!context.chat?.title) {
|
|
3434
3455
|
const firstUserMsg = uiMessages.find((m) => m.role === "user");
|
|
3435
3456
|
if (firstUserMsg) {
|
|
3436
|
-
await context.updateChat({ title: staticChatTitle(firstUserMsg) });
|
|
3437
3457
|
if (options?.generateTitle && agent2.model) {
|
|
3438
|
-
|
|
3458
|
+
title = await generateChatTitle({
|
|
3439
3459
|
message: firstUserMsg,
|
|
3440
|
-
model: agent2.model
|
|
3460
|
+
model: agent2.model,
|
|
3461
|
+
abortSignal: options?.abortSignal
|
|
3441
3462
|
});
|
|
3463
|
+
} else {
|
|
3464
|
+
title = staticChatTitle(firstUserMsg);
|
|
3442
3465
|
}
|
|
3466
|
+
await context.updateChat({ title });
|
|
3443
3467
|
}
|
|
3444
3468
|
}
|
|
3445
3469
|
const streamContextVariables = options?.contextVariables === void 0 ? {} : options.contextVariables;
|
|
3446
3470
|
const result = await agent2.stream(streamContextVariables, {
|
|
3447
|
-
transform: options?.transform
|
|
3471
|
+
transform: options?.transform,
|
|
3472
|
+
abortSignal: options?.abortSignal
|
|
3448
3473
|
});
|
|
3449
3474
|
const uiStream = result.toUIMessageStream({
|
|
3450
3475
|
onError: options?.onError ?? formatChatError,
|
|
@@ -3487,10 +3512,8 @@ async function chat(agent2, messages, options) {
|
|
|
3487
3512
|
},
|
|
3488
3513
|
execute: async ({ writer }) => {
|
|
3489
3514
|
writer.merge(uiStream);
|
|
3490
|
-
if (
|
|
3491
|
-
const title = await titlePromise;
|
|
3515
|
+
if (title) {
|
|
3492
3516
|
writer.write({ type: "data-chat-title", data: title });
|
|
3493
|
-
await context.updateChat({ title });
|
|
3494
3517
|
}
|
|
3495
3518
|
}
|
|
3496
3519
|
});
|
|
@@ -3791,6 +3814,115 @@ function fromFragment(fragment2, options) {
|
|
|
3791
3814
|
throw new Error(`Fragment "${fragment2.name}" is missing codec`);
|
|
3792
3815
|
}
|
|
3793
3816
|
|
|
3817
|
+
// packages/context/src/lib/fragments/reasoning.ts
|
|
3818
|
+
function reasoningFramework() {
|
|
3819
|
+
return [
|
|
3820
|
+
role(
|
|
3821
|
+
"You are a very strong reasoner and planner. Use these critical instructions to structure your plans, thoughts, and responses."
|
|
3822
|
+
),
|
|
3823
|
+
fragment(
|
|
3824
|
+
"meta_cognitive_reasoning_framework",
|
|
3825
|
+
hint(
|
|
3826
|
+
"Before taking any action (either tool calls *or* responses to the user), you must proactively, methodically, and independently plan and reason about:"
|
|
3827
|
+
),
|
|
3828
|
+
principle({
|
|
3829
|
+
title: "Logical dependencies and constraints",
|
|
3830
|
+
description: "Analyze the intended action against the following factors. Resolve conflicts in order of importance:",
|
|
3831
|
+
policies: [
|
|
3832
|
+
policy({
|
|
3833
|
+
rule: "Policy-based rules, mandatory prerequisites, and constraints."
|
|
3834
|
+
}),
|
|
3835
|
+
policy({
|
|
3836
|
+
rule: "Order of operations: Ensure taking an action does not prevent a subsequent necessary action.",
|
|
3837
|
+
policies: [
|
|
3838
|
+
"The user may request actions in a random order, but you may need to reorder operations to maximize successful completion of the task."
|
|
3839
|
+
]
|
|
3840
|
+
}),
|
|
3841
|
+
policy({
|
|
3842
|
+
rule: "Other prerequisites (information and/or actions needed)."
|
|
3843
|
+
}),
|
|
3844
|
+
policy({ rule: "Explicit user constraints or preferences." })
|
|
3845
|
+
]
|
|
3846
|
+
}),
|
|
3847
|
+
principle({
|
|
3848
|
+
title: "Risk assessment",
|
|
3849
|
+
description: "What are the consequences of taking the action? Will the new state cause any future issues?",
|
|
3850
|
+
policies: [
|
|
3851
|
+
"For exploratory tasks (like searches), missing *optional* parameters is a LOW risk. **Prefer calling the tool with the available information over asking the user, unless** your Rule 1 (Logical Dependencies) reasoning determines that optional information is required for a later step in your plan."
|
|
3852
|
+
]
|
|
3853
|
+
}),
|
|
3854
|
+
principle({
|
|
3855
|
+
title: "Abductive reasoning and hypothesis exploration",
|
|
3856
|
+
description: "At each step, identify the most logical and likely reason for any problem encountered.",
|
|
3857
|
+
policies: [
|
|
3858
|
+
"Look beyond immediate or obvious causes. The most likely reason may not be the simplest and may require deeper inference.",
|
|
3859
|
+
"Hypotheses may require additional research. Each hypothesis may take multiple steps to test.",
|
|
3860
|
+
"Prioritize hypotheses based on likelihood, but do not discard less likely ones prematurely. A low-probability event may still be the root cause."
|
|
3861
|
+
]
|
|
3862
|
+
}),
|
|
3863
|
+
principle({
|
|
3864
|
+
title: "Outcome evaluation and adaptability",
|
|
3865
|
+
description: "Does the previous observation require any changes to your plan?",
|
|
3866
|
+
policies: [
|
|
3867
|
+
"If your initial hypotheses are disproven, actively generate new ones based on the gathered information."
|
|
3868
|
+
]
|
|
3869
|
+
}),
|
|
3870
|
+
principle({
|
|
3871
|
+
title: "Information availability",
|
|
3872
|
+
description: "Incorporate all applicable and alternative sources of information, including:",
|
|
3873
|
+
policies: [
|
|
3874
|
+
"Using available tools and their capabilities",
|
|
3875
|
+
"All policies, rules, checklists, and constraints",
|
|
3876
|
+
"Previous observations and conversation history",
|
|
3877
|
+
"Information only available by asking the user"
|
|
3878
|
+
]
|
|
3879
|
+
}),
|
|
3880
|
+
principle({
|
|
3881
|
+
title: "Precision and Grounding",
|
|
3882
|
+
description: "Ensure your reasoning is extremely precise and relevant to each exact ongoing situation.",
|
|
3883
|
+
policies: [
|
|
3884
|
+
"Verify your claims by quoting the exact applicable information (including policies) when referring to them."
|
|
3885
|
+
]
|
|
3886
|
+
}),
|
|
3887
|
+
principle({
|
|
3888
|
+
title: "Completeness",
|
|
3889
|
+
description: "Ensure that all requirements, constraints, options, and preferences are exhaustively incorporated into your plan.",
|
|
3890
|
+
policies: [
|
|
3891
|
+
policy({
|
|
3892
|
+
rule: "Resolve conflicts using the order of importance in #1."
|
|
3893
|
+
}),
|
|
3894
|
+
policy({
|
|
3895
|
+
rule: "Avoid premature conclusions: There may be multiple relevant options for a given situation.",
|
|
3896
|
+
policies: [
|
|
3897
|
+
"To check for whether an option is relevant, reason about all information sources from #5.",
|
|
3898
|
+
"You may need to consult the user to even know whether something is applicable. Do not assume it is not applicable without checking."
|
|
3899
|
+
]
|
|
3900
|
+
}),
|
|
3901
|
+
policy({
|
|
3902
|
+
rule: "Review applicable sources of information from #5 to confirm which are relevant to the current state."
|
|
3903
|
+
})
|
|
3904
|
+
]
|
|
3905
|
+
}),
|
|
3906
|
+
principle({
|
|
3907
|
+
title: "Persistence and patience",
|
|
3908
|
+
description: "Do not give up unless all the reasoning above is exhausted.",
|
|
3909
|
+
policies: [
|
|
3910
|
+
"Don't be dissuaded by time taken or user frustration.",
|
|
3911
|
+
"This persistence must be intelligent: On *transient* errors (e.g. please try again), you *must* retry **unless an explicit retry limit (e.g., max x tries) has been reached**. If such a limit is hit, you *must* stop. On *other* errors, you must change your strategy or arguments, not repeat the same failed call."
|
|
3912
|
+
]
|
|
3913
|
+
}),
|
|
3914
|
+
principle({
|
|
3915
|
+
title: "Inhibit your response",
|
|
3916
|
+
description: "Only take an action after all the above reasoning is completed. Once you've taken an action, you cannot take it back."
|
|
3917
|
+
}),
|
|
3918
|
+
principle({
|
|
3919
|
+
title: "Continuous self-monitoring",
|
|
3920
|
+
description: "Constantly evaluate your own reasoning process for any gaps, biases, or errors. Apply the above principles iteratively as needed."
|
|
3921
|
+
})
|
|
3922
|
+
)
|
|
3923
|
+
];
|
|
3924
|
+
}
|
|
3925
|
+
|
|
3794
3926
|
// packages/context/src/lib/guardrails/error-recovery.guardrail.ts
|
|
3795
3927
|
import chalk2 from "chalk";
|
|
3796
3928
|
var errorRecoveryGuardrail = {
|
|
@@ -7219,11 +7351,14 @@ export {
|
|
|
7219
7351
|
TomlRenderer,
|
|
7220
7352
|
ToonRenderer,
|
|
7221
7353
|
XmlRenderer,
|
|
7354
|
+
afterTurn,
|
|
7222
7355
|
agent,
|
|
7223
7356
|
alias,
|
|
7224
7357
|
analogy,
|
|
7358
|
+
and,
|
|
7225
7359
|
applyInlineReminder,
|
|
7226
7360
|
applyPartReminder,
|
|
7361
|
+
applyReminderToMessage,
|
|
7227
7362
|
assistant,
|
|
7228
7363
|
assistantText,
|
|
7229
7364
|
chat,
|
|
@@ -7239,21 +7374,24 @@ export {
|
|
|
7239
7374
|
encodeSerializedValue,
|
|
7240
7375
|
errorRecoveryGuardrail,
|
|
7241
7376
|
estimate,
|
|
7377
|
+
everyNTurns,
|
|
7242
7378
|
example,
|
|
7243
7379
|
explain,
|
|
7244
7380
|
fail,
|
|
7381
|
+
firstN,
|
|
7245
7382
|
fragment,
|
|
7246
7383
|
fromFragment,
|
|
7247
7384
|
generateChatTitle,
|
|
7385
|
+
getConditionalReminder,
|
|
7248
7386
|
getFragmentData,
|
|
7249
7387
|
getModelsRegistry,
|
|
7250
7388
|
getReminderRanges,
|
|
7251
7389
|
glossary,
|
|
7252
7390
|
guardrail,
|
|
7253
|
-
hasSchedule,
|
|
7254
7391
|
hint,
|
|
7255
7392
|
identity,
|
|
7256
7393
|
isComposeOptions,
|
|
7394
|
+
isConditionalReminder,
|
|
7257
7395
|
isDockerfileOptions,
|
|
7258
7396
|
isFragment,
|
|
7259
7397
|
isFragmentObject,
|
|
@@ -7261,10 +7399,14 @@ export {
|
|
|
7261
7399
|
isMessageFragment,
|
|
7262
7400
|
lastAssistantMessage,
|
|
7263
7401
|
loadSkillMetadata,
|
|
7402
|
+
mergeReminderMetadata,
|
|
7264
7403
|
message,
|
|
7265
7404
|
nextAdaptivePollingDelay,
|
|
7266
7405
|
normalizeCancelPolling,
|
|
7267
7406
|
normalizeWatchPolling,
|
|
7407
|
+
not,
|
|
7408
|
+
once,
|
|
7409
|
+
or,
|
|
7268
7410
|
parseFrontmatter,
|
|
7269
7411
|
pass,
|
|
7270
7412
|
persistedWriter,
|
|
@@ -7273,13 +7415,13 @@ export {
|
|
|
7273
7415
|
preference,
|
|
7274
7416
|
principle,
|
|
7275
7417
|
quirk,
|
|
7418
|
+
reasoningFramework,
|
|
7276
7419
|
reminder,
|
|
7277
7420
|
render,
|
|
7278
7421
|
resetAdaptivePolling,
|
|
7279
7422
|
resolveReminderText,
|
|
7280
7423
|
role,
|
|
7281
7424
|
runGuardrailChain,
|
|
7282
|
-
shouldIncludeReminder,
|
|
7283
7425
|
skills,
|
|
7284
7426
|
skillsReminder,
|
|
7285
7427
|
soul,
|