@cognipeer/agent-sdk 0.6.4 → 0.6.6
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/README.md +26 -7
- package/dist/index.cjs +866 -171
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +258 -5
- package/dist/index.d.ts +258 -5
- package/dist/index.mjs +862 -172
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -206,6 +206,24 @@ type AgentLimits = {
|
|
|
206
206
|
maxToolCalls?: number;
|
|
207
207
|
maxParallelTools?: number;
|
|
208
208
|
maxContextTokens?: number;
|
|
209
|
+
/**
|
|
210
|
+
* Cap on cumulative model output tokens across the whole invoke. Once
|
|
211
|
+
* exceeded the loop terminates after the current iteration with a
|
|
212
|
+
* `metadata` event explaining the reason and emits `finalAnswer` so callers
|
|
213
|
+
* can still recover the partial result.
|
|
214
|
+
*/
|
|
215
|
+
maxTotalOutputTokens?: number;
|
|
216
|
+
/**
|
|
217
|
+
* Cap on cumulative cost in USD. Requires `costEstimator` on the agent
|
|
218
|
+
* options to be a no-op-free check; otherwise this limit is ignored.
|
|
219
|
+
*/
|
|
220
|
+
maxCostUsd?: number;
|
|
221
|
+
/**
|
|
222
|
+
* Cap on total wall-clock time for the invoke in milliseconds. Identical
|
|
223
|
+
* semantics to `InvokeConfig.timeoutMs` but lives on the agent definition
|
|
224
|
+
* so server-side defaults can be enforced without per-call wiring.
|
|
225
|
+
*/
|
|
226
|
+
maxWallClockMs?: number;
|
|
209
227
|
};
|
|
210
228
|
type SmartAgentLimits = AgentLimits;
|
|
211
229
|
type TraceSinkFileConfig = {
|
|
@@ -262,6 +280,31 @@ type AgentOptions = {
|
|
|
262
280
|
* When omitted or `enabled=false` the agent behaves exactly as before.
|
|
263
281
|
*/
|
|
264
282
|
reasoning?: ReasoningConfig;
|
|
283
|
+
/**
|
|
284
|
+
* Optional drop-in token counter. When provided, all internal token
|
|
285
|
+
* estimates (summarization trigger, hard caps, context budget) use this
|
|
286
|
+
* function instead of the built-in character heuristic. Recommended:
|
|
287
|
+
* tiktoken / @anthropic-ai/tokenizer for production accuracy.
|
|
288
|
+
*/
|
|
289
|
+
tokenCounter?: (text: string) => number;
|
|
290
|
+
/**
|
|
291
|
+
* Pluggable cost estimator: returns USD cost for a single model call's
|
|
292
|
+
* usage. Used by the `maxCostUsd` budget limit. When omitted the SDK has
|
|
293
|
+
* no built-in pricing table and the cost limit is a no-op.
|
|
294
|
+
*/
|
|
295
|
+
costEstimator?: (args: {
|
|
296
|
+
modelName?: string;
|
|
297
|
+
inputTokens: number;
|
|
298
|
+
outputTokens: number;
|
|
299
|
+
cachedInputTokens?: number;
|
|
300
|
+
reasoningTokens?: number;
|
|
301
|
+
}) => number;
|
|
302
|
+
/**
|
|
303
|
+
* Human-in-the-loop hooks. When `askUser` is enabled, the agent gains a
|
|
304
|
+
* built-in `ask_user_question` tool that pauses the run with structured
|
|
305
|
+
* questions for the host application to answer.
|
|
306
|
+
*/
|
|
307
|
+
humanInTheLoop?: HumanInTheLoopOptions;
|
|
265
308
|
};
|
|
266
309
|
type ReasoningLevel = "low" | "medium" | "high";
|
|
267
310
|
type ReflectionCadence = "off" | "every_turn" | "after_tool" | "on_branch";
|
|
@@ -282,6 +325,18 @@ type ReflectionConfig = {
|
|
|
282
325
|
promptTemplate?: string;
|
|
283
326
|
/** When true emits `reflection` SmartAgent events. Default true. */
|
|
284
327
|
emitEvents?: boolean;
|
|
328
|
+
/**
|
|
329
|
+
* Hard cap on the number of reflection calls within a single invoke. Once
|
|
330
|
+
* the cap is hit subsequent qualifying turns no longer trigger reflection.
|
|
331
|
+
* Default: unlimited.
|
|
332
|
+
*/
|
|
333
|
+
maxPerRun?: number;
|
|
334
|
+
/**
|
|
335
|
+
* Minimum number of tool-bearing turns between reflections. Defaults to 1
|
|
336
|
+
* (reflect on every qualifying turn). Set to 2 to reflect every other tool
|
|
337
|
+
* turn, etc. Independent of `cadence`.
|
|
338
|
+
*/
|
|
339
|
+
everyNTurns?: number;
|
|
285
340
|
};
|
|
286
341
|
type NativeReasoningConfig = {
|
|
287
342
|
effort?: "minimal" | "low" | "medium" | "high";
|
|
@@ -485,6 +540,12 @@ type SmartAgentOptions = {
|
|
|
485
540
|
* Unified reasoning configuration. Same shape as on `AgentOptions`. See `ReasoningConfig`.
|
|
486
541
|
*/
|
|
487
542
|
reasoning?: ReasoningConfig;
|
|
543
|
+
/** See AgentOptions.tokenCounter. */
|
|
544
|
+
tokenCounter?: (text: string) => number;
|
|
545
|
+
/** See AgentOptions.costEstimator. */
|
|
546
|
+
costEstimator?: AgentOptions["costEstimator"];
|
|
547
|
+
/** See AgentOptions.humanInTheLoop. */
|
|
548
|
+
humanInTheLoop?: HumanInTheLoopOptions;
|
|
488
549
|
};
|
|
489
550
|
type AgentRuntimeConfig = {
|
|
490
551
|
name?: string;
|
|
@@ -501,6 +562,7 @@ type AgentRuntimeConfig = {
|
|
|
501
562
|
tracing?: TracingConfig;
|
|
502
563
|
runtimeProfile?: RuntimeProfile;
|
|
503
564
|
smart?: ResolvedSmartAgentConfig;
|
|
565
|
+
humanInTheLoop?: HumanInTheLoopRuntimeConfig;
|
|
504
566
|
};
|
|
505
567
|
type TraceMessageSection = {
|
|
506
568
|
id?: string;
|
|
@@ -733,6 +795,7 @@ type AgentState = {
|
|
|
733
795
|
metadata?: Record<string, any>;
|
|
734
796
|
ctx?: Record<string, any>;
|
|
735
797
|
pendingApprovals?: PendingToolApproval[];
|
|
798
|
+
pendingUserQuestions?: PendingUserQuestion[];
|
|
736
799
|
usage?: {
|
|
737
800
|
perRequest: Array<{
|
|
738
801
|
id: string;
|
|
@@ -979,6 +1042,93 @@ type ToolApprovalEvent = {
|
|
|
979
1042
|
decidedBy?: string;
|
|
980
1043
|
comment?: string;
|
|
981
1044
|
};
|
|
1045
|
+
type UserQuestionOption = {
|
|
1046
|
+
/** Label shown to the user. */
|
|
1047
|
+
label: string;
|
|
1048
|
+
/** Value returned in the resolution. Defaults to `label` when omitted. */
|
|
1049
|
+
value?: string;
|
|
1050
|
+
/** Optional helper text rendered alongside the option. */
|
|
1051
|
+
description?: string;
|
|
1052
|
+
/** Optional code / ASCII preview rendered when the option is focused. */
|
|
1053
|
+
preview?: string;
|
|
1054
|
+
};
|
|
1055
|
+
type UserQuestionItem = {
|
|
1056
|
+
/** The full question text shown to the user. */
|
|
1057
|
+
question: string;
|
|
1058
|
+
/** Short label (chip / tag) displayed alongside the question. */
|
|
1059
|
+
header?: string;
|
|
1060
|
+
/** When true the user may pick multiple options. Default: false. */
|
|
1061
|
+
multiSelect?: boolean;
|
|
1062
|
+
/** Placeholder shown for the free-text input (when enabled globally). */
|
|
1063
|
+
placeholder?: string;
|
|
1064
|
+
/** Predefined options; omit for a pure free-text question. */
|
|
1065
|
+
options?: UserQuestionOption[];
|
|
1066
|
+
/** When true the user must answer this item. Default: true. */
|
|
1067
|
+
required?: boolean;
|
|
1068
|
+
};
|
|
1069
|
+
type UserQuestionStatus = "pending" | "answered" | "cancelled" | "executed";
|
|
1070
|
+
type UserQuestionAnswer = {
|
|
1071
|
+
/** Selected option values. Single-select questions report exactly one entry. */
|
|
1072
|
+
values: string[];
|
|
1073
|
+
/** Populated when the user typed a custom answer (only when free-text is enabled). */
|
|
1074
|
+
freeText?: string;
|
|
1075
|
+
/** Optional reviewer notes. */
|
|
1076
|
+
notes?: string;
|
|
1077
|
+
};
|
|
1078
|
+
/** Keyed by the question text (or `header`, if both questions share text). */
|
|
1079
|
+
type UserQuestionAnswerSet = Record<string, UserQuestionAnswer>;
|
|
1080
|
+
type PendingUserQuestion = {
|
|
1081
|
+
id: string;
|
|
1082
|
+
toolCallId: string;
|
|
1083
|
+
toolName: "ask_user_question";
|
|
1084
|
+
questions: UserQuestionItem[];
|
|
1085
|
+
status: UserQuestionStatus;
|
|
1086
|
+
requestedAt: string;
|
|
1087
|
+
answeredAt?: string;
|
|
1088
|
+
answeredBy?: string;
|
|
1089
|
+
answers?: UserQuestionAnswerSet;
|
|
1090
|
+
cancelled?: boolean;
|
|
1091
|
+
notes?: string;
|
|
1092
|
+
/** Snapshot of the global free-text flag at request time, for UI rendering. */
|
|
1093
|
+
allowFreeText?: boolean;
|
|
1094
|
+
metadata?: Record<string, any>;
|
|
1095
|
+
};
|
|
1096
|
+
type UserQuestionResolution = {
|
|
1097
|
+
id: string;
|
|
1098
|
+
answers?: UserQuestionAnswerSet;
|
|
1099
|
+
answeredBy?: string;
|
|
1100
|
+
notes?: string;
|
|
1101
|
+
/** When true the tool call is reported back as cancelled / unanswered. */
|
|
1102
|
+
cancelled?: boolean;
|
|
1103
|
+
};
|
|
1104
|
+
type UserQuestionEvent = {
|
|
1105
|
+
type: "user_question";
|
|
1106
|
+
status: "pending" | "answered" | "cancelled";
|
|
1107
|
+
id: string;
|
|
1108
|
+
toolCallId: string;
|
|
1109
|
+
questions?: UserQuestionItem[];
|
|
1110
|
+
answers?: UserQuestionAnswerSet;
|
|
1111
|
+
answeredBy?: string;
|
|
1112
|
+
allowFreeText?: boolean;
|
|
1113
|
+
};
|
|
1114
|
+
type HumanInTheLoopAskUserConfig = {
|
|
1115
|
+
enabled: boolean;
|
|
1116
|
+
allowFreeText: boolean;
|
|
1117
|
+
promptOverride?: string;
|
|
1118
|
+
};
|
|
1119
|
+
type HumanInTheLoopRuntimeConfig = {
|
|
1120
|
+
askUser?: HumanInTheLoopAskUserConfig;
|
|
1121
|
+
};
|
|
1122
|
+
type HumanInTheLoopOptions = {
|
|
1123
|
+
askUser?: boolean | {
|
|
1124
|
+
/** Allow the user to type a custom "Other" answer. Default: true. */
|
|
1125
|
+
allowFreeText?: boolean;
|
|
1126
|
+
/** Override the built-in tool description. */
|
|
1127
|
+
promptOverride?: string;
|
|
1128
|
+
/** Convenience: subscribe to user_question events without setting up onEvent. */
|
|
1129
|
+
onQuestion?: (event: UserQuestionEvent) => void;
|
|
1130
|
+
};
|
|
1131
|
+
};
|
|
982
1132
|
type GuardrailEvent = {
|
|
983
1133
|
type: "guardrail";
|
|
984
1134
|
phase: GuardrailPhase;
|
|
@@ -990,7 +1140,7 @@ type GuardrailEvent = {
|
|
|
990
1140
|
reason?: string;
|
|
991
1141
|
details?: Record<string, any>;
|
|
992
1142
|
};
|
|
993
|
-
type SmartAgentEvent = ToolCallEvent | ToolApprovalEvent | PlanEvent | SummarizationEvent | FinalAnswerEvent | MetadataEvent | HandoffEvent | GuardrailEvent | ProgressEvent | StreamEvent | CancelledEvent | ReflectionEvent;
|
|
1143
|
+
type SmartAgentEvent = ToolCallEvent | ToolApprovalEvent | UserQuestionEvent | PlanEvent | SummarizationEvent | FinalAnswerEvent | MetadataEvent | HandoffEvent | GuardrailEvent | ProgressEvent | StreamEvent | CancelledEvent | ReflectionEvent;
|
|
994
1144
|
type ReflectionEvent = {
|
|
995
1145
|
type: "reflection";
|
|
996
1146
|
id: string;
|
|
@@ -1083,6 +1233,7 @@ type AgentInstance<TOutput = unknown> = {
|
|
|
1083
1233
|
snapshot: (state: SmartState, options?: SnapshotOptions) => AgentSnapshot;
|
|
1084
1234
|
resume: (snapshot: AgentSnapshot, config?: InvokeConfig, restoreOptions?: RestoreSnapshotOptions) => Promise<AgentInvokeResult<TOutput>>;
|
|
1085
1235
|
resolveToolApproval: (state: SmartState, resolution: ToolApprovalResolution) => SmartState;
|
|
1236
|
+
resolveUserQuestion: (state: SmartState, resolution: UserQuestionResolution) => SmartState;
|
|
1086
1237
|
asTool: (opts: {
|
|
1087
1238
|
toolName: string;
|
|
1088
1239
|
description?: string;
|
|
@@ -1098,7 +1249,29 @@ type AgentInstance<TOutput = unknown> = {
|
|
|
1098
1249
|
type SmartAgentInstance<TOutput = unknown> = AgentInstance<TOutput>;
|
|
1099
1250
|
|
|
1100
1251
|
type SmartToolFn = (args: any) => Promise<any> | any;
|
|
1101
|
-
|
|
1252
|
+
type ToolCachePolicy = {
|
|
1253
|
+
/** Cache scope. "run" persists for the current invoke only. */
|
|
1254
|
+
scope?: "run";
|
|
1255
|
+
/** Override the cache key (default: stable JSON of args). */
|
|
1256
|
+
keyFn?: (args: any) => string;
|
|
1257
|
+
/** Time-to-live for the cached value, in ms. Default: full invoke. */
|
|
1258
|
+
ttlMs?: number;
|
|
1259
|
+
};
|
|
1260
|
+
type ToolRetryPolicy = {
|
|
1261
|
+
/** Max retry attempts after the initial failure. Default: 0. */
|
|
1262
|
+
maxRetries?: number;
|
|
1263
|
+
/** Initial backoff in ms (doubled on each retry). Default: 250. */
|
|
1264
|
+
backoffMs?: number;
|
|
1265
|
+
/** Decide whether an error is worth retrying. Default: every error. */
|
|
1266
|
+
shouldRetry?: (err: unknown, attempt: number) => boolean;
|
|
1267
|
+
/**
|
|
1268
|
+
* Open a circuit-breaker after this many consecutive failures across the
|
|
1269
|
+
* invoke; once tripped the tool short-circuits with the breaker error
|
|
1270
|
+
* until the loop ends. Default: never trip.
|
|
1271
|
+
*/
|
|
1272
|
+
circuitBreakerThreshold?: number;
|
|
1273
|
+
};
|
|
1274
|
+
declare function createTool({ name, description, schema, func, needsApproval, approvalPrompt, approvalDefaults, maxExecutionsPerRun, cache, retry, }: {
|
|
1102
1275
|
name: string;
|
|
1103
1276
|
description?: string;
|
|
1104
1277
|
schema: ZodSchema;
|
|
@@ -1107,6 +1280,10 @@ declare function createTool({ name, description, schema, func, needsApproval, ap
|
|
|
1107
1280
|
approvalPrompt?: string;
|
|
1108
1281
|
approvalDefaults?: any;
|
|
1109
1282
|
maxExecutionsPerRun?: number | null;
|
|
1283
|
+
/** When set, identical args within the same invoke short-circuit to the cached result. */
|
|
1284
|
+
cache?: boolean | ToolCachePolicy;
|
|
1285
|
+
/** Per-tool retry + circuit-breaker policy. */
|
|
1286
|
+
retry?: ToolRetryPolicy;
|
|
1110
1287
|
}): ToolInterface;
|
|
1111
1288
|
|
|
1112
1289
|
declare function buildSystemPrompt(extra?: string, planning?: boolean | PlanningMode, name?: string, todoListPrompt?: string): string;
|
|
@@ -1137,15 +1314,30 @@ declare function createToolLimitFinalizeNode(_opts: SmartAgentOptions): (state:
|
|
|
1137
1314
|
*/
|
|
1138
1315
|
declare function createContextSummarizeNode(opts: SmartAgentOptions): (state: SmartState) => Promise<Partial<SmartState>>;
|
|
1139
1316
|
|
|
1317
|
+
/**
|
|
1318
|
+
* Token counter contract used across the SDK. The default is a
|
|
1319
|
+
* character-based heuristic; users can swap in a real tokenizer (tiktoken,
|
|
1320
|
+
* @anthropic-ai/tokenizer, …) via SmartAgentOptions.tokenCounter.
|
|
1321
|
+
*/
|
|
1322
|
+
type TokenCounter = (text: string) => number;
|
|
1140
1323
|
/**
|
|
1141
1324
|
* Estimates token count from text using a character-based heuristic.
|
|
1142
1325
|
*
|
|
1143
|
-
*
|
|
1326
|
+
* Approximation:
|
|
1144
1327
|
* - For Latin/ASCII text: ~4 characters per token (GPT-family models)
|
|
1145
1328
|
* - For CJK/Unicode text: ~1.5 characters per token
|
|
1146
1329
|
*
|
|
1147
|
-
* For production accuracy,
|
|
1330
|
+
* For production accuracy, pass a `tokenCounter` option backed by tiktoken.
|
|
1331
|
+
*/
|
|
1332
|
+
declare function defaultTokenCounter(text: string): number;
|
|
1333
|
+
/**
|
|
1334
|
+
* Installs a custom token counter used by every callable in this module
|
|
1335
|
+
* (countApproxTokens, countMessagesTokens). Pass `undefined` or
|
|
1336
|
+
* `defaultTokenCounter` to restore the heuristic.
|
|
1148
1337
|
*/
|
|
1338
|
+
declare function setTokenCounter(counter?: TokenCounter | null): void;
|
|
1339
|
+
declare function getTokenCounter(): TokenCounter;
|
|
1340
|
+
/** Backwards-compatible alias that delegates to the active counter. */
|
|
1149
1341
|
declare function countApproxTokens(text: string): number;
|
|
1150
1342
|
/**
|
|
1151
1343
|
* Estimates the total token count for an array of messages.
|
|
@@ -1486,6 +1678,16 @@ declare function restoreSnapshot(snapshot: AgentSnapshot, restoreOptions?: Resto
|
|
|
1486
1678
|
|
|
1487
1679
|
declare function resolveToolApprovalState(state: SmartState, resolution: ToolApprovalResolution): SmartState;
|
|
1488
1680
|
|
|
1681
|
+
declare function resolveUserQuestionState(state: SmartState, resolution: UserQuestionResolution): SmartState;
|
|
1682
|
+
|
|
1683
|
+
type AskUserStateRef = {
|
|
1684
|
+
pendingUserQuestions?: PendingUserQuestion[];
|
|
1685
|
+
ctx?: Record<string, any>;
|
|
1686
|
+
__onEvent?: (event: any) => void;
|
|
1687
|
+
__currentToolCallId?: string;
|
|
1688
|
+
};
|
|
1689
|
+
declare function createAskUserQuestionTool(stateRef: AskUserStateRef, config: HumanInTheLoopAskUserConfig): ToolInterface<any, any, any>;
|
|
1690
|
+
|
|
1489
1691
|
declare function fromLangchainTools<T extends ToolInterface = ToolInterface>(tools: any[]): T[];
|
|
1490
1692
|
|
|
1491
1693
|
declare function fileSink(path?: string): TraceSinkConfig;
|
|
@@ -1624,6 +1826,16 @@ type ChatCompletionChunk = {
|
|
|
1624
1826
|
usage?: TokenUsage;
|
|
1625
1827
|
finishReason?: FinishReason;
|
|
1626
1828
|
};
|
|
1829
|
+
type ProviderRetryConfig = {
|
|
1830
|
+
/** Maximum retries on 429/5xx (default 3). */
|
|
1831
|
+
maxRetries?: number;
|
|
1832
|
+
/** Initial delay between retries in ms (default 500, doubled each attempt). */
|
|
1833
|
+
baseDelayMs?: number;
|
|
1834
|
+
/** Hard cap on a single retry delay in ms (default 8000). */
|
|
1835
|
+
maxDelayMs?: number;
|
|
1836
|
+
/** Custom predicate to opt in/out of a specific retry. */
|
|
1837
|
+
shouldRetry?: (error: any, attempt: number) => boolean;
|
|
1838
|
+
};
|
|
1627
1839
|
type OpenAIProviderConfig = {
|
|
1628
1840
|
provider: "openai";
|
|
1629
1841
|
apiKey: string;
|
|
@@ -1631,6 +1843,7 @@ type OpenAIProviderConfig = {
|
|
|
1631
1843
|
organization?: string;
|
|
1632
1844
|
defaultModel?: string;
|
|
1633
1845
|
defaultHeaders?: Record<string, string>;
|
|
1846
|
+
retry?: ProviderRetryConfig;
|
|
1634
1847
|
};
|
|
1635
1848
|
type AnthropicProviderConfig = {
|
|
1636
1849
|
provider: "anthropic";
|
|
@@ -1639,6 +1852,15 @@ type AnthropicProviderConfig = {
|
|
|
1639
1852
|
defaultModel?: string;
|
|
1640
1853
|
defaultHeaders?: Record<string, string>;
|
|
1641
1854
|
anthropicVersion?: string;
|
|
1855
|
+
retry?: ProviderRetryConfig;
|
|
1856
|
+
/**
|
|
1857
|
+
* Prompt caching configuration. When enabled, places cache_control:
|
|
1858
|
+
* ephemeral breakpoints on the system prompt and the final tool definition,
|
|
1859
|
+
* which is the recommended Anthropic recipe for static system + tools.
|
|
1860
|
+
*/
|
|
1861
|
+
prompt_caching?: {
|
|
1862
|
+
enabled: boolean;
|
|
1863
|
+
};
|
|
1642
1864
|
};
|
|
1643
1865
|
type AzureProviderConfig = {
|
|
1644
1866
|
provider: "azure";
|
|
@@ -1664,6 +1886,15 @@ type BedrockProviderConfig = {
|
|
|
1664
1886
|
sessionToken?: string;
|
|
1665
1887
|
defaultModel?: string;
|
|
1666
1888
|
defaultHeaders?: Record<string, string>;
|
|
1889
|
+
retry?: ProviderRetryConfig;
|
|
1890
|
+
/**
|
|
1891
|
+
* Insert Bedrock Converse `cachePoint` blocks at the end of the system
|
|
1892
|
+
* prompt and tools list. Only supported by models that implement Converse
|
|
1893
|
+
* prompt caching (most Anthropic Claude variants on Bedrock).
|
|
1894
|
+
*/
|
|
1895
|
+
prompt_caching?: {
|
|
1896
|
+
enabled: boolean;
|
|
1897
|
+
};
|
|
1667
1898
|
};
|
|
1668
1899
|
type VertexProviderConfig = {
|
|
1669
1900
|
provider: "vertex";
|
|
@@ -1683,12 +1914,32 @@ declare class ProviderError extends Error {
|
|
|
1683
1914
|
constructor(message: string, provider: string, statusCode?: number | undefined, responseBody?: any | undefined);
|
|
1684
1915
|
}
|
|
1685
1916
|
|
|
1917
|
+
type ProviderRetryPolicy = {
|
|
1918
|
+
/** Maximum number of retries on 429/5xx responses. Default: 3. */
|
|
1919
|
+
maxRetries?: number;
|
|
1920
|
+
/** Initial backoff in ms (doubled on each retry). Default: 500. */
|
|
1921
|
+
baseDelayMs?: number;
|
|
1922
|
+
/** Hard cap on individual delay between retries. Default: 8000. */
|
|
1923
|
+
maxDelayMs?: number;
|
|
1924
|
+
/**
|
|
1925
|
+
* Custom predicate to decide whether to retry. By default we retry 429
|
|
1926
|
+
* and 5xx responses; pass a function to broaden/narrow that set.
|
|
1927
|
+
*/
|
|
1928
|
+
shouldRetry?: (error: any, attempt: number) => boolean;
|
|
1929
|
+
};
|
|
1686
1930
|
declare abstract class BaseProvider {
|
|
1687
1931
|
abstract readonly providerName: ProviderType;
|
|
1932
|
+
protected retryPolicy: ProviderRetryPolicy;
|
|
1688
1933
|
/** Non-streaming completion */
|
|
1689
1934
|
abstract complete(request: ChatCompletionRequest): Promise<ChatCompletionResponse>;
|
|
1690
1935
|
/** Streaming completion – yields incremental chunks */
|
|
1691
1936
|
abstract completeStream(request: ChatCompletionRequest): AsyncGenerator<ChatCompletionChunk, void, unknown>;
|
|
1937
|
+
/**
|
|
1938
|
+
* Helper concrete providers can wrap their fetch with. Retries 429/5xx
|
|
1939
|
+
* with exponential backoff and respects Retry-After if the response
|
|
1940
|
+
* carries one.
|
|
1941
|
+
*/
|
|
1942
|
+
protected doFetchWithRetry(execute: () => Promise<Response>): Promise<Response>;
|
|
1692
1943
|
}
|
|
1693
1944
|
|
|
1694
1945
|
declare class OpenAIProvider extends BaseProvider {
|
|
@@ -1715,6 +1966,7 @@ declare class AnthropicProvider extends BaseProvider {
|
|
|
1715
1966
|
private readonly defaultModel;
|
|
1716
1967
|
private readonly defaultHeaders;
|
|
1717
1968
|
private readonly anthropicVersion;
|
|
1969
|
+
private readonly promptCachingEnabled;
|
|
1718
1970
|
constructor(config: AnthropicProviderConfig);
|
|
1719
1971
|
complete(request: ChatCompletionRequest): Promise<ChatCompletionResponse>;
|
|
1720
1972
|
completeStream(request: ChatCompletionRequest): AsyncGenerator<ChatCompletionChunk, void, unknown>;
|
|
@@ -1747,6 +1999,7 @@ declare class BedrockProvider extends BaseProvider {
|
|
|
1747
1999
|
private readonly credentials;
|
|
1748
2000
|
private readonly defaultModel;
|
|
1749
2001
|
private readonly defaultHeaders;
|
|
2002
|
+
private readonly promptCachingEnabled;
|
|
1750
2003
|
constructor(config: BedrockProviderConfig);
|
|
1751
2004
|
complete(request: ChatCompletionRequest): Promise<ChatCompletionResponse>;
|
|
1752
2005
|
completeStream(request: ChatCompletionRequest): AsyncGenerator<ChatCompletionChunk, void, unknown>;
|
|
@@ -1830,4 +2083,4 @@ declare function fromNativeProvider(provider: BaseProvider, options?: NativeMode
|
|
|
1830
2083
|
*/
|
|
1831
2084
|
declare function createProvider(config: ProviderConfig): BaseProvider;
|
|
1832
2085
|
|
|
1833
|
-
export { type AIMessage, type AgentInstance, type AgentInvokeResult, type AgentLimits, type AgentOptions, type AgentRuleOptions, type AgentRuntimeConfig, type AgentSnapshot, type AgentSnapshotMetadata, type AgentState, AnthropicProvider, type AnthropicProviderConfig, AzureProvider, type AzureProviderConfig, type BaseChatMessage, type BaseChatMessagePart, type BaseChatModel, type BaseMessage, BaseProvider, BedrockProvider, type BedrockProviderConfig, type BuiltInRuntimeProfile, type CancellationTokenLike, type CancelledEvent, type ChatCompletionChunk, type ChatCompletionRequest, type ChatCompletionResponse, type ChildContextPolicy, type CodeDetectionRuleOptions, type CodeGuardrailOptions, type ContextPolicy, type ContextToolsStateRef, type ConversationGuardrail, type CustomRuleCallback, type CustomRuleOptions, DEFAULT_PROFILE_CONFIGS, type DelegationMode, type EvalCase, type EvalCaseResult, type EvalFamily, type EvalHarnessMetrics, type EvalHarnessParams, type EvalHarnessResult, type EvalProfileDescriptor, type EvalProfileTarget, type FinalAnswerEvent, type FinishReason, type GuardrailContext, type GuardrailDisposition, type GuardrailEvent, type GuardrailIncident, type GuardrailOutcome, GuardrailPhase, type GuardrailRule, type HandoffDescriptor, type HandoffEvent, InMemoryMemoryStore, type InvokeConfig, type JsonGuardrailOptions, type JsonSchemaRuleOptions, type MemoryFact, type MemoryProviderKind, type MemoryReadPolicy, type MemoryScope, type MemoryStore, type MemoryWritePolicy, type Message, type MetadataEvent, type ModelCapabilities, NativeJsonSchemaStrategy, type NativeModelOptions, type NativeReasoningConfig, OpenAICompatibleProvider, type OpenAICompatibleProviderConfig, OpenAIProvider, type OpenAIProviderConfig, type PendingToolApproval, type PlanEvent, type PlanStepRecord, type PlanningMode, type ProfileConfig, type ProgressEvent, type ProgressUpdate, type ProviderConfig, ProviderError, type ToolCall as ProviderToolCall, type ToolDefinition as ProviderToolDefinition, type ProviderType, type ReasoningConfig, type ReasoningLevel, type ReflectionCadence, type ReflectionConfig, type ReflectionEvent, type ReflectionRecord, type RegexGuardrailOptions, type RegexRuleOptions, type ReplanPolicy, type ResolvedSmartAgentConfig, type ResolvedTraceConfig, type ResolvedTraceSink, type RestoreSnapshotOptions, type RuntimeProfile, type SerializableSmartState, type SmartAgentBudgetConfig, type SmartAgentContextConfig, type SmartAgentCustomProfileConfig, type SmartAgentDelegationConfig, type SmartAgentEvent, type SmartAgentInstance, type SmartAgentLimits, type SmartAgentMemoryConfig, type SmartAgentOptions, type SmartAgentPlanningConfig, type SmartAgentSummarizationConfig, type SmartAgentToolResponseConfig, type SmartAgentTracingConfig, type SmartModel, type SmartState, type SmartToolFn, type SnapshotOptions, type SnapshotRuntimeHint, type StreamChunk, type StreamEvent, type StructuredOutputError, type StructuredOutputFieldError, StructuredOutputManager, type StructuredOutputManagerConfig, type StructuredOutputResult, type StructuredOutputStrategy, type StructuredSummary, type SummarizationEvent, type SummarizationMode, type SummaryFactItem, type SummaryIntegrityCheck, type TokenUsage, type ToolApprovalEvent, type ToolApprovalResolution, type ToolApprovalStatus, ToolBasedStrategy, type ToolCallEvent, type ToolInterface, type ToolResponseClassification, type ToolResponseRetentionPolicy, type TraceDataSection, type TraceErrorRecord, type TraceEventRecord, type TraceMessageSection, type TraceMetadataSection, type TraceSessionConfigSnapshot, type TraceSessionFile, type TraceSessionStatus, type TraceSessionSummary, type TraceSinkCognipeerConfig, type TraceSinkConfig, type TraceSinkCustomConfig, type TraceSinkFileConfig, type TraceSinkHttpConfig, type TraceSinkOtlpConfig, type TraceSinkSnapshot, type TraceSummarySection, type TraceToolCallSection, type TraceToolResultSection, type TracingConfig, type TracingMode, type UnifiedMessage, VertexProvider, type VertexProviderConfig, agentVerdictRule, buildSystemPrompt, captureSnapshot, codePresenceRule, cognipeerSink, countApproxTokens, countMessagesTokens, createAgent, createAgentNode, createCodeGuardrail, createContextSummarizeNode, createContextTools, createGetToolResponseTool, createGuardrail, createJsonGuardrail, createManageTodoTool, createProvider, createRegexGuardrail, createResolverNode, createSmartAgent, createTool, createToolLimitFinalizeNode, createToolsNode, customCallbackRule, customSink, emptyUsage, evaluateGuardrails, fileSink, formatZodError, fromLangchainModel, fromLangchainTools, fromNativeProvider, generateSpanId, generateTraceId, getModelCapabilities, getNestedValue, getResolvedSmartConfig, hasToolResponseRecoveryReference, httpSink, isSmartModel, jsonSchemaRule, normalizeSmartAgentOptions, otlpSink, readMemoryFacts, regexRule, resolveMemoryStore, resolveStrategy, resolveToolApprovalState, restoreSnapshot, runSmartAgentEvalHarness, startStreamingSession, traceSessionToOtlp, withTools, writeSummaryFactsToMemory };
|
|
2086
|
+
export { type AIMessage, type AgentInstance, type AgentInvokeResult, type AgentLimits, type AgentOptions, type AgentRuleOptions, type AgentRuntimeConfig, type AgentSnapshot, type AgentSnapshotMetadata, type AgentState, AnthropicProvider, type AnthropicProviderConfig, AzureProvider, type AzureProviderConfig, type BaseChatMessage, type BaseChatMessagePart, type BaseChatModel, type BaseMessage, BaseProvider, BedrockProvider, type BedrockProviderConfig, type BuiltInRuntimeProfile, type CancellationTokenLike, type CancelledEvent, type ChatCompletionChunk, type ChatCompletionRequest, type ChatCompletionResponse, type ChildContextPolicy, type CodeDetectionRuleOptions, type CodeGuardrailOptions, type ContextPolicy, type ContextToolsStateRef, type ConversationGuardrail, type CustomRuleCallback, type CustomRuleOptions, DEFAULT_PROFILE_CONFIGS, type DelegationMode, type EvalCase, type EvalCaseResult, type EvalFamily, type EvalHarnessMetrics, type EvalHarnessParams, type EvalHarnessResult, type EvalProfileDescriptor, type EvalProfileTarget, type FinalAnswerEvent, type FinishReason, type GuardrailContext, type GuardrailDisposition, type GuardrailEvent, type GuardrailIncident, type GuardrailOutcome, GuardrailPhase, type GuardrailRule, type HandoffDescriptor, type HandoffEvent, type HumanInTheLoopAskUserConfig, type HumanInTheLoopOptions, type HumanInTheLoopRuntimeConfig, InMemoryMemoryStore, type InvokeConfig, type JsonGuardrailOptions, type JsonSchemaRuleOptions, type MemoryFact, type MemoryProviderKind, type MemoryReadPolicy, type MemoryScope, type MemoryStore, type MemoryWritePolicy, type Message, type MetadataEvent, type ModelCapabilities, NativeJsonSchemaStrategy, type NativeModelOptions, type NativeReasoningConfig, OpenAICompatibleProvider, type OpenAICompatibleProviderConfig, OpenAIProvider, type OpenAIProviderConfig, type PendingToolApproval, type PendingUserQuestion, type PlanEvent, type PlanStepRecord, type PlanningMode, type ProfileConfig, type ProgressEvent, type ProgressUpdate, type ProviderConfig, ProviderError, type ToolCall as ProviderToolCall, type ToolDefinition as ProviderToolDefinition, type ProviderType, type ReasoningConfig, type ReasoningLevel, type ReflectionCadence, type ReflectionConfig, type ReflectionEvent, type ReflectionRecord, type RegexGuardrailOptions, type RegexRuleOptions, type ReplanPolicy, type ResolvedSmartAgentConfig, type ResolvedTraceConfig, type ResolvedTraceSink, type RestoreSnapshotOptions, type RuntimeProfile, type SerializableSmartState, type SmartAgentBudgetConfig, type SmartAgentContextConfig, type SmartAgentCustomProfileConfig, type SmartAgentDelegationConfig, type SmartAgentEvent, type SmartAgentInstance, type SmartAgentLimits, type SmartAgentMemoryConfig, type SmartAgentOptions, type SmartAgentPlanningConfig, type SmartAgentSummarizationConfig, type SmartAgentToolResponseConfig, type SmartAgentTracingConfig, type SmartModel, type SmartState, type SmartToolFn, type SnapshotOptions, type SnapshotRuntimeHint, type StreamChunk, type StreamEvent, type StructuredOutputError, type StructuredOutputFieldError, StructuredOutputManager, type StructuredOutputManagerConfig, type StructuredOutputResult, type StructuredOutputStrategy, type StructuredSummary, type SummarizationEvent, type SummarizationMode, type SummaryFactItem, type SummaryIntegrityCheck, type TokenCounter, type TokenUsage, type ToolApprovalEvent, type ToolApprovalResolution, type ToolApprovalStatus, ToolBasedStrategy, type ToolCachePolicy, type ToolCallEvent, type ToolInterface, type ToolResponseClassification, type ToolResponseRetentionPolicy, type ToolRetryPolicy, type TraceDataSection, type TraceErrorRecord, type TraceEventRecord, type TraceMessageSection, type TraceMetadataSection, type TraceSessionConfigSnapshot, type TraceSessionFile, type TraceSessionStatus, type TraceSessionSummary, type TraceSinkCognipeerConfig, type TraceSinkConfig, type TraceSinkCustomConfig, type TraceSinkFileConfig, type TraceSinkHttpConfig, type TraceSinkOtlpConfig, type TraceSinkSnapshot, type TraceSummarySection, type TraceToolCallSection, type TraceToolResultSection, type TracingConfig, type TracingMode, type UnifiedMessage, type UserQuestionAnswer, type UserQuestionAnswerSet, type UserQuestionEvent, type UserQuestionItem, type UserQuestionOption, type UserQuestionResolution, type UserQuestionStatus, VertexProvider, type VertexProviderConfig, agentVerdictRule, buildSystemPrompt, captureSnapshot, codePresenceRule, cognipeerSink, countApproxTokens, countMessagesTokens, createAgent, createAgentNode, createAskUserQuestionTool, createCodeGuardrail, createContextSummarizeNode, createContextTools, createGetToolResponseTool, createGuardrail, createJsonGuardrail, createManageTodoTool, createProvider, createRegexGuardrail, createResolverNode, createSmartAgent, createTool, createToolLimitFinalizeNode, createToolsNode, customCallbackRule, customSink, defaultTokenCounter, emptyUsage, evaluateGuardrails, fileSink, formatZodError, fromLangchainModel, fromLangchainTools, fromNativeProvider, generateSpanId, generateTraceId, getModelCapabilities, getNestedValue, getResolvedSmartConfig, getTokenCounter, hasToolResponseRecoveryReference, httpSink, isSmartModel, jsonSchemaRule, normalizeSmartAgentOptions, otlpSink, readMemoryFacts, regexRule, resolveMemoryStore, resolveStrategy, resolveToolApprovalState, resolveUserQuestionState, restoreSnapshot, runSmartAgentEvalHarness, setTokenCounter, startStreamingSession, traceSessionToOtlp, withTools, writeSummaryFactsToMemory };
|