@cognipeer/agent-sdk 0.1.1 → 0.2.0
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 +192 -103
- package/dist/index.cjs +2203 -635
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +545 -115
- package/dist/index.d.ts +545 -115
- package/dist/index.mjs +2797 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +42 -26
- package/dist/index.js +0 -1212
- package/dist/index.js.map +0 -1
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { ZodSchema, z } from 'zod';
|
|
2
|
+
import { JSONSchema7 } from 'json-schema';
|
|
3
3
|
|
|
4
4
|
interface BaseChatMessagePart {
|
|
5
5
|
type?: string;
|
|
@@ -35,22 +35,6 @@ declare function isSmartModel(m: any): m is SmartModel;
|
|
|
35
35
|
declare function withTools(model: SmartModel, tools: any[]): BaseChatModel;
|
|
36
36
|
declare function fromLangchainModel(lcModel: any): BaseChatModel;
|
|
37
37
|
|
|
38
|
-
type SmartToolFn = (args: any) => Promise<any> | any;
|
|
39
|
-
declare function createSmartTool({ name, description, schema, func, }: {
|
|
40
|
-
name: string;
|
|
41
|
-
description?: string;
|
|
42
|
-
schema: ZodSchema;
|
|
43
|
-
func: SmartToolFn;
|
|
44
|
-
}): ToolInterface$1;
|
|
45
|
-
declare function createTool({ name, description, schema, func, }: {
|
|
46
|
-
name: string;
|
|
47
|
-
description?: string;
|
|
48
|
-
schema: ZodSchema;
|
|
49
|
-
func: SmartToolFn;
|
|
50
|
-
}): ToolInterface$1;
|
|
51
|
-
|
|
52
|
-
declare function buildSystemPrompt(extra?: string, planning?: boolean, name?: string): string;
|
|
53
|
-
|
|
54
38
|
type ImageURL = {
|
|
55
39
|
url: string;
|
|
56
40
|
detail?: 'auto' | 'low' | 'high';
|
|
@@ -75,6 +59,9 @@ interface ToolInterface<TInput = any, TOutput = any, TCallOptions = any> {
|
|
|
75
59
|
invoke?: (input: TInput, config?: TCallOptions) => Promise<TOutput> | TOutput;
|
|
76
60
|
call?: (input: TInput, config?: TCallOptions) => Promise<TOutput> | TOutput;
|
|
77
61
|
schema?: any;
|
|
62
|
+
needsApproval?: boolean;
|
|
63
|
+
approvalPrompt?: string;
|
|
64
|
+
approvalDefaults?: any;
|
|
78
65
|
[key: string]: any;
|
|
79
66
|
}
|
|
80
67
|
type RunnableConfig = {
|
|
@@ -92,47 +79,289 @@ type AIMessage = BaseMessage & {
|
|
|
92
79
|
role: 'assistant';
|
|
93
80
|
};
|
|
94
81
|
type Message = BaseMessage;
|
|
95
|
-
|
|
82
|
+
declare enum GuardrailPhase {
|
|
83
|
+
Request = "request",
|
|
84
|
+
Response = "response"
|
|
85
|
+
}
|
|
86
|
+
type GuardrailDisposition = "block" | "warn" | "allow";
|
|
87
|
+
type GuardrailContext = {
|
|
88
|
+
phase: GuardrailPhase;
|
|
89
|
+
messages: Message[];
|
|
90
|
+
latestMessage?: Message;
|
|
91
|
+
state: SmartState;
|
|
92
|
+
runtime?: AgentRuntimeConfig;
|
|
93
|
+
options: SmartAgentOptions;
|
|
94
|
+
};
|
|
95
|
+
type GuardrailRuleResult = {
|
|
96
|
+
passed: boolean;
|
|
97
|
+
reason?: string;
|
|
98
|
+
details?: Record<string, any>;
|
|
99
|
+
disposition?: GuardrailDisposition;
|
|
100
|
+
};
|
|
101
|
+
type GuardrailRule = {
|
|
102
|
+
id?: string;
|
|
103
|
+
title?: string;
|
|
104
|
+
description?: string;
|
|
105
|
+
evaluate: (context: GuardrailContext) => Promise<GuardrailRuleResult> | GuardrailRuleResult;
|
|
106
|
+
metadata?: Record<string, any>;
|
|
107
|
+
};
|
|
108
|
+
type GuardrailIncident = {
|
|
109
|
+
guardrailId?: string;
|
|
110
|
+
guardrailTitle?: string;
|
|
111
|
+
ruleId?: string;
|
|
112
|
+
ruleTitle?: string;
|
|
113
|
+
phase: GuardrailPhase;
|
|
114
|
+
reason?: string;
|
|
115
|
+
details?: Record<string, any>;
|
|
116
|
+
disposition: GuardrailDisposition;
|
|
117
|
+
};
|
|
118
|
+
type ConversationGuardrail = {
|
|
119
|
+
id?: string;
|
|
120
|
+
title?: string;
|
|
121
|
+
description?: string;
|
|
122
|
+
appliesTo: GuardrailPhase[];
|
|
123
|
+
rules: GuardrailRule[];
|
|
124
|
+
haltOnViolation?: boolean;
|
|
125
|
+
onViolation?: (incident: GuardrailIncident, context: GuardrailContext) => Promise<GuardrailDisposition | void> | GuardrailDisposition | void;
|
|
126
|
+
metadata?: Record<string, any>;
|
|
127
|
+
};
|
|
128
|
+
type GuardrailOutcome = {
|
|
129
|
+
ok: boolean;
|
|
130
|
+
incidents: GuardrailIncident[];
|
|
131
|
+
};
|
|
132
|
+
type AgentLimits = {
|
|
96
133
|
maxToolCalls?: number;
|
|
97
|
-
toolOutputTokenLimit?: number;
|
|
98
|
-
contextTokenLimit?: number;
|
|
99
|
-
summaryTokenLimit?: number;
|
|
100
|
-
summary_token_limit?: number;
|
|
101
|
-
maxToken?: number;
|
|
102
134
|
maxParallelTools?: number;
|
|
103
135
|
};
|
|
136
|
+
type SmartAgentLimits = AgentLimits;
|
|
137
|
+
type TraceSinkFileConfig = {
|
|
138
|
+
type: "file";
|
|
139
|
+
path?: string;
|
|
140
|
+
};
|
|
141
|
+
type TraceSinkCustomConfig = {
|
|
142
|
+
type: "custom";
|
|
143
|
+
onEvent?: (event: TraceEventRecord) => void | Promise<void>;
|
|
144
|
+
onSession?: (session: TraceSessionFile) => void | Promise<void>;
|
|
145
|
+
};
|
|
146
|
+
type TraceSinkCognipeerConfig = {
|
|
147
|
+
type: "cognipeer";
|
|
148
|
+
apiKey: string;
|
|
149
|
+
url?: string;
|
|
150
|
+
};
|
|
151
|
+
type TraceSinkHttpConfig = {
|
|
152
|
+
type: "http";
|
|
153
|
+
url: string;
|
|
154
|
+
headers?: Record<string, string>;
|
|
155
|
+
};
|
|
156
|
+
type TraceSinkConfig = TraceSinkFileConfig | TraceSinkCustomConfig | TraceSinkCognipeerConfig | TraceSinkHttpConfig;
|
|
157
|
+
type TracingConfig = {
|
|
158
|
+
enabled: boolean;
|
|
159
|
+
logData?: boolean;
|
|
160
|
+
sink?: TraceSinkConfig;
|
|
161
|
+
};
|
|
162
|
+
type SmartAgentTracingConfig = TracingConfig;
|
|
163
|
+
type AgentOptions = {
|
|
164
|
+
name?: string;
|
|
165
|
+
version?: string;
|
|
166
|
+
model: any;
|
|
167
|
+
tools?: Array<ToolInterface<any, any, any>>;
|
|
168
|
+
guardrails?: ConversationGuardrail[];
|
|
169
|
+
handoffs?: HandoffDescriptor[];
|
|
170
|
+
limits?: AgentLimits;
|
|
171
|
+
usageConverter?: (finalMessage: AIMessage, fullState: SmartState, model: any) => any;
|
|
172
|
+
outputSchema?: ZodSchema<any>;
|
|
173
|
+
tracing?: TracingConfig;
|
|
174
|
+
};
|
|
104
175
|
type SmartAgentOptions = {
|
|
105
176
|
name?: string;
|
|
177
|
+
version?: string;
|
|
106
178
|
model: any;
|
|
107
179
|
tools?: Array<ToolInterface<any, any, any>>;
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
180
|
+
guardrails?: ConversationGuardrail[];
|
|
181
|
+
handoffs?: HandoffDescriptor[];
|
|
182
|
+
limits?: AgentLimits;
|
|
183
|
+
summarization?: boolean | {
|
|
184
|
+
enable: boolean;
|
|
185
|
+
maxTokens: number;
|
|
186
|
+
};
|
|
111
187
|
systemPrompt?: string;
|
|
112
188
|
useTodoList?: boolean;
|
|
113
189
|
usageConverter?: (finalMessage: AIMessage, fullState: SmartState, model: any) => any;
|
|
114
|
-
debug?: {
|
|
115
|
-
enabled: boolean;
|
|
116
|
-
path?: string;
|
|
117
|
-
callback?: (entry: {
|
|
118
|
-
sessionId: string;
|
|
119
|
-
stepIndex: number;
|
|
120
|
-
fileName: string;
|
|
121
|
-
markdown: string;
|
|
122
|
-
}) => void;
|
|
123
|
-
};
|
|
124
190
|
outputSchema?: ZodSchema<any>;
|
|
191
|
+
tracing?: TracingConfig;
|
|
125
192
|
};
|
|
126
193
|
type AgentRuntimeConfig = {
|
|
127
194
|
name?: string;
|
|
195
|
+
version?: string;
|
|
128
196
|
model: any;
|
|
129
197
|
tools: Array<ToolInterface<any, any, any>>;
|
|
198
|
+
guardrails?: ConversationGuardrail[];
|
|
130
199
|
systemPrompt?: string;
|
|
131
|
-
limits?:
|
|
200
|
+
limits?: AgentLimits;
|
|
132
201
|
useTodoList?: boolean;
|
|
133
202
|
outputSchema?: ZodSchema<any>;
|
|
203
|
+
tracing?: TracingConfig;
|
|
204
|
+
};
|
|
205
|
+
type TraceMessageSection = {
|
|
206
|
+
id?: string;
|
|
207
|
+
kind: "message";
|
|
208
|
+
label: string;
|
|
209
|
+
role: string;
|
|
210
|
+
content: string;
|
|
211
|
+
metadata?: Record<string, any>;
|
|
212
|
+
};
|
|
213
|
+
type TraceToolCallSection = {
|
|
214
|
+
id?: string;
|
|
215
|
+
kind: "tool_call";
|
|
216
|
+
label: string;
|
|
217
|
+
tool: string;
|
|
218
|
+
arguments?: any;
|
|
219
|
+
};
|
|
220
|
+
type TraceToolResultItem = {
|
|
221
|
+
title?: string;
|
|
222
|
+
url?: string;
|
|
223
|
+
snippet?: string;
|
|
224
|
+
[key: string]: any;
|
|
225
|
+
};
|
|
226
|
+
type TraceToolResultSection = {
|
|
227
|
+
id?: string;
|
|
228
|
+
kind: "tool_result";
|
|
229
|
+
label: string;
|
|
230
|
+
tool: string;
|
|
231
|
+
summary?: string;
|
|
232
|
+
items?: TraceToolResultItem[];
|
|
233
|
+
output?: any;
|
|
234
|
+
};
|
|
235
|
+
type TraceToolResponseSection = {
|
|
236
|
+
id?: string;
|
|
237
|
+
kind: "tool_response";
|
|
238
|
+
label: string;
|
|
239
|
+
tool: string;
|
|
240
|
+
summary?: string;
|
|
241
|
+
items?: TraceToolResultItem[];
|
|
242
|
+
output?: any;
|
|
243
|
+
};
|
|
244
|
+
type TraceSummarySection = {
|
|
245
|
+
id?: string;
|
|
246
|
+
kind: "summary";
|
|
247
|
+
label: string;
|
|
248
|
+
content: string;
|
|
249
|
+
};
|
|
250
|
+
type TraceMetadataSection = {
|
|
251
|
+
id?: string;
|
|
252
|
+
kind: "metadata";
|
|
253
|
+
label: string;
|
|
254
|
+
data: Record<string, any>;
|
|
255
|
+
};
|
|
256
|
+
type TraceDataSection = TraceMessageSection | TraceToolCallSection | TraceToolResultSection | TraceToolResponseSection | TraceSummarySection | TraceMetadataSection;
|
|
257
|
+
type TraceEventRecord = {
|
|
258
|
+
sessionId: string;
|
|
259
|
+
id: string;
|
|
260
|
+
type: string;
|
|
261
|
+
label: string;
|
|
262
|
+
sequence: number;
|
|
263
|
+
timestamp: string;
|
|
264
|
+
actor?: {
|
|
265
|
+
scope?: string;
|
|
266
|
+
name?: string;
|
|
267
|
+
role?: string;
|
|
268
|
+
version?: string;
|
|
269
|
+
};
|
|
270
|
+
status: "success" | "error" | "skipped" | "retry";
|
|
271
|
+
durationMs?: number;
|
|
272
|
+
inputTokens?: number;
|
|
273
|
+
outputTokens?: number;
|
|
274
|
+
totalTokens?: number;
|
|
275
|
+
cachedInputTokens?: number;
|
|
276
|
+
requestBytes?: number;
|
|
277
|
+
responseBytes?: number;
|
|
278
|
+
model?: string;
|
|
279
|
+
provider?: string;
|
|
280
|
+
toolExecutionId?: string;
|
|
281
|
+
retryOf?: string;
|
|
282
|
+
error?: {
|
|
283
|
+
message: string;
|
|
284
|
+
stack?: string;
|
|
285
|
+
} | null;
|
|
286
|
+
data?: {
|
|
287
|
+
sections: TraceDataSection[];
|
|
288
|
+
};
|
|
289
|
+
debug?: Record<string, any>;
|
|
290
|
+
};
|
|
291
|
+
type TraceErrorRecord = {
|
|
292
|
+
eventId: string;
|
|
293
|
+
message: string;
|
|
294
|
+
stack?: string;
|
|
295
|
+
type?: string;
|
|
296
|
+
timestamp?: string;
|
|
297
|
+
};
|
|
298
|
+
type TraceSessionSummary = {
|
|
299
|
+
totalDurationMs: number;
|
|
300
|
+
totalInputTokens: number;
|
|
301
|
+
totalOutputTokens: number;
|
|
302
|
+
totalCachedInputTokens: number;
|
|
303
|
+
totalBytesIn: number;
|
|
304
|
+
totalBytesOut: number;
|
|
305
|
+
eventCounts: Record<string, number>;
|
|
306
|
+
};
|
|
307
|
+
type TraceSessionStatus = "in_progress" | "success" | "error" | "partial";
|
|
308
|
+
type TraceSinkSnapshot = {
|
|
309
|
+
type: "file";
|
|
310
|
+
path: string;
|
|
311
|
+
} | {
|
|
312
|
+
type: "custom";
|
|
313
|
+
} | {
|
|
314
|
+
type: "cognipeer";
|
|
315
|
+
url: string;
|
|
316
|
+
} | {
|
|
317
|
+
type: "http";
|
|
318
|
+
url: string;
|
|
134
319
|
};
|
|
135
|
-
type
|
|
320
|
+
type TraceSessionConfigSnapshot = {
|
|
321
|
+
enabled: boolean;
|
|
322
|
+
logData: boolean;
|
|
323
|
+
sink: TraceSinkSnapshot;
|
|
324
|
+
};
|
|
325
|
+
type TraceSessionFile = {
|
|
326
|
+
sessionId: string;
|
|
327
|
+
startedAt: string;
|
|
328
|
+
endedAt?: string;
|
|
329
|
+
durationMs?: number;
|
|
330
|
+
agent?: {
|
|
331
|
+
name?: string;
|
|
332
|
+
version?: string;
|
|
333
|
+
model?: string;
|
|
334
|
+
provider?: string;
|
|
335
|
+
};
|
|
336
|
+
config: TraceSessionConfigSnapshot;
|
|
337
|
+
summary: TraceSessionSummary;
|
|
338
|
+
events: TraceEventRecord[];
|
|
339
|
+
status: TraceSessionStatus;
|
|
340
|
+
errors: TraceErrorRecord[];
|
|
341
|
+
};
|
|
342
|
+
type ResolvedTraceSink = {
|
|
343
|
+
type: "file";
|
|
344
|
+
baseDir: string;
|
|
345
|
+
} | {
|
|
346
|
+
type: "custom";
|
|
347
|
+
onEvent?: (event: TraceEventRecord) => void | Promise<void>;
|
|
348
|
+
onSession?: (session: TraceSessionFile) => void | Promise<void>;
|
|
349
|
+
} | {
|
|
350
|
+
type: "cognipeer";
|
|
351
|
+
url: string;
|
|
352
|
+
apiKey: string;
|
|
353
|
+
} | {
|
|
354
|
+
type: "http";
|
|
355
|
+
url: string;
|
|
356
|
+
headers?: Record<string, string>;
|
|
357
|
+
};
|
|
358
|
+
type ResolvedTraceConfig = {
|
|
359
|
+
enabled: boolean;
|
|
360
|
+
mode: "batched";
|
|
361
|
+
logData: boolean;
|
|
362
|
+
sink: ResolvedTraceSink;
|
|
363
|
+
};
|
|
364
|
+
type HandoffDescriptor<TParsed = any> = {
|
|
136
365
|
type: "handoff";
|
|
137
366
|
toolName: string;
|
|
138
367
|
description: string;
|
|
@@ -141,10 +370,9 @@ type HandoffDescriptor<TIn = any, TOut = any, TParsed = any> = {
|
|
|
141
370
|
__runtime: AgentRuntimeConfig;
|
|
142
371
|
};
|
|
143
372
|
};
|
|
144
|
-
type
|
|
373
|
+
type AgentState = {
|
|
145
374
|
messages: Message[];
|
|
146
375
|
agent?: AgentRuntimeConfig;
|
|
147
|
-
summaries?: string[];
|
|
148
376
|
toolHistory?: Array<{
|
|
149
377
|
executionId: string;
|
|
150
378
|
toolName: string;
|
|
@@ -158,6 +386,31 @@ type SmartState = {
|
|
|
158
386
|
tool_call_id?: string;
|
|
159
387
|
fromCache?: boolean;
|
|
160
388
|
}>;
|
|
389
|
+
toolCache?: Record<string, any>;
|
|
390
|
+
toolCallCount?: number;
|
|
391
|
+
metadata?: Record<string, any>;
|
|
392
|
+
ctx?: Record<string, any>;
|
|
393
|
+
pendingApprovals?: PendingToolApproval[];
|
|
394
|
+
usage?: {
|
|
395
|
+
perRequest: Array<{
|
|
396
|
+
id: string;
|
|
397
|
+
modelName: string;
|
|
398
|
+
usage: any;
|
|
399
|
+
timestamp: string;
|
|
400
|
+
turn: number;
|
|
401
|
+
cachedInput?: number;
|
|
402
|
+
}>;
|
|
403
|
+
totals: Record<string, {
|
|
404
|
+
input: number;
|
|
405
|
+
output: number;
|
|
406
|
+
total: number;
|
|
407
|
+
cachedInput: number;
|
|
408
|
+
}>;
|
|
409
|
+
};
|
|
410
|
+
guardrailResult?: GuardrailOutcome;
|
|
411
|
+
};
|
|
412
|
+
type SmartState = AgentState & {
|
|
413
|
+
summaries?: string[];
|
|
161
414
|
toolHistoryArchived?: Array<{
|
|
162
415
|
executionId: string;
|
|
163
416
|
toolName: string;
|
|
@@ -171,8 +424,6 @@ type SmartState = {
|
|
|
171
424
|
tool_call_id?: string;
|
|
172
425
|
fromCache?: boolean;
|
|
173
426
|
}>;
|
|
174
|
-
toolCache?: Record<string, any>;
|
|
175
|
-
toolCallCount?: number;
|
|
176
427
|
plan?: {
|
|
177
428
|
version: number;
|
|
178
429
|
steps: Array<{
|
|
@@ -183,24 +434,6 @@ type SmartState = {
|
|
|
183
434
|
lastUpdated?: string;
|
|
184
435
|
} | null;
|
|
185
436
|
planVersion?: number;
|
|
186
|
-
metadata?: Record<string, any>;
|
|
187
|
-
ctx?: Record<string, any>;
|
|
188
|
-
usage?: {
|
|
189
|
-
perRequest: Array<{
|
|
190
|
-
id: string;
|
|
191
|
-
modelName: string;
|
|
192
|
-
usage: any;
|
|
193
|
-
timestamp: string;
|
|
194
|
-
turn: number;
|
|
195
|
-
cachedInput?: number;
|
|
196
|
-
}>;
|
|
197
|
-
totals: Record<string, {
|
|
198
|
-
input: number;
|
|
199
|
-
output: number;
|
|
200
|
-
total: number;
|
|
201
|
-
cachedInput: number;
|
|
202
|
-
}>;
|
|
203
|
-
};
|
|
204
437
|
};
|
|
205
438
|
type ToolCallEvent = {
|
|
206
439
|
type: "tool_call";
|
|
@@ -249,9 +482,86 @@ type HandoffEvent = {
|
|
|
249
482
|
to?: string;
|
|
250
483
|
toolName: string;
|
|
251
484
|
};
|
|
252
|
-
type
|
|
485
|
+
type ToolApprovalStatus = "pending" | "approved" | "rejected" | "executed";
|
|
486
|
+
type PendingToolApproval = {
|
|
487
|
+
id: string;
|
|
488
|
+
toolCallId: string;
|
|
489
|
+
toolName: string;
|
|
490
|
+
args: any;
|
|
491
|
+
status: ToolApprovalStatus;
|
|
492
|
+
requestedAt: string;
|
|
493
|
+
decidedAt?: string;
|
|
494
|
+
decidedBy?: string;
|
|
495
|
+
comment?: string;
|
|
496
|
+
approvedArgs?: any;
|
|
497
|
+
resolvedAt?: string;
|
|
498
|
+
executionId?: string;
|
|
499
|
+
metadata?: Record<string, any>;
|
|
500
|
+
};
|
|
501
|
+
type ToolApprovalResolution = {
|
|
502
|
+
id: string;
|
|
503
|
+
approved: boolean;
|
|
504
|
+
approvedArgs?: any;
|
|
505
|
+
decidedBy?: string;
|
|
506
|
+
comment?: string;
|
|
507
|
+
};
|
|
508
|
+
type ToolApprovalEvent = {
|
|
509
|
+
type: "tool_approval";
|
|
510
|
+
status: "pending" | "approved" | "rejected";
|
|
511
|
+
id: string;
|
|
512
|
+
toolName: string;
|
|
513
|
+
toolCallId?: string;
|
|
514
|
+
args?: any;
|
|
515
|
+
decidedBy?: string;
|
|
516
|
+
comment?: string;
|
|
517
|
+
};
|
|
518
|
+
type GuardrailEvent = {
|
|
519
|
+
type: "guardrail";
|
|
520
|
+
phase: GuardrailPhase;
|
|
521
|
+
guardrailId?: string;
|
|
522
|
+
guardrailTitle?: string;
|
|
523
|
+
ruleId?: string;
|
|
524
|
+
ruleTitle?: string;
|
|
525
|
+
disposition: GuardrailDisposition;
|
|
526
|
+
reason?: string;
|
|
527
|
+
details?: Record<string, any>;
|
|
528
|
+
};
|
|
529
|
+
type SmartAgentEvent = ToolCallEvent | ToolApprovalEvent | PlanEvent | SummarizationEvent | FinalAnswerEvent | MetadataEvent | HandoffEvent | GuardrailEvent;
|
|
253
530
|
type InvokeConfig = RunnableConfig & {
|
|
254
531
|
onEvent?: (event: SmartAgentEvent) => void;
|
|
532
|
+
onStateChange?: (state: SmartState) => boolean;
|
|
533
|
+
checkpointReason?: string;
|
|
534
|
+
};
|
|
535
|
+
type SnapshotRuntimeHint = {
|
|
536
|
+
name?: string;
|
|
537
|
+
version?: string;
|
|
538
|
+
tools?: string[];
|
|
539
|
+
};
|
|
540
|
+
type SerializableSmartState = Omit<SmartState, "agent"> & {
|
|
541
|
+
agent?: undefined;
|
|
542
|
+
};
|
|
543
|
+
type AgentSnapshotMetadata = {
|
|
544
|
+
createdAt: string;
|
|
545
|
+
tag?: string;
|
|
546
|
+
paused?: {
|
|
547
|
+
stage?: string;
|
|
548
|
+
iteration?: number;
|
|
549
|
+
reason?: string;
|
|
550
|
+
} | null;
|
|
551
|
+
};
|
|
552
|
+
type AgentSnapshot = {
|
|
553
|
+
state: SerializableSmartState;
|
|
554
|
+
runtimeHint?: SnapshotRuntimeHint;
|
|
555
|
+
metadata: AgentSnapshotMetadata;
|
|
556
|
+
};
|
|
557
|
+
type SnapshotOptions = {
|
|
558
|
+
tag?: string;
|
|
559
|
+
includeRuntimeHint?: boolean;
|
|
560
|
+
};
|
|
561
|
+
type RestoreSnapshotOptions = {
|
|
562
|
+
agent?: AgentRuntimeConfig;
|
|
563
|
+
ctx?: Record<string, any>;
|
|
564
|
+
mergeCtx?: boolean;
|
|
255
565
|
};
|
|
256
566
|
type AgentInvokeResult<TOutput = unknown> = {
|
|
257
567
|
content: string;
|
|
@@ -262,8 +572,11 @@ type AgentInvokeResult<TOutput = unknown> = {
|
|
|
262
572
|
messages: Message[];
|
|
263
573
|
state?: SmartState;
|
|
264
574
|
};
|
|
265
|
-
type
|
|
575
|
+
type AgentInstance<TOutput = unknown> = {
|
|
266
576
|
invoke: (input: SmartState, config?: InvokeConfig) => Promise<AgentInvokeResult<TOutput>>;
|
|
577
|
+
snapshot: (state: SmartState, options?: SnapshotOptions) => AgentSnapshot;
|
|
578
|
+
resume: (snapshot: AgentSnapshot, config?: InvokeConfig, restoreOptions?: RestoreSnapshotOptions) => Promise<AgentInvokeResult<TOutput>>;
|
|
579
|
+
resolveToolApproval: (state: SmartState, resolution: ToolApprovalResolution) => SmartState;
|
|
267
580
|
asTool: (opts: {
|
|
268
581
|
toolName: string;
|
|
269
582
|
description?: string;
|
|
@@ -273,15 +586,23 @@ type SmartAgentInstance<TOutput = unknown> = {
|
|
|
273
586
|
toolName?: string;
|
|
274
587
|
description?: string;
|
|
275
588
|
schema?: ZodSchema<any>;
|
|
276
|
-
}) => HandoffDescriptor<
|
|
589
|
+
}) => HandoffDescriptor<TOutput>;
|
|
277
590
|
__runtime: AgentRuntimeConfig;
|
|
278
591
|
};
|
|
279
|
-
type
|
|
280
|
-
|
|
281
|
-
type
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
592
|
+
type SmartAgentInstance<TOutput = unknown> = AgentInstance<TOutput>;
|
|
593
|
+
|
|
594
|
+
type SmartToolFn = (args: any) => Promise<any> | any;
|
|
595
|
+
declare function createTool({ name, description, schema, func, needsApproval, approvalPrompt, approvalDefaults, }: {
|
|
596
|
+
name: string;
|
|
597
|
+
description?: string;
|
|
598
|
+
schema: ZodSchema;
|
|
599
|
+
func: SmartToolFn;
|
|
600
|
+
needsApproval?: boolean;
|
|
601
|
+
approvalPrompt?: string;
|
|
602
|
+
approvalDefaults?: any;
|
|
603
|
+
}): ToolInterface;
|
|
604
|
+
|
|
605
|
+
declare function buildSystemPrompt(extra?: string, planning?: boolean, name?: string): string;
|
|
285
606
|
|
|
286
607
|
declare function createAgent<TOutput = unknown>(opts: AgentOptions & {
|
|
287
608
|
outputSchema?: ZodSchema<TOutput>;
|
|
@@ -289,24 +610,35 @@ declare function createAgent<TOutput = unknown>(opts: AgentOptions & {
|
|
|
289
610
|
|
|
290
611
|
declare function createAgentNode(opts: SmartAgentOptions): (state: SmartState) => Promise<Partial<SmartState>>;
|
|
291
612
|
|
|
292
|
-
declare function createToolsNode(initialTools: Array<ToolInterface
|
|
613
|
+
declare function createToolsNode(initialTools: Array<ToolInterface<any, any, any>>, opts?: SmartAgentOptions): (state: SmartState) => Promise<any>;
|
|
293
614
|
|
|
294
615
|
declare function createResolverNode(): (state: SmartState) => Promise<SmartState>;
|
|
295
616
|
|
|
296
617
|
declare function createToolLimitFinalizeNode(_opts: SmartAgentOptions): (state: SmartState) => Promise<Partial<SmartState>>;
|
|
297
618
|
|
|
619
|
+
/**
|
|
620
|
+
* Creates the summarization node.
|
|
621
|
+
*
|
|
622
|
+
* Logic:
|
|
623
|
+
* 1. Check if summarization is enabled.
|
|
624
|
+
* 2. Convert current conversation history into a text suitable for summarization.
|
|
625
|
+
* 3. Invoke the model to generate a summary of the conversation.
|
|
626
|
+
* 4. Rewrite the message history:
|
|
627
|
+
* - All tool messages (role='tool') have their content replaced with "SUMMARIZED".
|
|
628
|
+
* - A new assistant message calling 'summarize_context' is appended.
|
|
629
|
+
* - A new tool message with the summary content is appended.
|
|
630
|
+
*/
|
|
298
631
|
declare function createContextSummarizeNode(opts: SmartAgentOptions): (state: SmartState) => Promise<Partial<SmartState>>;
|
|
299
632
|
|
|
300
633
|
type TokenLimits = {
|
|
301
634
|
contextTokenLimit: number;
|
|
302
635
|
summaryTokenLimit: number;
|
|
303
636
|
};
|
|
304
|
-
declare function applyTokenLimits({ state,
|
|
637
|
+
declare function applyTokenLimits({ state, limits, }: {
|
|
305
638
|
state: {
|
|
306
639
|
messages: Message[];
|
|
307
640
|
summaries?: string[];
|
|
308
641
|
};
|
|
309
|
-
model: any;
|
|
310
642
|
limits: {
|
|
311
643
|
contextTokenLimit: number;
|
|
312
644
|
summaryTokenLimit: number;
|
|
@@ -327,47 +659,145 @@ declare function createContextTools(stateRef: {
|
|
|
327
659
|
outputSchema?: any;
|
|
328
660
|
}): any[];
|
|
329
661
|
|
|
330
|
-
|
|
331
|
-
sessionId: string;
|
|
332
|
-
baseDir: string;
|
|
333
|
-
sessionDir: string;
|
|
334
|
-
stepIndex: number;
|
|
335
|
-
callback?: (entry: {
|
|
336
|
-
sessionId: string;
|
|
337
|
-
stepIndex: number;
|
|
338
|
-
fileName: string;
|
|
339
|
-
markdown: string;
|
|
340
|
-
messages: Message[];
|
|
341
|
-
usage?: any;
|
|
342
|
-
modelName?: string;
|
|
343
|
-
limits?: any;
|
|
344
|
-
tools?: any[];
|
|
345
|
-
}) => void;
|
|
346
|
-
};
|
|
347
|
-
declare function resolveLogsBaseDir(customPath?: string): string;
|
|
348
|
-
declare function createDebugSession(opts: SmartAgentOptions): DebugSession | undefined;
|
|
349
|
-
declare function bumpStep(session: DebugSession): number;
|
|
350
|
-
type UsageLike = any;
|
|
351
|
-
declare function getModelName(model: any): string | undefined;
|
|
352
|
-
declare function serializeAgentTools(tools: any[]): any[];
|
|
353
|
-
declare function formatMarkdown(params: {
|
|
354
|
-
modelName: string | undefined;
|
|
355
|
-
date: string;
|
|
356
|
-
limits?: any;
|
|
357
|
-
usage?: UsageLike;
|
|
358
|
-
tools?: any[];
|
|
359
|
-
messages: Message[];
|
|
360
|
-
}): string;
|
|
361
|
-
declare function writeStepMarkdown(session: DebugSession, fileName: string, markdown: string, payload?: {
|
|
362
|
-
messages: Message[];
|
|
363
|
-
usage?: any;
|
|
364
|
-
modelName?: string;
|
|
365
|
-
limits?: any;
|
|
366
|
-
tools?: any[];
|
|
367
|
-
}): Promise<void>;
|
|
368
|
-
|
|
369
|
-
declare function createSmartAgent<TOutput = unknown>(opts: AgentOptions & {
|
|
662
|
+
declare function createSmartAgent<TOutput = unknown>(opts: SmartAgentOptions & {
|
|
370
663
|
outputSchema?: ZodSchema<TOutput>;
|
|
371
|
-
}):
|
|
664
|
+
}): SmartAgentInstance<TOutput>;
|
|
665
|
+
|
|
666
|
+
type GuardrailEvaluationParams = {
|
|
667
|
+
guardrails?: ConversationGuardrail[];
|
|
668
|
+
phase: GuardrailPhase;
|
|
669
|
+
state: SmartState;
|
|
670
|
+
runtime: AgentRuntimeConfig;
|
|
671
|
+
options: SmartAgentOptions;
|
|
672
|
+
emit?: (event: SmartAgentEvent) => void;
|
|
673
|
+
};
|
|
674
|
+
declare function evaluateGuardrails(params: GuardrailEvaluationParams): Promise<GuardrailOutcome>;
|
|
675
|
+
type CreateGuardrailOptions = {
|
|
676
|
+
id?: string;
|
|
677
|
+
title?: string;
|
|
678
|
+
description?: string;
|
|
679
|
+
appliesTo?: GuardrailPhase[];
|
|
680
|
+
checks: GuardrailRule[];
|
|
681
|
+
haltOnViolation?: boolean;
|
|
682
|
+
onViolation?: ConversationGuardrail["onViolation"];
|
|
683
|
+
metadata?: Record<string, any>;
|
|
684
|
+
};
|
|
685
|
+
declare function createGuardrail(options: CreateGuardrailOptions): ConversationGuardrail;
|
|
686
|
+
|
|
687
|
+
type RegexRuleOptions = {
|
|
688
|
+
id?: string;
|
|
689
|
+
title?: string;
|
|
690
|
+
description?: string;
|
|
691
|
+
pattern: RegExp | string;
|
|
692
|
+
flags?: string;
|
|
693
|
+
matchDisposition?: GuardrailDisposition;
|
|
694
|
+
selector?: (context: GuardrailContext) => string;
|
|
695
|
+
allowIfMatch?: boolean;
|
|
696
|
+
failureMessage?: string;
|
|
697
|
+
};
|
|
698
|
+
declare function regexRule(options: RegexRuleOptions): GuardrailRule;
|
|
699
|
+
type JsonSchemaRuleOptions = {
|
|
700
|
+
id?: string;
|
|
701
|
+
title?: string;
|
|
702
|
+
description?: string;
|
|
703
|
+
schema: JSONSchema7 | z.ZodTypeAny;
|
|
704
|
+
selector?: (context: GuardrailContext) => string;
|
|
705
|
+
disposition?: GuardrailDisposition;
|
|
706
|
+
allowOnParseError?: boolean;
|
|
707
|
+
};
|
|
708
|
+
declare function jsonSchemaRule(options: JsonSchemaRuleOptions): GuardrailRule;
|
|
709
|
+
type CodeDetectionRuleOptions = {
|
|
710
|
+
id?: string;
|
|
711
|
+
title?: string;
|
|
712
|
+
description?: string;
|
|
713
|
+
selector?: (context: GuardrailContext) => string;
|
|
714
|
+
disposition?: GuardrailDisposition;
|
|
715
|
+
allowList?: Array<RegExp | string>;
|
|
716
|
+
};
|
|
717
|
+
declare function codePresenceRule(options?: CodeDetectionRuleOptions): GuardrailRule;
|
|
718
|
+
declare const guardianSchema: z.ZodObject<{
|
|
719
|
+
allow: z.ZodBoolean;
|
|
720
|
+
disposition: z.ZodOptional<z.ZodEnum<["allow", "warn", "block"]>>;
|
|
721
|
+
reason: z.ZodOptional<z.ZodString>;
|
|
722
|
+
details: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
|
|
723
|
+
}, "strip", z.ZodTypeAny, {
|
|
724
|
+
allow: boolean;
|
|
725
|
+
disposition?: "block" | "warn" | "allow" | undefined;
|
|
726
|
+
reason?: string | undefined;
|
|
727
|
+
details?: Record<string, any> | undefined;
|
|
728
|
+
}, {
|
|
729
|
+
allow: boolean;
|
|
730
|
+
disposition?: "block" | "warn" | "allow" | undefined;
|
|
731
|
+
reason?: string | undefined;
|
|
732
|
+
details?: Record<string, any> | undefined;
|
|
733
|
+
}>;
|
|
734
|
+
type AgentRuleOptions = {
|
|
735
|
+
id?: string;
|
|
736
|
+
title?: string;
|
|
737
|
+
description?: string;
|
|
738
|
+
agent: SmartAgentInstance<z.infer<typeof guardianSchema>>;
|
|
739
|
+
systemPrompt?: string;
|
|
740
|
+
payloadBuilder?: (context: GuardrailContext) => string;
|
|
741
|
+
dispositionFallback?: GuardrailDisposition;
|
|
742
|
+
};
|
|
743
|
+
declare function agentVerdictRule(options: AgentRuleOptions): GuardrailRule;
|
|
744
|
+
type CustomRuleCallback = (context: GuardrailContext) => boolean | {
|
|
745
|
+
allow: boolean;
|
|
746
|
+
reason?: string;
|
|
747
|
+
disposition?: GuardrailDisposition;
|
|
748
|
+
details?: Record<string, any>;
|
|
749
|
+
} | Promise<boolean | {
|
|
750
|
+
allow: boolean;
|
|
751
|
+
reason?: string;
|
|
752
|
+
disposition?: GuardrailDisposition;
|
|
753
|
+
details?: Record<string, any>;
|
|
754
|
+
}>;
|
|
755
|
+
type CustomRuleOptions = {
|
|
756
|
+
id?: string;
|
|
757
|
+
title?: string;
|
|
758
|
+
description?: string;
|
|
759
|
+
callback: CustomRuleCallback;
|
|
760
|
+
defaultDisposition?: GuardrailDisposition;
|
|
761
|
+
};
|
|
762
|
+
declare function customCallbackRule(options: CustomRuleOptions): GuardrailRule;
|
|
763
|
+
|
|
764
|
+
type GuardrailPresetBase = {
|
|
765
|
+
guardrailId?: string;
|
|
766
|
+
guardrailTitle?: string;
|
|
767
|
+
guardrailDescription?: string;
|
|
768
|
+
phases?: GuardrailPhase[];
|
|
769
|
+
haltOnViolation?: boolean;
|
|
770
|
+
onViolation?: ConversationGuardrail["onViolation"];
|
|
771
|
+
metadata?: Record<string, any>;
|
|
772
|
+
};
|
|
773
|
+
type RegexGuardrailOptions = GuardrailPresetBase & {
|
|
774
|
+
rule?: Omit<RegexRuleOptions, "pattern">;
|
|
775
|
+
};
|
|
776
|
+
declare function createRegexGuardrail(pattern: RegExp | string, options?: RegexGuardrailOptions): ConversationGuardrail;
|
|
777
|
+
type JsonGuardrailOptions = GuardrailPresetBase & {
|
|
778
|
+
rule?: Omit<JsonSchemaRuleOptions, "schema">;
|
|
779
|
+
};
|
|
780
|
+
declare function createJsonGuardrail(schema: JsonSchemaRuleOptions["schema"], options?: JsonGuardrailOptions): ConversationGuardrail;
|
|
781
|
+
type CodeGuardrailOptions = GuardrailPresetBase & {
|
|
782
|
+
rule?: CodeDetectionRuleOptions;
|
|
783
|
+
};
|
|
784
|
+
declare function createCodeGuardrail(options?: CodeGuardrailOptions): ConversationGuardrail;
|
|
785
|
+
|
|
786
|
+
declare function captureSnapshot(state: SmartState, options?: SnapshotOptions): AgentSnapshot;
|
|
787
|
+
declare function restoreSnapshot(snapshot: AgentSnapshot, restoreOptions?: RestoreSnapshotOptions): SmartState;
|
|
788
|
+
|
|
789
|
+
declare function resolveToolApprovalState(state: SmartState, resolution: ToolApprovalResolution): SmartState;
|
|
790
|
+
|
|
791
|
+
declare function fromLangchainTools<T extends ToolInterface = ToolInterface>(tools: any[]): T[];
|
|
792
|
+
|
|
793
|
+
declare function fileSink(path?: string): TraceSinkConfig;
|
|
794
|
+
type CustomSinkArg = ((event: TraceEventRecord) => void | Promise<void>) | {
|
|
795
|
+
onEvent?: (event: TraceEventRecord) => void | Promise<void>;
|
|
796
|
+
onSession?: (session: TraceSessionFile) => void | Promise<void>;
|
|
797
|
+
};
|
|
798
|
+
declare function customSink(handler: CustomSinkArg): TraceSinkConfig;
|
|
799
|
+
declare function cognipeerSink(apiKey: string): TraceSinkConfig;
|
|
800
|
+
declare function cognipeerSink(url: string | undefined, apiKey: string): TraceSinkConfig;
|
|
801
|
+
declare function httpSink(url: string, headers?: Record<string, string>): TraceSinkConfig;
|
|
372
802
|
|
|
373
|
-
export { type
|
|
803
|
+
export { type AIMessage, type AgentInstance, type AgentInvokeResult, type AgentLimits, type AgentOptions, type AgentRuleOptions, type AgentRuntimeConfig, type AgentSnapshot, type AgentSnapshotMetadata, type AgentState, type BaseChatMessage, type BaseChatMessagePart, type BaseChatModel, type BaseMessage, type CodeDetectionRuleOptions, type CodeGuardrailOptions, type ConversationGuardrail, type CustomRuleCallback, type CustomRuleOptions, type GuardrailContext, type GuardrailDisposition, type GuardrailEvent, type GuardrailIncident, type GuardrailOutcome, GuardrailPhase, type GuardrailRule, type HandoffDescriptor, type InvokeConfig, type JsonGuardrailOptions, type JsonSchemaRuleOptions, type Message, type PendingToolApproval, type RegexGuardrailOptions, type RegexRuleOptions, type ResolvedTraceConfig, type ResolvedTraceSink, type RestoreSnapshotOptions, type SerializableSmartState, type SmartAgentEvent, type SmartAgentInstance, type SmartAgentLimits, type SmartAgentOptions, type SmartAgentTracingConfig, type SmartModel, type SmartState, type SmartToolFn, type SnapshotOptions, type SnapshotRuntimeHint, type TokenLimits, type ToolApprovalEvent, type ToolApprovalResolution, type ToolInterface, 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 TraceSinkSnapshot, type TraceSummarySection, type TraceToolCallSection, type TraceToolResultSection, type TracingConfig, agentVerdictRule, applyTokenLimits, buildSystemPrompt, captureSnapshot, codePresenceRule, cognipeerSink, countApproxTokens, createAgent, createAgentNode, createCodeGuardrail, createContextSummarizeNode, createContextTools, createGuardrail, createJsonGuardrail, createRegexGuardrail, createResolverNode, createSmartAgent, createTool, createToolLimitFinalizeNode, createToolsNode, customCallbackRule, customSink, evaluateGuardrails, fileSink, fromLangchainModel, fromLangchainTools, httpSink, isSmartModel, jsonSchemaRule, regexRule, resolveToolApprovalState, restoreSnapshot, withTools };
|