@cognipeer/agent-sdk 0.1.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/README.md +179 -0
- package/dist/index.cjs +1271 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +373 -0
- package/dist/index.d.ts +373 -0
- package/dist/index.js +1212 -0
- package/dist/index.js.map +1 -0
- package/package.json +64 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,373 @@
|
|
|
1
|
+
import { ToolInterface as ToolInterface$1 } from '@langchain/core/tools';
|
|
2
|
+
import { ZodSchema } from 'zod';
|
|
3
|
+
|
|
4
|
+
interface BaseChatMessagePart {
|
|
5
|
+
type?: string;
|
|
6
|
+
text?: string;
|
|
7
|
+
content?: string;
|
|
8
|
+
[key: string]: any;
|
|
9
|
+
}
|
|
10
|
+
interface BaseChatMessage {
|
|
11
|
+
role: 'system' | 'user' | 'assistant' | 'tool' | string;
|
|
12
|
+
name?: string;
|
|
13
|
+
content: string | BaseChatMessagePart[];
|
|
14
|
+
tool_calls?: Array<{
|
|
15
|
+
id: string;
|
|
16
|
+
type?: string;
|
|
17
|
+
function?: {
|
|
18
|
+
name: string;
|
|
19
|
+
arguments: string;
|
|
20
|
+
};
|
|
21
|
+
}>;
|
|
22
|
+
tool_call_id?: string;
|
|
23
|
+
usage?: any;
|
|
24
|
+
response_metadata?: any;
|
|
25
|
+
[key: string]: any;
|
|
26
|
+
}
|
|
27
|
+
interface BaseChatModel {
|
|
28
|
+
invoke(messages: BaseChatMessage[]): Promise<BaseChatMessage>;
|
|
29
|
+
bindTools?(tools: any[]): BaseChatModel;
|
|
30
|
+
modelName?: string;
|
|
31
|
+
[key: string]: any;
|
|
32
|
+
}
|
|
33
|
+
type SmartModel = BaseChatModel;
|
|
34
|
+
declare function isSmartModel(m: any): m is SmartModel;
|
|
35
|
+
declare function withTools(model: SmartModel, tools: any[]): BaseChatModel;
|
|
36
|
+
declare function fromLangchainModel(lcModel: any): BaseChatModel;
|
|
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
|
+
type ImageURL = {
|
|
55
|
+
url: string;
|
|
56
|
+
detail?: 'auto' | 'low' | 'high';
|
|
57
|
+
} | {
|
|
58
|
+
base64: string;
|
|
59
|
+
media_type?: string;
|
|
60
|
+
detail?: 'auto' | 'low' | 'high';
|
|
61
|
+
} | string;
|
|
62
|
+
type ContentPart = {
|
|
63
|
+
type: 'text';
|
|
64
|
+
text: string;
|
|
65
|
+
} | {
|
|
66
|
+
type: 'image_url';
|
|
67
|
+
image_url: ImageURL;
|
|
68
|
+
} | {
|
|
69
|
+
type: string;
|
|
70
|
+
[key: string]: any;
|
|
71
|
+
};
|
|
72
|
+
interface ToolInterface<TInput = any, TOutput = any, TCallOptions = any> {
|
|
73
|
+
name: string;
|
|
74
|
+
description?: string;
|
|
75
|
+
invoke?: (input: TInput, config?: TCallOptions) => Promise<TOutput> | TOutput;
|
|
76
|
+
call?: (input: TInput, config?: TCallOptions) => Promise<TOutput> | TOutput;
|
|
77
|
+
schema?: any;
|
|
78
|
+
[key: string]: any;
|
|
79
|
+
}
|
|
80
|
+
type RunnableConfig = {
|
|
81
|
+
[key: string]: any;
|
|
82
|
+
};
|
|
83
|
+
type BaseMessage = {
|
|
84
|
+
role: string;
|
|
85
|
+
name?: string;
|
|
86
|
+
content: string | ContentPart[];
|
|
87
|
+
tool_calls?: any;
|
|
88
|
+
tool_call_id?: string;
|
|
89
|
+
[key: string]: any;
|
|
90
|
+
};
|
|
91
|
+
type AIMessage = BaseMessage & {
|
|
92
|
+
role: 'assistant';
|
|
93
|
+
};
|
|
94
|
+
type Message = BaseMessage;
|
|
95
|
+
type SmartAgentLimits = {
|
|
96
|
+
maxToolCalls?: number;
|
|
97
|
+
toolOutputTokenLimit?: number;
|
|
98
|
+
contextTokenLimit?: number;
|
|
99
|
+
summaryTokenLimit?: number;
|
|
100
|
+
summary_token_limit?: number;
|
|
101
|
+
maxToken?: number;
|
|
102
|
+
maxParallelTools?: number;
|
|
103
|
+
};
|
|
104
|
+
type SmartAgentOptions = {
|
|
105
|
+
name?: string;
|
|
106
|
+
model: any;
|
|
107
|
+
tools?: Array<ToolInterface<any, any, any>>;
|
|
108
|
+
handoffs?: HandoffDescriptor<any, any, any>[];
|
|
109
|
+
limits?: SmartAgentLimits;
|
|
110
|
+
summarization?: boolean;
|
|
111
|
+
systemPrompt?: string;
|
|
112
|
+
useTodoList?: boolean;
|
|
113
|
+
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
|
+
outputSchema?: ZodSchema<any>;
|
|
125
|
+
};
|
|
126
|
+
type AgentRuntimeConfig = {
|
|
127
|
+
name?: string;
|
|
128
|
+
model: any;
|
|
129
|
+
tools: Array<ToolInterface<any, any, any>>;
|
|
130
|
+
systemPrompt?: string;
|
|
131
|
+
limits?: SmartAgentLimits;
|
|
132
|
+
useTodoList?: boolean;
|
|
133
|
+
outputSchema?: ZodSchema<any>;
|
|
134
|
+
};
|
|
135
|
+
type HandoffDescriptor<TIn = any, TOut = any, TParsed = any> = {
|
|
136
|
+
type: "handoff";
|
|
137
|
+
toolName: string;
|
|
138
|
+
description: string;
|
|
139
|
+
schema?: ZodSchema<any>;
|
|
140
|
+
target: SmartAgentInstance<TParsed> & {
|
|
141
|
+
__runtime: AgentRuntimeConfig;
|
|
142
|
+
};
|
|
143
|
+
};
|
|
144
|
+
type SmartState = {
|
|
145
|
+
messages: Message[];
|
|
146
|
+
agent?: AgentRuntimeConfig;
|
|
147
|
+
summaries?: string[];
|
|
148
|
+
toolHistory?: Array<{
|
|
149
|
+
executionId: string;
|
|
150
|
+
toolName: string;
|
|
151
|
+
args: any;
|
|
152
|
+
output: any;
|
|
153
|
+
rawOutput?: any;
|
|
154
|
+
timestamp?: string;
|
|
155
|
+
summarized?: boolean;
|
|
156
|
+
originalTokenCount?: number | null;
|
|
157
|
+
messageId?: string;
|
|
158
|
+
tool_call_id?: string;
|
|
159
|
+
fromCache?: boolean;
|
|
160
|
+
}>;
|
|
161
|
+
toolHistoryArchived?: Array<{
|
|
162
|
+
executionId: string;
|
|
163
|
+
toolName: string;
|
|
164
|
+
args: any;
|
|
165
|
+
output: any;
|
|
166
|
+
rawOutput?: any;
|
|
167
|
+
timestamp?: string;
|
|
168
|
+
summarized?: boolean;
|
|
169
|
+
originalTokenCount?: number | null;
|
|
170
|
+
messageId?: string;
|
|
171
|
+
tool_call_id?: string;
|
|
172
|
+
fromCache?: boolean;
|
|
173
|
+
}>;
|
|
174
|
+
toolCache?: Record<string, any>;
|
|
175
|
+
toolCallCount?: number;
|
|
176
|
+
plan?: {
|
|
177
|
+
version: number;
|
|
178
|
+
steps: Array<{
|
|
179
|
+
index: number;
|
|
180
|
+
title: string;
|
|
181
|
+
status: string;
|
|
182
|
+
}>;
|
|
183
|
+
lastUpdated?: string;
|
|
184
|
+
} | null;
|
|
185
|
+
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
|
+
};
|
|
205
|
+
type ToolCallEvent = {
|
|
206
|
+
type: "tool_call";
|
|
207
|
+
phase: "start" | "success" | "error" | "skipped";
|
|
208
|
+
name: string;
|
|
209
|
+
id?: string;
|
|
210
|
+
args?: any;
|
|
211
|
+
result?: any;
|
|
212
|
+
error?: {
|
|
213
|
+
message: string;
|
|
214
|
+
} | undefined;
|
|
215
|
+
durationMs?: number;
|
|
216
|
+
};
|
|
217
|
+
type PlanEvent = {
|
|
218
|
+
type: "plan";
|
|
219
|
+
source: "manage_todo_list" | "system";
|
|
220
|
+
operation?: "write" | "read";
|
|
221
|
+
todoList?: Array<{
|
|
222
|
+
id: number;
|
|
223
|
+
title: string;
|
|
224
|
+
description: string;
|
|
225
|
+
status: string;
|
|
226
|
+
evidence?: string;
|
|
227
|
+
}>;
|
|
228
|
+
version?: number;
|
|
229
|
+
};
|
|
230
|
+
type SummarizationEvent = {
|
|
231
|
+
type: "summarization";
|
|
232
|
+
summary: string;
|
|
233
|
+
archivedCount?: number;
|
|
234
|
+
};
|
|
235
|
+
type FinalAnswerEvent = {
|
|
236
|
+
type: "finalAnswer";
|
|
237
|
+
content: string;
|
|
238
|
+
};
|
|
239
|
+
type MetadataEvent = {
|
|
240
|
+
type: "metadata";
|
|
241
|
+
usage?: any;
|
|
242
|
+
modelName?: string;
|
|
243
|
+
limits?: SmartAgentLimits;
|
|
244
|
+
[key: string]: any;
|
|
245
|
+
};
|
|
246
|
+
type HandoffEvent = {
|
|
247
|
+
type: "handoff";
|
|
248
|
+
from?: string;
|
|
249
|
+
to?: string;
|
|
250
|
+
toolName: string;
|
|
251
|
+
};
|
|
252
|
+
type SmartAgentEvent = ToolCallEvent | PlanEvent | SummarizationEvent | FinalAnswerEvent | MetadataEvent | HandoffEvent;
|
|
253
|
+
type InvokeConfig = RunnableConfig & {
|
|
254
|
+
onEvent?: (event: SmartAgentEvent) => void;
|
|
255
|
+
};
|
|
256
|
+
type AgentInvokeResult<TOutput = unknown> = {
|
|
257
|
+
content: string;
|
|
258
|
+
output?: TOutput;
|
|
259
|
+
metadata: {
|
|
260
|
+
usage?: any;
|
|
261
|
+
};
|
|
262
|
+
messages: Message[];
|
|
263
|
+
state?: SmartState;
|
|
264
|
+
};
|
|
265
|
+
type SmartAgentInstance<TOutput = unknown> = {
|
|
266
|
+
invoke: (input: SmartState, config?: InvokeConfig) => Promise<AgentInvokeResult<TOutput>>;
|
|
267
|
+
asTool: (opts: {
|
|
268
|
+
toolName: string;
|
|
269
|
+
description?: string;
|
|
270
|
+
inputDescription?: string;
|
|
271
|
+
}) => ToolInterface<any, any, any>;
|
|
272
|
+
asHandoff: (opts: {
|
|
273
|
+
toolName?: string;
|
|
274
|
+
description?: string;
|
|
275
|
+
schema?: ZodSchema<any>;
|
|
276
|
+
}) => HandoffDescriptor<any, any, TOutput>;
|
|
277
|
+
__runtime: AgentRuntimeConfig;
|
|
278
|
+
};
|
|
279
|
+
type AgentLimits = SmartAgentLimits;
|
|
280
|
+
type AgentOptions = SmartAgentOptions;
|
|
281
|
+
type AgentState = SmartState;
|
|
282
|
+
type AgentEvent = SmartAgentEvent;
|
|
283
|
+
type AgentResult<T = unknown> = AgentInvokeResult<T>;
|
|
284
|
+
type AgentInstance<T = unknown> = SmartAgentInstance<T>;
|
|
285
|
+
|
|
286
|
+
declare function createAgent<TOutput = unknown>(opts: AgentOptions & {
|
|
287
|
+
outputSchema?: ZodSchema<TOutput>;
|
|
288
|
+
}): AgentInstance<TOutput>;
|
|
289
|
+
|
|
290
|
+
declare function createAgentNode(opts: SmartAgentOptions): (state: SmartState) => Promise<Partial<SmartState>>;
|
|
291
|
+
|
|
292
|
+
declare function createToolsNode(initialTools: Array<ToolInterface$1<any, any, any>>, opts?: SmartAgentOptions): (state: SmartState) => Promise<any>;
|
|
293
|
+
|
|
294
|
+
declare function createResolverNode(): (state: SmartState) => Promise<SmartState>;
|
|
295
|
+
|
|
296
|
+
declare function createToolLimitFinalizeNode(_opts: SmartAgentOptions): (state: SmartState) => Promise<Partial<SmartState>>;
|
|
297
|
+
|
|
298
|
+
declare function createContextSummarizeNode(opts: SmartAgentOptions): (state: SmartState) => Promise<Partial<SmartState>>;
|
|
299
|
+
|
|
300
|
+
type TokenLimits = {
|
|
301
|
+
contextTokenLimit: number;
|
|
302
|
+
summaryTokenLimit: number;
|
|
303
|
+
};
|
|
304
|
+
declare function applyTokenLimits({ state, model, limits, }: {
|
|
305
|
+
state: {
|
|
306
|
+
messages: Message[];
|
|
307
|
+
summaries?: string[];
|
|
308
|
+
};
|
|
309
|
+
model: any;
|
|
310
|
+
limits: {
|
|
311
|
+
contextTokenLimit: number;
|
|
312
|
+
summaryTokenLimit: number;
|
|
313
|
+
};
|
|
314
|
+
}): Promise<{
|
|
315
|
+
messages: Message[];
|
|
316
|
+
summaries?: string[];
|
|
317
|
+
}>;
|
|
318
|
+
|
|
319
|
+
declare function countApproxTokens(text: string): number;
|
|
320
|
+
|
|
321
|
+
declare function createContextTools(stateRef: {
|
|
322
|
+
toolHistory?: any[];
|
|
323
|
+
toolHistoryArchived?: any[];
|
|
324
|
+
todoList?: any[];
|
|
325
|
+
}, opts?: {
|
|
326
|
+
planningEnabled?: boolean;
|
|
327
|
+
outputSchema?: any;
|
|
328
|
+
}): any[];
|
|
329
|
+
|
|
330
|
+
type DebugSession = {
|
|
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 & {
|
|
370
|
+
outputSchema?: ZodSchema<TOutput>;
|
|
371
|
+
}): AgentInstance<TOutput>;
|
|
372
|
+
|
|
373
|
+
export { type AgentEvent, type AgentInstance, type AgentInvokeResult, type AgentLimits, type AgentOptions, type AgentResult, type AgentState, type BaseChatMessage, type BaseChatMessagePart, type BaseChatModel, type DebugSession, type InvokeConfig, type SmartAgentInstance, type SmartAgentLimits, type SmartAgentOptions, type SmartModel, type SmartState, type SmartToolFn, type TokenLimits, applyTokenLimits, buildSystemPrompt, bumpStep, countApproxTokens, createAgent, createAgentNode, createContextSummarizeNode, createContextTools, createDebugSession, createResolverNode, createSmartAgent, createSmartTool, createTool, createToolLimitFinalizeNode, createToolsNode, formatMarkdown, fromLangchainModel, getModelName, isSmartModel, resolveLogsBaseDir, serializeAgentTools, withTools, writeStepMarkdown };
|