@agentionai/agents 0.6.1 → 0.8.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/dist/agents/BaseAgent.d.ts +0 -39
- package/dist/agents/BaseAgent.js +1 -100
- package/dist/agents/anthropic/ClaudeAgent.d.ts +2 -0
- package/dist/agents/anthropic/ClaudeAgent.js +4 -8
- package/dist/agents/google/GeminiAgent.d.ts +2 -0
- package/dist/agents/google/GeminiAgent.js +4 -4
- package/dist/agents/mistral/MistralAgent.d.ts +2 -0
- package/dist/agents/mistral/MistralAgent.js +4 -4
- package/dist/agents/openai/OpenAiAgent.d.ts +2 -0
- package/dist/agents/openai/OpenAiAgent.js +4 -4
- package/dist/chunkers/Chunker.d.ts +1 -1
- package/dist/chunkers/Chunker.js +19 -20
- package/dist/chunkers/TokenChunker.d.ts +1 -1
- package/dist/chunkers/TokenChunker.js +2 -3
- package/dist/chunkers/types.d.ts +17 -11
- package/dist/core.d.ts +1 -0
- package/dist/core.js +2 -0
- package/dist/graph/planning/PlanExecutor.d.ts +0 -12
- package/dist/graph/planning/PlanExecutor.js +19 -74
- package/dist/graph/planning/PlanStore.js +2 -6
- package/dist/index.d.ts +1 -0
- package/dist/index.js +2 -0
- package/dist/mcp/MCPClient.d.ts +106 -0
- package/dist/mcp/MCPClient.js +264 -0
- package/dist/mcp/index.d.ts +64 -0
- package/dist/mcp/index.js +67 -0
- package/dist/mcp/types.d.ts +51 -0
- package/dist/mcp/types.js +3 -0
- package/dist/vectorstore/LanceDBVectorStore.d.ts +102 -54
- package/dist/vectorstore/LanceDBVectorStore.js +231 -135
- package/dist/vectorstore/VectorStore.d.ts +2 -2
- package/dist/vectorstore/VectorStore.js +3 -3
- package/package.json +7 -3
|
@@ -4,11 +4,6 @@ import { History, HistoryEntry, MessageRole, MessageContent } from "../history/H
|
|
|
4
4
|
import { AgentVendor, CommonAgentConfig, VendorSpecificConfig } from "./AgentConfig";
|
|
5
5
|
export type { HistoryEntry, MessageRole, MessageContent };
|
|
6
6
|
export type { AgentVendor };
|
|
7
|
-
/**
|
|
8
|
-
* Parses a `retry-after` header value (seconds as string) into milliseconds.
|
|
9
|
-
*/
|
|
10
|
-
declare function parseRetryAfterHeader(header: string | undefined): number | undefined;
|
|
11
|
-
export { parseRetryAfterHeader };
|
|
12
7
|
/**
|
|
13
8
|
* Agent config as used across all agents
|
|
14
9
|
* @deprecated Use CommonAgentConfig with vendorConfig instead
|
|
@@ -38,16 +33,6 @@ export declare abstract class BaseAgent<TInput = unknown, TOutput = unknown> ext
|
|
|
38
33
|
protected vendor: AgentVendor;
|
|
39
34
|
/** The model identifier for this agent */
|
|
40
35
|
protected model: string;
|
|
41
|
-
/** Token usage from the last execution (for metrics tracking) */
|
|
42
|
-
lastTokenUsage?: TokenUsage;
|
|
43
|
-
/** Maximum number of retry attempts (0 = disabled) */
|
|
44
|
-
protected maxRetries: number;
|
|
45
|
-
/** Initial backoff delay in ms */
|
|
46
|
-
private retryDelayMs;
|
|
47
|
-
/** Multiplier applied to delay after each attempt */
|
|
48
|
-
private retryBackoffFactor;
|
|
49
|
-
/** Maximum backoff delay cap in ms */
|
|
50
|
-
private retryMaxDelayMs;
|
|
51
36
|
/**
|
|
52
37
|
* An Agent is the primary LLM entity.
|
|
53
38
|
*
|
|
@@ -83,30 +68,6 @@ export declare abstract class BaseAgent<TInput = unknown, TOutput = unknown> ext
|
|
|
83
68
|
* Add a message with content blocks to history
|
|
84
69
|
*/
|
|
85
70
|
protected addMessageToHistory(role: MessageRole, content: MessageContent[]): void;
|
|
86
|
-
/**
|
|
87
|
-
* Enable retry with exponential backoff for this agent.
|
|
88
|
-
* @param options.maxRetries - Number of retry attempts (default: 3)
|
|
89
|
-
* @param options.initialDelay - Initial backoff delay in ms (default: 1000)
|
|
90
|
-
* @param options.backoffFactor - Multiplier per attempt (default: 2)
|
|
91
|
-
* @param options.maxDelay - Maximum delay cap in ms (default: 30000)
|
|
92
|
-
*/
|
|
93
|
-
withRetry(options?: {
|
|
94
|
-
maxRetries?: number;
|
|
95
|
-
initialDelay?: number;
|
|
96
|
-
backoffFactor?: number;
|
|
97
|
-
maxDelay?: number;
|
|
98
|
-
}): this;
|
|
99
|
-
/**
|
|
100
|
-
* Executes a function with retry and exponential backoff.
|
|
101
|
-
*
|
|
102
|
-
* Retries on 429 (rate limit) and 5xx (server error) responses.
|
|
103
|
-
* Never retries on MaxTokensExceededError or 4xx client errors.
|
|
104
|
-
* Throws MaxRetriesExceededError when all attempts are exhausted.
|
|
105
|
-
*
|
|
106
|
-
* @param fn - The async function to execute
|
|
107
|
-
* @param getRetryAfterMs - Optional extractor for retry-after header (returns ms to wait)
|
|
108
|
-
*/
|
|
109
|
-
protected executeWithRetry<T>(fn: () => Promise<T>, getRetryAfterMs?: (error: unknown) => number | undefined): Promise<T>;
|
|
110
71
|
addTools(tools: Tool<unknown>[]): void;
|
|
111
72
|
getId(): string;
|
|
112
73
|
getName(): string;
|
package/dist/agents/BaseAgent.js
CHANGED
|
@@ -4,30 +4,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.BaseAgent = void 0;
|
|
7
|
-
exports.parseRetryAfterHeader = parseRetryAfterHeader;
|
|
8
7
|
const events_1 = __importDefault(require("events"));
|
|
9
8
|
const Tool_1 = require("../tools/Tool");
|
|
10
9
|
const History_1 = require("../history/History");
|
|
11
|
-
const AgentEvent_1 = require("./AgentEvent");
|
|
12
|
-
const AgentError_1 = require("./errors/AgentError");
|
|
13
|
-
/**
|
|
14
|
-
* Extracts an HTTP status code from a raw SDK error of any vendor shape.
|
|
15
|
-
*/
|
|
16
|
-
function extractStatusCode(error) {
|
|
17
|
-
if (error instanceof AgentError_1.ApiError)
|
|
18
|
-
return error.statusCode;
|
|
19
|
-
const e = error;
|
|
20
|
-
return typeof e.status === "number" ? e.status : undefined;
|
|
21
|
-
}
|
|
22
|
-
/**
|
|
23
|
-
* Parses a `retry-after` header value (seconds as string) into milliseconds.
|
|
24
|
-
*/
|
|
25
|
-
function parseRetryAfterHeader(header) {
|
|
26
|
-
if (!header)
|
|
27
|
-
return undefined;
|
|
28
|
-
const seconds = parseFloat(header);
|
|
29
|
-
return isNaN(seconds) ? undefined : Math.ceil(seconds * 1000);
|
|
30
|
-
}
|
|
31
10
|
/**
|
|
32
11
|
* The base agent is what the other agents are inheriting from
|
|
33
12
|
* Handles the BaseConfig
|
|
@@ -45,15 +24,7 @@ class BaseAgent extends events_1.default {
|
|
|
45
24
|
constructor(config, history = new History_1.History([], { transient: true })) {
|
|
46
25
|
super();
|
|
47
26
|
this.history = history;
|
|
48
|
-
this.debug =
|
|
49
|
-
/** Maximum number of retry attempts (0 = disabled) */
|
|
50
|
-
this.maxRetries = 0;
|
|
51
|
-
/** Initial backoff delay in ms */
|
|
52
|
-
this.retryDelayMs = 1000;
|
|
53
|
-
/** Multiplier applied to delay after each attempt */
|
|
54
|
-
this.retryBackoffFactor = 2;
|
|
55
|
-
/** Maximum backoff delay cap in ms */
|
|
56
|
-
this.retryMaxDelayMs = 30000;
|
|
27
|
+
this.debug = true;
|
|
57
28
|
this.id = config.id;
|
|
58
29
|
this.debug = config.debug || false;
|
|
59
30
|
this.name = config.name;
|
|
@@ -70,7 +41,6 @@ class BaseAgent extends events_1.default {
|
|
|
70
41
|
}
|
|
71
42
|
this.tools = new Map((config.tools || []).map((tool) => [tool.name, tool]));
|
|
72
43
|
this.maxHistoryLength = config.maxHistoryLength || 100;
|
|
73
|
-
this.maxRetries = config.maxRetries ?? 0;
|
|
74
44
|
}
|
|
75
45
|
getToolDefinitions() {
|
|
76
46
|
return Array.from(this.tools.values()).map((tool) => tool.getPrompt());
|
|
@@ -111,75 +81,6 @@ class BaseAgent extends events_1.default {
|
|
|
111
81
|
addMessageToHistory(role, content) {
|
|
112
82
|
this.history.addMessage(role, content);
|
|
113
83
|
}
|
|
114
|
-
/**
|
|
115
|
-
* Enable retry with exponential backoff for this agent.
|
|
116
|
-
* @param options.maxRetries - Number of retry attempts (default: 3)
|
|
117
|
-
* @param options.initialDelay - Initial backoff delay in ms (default: 1000)
|
|
118
|
-
* @param options.backoffFactor - Multiplier per attempt (default: 2)
|
|
119
|
-
* @param options.maxDelay - Maximum delay cap in ms (default: 30000)
|
|
120
|
-
*/
|
|
121
|
-
withRetry(options) {
|
|
122
|
-
this.maxRetries = options?.maxRetries ?? 3;
|
|
123
|
-
if (options?.initialDelay !== undefined)
|
|
124
|
-
this.retryDelayMs = options.initialDelay;
|
|
125
|
-
if (options?.backoffFactor !== undefined)
|
|
126
|
-
this.retryBackoffFactor = options.backoffFactor;
|
|
127
|
-
if (options?.maxDelay !== undefined)
|
|
128
|
-
this.retryMaxDelayMs = options.maxDelay;
|
|
129
|
-
return this;
|
|
130
|
-
}
|
|
131
|
-
/**
|
|
132
|
-
* Executes a function with retry and exponential backoff.
|
|
133
|
-
*
|
|
134
|
-
* Retries on 429 (rate limit) and 5xx (server error) responses.
|
|
135
|
-
* Never retries on MaxTokensExceededError or 4xx client errors.
|
|
136
|
-
* Throws MaxRetriesExceededError when all attempts are exhausted.
|
|
137
|
-
*
|
|
138
|
-
* @param fn - The async function to execute
|
|
139
|
-
* @param getRetryAfterMs - Optional extractor for retry-after header (returns ms to wait)
|
|
140
|
-
*/
|
|
141
|
-
async executeWithRetry(fn, getRetryAfterMs) {
|
|
142
|
-
let attempt = 0;
|
|
143
|
-
let delayMs = this.retryDelayMs;
|
|
144
|
-
while (true) {
|
|
145
|
-
try {
|
|
146
|
-
return await fn();
|
|
147
|
-
}
|
|
148
|
-
catch (error) {
|
|
149
|
-
// MaxTokensExceededError is never retryable
|
|
150
|
-
if (error instanceof AgentError_1.MaxTokensExceededError)
|
|
151
|
-
throw error;
|
|
152
|
-
const statusCode = extractStatusCode(error);
|
|
153
|
-
const isRetryable = statusCode === 429 ||
|
|
154
|
-
(statusCode !== undefined && statusCode >= 500);
|
|
155
|
-
if (!isRetryable || attempt >= this.maxRetries) {
|
|
156
|
-
if (attempt > 0) {
|
|
157
|
-
this.emit(AgentEvent_1.AgentEvent.MAX_RETRIES_EXCEEDED, {
|
|
158
|
-
maxRetries: this.maxRetries,
|
|
159
|
-
error,
|
|
160
|
-
});
|
|
161
|
-
throw new AgentError_1.MaxRetriesExceededError(`Max retries (${this.maxRetries}) exceeded`, this.maxRetries);
|
|
162
|
-
}
|
|
163
|
-
throw error;
|
|
164
|
-
}
|
|
165
|
-
attempt++;
|
|
166
|
-
// Respect retry-after header if the SDK provides it
|
|
167
|
-
const retryAfter = getRetryAfterMs?.(error);
|
|
168
|
-
// Add ±10% jitter to avoid thundering herd
|
|
169
|
-
const jitter = delayMs * 0.1 * (Math.random() * 2 - 1);
|
|
170
|
-
const waitMs = Math.min(retryAfter ?? delayMs + jitter, this.retryMaxDelayMs);
|
|
171
|
-
this.emit(AgentEvent_1.AgentEvent.RETRY, {
|
|
172
|
-
attempt,
|
|
173
|
-
maxRetries: this.maxRetries,
|
|
174
|
-
delayMs: waitMs,
|
|
175
|
-
statusCode,
|
|
176
|
-
error,
|
|
177
|
-
});
|
|
178
|
-
await new Promise((resolve) => setTimeout(resolve, waitMs));
|
|
179
|
-
delayMs = Math.min(delayMs * this.retryBackoffFactor, this.retryMaxDelayMs);
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
84
|
addTools(tools) {
|
|
184
85
|
tools.forEach((tool) => {
|
|
185
86
|
if (!this.tools.has(tool.name)) {
|
|
@@ -28,6 +28,8 @@ type AgentConfig = BaseAgentConfig & {
|
|
|
28
28
|
export declare class ClaudeAgent extends BaseAgent {
|
|
29
29
|
private client;
|
|
30
30
|
protected config: Partial<AgentConfig>;
|
|
31
|
+
/** Token usage from the last execution (for metrics tracking) */
|
|
32
|
+
lastTokenUsage?: TokenUsage;
|
|
31
33
|
/** Current visualization event ID for tracking */
|
|
32
34
|
private vizEventId?;
|
|
33
35
|
/** Count of tool calls in current execution */
|
|
@@ -77,7 +77,7 @@ class ClaudeAgent extends BaseAgent_1.BaseAgent {
|
|
|
77
77
|
try {
|
|
78
78
|
const messages = transformers_1.anthropicTransformer.toProvider(this.history.entries);
|
|
79
79
|
const systemMessage = this.history.getSystemMessage();
|
|
80
|
-
const response = await this.
|
|
80
|
+
const response = await this.client.messages.create({
|
|
81
81
|
model: this.config.model,
|
|
82
82
|
system: systemMessage,
|
|
83
83
|
max_tokens: this.config.maxTokens,
|
|
@@ -88,9 +88,7 @@ class ClaudeAgent extends BaseAgent_1.BaseAgent {
|
|
|
88
88
|
top_k: this.config.topK,
|
|
89
89
|
stop_sequences: this.config.stopSequences,
|
|
90
90
|
metadata: this.config.metadata,
|
|
91
|
-
})
|
|
92
|
-
? (0, BaseAgent_1.parseRetryAfterHeader)(err.headers?.["retry-after"])
|
|
93
|
-
: undefined);
|
|
91
|
+
});
|
|
94
92
|
this.emit(AgentEvent_1.AgentEvent.AFTER_EXECUTE, response);
|
|
95
93
|
return await this.handleResponse(response);
|
|
96
94
|
}
|
|
@@ -180,7 +178,7 @@ class ClaudeAgent extends BaseAgent_1.BaseAgent {
|
|
|
180
178
|
// Continue conversation with tool results
|
|
181
179
|
try {
|
|
182
180
|
const messages = transformers_1.anthropicTransformer.toProvider(this.history.entries);
|
|
183
|
-
const newResponse = await this.
|
|
181
|
+
const newResponse = await this.client.messages.create({
|
|
184
182
|
model: this.config.model,
|
|
185
183
|
max_tokens: this.config.maxTokens,
|
|
186
184
|
messages,
|
|
@@ -190,9 +188,7 @@ class ClaudeAgent extends BaseAgent_1.BaseAgent {
|
|
|
190
188
|
top_k: this.config.topK,
|
|
191
189
|
stop_sequences: this.config.stopSequences,
|
|
192
190
|
metadata: this.config.metadata,
|
|
193
|
-
})
|
|
194
|
-
? (0, BaseAgent_1.parseRetryAfterHeader)(err.headers?.["retry-after"])
|
|
195
|
-
: undefined);
|
|
191
|
+
});
|
|
196
192
|
this.emit(AgentEvent_1.AgentEvent.AFTER_EXECUTE, newResponse);
|
|
197
193
|
return this.handleResponse(newResponse);
|
|
198
194
|
}
|
|
@@ -29,6 +29,8 @@ export declare class GeminiAgent extends BaseAgent {
|
|
|
29
29
|
private client;
|
|
30
30
|
private generativeModel;
|
|
31
31
|
protected config: Partial<AgentConfig>;
|
|
32
|
+
/** Token usage from the last execution (for metrics tracking) */
|
|
33
|
+
lastTokenUsage?: TokenUsage;
|
|
32
34
|
/** Current visualization event ID for tracking */
|
|
33
35
|
private vizEventId?;
|
|
34
36
|
/** Count of tool calls in current execution */
|
|
@@ -179,7 +179,7 @@ class GeminiAgent extends BaseAgent_1.BaseAgent {
|
|
|
179
179
|
const contents = transformers_1.geminiTransformer.toProvider(this.history.entries);
|
|
180
180
|
const systemMessage = this.history.getSystemMessage();
|
|
181
181
|
const tools = this.getToolDefinitionsForGemini();
|
|
182
|
-
const response = await this.
|
|
182
|
+
const response = await this.generativeModel.generateContent({
|
|
183
183
|
contents,
|
|
184
184
|
systemInstruction: systemMessage,
|
|
185
185
|
tools: tools ? [tools] : undefined,
|
|
@@ -193,7 +193,7 @@ class GeminiAgent extends BaseAgent_1.BaseAgent {
|
|
|
193
193
|
responseMimeType: this.config.responseMimeType,
|
|
194
194
|
responseSchema: this.config.responseSchema,
|
|
195
195
|
},
|
|
196
|
-
})
|
|
196
|
+
});
|
|
197
197
|
this.emit(AgentEvent_1.AgentEvent.AFTER_EXECUTE, response);
|
|
198
198
|
return await this.handleResponse(response);
|
|
199
199
|
}
|
|
@@ -293,7 +293,7 @@ class GeminiAgent extends BaseAgent_1.BaseAgent {
|
|
|
293
293
|
const newContents = transformers_1.geminiTransformer.toProvider(this.history.entries);
|
|
294
294
|
const systemMessage = this.history.getSystemMessage();
|
|
295
295
|
const tools = this.getToolDefinitionsForGemini();
|
|
296
|
-
const newResponse = await this.
|
|
296
|
+
const newResponse = await this.generativeModel.generateContent({
|
|
297
297
|
contents: newContents,
|
|
298
298
|
systemInstruction: systemMessage,
|
|
299
299
|
tools: tools ? [tools] : undefined,
|
|
@@ -307,7 +307,7 @@ class GeminiAgent extends BaseAgent_1.BaseAgent {
|
|
|
307
307
|
responseMimeType: this.config.responseMimeType,
|
|
308
308
|
responseSchema: this.config.responseSchema,
|
|
309
309
|
},
|
|
310
|
-
})
|
|
310
|
+
});
|
|
311
311
|
this.emit(AgentEvent_1.AgentEvent.AFTER_EXECUTE, newResponse);
|
|
312
312
|
return this.handleResponse(newResponse);
|
|
313
313
|
}
|
|
@@ -29,6 +29,8 @@ type AgentConfig = BaseAgentConfig & {
|
|
|
29
29
|
export declare class MistralAgent extends BaseAgent {
|
|
30
30
|
private client;
|
|
31
31
|
protected config: Partial<AgentConfig>;
|
|
32
|
+
/** Token usage from the last execution (for metrics tracking) */
|
|
33
|
+
lastTokenUsage?: TokenUsage;
|
|
32
34
|
/** Current visualization event ID for tracking */
|
|
33
35
|
private vizEventId?;
|
|
34
36
|
/** Count of tool calls in current execution */
|
|
@@ -87,7 +87,7 @@ class MistralAgent extends BaseAgent_1.BaseAgent {
|
|
|
87
87
|
this.addTextToHistory("user", input);
|
|
88
88
|
try {
|
|
89
89
|
const messages = transformers_1.mistralTransformer.toProvider(this.history.entries);
|
|
90
|
-
const response = await this.
|
|
90
|
+
const response = await this.client.chat.complete({
|
|
91
91
|
model: this.config.model,
|
|
92
92
|
messages: messages,
|
|
93
93
|
tools: this.getToolDefinitions(),
|
|
@@ -97,7 +97,7 @@ class MistralAgent extends BaseAgent_1.BaseAgent {
|
|
|
97
97
|
randomSeed: this.config.randomSeed,
|
|
98
98
|
safePrompt: this.config.safePrompt,
|
|
99
99
|
stop: this.config.stopSequences,
|
|
100
|
-
})
|
|
100
|
+
});
|
|
101
101
|
this.emit(AgentEvent_1.AgentEvent.AFTER_EXECUTE, response);
|
|
102
102
|
return await this.handleResponse(response);
|
|
103
103
|
}
|
|
@@ -203,7 +203,7 @@ class MistralAgent extends BaseAgent_1.BaseAgent {
|
|
|
203
203
|
// Continue conversation
|
|
204
204
|
try {
|
|
205
205
|
const messages = transformers_1.mistralTransformer.toProvider(this.history.entries);
|
|
206
|
-
const newResponse = await this.
|
|
206
|
+
const newResponse = await this.client.chat.complete({
|
|
207
207
|
model: this.config.model,
|
|
208
208
|
messages: messages,
|
|
209
209
|
tools: this.getToolDefinitions(),
|
|
@@ -213,7 +213,7 @@ class MistralAgent extends BaseAgent_1.BaseAgent {
|
|
|
213
213
|
randomSeed: this.config.randomSeed,
|
|
214
214
|
safePrompt: this.config.safePrompt,
|
|
215
215
|
stop: this.config.stopSequences,
|
|
216
|
-
})
|
|
216
|
+
});
|
|
217
217
|
this.emit(AgentEvent_1.AgentEvent.AFTER_EXECUTE, newResponse);
|
|
218
218
|
return this.handleResponse(newResponse);
|
|
219
219
|
}
|
|
@@ -30,6 +30,8 @@ type AgentConfig = BaseAgentConfig & {
|
|
|
30
30
|
export declare class OpenAiAgent extends BaseAgent {
|
|
31
31
|
private client;
|
|
32
32
|
protected config: Partial<AgentConfig>;
|
|
33
|
+
/** Token usage from the last execution (for metrics tracking) */
|
|
34
|
+
lastTokenUsage?: TokenUsage;
|
|
33
35
|
/** Current visualization event ID for tracking */
|
|
34
36
|
private vizEventId?;
|
|
35
37
|
/** Count of tool calls in current execution */
|
|
@@ -98,7 +98,7 @@ class OpenAiAgent extends BaseAgent_1.BaseAgent {
|
|
|
98
98
|
this.addTextToHistory("user", input);
|
|
99
99
|
try {
|
|
100
100
|
const inputMessages = transformers_1.openAiTransformer.toProvider(this.history.entries);
|
|
101
|
-
const response = await this.
|
|
101
|
+
const response = await this.client.responses.create({
|
|
102
102
|
model: this.config.model,
|
|
103
103
|
max_output_tokens: this.config.maxTokens,
|
|
104
104
|
input: inputMessages,
|
|
@@ -110,7 +110,7 @@ class OpenAiAgent extends BaseAgent_1.BaseAgent {
|
|
|
110
110
|
user: this.config.user,
|
|
111
111
|
...(this.config.disableReasoning && { reasoning: { effort: null } }),
|
|
112
112
|
reasoning: { effort: this.config.reasoningEffort },
|
|
113
|
-
})
|
|
113
|
+
});
|
|
114
114
|
this.emit(AgentEvent_1.AgentEvent.AFTER_EXECUTE, response);
|
|
115
115
|
return await this.handleResponse(response);
|
|
116
116
|
}
|
|
@@ -217,7 +217,7 @@ class OpenAiAgent extends BaseAgent_1.BaseAgent {
|
|
|
217
217
|
// Continue conversation
|
|
218
218
|
try {
|
|
219
219
|
const inputMessages = transformers_1.openAiTransformer.toProvider(this.history.entries);
|
|
220
|
-
const newResponse = await this.
|
|
220
|
+
const newResponse = await this.client.responses.create({
|
|
221
221
|
model: this.config.model,
|
|
222
222
|
max_output_tokens: this.config.maxTokens,
|
|
223
223
|
input: inputMessages,
|
|
@@ -234,7 +234,7 @@ class OpenAiAgent extends BaseAgent_1.BaseAgent {
|
|
|
234
234
|
!this.config.disableReasoning && {
|
|
235
235
|
reasoning: { effort: this.config.reasoningEffort },
|
|
236
236
|
}),
|
|
237
|
-
})
|
|
237
|
+
});
|
|
238
238
|
this.emit(AgentEvent_1.AgentEvent.AFTER_EXECUTE, newResponse);
|
|
239
239
|
return this.handleResponse(newResponse);
|
|
240
240
|
}
|
|
@@ -29,7 +29,7 @@ export declare abstract class Chunker {
|
|
|
29
29
|
*/
|
|
30
30
|
protected computeHash(content: string): string;
|
|
31
31
|
/**
|
|
32
|
-
* Link chunks with
|
|
32
|
+
* Link chunks with prev_id and next_id.
|
|
33
33
|
*/
|
|
34
34
|
protected linkChunks(chunks: Chunk[]): void;
|
|
35
35
|
/**
|
package/dist/chunkers/Chunker.js
CHANGED
|
@@ -53,17 +53,17 @@ class Chunker {
|
|
|
53
53
|
}
|
|
54
54
|
const id = this.generateId(content, i, options?.sourceId);
|
|
55
55
|
const metadata = {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
startOffset,
|
|
61
|
-
endOffset,
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
56
|
+
index: i,
|
|
57
|
+
total: splits.length,
|
|
58
|
+
prev_id: null, // Will be linked after
|
|
59
|
+
next_id: null, // Will be linked after
|
|
60
|
+
start: startOffset,
|
|
61
|
+
end: endOffset,
|
|
62
|
+
source_id: options?.sourceId,
|
|
63
|
+
source_path: options?.sourcePath,
|
|
64
|
+
char_count: content.length,
|
|
65
65
|
hash: this.computeHash(content),
|
|
66
|
-
|
|
66
|
+
section: currentSection,
|
|
67
67
|
...options?.metadata,
|
|
68
68
|
};
|
|
69
69
|
chunks.push({ id, content, metadata });
|
|
@@ -71,9 +71,9 @@ class Chunker {
|
|
|
71
71
|
}
|
|
72
72
|
// Link chunks together
|
|
73
73
|
this.linkChunks(chunks);
|
|
74
|
-
// Update
|
|
74
|
+
// Update total now that we know the final count
|
|
75
75
|
for (const chunk of chunks) {
|
|
76
|
-
chunk.metadata.
|
|
76
|
+
chunk.metadata.total = chunks.length;
|
|
77
77
|
}
|
|
78
78
|
// Apply processor if provided
|
|
79
79
|
if (this.config.chunkProcessor) {
|
|
@@ -100,15 +100,15 @@ class Chunker {
|
|
|
100
100
|
return (0, crypto_1.createHash)("sha256").update(content).digest("hex");
|
|
101
101
|
}
|
|
102
102
|
/**
|
|
103
|
-
* Link chunks with
|
|
103
|
+
* Link chunks with prev_id and next_id.
|
|
104
104
|
*/
|
|
105
105
|
linkChunks(chunks) {
|
|
106
106
|
for (let i = 0; i < chunks.length; i++) {
|
|
107
107
|
if (i > 0) {
|
|
108
|
-
chunks[i].metadata.
|
|
108
|
+
chunks[i].metadata.prev_id = chunks[i - 1].id;
|
|
109
109
|
}
|
|
110
110
|
if (i < chunks.length - 1) {
|
|
111
|
-
chunks[i].metadata.
|
|
111
|
+
chunks[i].metadata.next_id = chunks[i + 1].id;
|
|
112
112
|
}
|
|
113
113
|
}
|
|
114
114
|
}
|
|
@@ -128,11 +128,10 @@ class Chunker {
|
|
|
128
128
|
}
|
|
129
129
|
// Re-link after filtering and update indices
|
|
130
130
|
for (let i = 0; i < processed.length; i++) {
|
|
131
|
-
processed[i].metadata.
|
|
132
|
-
processed[i].metadata.
|
|
133
|
-
processed[i].metadata.
|
|
134
|
-
|
|
135
|
-
processed[i].metadata.nextChunkId =
|
|
131
|
+
processed[i].metadata.index = i;
|
|
132
|
+
processed[i].metadata.total = processed.length;
|
|
133
|
+
processed[i].metadata.prev_id = i > 0 ? processed[i - 1].id : null;
|
|
134
|
+
processed[i].metadata.next_id =
|
|
136
135
|
i < processed.length - 1 ? processed[i + 1].id : null;
|
|
137
136
|
}
|
|
138
137
|
return processed;
|
|
@@ -26,7 +26,7 @@ export declare function resetTokenxCache(): void;
|
|
|
26
26
|
* });
|
|
27
27
|
*
|
|
28
28
|
* const chunks = await chunker.chunk(longDocument);
|
|
29
|
-
* // Each chunk.metadata.
|
|
29
|
+
* // Each chunk.metadata.token_count contains estimated tokens
|
|
30
30
|
* ```
|
|
31
31
|
*/
|
|
32
32
|
export declare class TokenChunker extends Chunker {
|
|
@@ -46,7 +46,6 @@ let tokenxModule = null;
|
|
|
46
46
|
*/
|
|
47
47
|
async function loadTokenx() {
|
|
48
48
|
if (!tokenxModule) {
|
|
49
|
-
// Use dynamic import for ESM module
|
|
50
49
|
tokenxModule = await Promise.resolve().then(() => __importStar(require("tokenx")));
|
|
51
50
|
}
|
|
52
51
|
return tokenxModule;
|
|
@@ -73,7 +72,7 @@ function resetTokenxCache() {
|
|
|
73
72
|
* });
|
|
74
73
|
*
|
|
75
74
|
* const chunks = await chunker.chunk(longDocument);
|
|
76
|
-
* // Each chunk.metadata.
|
|
75
|
+
* // Each chunk.metadata.token_count contains estimated tokens
|
|
77
76
|
* ```
|
|
78
77
|
*/
|
|
79
78
|
class TokenChunker extends Chunker_1.Chunker {
|
|
@@ -160,7 +159,7 @@ class TokenChunker extends Chunker_1.Chunker {
|
|
|
160
159
|
const { estimateTokenCount } = tokenx;
|
|
161
160
|
// Add token count to each chunk's metadata
|
|
162
161
|
for (const chunk of chunks) {
|
|
163
|
-
chunk.metadata.
|
|
162
|
+
chunk.metadata.token_count = estimateTokenCount(chunk.content);
|
|
164
163
|
}
|
|
165
164
|
return chunks;
|
|
166
165
|
}
|
package/dist/chunkers/types.d.ts
CHANGED
|
@@ -11,32 +11,38 @@ export interface Chunk {
|
|
|
11
11
|
}
|
|
12
12
|
/**
|
|
13
13
|
* Metadata associated with each chunk.
|
|
14
|
+
*
|
|
15
|
+
* When stored in LanceDB via `LanceDBVectorStore`, these fields are
|
|
16
|
+
* automatically packed into a `chunk_metadata` struct column — they do
|
|
17
|
+
* not need to be declared in `metadataFields`.
|
|
14
18
|
*/
|
|
15
19
|
export interface ChunkMetadata {
|
|
16
20
|
/** Zero-based index of this chunk in the sequence */
|
|
17
|
-
|
|
21
|
+
index: number;
|
|
18
22
|
/** Total number of chunks in the sequence */
|
|
19
|
-
|
|
23
|
+
total: number;
|
|
20
24
|
/** ID of the previous chunk, or null if first */
|
|
21
|
-
|
|
25
|
+
prev_id: string | null;
|
|
22
26
|
/** ID of the next chunk, or null if last */
|
|
23
|
-
|
|
27
|
+
next_id: string | null;
|
|
24
28
|
/** Character offset where this chunk starts in the source text */
|
|
25
|
-
|
|
29
|
+
start: number;
|
|
26
30
|
/** Character offset where this chunk ends in the source text */
|
|
27
|
-
|
|
31
|
+
end: number;
|
|
28
32
|
/** Optional identifier for the source document */
|
|
29
|
-
|
|
33
|
+
source_id?: string;
|
|
30
34
|
/** Optional path to the source file */
|
|
31
|
-
|
|
35
|
+
source_path?: string;
|
|
32
36
|
/** Number of characters in the chunk content */
|
|
33
|
-
|
|
37
|
+
char_count: number;
|
|
34
38
|
/** Estimated number of tokens (when available) */
|
|
35
|
-
|
|
39
|
+
token_count?: number;
|
|
36
40
|
/** SHA-256 hash of the content for deduplication */
|
|
37
41
|
hash: string;
|
|
38
42
|
/** Section title if detected (e.g., markdown headers) */
|
|
39
|
-
|
|
43
|
+
section?: string;
|
|
44
|
+
/** Page number in the source document (e.g., PDF page) */
|
|
45
|
+
page?: number;
|
|
40
46
|
[key: string]: unknown;
|
|
41
47
|
}
|
|
42
48
|
/**
|
package/dist/core.d.ts
CHANGED
package/dist/core.js
CHANGED
|
@@ -29,6 +29,8 @@ __exportStar(require("./history/types"), exports);
|
|
|
29
29
|
__exportStar(require("./graph/AgentGraph"), exports);
|
|
30
30
|
// Tools
|
|
31
31
|
__exportStar(require("./tools/Tool"), exports);
|
|
32
|
+
// MCP (Model Context Protocol)
|
|
33
|
+
__exportStar(require("./mcp"), exports);
|
|
32
34
|
// Visualization
|
|
33
35
|
__exportStar(require("./viz"), exports);
|
|
34
36
|
// Vector Store
|
|
@@ -23,14 +23,6 @@ export interface PlanExecutorOptions {
|
|
|
23
23
|
* @default true
|
|
24
24
|
*/
|
|
25
25
|
stopOnFailure?: boolean;
|
|
26
|
-
/**
|
|
27
|
-
* Maximum number of previous step results to include in worker context.
|
|
28
|
-
* This prevents context overflow by limiting how much history is passed to each step.
|
|
29
|
-
* Set to 0 to include no previous steps (workers should use context_get to retrieve data).
|
|
30
|
-
* Set to a small number (1-3) to include only recent context.
|
|
31
|
-
* @default 0 (workers request context explicitly)
|
|
32
|
-
*/
|
|
33
|
-
maxContextSteps?: number;
|
|
34
26
|
/**
|
|
35
27
|
* Callback invoked when planning phase completes.
|
|
36
28
|
*/
|
|
@@ -153,10 +145,6 @@ export declare class PlanExecutor extends BaseExecutor<string, string> {
|
|
|
153
145
|
private createPlanningPrompt;
|
|
154
146
|
/**
|
|
155
147
|
* Create input for a step execution.
|
|
156
|
-
*
|
|
157
|
-
* By default, only includes the current step information.
|
|
158
|
-
* Workers should use context_get to retrieve data from previous steps.
|
|
159
|
-
* This prevents token overflow from accumulating context.
|
|
160
148
|
*/
|
|
161
149
|
private createStepInput;
|
|
162
150
|
/**
|