@agentionai/agents 0.4.2 → 0.6.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 +2 -2
- package/dist/agents/AgentConfig.d.ts +19 -0
- package/dist/agents/BaseAgent.d.ts +39 -0
- package/dist/agents/BaseAgent.js +100 -1
- package/dist/agents/anthropic/ClaudeAgent.d.ts +0 -2
- package/dist/agents/anthropic/ClaudeAgent.js +8 -4
- package/dist/agents/google/GeminiAgent.d.ts +0 -2
- package/dist/agents/google/GeminiAgent.js +4 -4
- package/dist/agents/mistral/MistralAgent.d.ts +0 -2
- package/dist/agents/mistral/MistralAgent.js +4 -4
- package/dist/agents/openai/OpenAiAgent.d.ts +0 -2
- package/dist/agents/openai/OpenAiAgent.js +4 -4
- package/dist/{vectorstore → embeddings}/OpenAIEmbeddings.d.ts +10 -2
- package/dist/{vectorstore → embeddings}/OpenAIEmbeddings.js +5 -1
- package/dist/embeddings/VoyageAIEmbeddings.d.ts +80 -0
- package/dist/embeddings/VoyageAIEmbeddings.js +139 -0
- package/dist/embeddings/index.d.ts +23 -0
- package/dist/embeddings/index.js +29 -0
- package/dist/graph/AgentGraph.d.ts +77 -0
- package/dist/graph/AgentGraph.js +112 -1
- package/dist/graph/context/ContextStore.d.ts +69 -0
- package/dist/graph/context/ContextStore.js +101 -0
- package/dist/graph/context/ContextTools.d.ts +52 -0
- package/dist/graph/context/ContextTools.js +148 -0
- package/dist/graph/context/index.d.ts +3 -0
- package/dist/graph/context/index.js +11 -0
- package/dist/graph/planning/PlanExecutor.d.ts +184 -0
- package/dist/graph/planning/PlanExecutor.js +396 -0
- package/dist/graph/planning/PlanStore.d.ts +81 -0
- package/dist/graph/planning/PlanStore.js +199 -0
- package/dist/graph/planning/PlanningTools.d.ts +45 -0
- package/dist/graph/planning/PlanningTools.js +178 -0
- package/dist/graph/planning/index.d.ts +5 -0
- package/dist/graph/planning/index.js +14 -0
- package/dist/graph/planning/types.d.ts +41 -0
- package/dist/graph/planning/types.js +3 -0
- package/dist/history/History.js +3 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +2 -0
- package/dist/ingestion/IngestionPipeline.d.ts +1 -1
- package/dist/vectorstore/LanceDBVectorStore.d.ts +67 -2
- package/dist/vectorstore/LanceDBVectorStore.js +134 -23
- package/dist/vectorstore/index.d.ts +6 -4
- package/dist/vectorstore/index.js +10 -6
- package/package.json +12 -3
- /package/dist/{vectorstore → embeddings}/Embeddings.d.ts +0 -0
- /package/dist/{vectorstore → embeddings}/Embeddings.js +0 -0
package/README.md
CHANGED
|
@@ -86,14 +86,14 @@ import { GeminiAgent, Tool } from '@agentionai/agents/gemini';
|
|
|
86
86
|
const weatherTool = new Tool({
|
|
87
87
|
name: 'get_weather',
|
|
88
88
|
description: 'Get the current weather for a location',
|
|
89
|
-
|
|
89
|
+
inputSchema: {
|
|
90
90
|
type: 'object',
|
|
91
91
|
properties: {
|
|
92
92
|
location: { type: 'string', description: 'City name' },
|
|
93
93
|
},
|
|
94
94
|
required: ['location'],
|
|
95
95
|
},
|
|
96
|
-
|
|
96
|
+
execute: async ({ location }) => {
|
|
97
97
|
// In production, call a weather API
|
|
98
98
|
return JSON.stringify({
|
|
99
99
|
location,
|
|
@@ -6,24 +6,43 @@ export type AgentVendor = "openai" | "anthropic" | "mistral" | "gemini";
|
|
|
6
6
|
* Common configuration shared by all agents
|
|
7
7
|
*/
|
|
8
8
|
export interface CommonAgentConfig {
|
|
9
|
+
/** Unique identifier for the agent instance */
|
|
9
10
|
id: string;
|
|
11
|
+
/** Human-readable name for the agent */
|
|
10
12
|
name: string;
|
|
13
|
+
/** Description of the agent's purpose and capabilities */
|
|
11
14
|
description: string;
|
|
15
|
+
/** API key for authenticating with the LLM provider */
|
|
12
16
|
apiKey: string;
|
|
17
|
+
/** Enable debug logging for troubleshooting (default: false) */
|
|
13
18
|
debug?: boolean;
|
|
19
|
+
/** Maximum number of messages to retain in conversation history */
|
|
14
20
|
maxHistoryLength?: number;
|
|
21
|
+
/** Model identifier (e.g., "claude-3-5-sonnet-20241022", "gpt-4") */
|
|
15
22
|
model?: string;
|
|
23
|
+
/** Array of tools the agent can use during execution */
|
|
16
24
|
tools?: Tool<unknown>[];
|
|
25
|
+
/** Array of sub-agents this agent can delegate tasks to */
|
|
17
26
|
agents?: BaseAgent[];
|
|
27
|
+
/** Maximum number of tokens to generate in the response */
|
|
18
28
|
maxTokens?: number;
|
|
29
|
+
/** Sampling temperature (0.0-1.0). Higher values increase randomness */
|
|
19
30
|
temperature?: number;
|
|
31
|
+
/** Nucleus sampling threshold (0.0-1.0). Considers tokens with top cumulative probability */
|
|
20
32
|
topP?: number;
|
|
33
|
+
/** Top-K sampling. Only considers the K most likely tokens (Anthropic, Gemini) */
|
|
21
34
|
topK?: number;
|
|
35
|
+
/** Sequences that will stop generation when encountered */
|
|
22
36
|
stopSequences?: string[];
|
|
37
|
+
/** Request timeout in milliseconds */
|
|
23
38
|
timeout?: number;
|
|
39
|
+
/** Maximum number of retry attempts on API failures */
|
|
24
40
|
maxRetries?: number;
|
|
41
|
+
/** Random seed for deterministic outputs (when supported by vendor) */
|
|
25
42
|
seed?: number;
|
|
43
|
+
/** Penalty for using tokens that already appear in the text (-2.0 to 2.0) */
|
|
26
44
|
presencePenalty?: number;
|
|
45
|
+
/** Penalty based on token frequency in the text (-2.0 to 2.0) */
|
|
27
46
|
frequencyPenalty?: number;
|
|
28
47
|
}
|
|
29
48
|
/**
|
|
@@ -4,6 +4,11 @@ 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 };
|
|
7
12
|
/**
|
|
8
13
|
* Agent config as used across all agents
|
|
9
14
|
* @deprecated Use CommonAgentConfig with vendorConfig instead
|
|
@@ -33,6 +38,16 @@ export declare abstract class BaseAgent<TInput = unknown, TOutput = unknown> ext
|
|
|
33
38
|
protected vendor: AgentVendor;
|
|
34
39
|
/** The model identifier for this agent */
|
|
35
40
|
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;
|
|
36
51
|
/**
|
|
37
52
|
* An Agent is the primary LLM entity.
|
|
38
53
|
*
|
|
@@ -68,6 +83,30 @@ export declare abstract class BaseAgent<TInput = unknown, TOutput = unknown> ext
|
|
|
68
83
|
* Add a message with content blocks to history
|
|
69
84
|
*/
|
|
70
85
|
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>;
|
|
71
110
|
addTools(tools: Tool<unknown>[]): void;
|
|
72
111
|
getId(): string;
|
|
73
112
|
getName(): string;
|
package/dist/agents/BaseAgent.js
CHANGED
|
@@ -4,9 +4,30 @@ 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;
|
|
7
8
|
const events_1 = __importDefault(require("events"));
|
|
8
9
|
const Tool_1 = require("../tools/Tool");
|
|
9
10
|
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
|
+
}
|
|
10
31
|
/**
|
|
11
32
|
* The base agent is what the other agents are inheriting from
|
|
12
33
|
* Handles the BaseConfig
|
|
@@ -24,7 +45,15 @@ class BaseAgent extends events_1.default {
|
|
|
24
45
|
constructor(config, history = new History_1.History([], { transient: true })) {
|
|
25
46
|
super();
|
|
26
47
|
this.history = history;
|
|
27
|
-
this.debug =
|
|
48
|
+
this.debug = false;
|
|
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;
|
|
28
57
|
this.id = config.id;
|
|
29
58
|
this.debug = config.debug || false;
|
|
30
59
|
this.name = config.name;
|
|
@@ -41,6 +70,7 @@ class BaseAgent extends events_1.default {
|
|
|
41
70
|
}
|
|
42
71
|
this.tools = new Map((config.tools || []).map((tool) => [tool.name, tool]));
|
|
43
72
|
this.maxHistoryLength = config.maxHistoryLength || 100;
|
|
73
|
+
this.maxRetries = config.maxRetries ?? 0;
|
|
44
74
|
}
|
|
45
75
|
getToolDefinitions() {
|
|
46
76
|
return Array.from(this.tools.values()).map((tool) => tool.getPrompt());
|
|
@@ -81,6 +111,75 @@ class BaseAgent extends events_1.default {
|
|
|
81
111
|
addMessageToHistory(role, content) {
|
|
82
112
|
this.history.addMessage(role, content);
|
|
83
113
|
}
|
|
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
|
+
}
|
|
84
183
|
addTools(tools) {
|
|
85
184
|
tools.forEach((tool) => {
|
|
86
185
|
if (!this.tools.has(tool.name)) {
|
|
@@ -28,8 +28,6 @@ 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;
|
|
33
31
|
/** Current visualization event ID for tracking */
|
|
34
32
|
private vizEventId?;
|
|
35
33
|
/** 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.client.messages.create({
|
|
80
|
+
const response = await this.executeWithRetry(() => this.client.messages.create({
|
|
81
81
|
model: this.config.model,
|
|
82
82
|
system: systemMessage,
|
|
83
83
|
max_tokens: this.config.maxTokens,
|
|
@@ -88,7 +88,9 @@ 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
|
-
})
|
|
91
|
+
}), (err) => err instanceof sdk_1.APIError
|
|
92
|
+
? (0, BaseAgent_1.parseRetryAfterHeader)(err.headers?.["retry-after"])
|
|
93
|
+
: undefined);
|
|
92
94
|
this.emit(AgentEvent_1.AgentEvent.AFTER_EXECUTE, response);
|
|
93
95
|
return await this.handleResponse(response);
|
|
94
96
|
}
|
|
@@ -178,7 +180,7 @@ class ClaudeAgent extends BaseAgent_1.BaseAgent {
|
|
|
178
180
|
// Continue conversation with tool results
|
|
179
181
|
try {
|
|
180
182
|
const messages = transformers_1.anthropicTransformer.toProvider(this.history.entries);
|
|
181
|
-
const newResponse = await this.client.messages.create({
|
|
183
|
+
const newResponse = await this.executeWithRetry(() => this.client.messages.create({
|
|
182
184
|
model: this.config.model,
|
|
183
185
|
max_tokens: this.config.maxTokens,
|
|
184
186
|
messages,
|
|
@@ -188,7 +190,9 @@ class ClaudeAgent extends BaseAgent_1.BaseAgent {
|
|
|
188
190
|
top_k: this.config.topK,
|
|
189
191
|
stop_sequences: this.config.stopSequences,
|
|
190
192
|
metadata: this.config.metadata,
|
|
191
|
-
})
|
|
193
|
+
}), (err) => err instanceof sdk_1.APIError
|
|
194
|
+
? (0, BaseAgent_1.parseRetryAfterHeader)(err.headers?.["retry-after"])
|
|
195
|
+
: undefined);
|
|
192
196
|
this.emit(AgentEvent_1.AgentEvent.AFTER_EXECUTE, newResponse);
|
|
193
197
|
return this.handleResponse(newResponse);
|
|
194
198
|
}
|
|
@@ -29,8 +29,6 @@ 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;
|
|
34
32
|
/** Current visualization event ID for tracking */
|
|
35
33
|
private vizEventId?;
|
|
36
34
|
/** 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.generativeModel.generateContent({
|
|
182
|
+
const response = await this.executeWithRetry(() => 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.generativeModel.generateContent({
|
|
296
|
+
const newResponse = await this.executeWithRetry(() => 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,8 +29,6 @@ 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;
|
|
34
32
|
/** Current visualization event ID for tracking */
|
|
35
33
|
private vizEventId?;
|
|
36
34
|
/** 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.client.chat.complete({
|
|
90
|
+
const response = await this.executeWithRetry(() => 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.client.chat.complete({
|
|
206
|
+
const newResponse = await this.executeWithRetry(() => 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,8 +30,6 @@ 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;
|
|
35
33
|
/** Current visualization event ID for tracking */
|
|
36
34
|
private vizEventId?;
|
|
37
35
|
/** 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.client.responses.create({
|
|
101
|
+
const response = await this.executeWithRetry(() => 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.client.responses.create({
|
|
220
|
+
const newResponse = await this.executeWithRetry(() => 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
|
}
|
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* OpenAI embeddings implementation.
|
|
3
3
|
*
|
|
4
|
-
* @requires openai - Uses the OpenAI SDK (
|
|
4
|
+
* @requires openai - Uses the OpenAI SDK (peer dependency, dynamically imported)
|
|
5
5
|
*/
|
|
6
6
|
import { Embeddings } from "./Embeddings";
|
|
7
|
+
/**
|
|
8
|
+
* Available OpenAI embedding models with their dimensions.
|
|
9
|
+
*/
|
|
10
|
+
export type OpenAIEmbeddingModel = "text-embedding-3-small" | "text-embedding-3-large" | "text-embedding-ada-002";
|
|
7
11
|
/**
|
|
8
12
|
* Configuration for OpenAI embeddings.
|
|
9
13
|
*/
|
|
@@ -11,7 +15,7 @@ export interface OpenAIEmbeddingsConfig {
|
|
|
11
15
|
/** OpenAI API key (defaults to OPENAI_API_KEY env var) */
|
|
12
16
|
apiKey?: string;
|
|
13
17
|
/** Model to use for embeddings */
|
|
14
|
-
model?:
|
|
18
|
+
model?: OpenAIEmbeddingModel | string;
|
|
15
19
|
/** Number of dimensions (only for text-embedding-3-* models) */
|
|
16
20
|
dimensions?: number;
|
|
17
21
|
/** Base URL for API (for proxies or compatible APIs) */
|
|
@@ -20,10 +24,14 @@ export interface OpenAIEmbeddingsConfig {
|
|
|
20
24
|
/**
|
|
21
25
|
* OpenAI embeddings provider.
|
|
22
26
|
*
|
|
27
|
+
* Supports all OpenAI embedding models including text-embedding-3-small,
|
|
28
|
+
* text-embedding-3-large, and text-embedding-ada-002.
|
|
29
|
+
*
|
|
23
30
|
* @example
|
|
24
31
|
* ```typescript
|
|
25
32
|
* const embeddings = new OpenAIEmbeddings({
|
|
26
33
|
* model: 'text-embedding-3-small',
|
|
34
|
+
* dimensions: 512, // Optional: reduce dimensions for faster search
|
|
27
35
|
* });
|
|
28
36
|
*
|
|
29
37
|
* const vectors = await embeddings.embed(['Hello world', 'Goodbye world']);
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
/**
|
|
3
3
|
* OpenAI embeddings implementation.
|
|
4
4
|
*
|
|
5
|
-
* @requires openai - Uses the OpenAI SDK (
|
|
5
|
+
* @requires openai - Uses the OpenAI SDK (peer dependency, dynamically imported)
|
|
6
6
|
*/
|
|
7
7
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
8
8
|
if (k2 === undefined) k2 = k;
|
|
@@ -49,10 +49,14 @@ const MODEL_DIMENSIONS = {
|
|
|
49
49
|
/**
|
|
50
50
|
* OpenAI embeddings provider.
|
|
51
51
|
*
|
|
52
|
+
* Supports all OpenAI embedding models including text-embedding-3-small,
|
|
53
|
+
* text-embedding-3-large, and text-embedding-ada-002.
|
|
54
|
+
*
|
|
52
55
|
* @example
|
|
53
56
|
* ```typescript
|
|
54
57
|
* const embeddings = new OpenAIEmbeddings({
|
|
55
58
|
* model: 'text-embedding-3-small',
|
|
59
|
+
* dimensions: 512, // Optional: reduce dimensions for faster search
|
|
56
60
|
* });
|
|
57
61
|
*
|
|
58
62
|
* const vectors = await embeddings.embed(['Hello world', 'Goodbye world']);
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* VoyageAI embeddings implementation.
|
|
3
|
+
*
|
|
4
|
+
* @requires voyageai - Uses the VoyageAI SDK (peer dependency, dynamically imported)
|
|
5
|
+
*/
|
|
6
|
+
import { Embeddings } from "./Embeddings";
|
|
7
|
+
/**
|
|
8
|
+
* Available VoyageAI embedding models with their dimensions and rate limits.
|
|
9
|
+
*/
|
|
10
|
+
export type VoyageAIEmbeddingModel = "voyage-4-large" | "voyage-3-large" | "voyage-context-3" | "voyage-code-3" | "voyage-4" | "voyage-3.5" | "voyage-4-lite" | "voyage-3.5-lite";
|
|
11
|
+
/**
|
|
12
|
+
* Available VoyageAI multimodal models.
|
|
13
|
+
*/
|
|
14
|
+
export type VoyageAIMultimodalModel = "voyage-multimodal-3.5" | "voyage-multimodal-3";
|
|
15
|
+
/**
|
|
16
|
+
* Configuration for VoyageAI embeddings.
|
|
17
|
+
*/
|
|
18
|
+
export interface VoyageAIEmbeddingsConfig {
|
|
19
|
+
/** VoyageAI API key (defaults to VOYAGE_API_KEY env var) */
|
|
20
|
+
apiKey?: string;
|
|
21
|
+
/** Model to use for embeddings */
|
|
22
|
+
model?: VoyageAIEmbeddingModel | VoyageAIMultimodalModel | string;
|
|
23
|
+
/** Input type for optimization (default: "document") */
|
|
24
|
+
inputType?: "query" | "document";
|
|
25
|
+
/** Optional truncation mode */
|
|
26
|
+
truncation?: boolean;
|
|
27
|
+
/** Base URL for API (for proxies or compatible APIs) */
|
|
28
|
+
baseURL?: string;
|
|
29
|
+
/** Maximum number of retries (default: 2) */
|
|
30
|
+
maxRetries?: number;
|
|
31
|
+
/** Timeout in seconds (default: 60) */
|
|
32
|
+
timeoutInSeconds?: number;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* VoyageAI embeddings provider.
|
|
36
|
+
*
|
|
37
|
+
* Supports VoyageAI's embedding models including voyage-4, voyage-3.5, voyage-code-3,
|
|
38
|
+
* and multimodal models. Features automatic retries with exponential backoff.
|
|
39
|
+
*
|
|
40
|
+
* @example
|
|
41
|
+
* ```typescript
|
|
42
|
+
* const embeddings = new VoyageAIEmbeddings({
|
|
43
|
+
* model: 'voyage-4',
|
|
44
|
+
* inputType: 'document', // or 'query' for search queries
|
|
45
|
+
* });
|
|
46
|
+
*
|
|
47
|
+
* const vectors = await embeddings.embed(['Hello world', 'Goodbye world']);
|
|
48
|
+
* ```
|
|
49
|
+
*
|
|
50
|
+
* @example With custom configuration
|
|
51
|
+
* ```typescript
|
|
52
|
+
* const embeddings = new VoyageAIEmbeddings({
|
|
53
|
+
* model: 'voyage-code-3',
|
|
54
|
+
* maxRetries: 3,
|
|
55
|
+
* timeoutInSeconds: 30,
|
|
56
|
+
* });
|
|
57
|
+
* ```
|
|
58
|
+
*/
|
|
59
|
+
export declare class VoyageAIEmbeddings extends Embeddings {
|
|
60
|
+
readonly name = "voyageai";
|
|
61
|
+
readonly model: string;
|
|
62
|
+
readonly dimensions: number;
|
|
63
|
+
private apiKey;
|
|
64
|
+
private inputType;
|
|
65
|
+
private truncation?;
|
|
66
|
+
private baseURL?;
|
|
67
|
+
private maxRetries;
|
|
68
|
+
private timeoutInSeconds;
|
|
69
|
+
constructor(config?: VoyageAIEmbeddingsConfig);
|
|
70
|
+
/**
|
|
71
|
+
* Generate embeddings for multiple texts using VoyageAI API.
|
|
72
|
+
*/
|
|
73
|
+
embed(texts: string[]): Promise<number[][]>;
|
|
74
|
+
/**
|
|
75
|
+
* Generate embedding for a search query.
|
|
76
|
+
* Overrides the default to use inputType: "query" for better search results.
|
|
77
|
+
*/
|
|
78
|
+
embedQuery(query: string): Promise<number[]>;
|
|
79
|
+
}
|
|
80
|
+
//# sourceMappingURL=VoyageAIEmbeddings.d.ts.map
|