@arvo-tools/agentic 1.0.1 → 1.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/dist/Agent/AgentDefaults.d.ts +10 -2
- package/dist/Agent/AgentDefaults.d.ts.map +1 -1
- package/dist/Agent/AgentDefaults.js +27 -11
- package/dist/Agent/AgentDefaults.js.map +1 -1
- package/dist/Agent/agentLoop.d.ts +25 -11
- package/dist/Agent/agentLoop.d.ts.map +1 -1
- package/dist/Agent/agentLoop.js +84 -23
- package/dist/Agent/agentLoop.js.map +1 -1
- package/dist/Agent/index.d.ts +5 -1
- package/dist/Agent/index.d.ts.map +1 -1
- package/dist/Agent/index.js +36 -7
- package/dist/Agent/index.js.map +1 -1
- package/dist/Agent/schema.d.ts +76 -76
- package/dist/Agent/schema.js +4 -4
- package/dist/Agent/schema.js.map +1 -1
- package/dist/Agent/stream/schema.d.ts +456 -0
- package/dist/Agent/stream/schema.d.ts.map +1 -0
- package/dist/Agent/stream/schema.js +88 -0
- package/dist/Agent/stream/schema.js.map +1 -0
- package/dist/Agent/stream/types.d.ts +13 -0
- package/dist/Agent/stream/types.d.ts.map +1 -0
- package/dist/Agent/stream/types.js +3 -0
- package/dist/Agent/stream/types.js.map +1 -0
- package/dist/Agent/stream/utils.d.ts +23 -0
- package/dist/Agent/stream/utils.d.ts.map +1 -0
- package/dist/Agent/stream/utils.js +37 -0
- package/dist/Agent/stream/utils.js.map +1 -0
- package/dist/Agent/types.d.ts +5 -0
- package/dist/Agent/types.d.ts.map +1 -1
- package/dist/Integrations/anthropic/index.d.ts +24 -0
- package/dist/Integrations/anthropic/index.d.ts.map +1 -0
- package/dist/Integrations/anthropic/index.js +278 -0
- package/dist/Integrations/anthropic/index.js.map +1 -0
- package/dist/Integrations/anthropic/types.d.ts +17 -0
- package/dist/Integrations/anthropic/types.d.ts.map +1 -0
- package/dist/Integrations/anthropic/types.js +3 -0
- package/dist/Integrations/anthropic/types.js.map +1 -0
- package/dist/Integrations/anthropic/utils.d.ts +14 -0
- package/dist/Integrations/anthropic/utils.d.ts.map +1 -0
- package/dist/Integrations/anthropic/utils.js +158 -0
- package/dist/Integrations/anthropic/utils.js.map +1 -0
- package/dist/Integrations/openai/index.d.ts +15 -19
- package/dist/Integrations/openai/index.d.ts.map +1 -1
- package/dist/Integrations/openai/index.js +74 -179
- package/dist/Integrations/openai/index.js.map +1 -1
- package/dist/Integrations/openai/types.d.ts +33 -0
- package/dist/Integrations/openai/types.d.ts.map +1 -0
- package/dist/Integrations/openai/types.js +3 -0
- package/dist/Integrations/openai/types.js.map +1 -0
- package/dist/Integrations/openai/utils.d.ts +13 -0
- package/dist/Integrations/openai/utils.d.ts.map +1 -0
- package/dist/Integrations/openai/utils.js +133 -0
- package/dist/Integrations/openai/utils.js.map +1 -0
- package/dist/Integrations/prompts.d.ts +1 -0
- package/dist/Integrations/prompts.d.ts.map +1 -1
- package/dist/Integrations/prompts.js +5 -1
- package/dist/Integrations/prompts.js.map +1 -1
- package/dist/Integrations/types.d.ts +41 -1
- package/dist/Integrations/types.d.ts.map +1 -1
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -1
- package/dist/index.js.map +1 -1
- package/package.json +2 -1
|
@@ -65,132 +65,21 @@ var arvo_core_1 = require("arvo-core");
|
|
|
65
65
|
var zod_to_json_schema_1 = require("zod-to-json-schema");
|
|
66
66
|
var utils_1 = require("../../Agent/utils");
|
|
67
67
|
var prompts_1 = require("../prompts");
|
|
68
|
+
var utils_2 = require("./utils");
|
|
68
69
|
/**
|
|
69
|
-
*
|
|
70
|
+
* Creates an Arvo-compatible LLM Adapter for OpenAI and compatible models (e.g., Azure OpenAI).
|
|
70
71
|
*
|
|
71
|
-
*
|
|
72
|
-
* -
|
|
73
|
-
* - Mapping Tool Results to their originating Tool Call IDs.
|
|
74
|
-
* - Multimodal Content (converting Arvo media objects to OpenAI Image/File URLs).
|
|
75
|
-
* - Reconstructs the specific message ordering OpenAI expects (User -> Assistant(ToolCall) -> Tool(Result)).
|
|
76
|
-
*/
|
|
77
|
-
var formatMessagesForOpenAI = function (messages, systemPrompt) {
|
|
78
|
-
var e_1, _a, e_2, _b;
|
|
79
|
-
var _c;
|
|
80
|
-
var formattedMessages = [];
|
|
81
|
-
if (systemPrompt) {
|
|
82
|
-
formattedMessages.push({
|
|
83
|
-
role: 'system',
|
|
84
|
-
content: systemPrompt,
|
|
85
|
-
});
|
|
86
|
-
}
|
|
87
|
-
var toolResponseMap = {};
|
|
88
|
-
try {
|
|
89
|
-
for (var messages_1 = __values(messages), messages_1_1 = messages_1.next(); !messages_1_1.done; messages_1_1 = messages_1.next()) {
|
|
90
|
-
var message = messages_1_1.value;
|
|
91
|
-
if (message.role === 'user' && message.content.type === 'tool_result') {
|
|
92
|
-
toolResponseMap[message.content.toolUseId] = message.content;
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
97
|
-
finally {
|
|
98
|
-
try {
|
|
99
|
-
if (messages_1_1 && !messages_1_1.done && (_a = messages_1.return)) _a.call(messages_1);
|
|
100
|
-
}
|
|
101
|
-
finally { if (e_1) throw e_1.error; }
|
|
102
|
-
}
|
|
103
|
-
try {
|
|
104
|
-
for (var messages_2 = __values(messages), messages_2_1 = messages_2.next(); !messages_2_1.done; messages_2_1 = messages_2.next()) {
|
|
105
|
-
var message = messages_2_1.value;
|
|
106
|
-
if (message.role === 'user') {
|
|
107
|
-
if (message.content.type === 'text') {
|
|
108
|
-
formattedMessages.push({
|
|
109
|
-
role: 'user',
|
|
110
|
-
content: message.content.content,
|
|
111
|
-
});
|
|
112
|
-
}
|
|
113
|
-
else if (message.content.type === 'media' && message.content.contentType.type === 'image') {
|
|
114
|
-
formattedMessages.push({
|
|
115
|
-
role: 'user',
|
|
116
|
-
content: [
|
|
117
|
-
{
|
|
118
|
-
type: 'image_url',
|
|
119
|
-
image_url: {
|
|
120
|
-
url: message.content.content,
|
|
121
|
-
},
|
|
122
|
-
},
|
|
123
|
-
],
|
|
124
|
-
});
|
|
125
|
-
}
|
|
126
|
-
else if (message.content.type === 'media' && message.content.contentType.type === 'file') {
|
|
127
|
-
formattedMessages.push({
|
|
128
|
-
role: 'user',
|
|
129
|
-
content: [
|
|
130
|
-
{
|
|
131
|
-
type: 'file',
|
|
132
|
-
file: {
|
|
133
|
-
filename: message.content.contentType.filename,
|
|
134
|
-
file_data: message.content.content,
|
|
135
|
-
},
|
|
136
|
-
},
|
|
137
|
-
],
|
|
138
|
-
});
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
else if (message.role === 'assistant') {
|
|
142
|
-
if (message.content.type === 'text') {
|
|
143
|
-
formattedMessages.push({
|
|
144
|
-
role: 'assistant',
|
|
145
|
-
content: message.content.content,
|
|
146
|
-
});
|
|
147
|
-
}
|
|
148
|
-
else if (message.content.type === 'tool_use') {
|
|
149
|
-
formattedMessages.push({
|
|
150
|
-
role: 'assistant',
|
|
151
|
-
tool_calls: [
|
|
152
|
-
{
|
|
153
|
-
type: 'function',
|
|
154
|
-
id: message.content.toolUseId,
|
|
155
|
-
function: {
|
|
156
|
-
name: message.content.name,
|
|
157
|
-
arguments: JSON.stringify(message.content.input),
|
|
158
|
-
},
|
|
159
|
-
},
|
|
160
|
-
],
|
|
161
|
-
});
|
|
162
|
-
var toolResult = toolResponseMap[message.content.toolUseId];
|
|
163
|
-
formattedMessages.push({
|
|
164
|
-
role: 'tool',
|
|
165
|
-
tool_call_id: message.content.toolUseId,
|
|
166
|
-
content: (_c = toolResult === null || toolResult === void 0 ? void 0 : toolResult.content) !== null && _c !== void 0 ? _c : JSON.stringify({ error: 'No tool response' }),
|
|
167
|
-
});
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
173
|
-
finally {
|
|
174
|
-
try {
|
|
175
|
-
if (messages_2_1 && !messages_2_1.done && (_b = messages_2.return)) _b.call(messages_2);
|
|
176
|
-
}
|
|
177
|
-
finally { if (e_2) throw e_2.error; }
|
|
178
|
-
}
|
|
179
|
-
return formattedMessages;
|
|
180
|
-
};
|
|
181
|
-
/**
|
|
182
|
-
* Creates an Arvo-compatible LLM Adapter for OpenAI models (GPT-4, GPT-3.5, etc.).
|
|
72
|
+
* This factory configures an integration that bridges the generic `Arvo` agent runner with the specific
|
|
73
|
+
* OpenAI API requirements. It includes built-in features for:
|
|
183
74
|
*
|
|
184
|
-
*
|
|
185
|
-
*
|
|
186
|
-
*
|
|
187
|
-
*
|
|
188
|
-
* 4. **Safety:** Injects a tool limit prompt when the Agent exhausts its tool budget (customizable via `toolLimitPrompt`).
|
|
75
|
+
* - **Structured Outputs:** Automatically converts Zod schemas provided in `outputFormat` to OpenAI's `json_schema` format.
|
|
76
|
+
* - **Token Optimization:** Automatically replaces large media payloads (images/files) with placeholder text in the conversational history after they have been processed once to reduce context window usage.
|
|
77
|
+
* - **Observability:** Instruments calls with OpenInference-compliant OpenTelemetry attributes, including detailed input/output recording and token usage.
|
|
78
|
+
* - **Safety:** Automatically injects a "tool limit reached" system instruction when the agent exhausts its configured tool budget.
|
|
189
79
|
*
|
|
190
|
-
* @param client - An initialized `OpenAI` SDK client instance.
|
|
191
|
-
* @param config - Configuration for model
|
|
192
|
-
* @
|
|
193
|
-
* @returns An `AgentLLMIntegration` function ready to be passed to `createArvoAgent`.
|
|
80
|
+
* @param client - An initialized `OpenAI` or `AzureOpenAI` SDK client instance.
|
|
81
|
+
* @param config - Configuration for model parameters (e.g., temperature, max tokens), cost calculations, and telemetry metadata.
|
|
82
|
+
* @returns An `AgentLLMIntegration` function ready for use with `createArvoAgent`.
|
|
194
83
|
*/
|
|
195
84
|
var openaiLLMIntegration = function (client, config) {
|
|
196
85
|
return function (_a, _b) { return __awaiter(void 0, [_a, _b], void 0, function (_c, _d) {
|
|
@@ -212,33 +101,40 @@ var openaiLLMIntegration = function (client, config) {
|
|
|
212
101
|
_e),
|
|
213
102
|
},
|
|
214
103
|
fn: function (span) { return __awaiter(void 0, void 0, void 0, function () {
|
|
215
|
-
var
|
|
216
|
-
var
|
|
217
|
-
var
|
|
218
|
-
return __generator(this, function (
|
|
219
|
-
switch (
|
|
104
|
+
var llmChatCompletionParams, _a, messages, system, limitMessage, toolDef, tools_1, tools_1_1, tool, formattedMessages, responseFormat, completion, choice, llmUsage, executionUnits, toolRequests, _b, _c, toolCall, content, e_1;
|
|
105
|
+
var e_2, _d, e_3, _e;
|
|
106
|
+
var _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0;
|
|
107
|
+
return __generator(this, function (_1) {
|
|
108
|
+
switch (_1.label) {
|
|
220
109
|
case 0:
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
110
|
+
llmChatCompletionParams = (_f = config === null || config === void 0 ? void 0 : config.invocationParam) !== null && _f !== void 0 ? _f : {
|
|
111
|
+
model: 'gpt-4o',
|
|
112
|
+
max_completion_tokens: 4096,
|
|
113
|
+
temperature: 0,
|
|
225
114
|
};
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
115
|
+
return [4 /*yield*/, ((_g = config === null || config === void 0 ? void 0 : config.contextTransformer) === null || _g === void 0 ? void 0 : _g.call(config, {
|
|
116
|
+
messages: _messages,
|
|
117
|
+
system: _system,
|
|
118
|
+
}))];
|
|
119
|
+
case 1:
|
|
120
|
+
_a = (_h = (_1.sent())) !== null && _h !== void 0 ? _h : {
|
|
121
|
+
messages: _messages.map(function (item) {
|
|
122
|
+
if (item.content.type === 'media' && item.seenCount > 0) {
|
|
123
|
+
return {
|
|
124
|
+
role: item.role,
|
|
125
|
+
content: {
|
|
126
|
+
type: 'text',
|
|
127
|
+
content: "Media file (type: ".concat(item.content.contentType.type, "@").concat(item.content.contentType.format, ") already parsed and looked at. No need for you to look at it again"),
|
|
128
|
+
},
|
|
129
|
+
seenCount: item.seenCount,
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
return item;
|
|
133
|
+
}),
|
|
134
|
+
system: _system,
|
|
135
|
+
}, messages = _a.messages, system = _a.system;
|
|
240
136
|
if (toolInteractions.exhausted) {
|
|
241
|
-
limitMessage = (
|
|
137
|
+
limitMessage = (_k = (_j = config === null || config === void 0 ? void 0 : config.toolLimitPrompt) === null || _j === void 0 ? void 0 : _j.call(config, toolInteractions)) !== null && _k !== void 0 ? _k : prompts_1.DEFAULT_TOOL_LIMIT_PROMPT;
|
|
242
138
|
messages.push({
|
|
243
139
|
role: 'user',
|
|
244
140
|
content: {
|
|
@@ -251,18 +147,18 @@ var openaiLLMIntegration = function (client, config) {
|
|
|
251
147
|
}
|
|
252
148
|
(0, utils_1.setOpenInferenceInputAttr)({
|
|
253
149
|
llm: {
|
|
254
|
-
provider: 'openai',
|
|
255
|
-
system: 'openai',
|
|
256
|
-
model:
|
|
257
|
-
invocationParam:
|
|
150
|
+
provider: (_m = (_l = config === null || config === void 0 ? void 0 : config.telemetry) === null || _l === void 0 ? void 0 : _l.modelProvider) !== null && _m !== void 0 ? _m : 'openai',
|
|
151
|
+
system: (_p = (_o = config === null || config === void 0 ? void 0 : config.telemetry) === null || _o === void 0 ? void 0 : _o.modelSystem) !== null && _p !== void 0 ? _p : (((_q = config === null || config === void 0 ? void 0 : config.telemetry) === null || _q === void 0 ? void 0 : _q.modelProvider) === 'azure' ? 'azure_openai' : 'openai'),
|
|
152
|
+
model: llmChatCompletionParams === null || llmChatCompletionParams === void 0 ? void 0 : llmChatCompletionParams.model,
|
|
153
|
+
invocationParam: llmChatCompletionParams,
|
|
258
154
|
},
|
|
259
155
|
messages: messages,
|
|
260
156
|
system: system,
|
|
261
157
|
tools: tools,
|
|
262
158
|
}, span);
|
|
263
|
-
|
|
264
|
-
case
|
|
265
|
-
|
|
159
|
+
_1.label = 2;
|
|
160
|
+
case 2:
|
|
161
|
+
_1.trys.push([2, 4, 5, 6]);
|
|
266
162
|
toolDef = [];
|
|
267
163
|
try {
|
|
268
164
|
for (tools_1 = __values(tools), tools_1_1 = tools_1.next(); !tools_1_1.done; tools_1_1 = tools_1.next()) {
|
|
@@ -277,14 +173,14 @@ var openaiLLMIntegration = function (client, config) {
|
|
|
277
173
|
});
|
|
278
174
|
}
|
|
279
175
|
}
|
|
280
|
-
catch (
|
|
176
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
281
177
|
finally {
|
|
282
178
|
try {
|
|
283
|
-
if (tools_1_1 && !tools_1_1.done && (
|
|
179
|
+
if (tools_1_1 && !tools_1_1.done && (_d = tools_1.return)) _d.call(tools_1);
|
|
284
180
|
}
|
|
285
|
-
finally { if (
|
|
181
|
+
finally { if (e_2) throw e_2.error; }
|
|
286
182
|
}
|
|
287
|
-
formattedMessages = formatMessagesForOpenAI(messages, system);
|
|
183
|
+
formattedMessages = (0, utils_2.formatMessagesForOpenAI)(messages, system);
|
|
288
184
|
responseFormat = outputFormat.type === 'json'
|
|
289
185
|
? {
|
|
290
186
|
type: 'json_schema',
|
|
@@ -296,26 +192,24 @@ var openaiLLMIntegration = function (client, config) {
|
|
|
296
192
|
},
|
|
297
193
|
}
|
|
298
194
|
: undefined;
|
|
299
|
-
return [4 /*yield*/, client.chat.completions.create(__assign(__assign({
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
case 2:
|
|
303
|
-
completion = _u.sent();
|
|
195
|
+
return [4 /*yield*/, client.chat.completions.create(__assign(__assign({}, llmChatCompletionParams), { tools: toolDef.length ? toolDef : undefined, messages: formattedMessages, response_format: responseFormat }))];
|
|
196
|
+
case 3:
|
|
197
|
+
completion = _1.sent();
|
|
304
198
|
choice = completion.choices[0];
|
|
305
199
|
llmUsage = {
|
|
306
200
|
tokens: {
|
|
307
|
-
prompt: (
|
|
308
|
-
completion: (
|
|
201
|
+
prompt: (_s = (_r = completion.usage) === null || _r === void 0 ? void 0 : _r.prompt_tokens) !== null && _s !== void 0 ? _s : 0,
|
|
202
|
+
completion: (_u = (_t = completion.usage) === null || _t === void 0 ? void 0 : _t.completion_tokens) !== null && _u !== void 0 ? _u : 0,
|
|
309
203
|
},
|
|
310
204
|
};
|
|
311
|
-
executionUnits = (
|
|
205
|
+
executionUnits = (_w = (_v = config === null || config === void 0 ? void 0 : config.executionunits) === null || _v === void 0 ? void 0 : _v.call(config, llmUsage.tokens.prompt, llmUsage.tokens.completion)) !== null && _w !== void 0 ? _w : llmUsage.tokens.prompt + llmUsage.tokens.completion;
|
|
312
206
|
(0, utils_1.setOpenInferenceUsageOutputAttr)(llmUsage, span);
|
|
313
|
-
if ((
|
|
207
|
+
if ((_x = choice === null || choice === void 0 ? void 0 : choice.message) === null || _x === void 0 ? void 0 : _x.tool_calls) {
|
|
314
208
|
toolRequests = [];
|
|
315
209
|
try {
|
|
316
|
-
for (
|
|
317
|
-
.tool_calls),
|
|
318
|
-
toolCall =
|
|
210
|
+
for (_b = __values(choice.message
|
|
211
|
+
.tool_calls), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
212
|
+
toolCall = _c.value;
|
|
319
213
|
try {
|
|
320
214
|
toolRequests.push({
|
|
321
215
|
toolUseId: toolCall.id,
|
|
@@ -328,12 +222,12 @@ var openaiLLMIntegration = function (client, config) {
|
|
|
328
222
|
}
|
|
329
223
|
}
|
|
330
224
|
}
|
|
331
|
-
catch (
|
|
225
|
+
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
332
226
|
finally {
|
|
333
227
|
try {
|
|
334
|
-
if (
|
|
228
|
+
if (_c && !_c.done && (_e = _b.return)) _e.call(_b);
|
|
335
229
|
}
|
|
336
|
-
finally { if (
|
|
230
|
+
finally { if (e_3) throw e_3.error; }
|
|
337
231
|
}
|
|
338
232
|
if (toolRequests.length) {
|
|
339
233
|
(0, utils_1.setOpenInferenceToolCallOutputAttr)({ toolCalls: toolRequests }, span);
|
|
@@ -345,9 +239,10 @@ var openaiLLMIntegration = function (client, config) {
|
|
|
345
239
|
}];
|
|
346
240
|
}
|
|
347
241
|
}
|
|
348
|
-
content = (
|
|
242
|
+
content = (_z = (_y = choice === null || choice === void 0 ? void 0 : choice.message) === null || _y === void 0 ? void 0 : _y.content) !== null && _z !== void 0 ? _z : '';
|
|
349
243
|
if (choice.finish_reason === 'length') {
|
|
350
|
-
content = "".concat(content, " [Max response token limit ").concat(
|
|
244
|
+
content = "".concat(content, " [Max response token limit (<= ").concat((_0 = llmChatCompletionParams.max_tokens) !== null && _0 !== void 0 ? _0 : llmChatCompletionParams.max_completion_tokens, ") reached]");
|
|
245
|
+
throw new Error("Agent reached max token limit. The partial response is \"".concat(content, "\""));
|
|
351
246
|
}
|
|
352
247
|
if (choice.finish_reason === 'content_filter') {
|
|
353
248
|
content = "".concat(content, " [Request blocked due to OpenAI content filtering policies]");
|
|
@@ -368,14 +263,14 @@ var openaiLLMIntegration = function (client, config) {
|
|
|
368
263
|
usage: llmUsage,
|
|
369
264
|
executionUnits: executionUnits,
|
|
370
265
|
}];
|
|
371
|
-
case 3:
|
|
372
|
-
e_3 = _u.sent();
|
|
373
|
-
span.setStatus({ code: api_1.SpanStatusCode.ERROR, message: e_3 === null || e_3 === void 0 ? void 0 : e_3.message });
|
|
374
|
-
throw e_3;
|
|
375
266
|
case 4:
|
|
267
|
+
e_1 = _1.sent();
|
|
268
|
+
span.setStatus({ code: api_1.SpanStatusCode.ERROR, message: e_1 === null || e_1 === void 0 ? void 0 : e_1.message });
|
|
269
|
+
throw e_1;
|
|
270
|
+
case 5:
|
|
376
271
|
span.end();
|
|
377
272
|
return [7 /*endfinally*/];
|
|
378
|
-
case
|
|
273
|
+
case 6: return [2 /*return*/];
|
|
379
274
|
}
|
|
380
275
|
});
|
|
381
276
|
}); },
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/Integrations/openai/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,kGAGqD;AACrD,0CAAoD;AACpD,uCAA+D;AAK/D,yDAAqD;AAErD,2CAM2B;AAC3B,sCAAuD;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/Integrations/openai/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,kGAGqD;AACrD,0CAAoD;AACpD,uCAA+D;AAK/D,yDAAqD;AAErD,2CAM2B;AAC3B,sCAAuD;AAGvD,iCAAkD;AAElD;;;;;;;;;;;;;;GAcG;AACI,IAAM,oBAAoB,GAC/B,UACE,MAAe,EACf,MAA4C;IAE9C,OAAA,yEACE,EAA0F,EAC1F,EAAY;;YADA,SAAS,cAAA,EAAU,OAAO,YAAA,EAAE,KAAK,WAAA,EAAE,YAAY,kBAAA,EAAE,SAAS,eAAA,EAAE,gBAAgB,sBAAA;YACtF,QAAQ,cAAA;;;wBAEV,qBAAM,6BAAiB,CAAC,WAAW,EAAE,CAAC,eAAe,CAAC;wBACpD,IAAI,EAAE,qBAAc,SAAS,KAAK,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS,KAAK,aAAa,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,4BAA4B,MAAG;wBAC5H,qBAAqB,EAAE,IAAI;wBAC3B,OAAO,EAAE;4BACP,WAAW,EAAE,eAAe;4BAC5B,YAAY,EAAE,QAAQ,CAAC,OAAO;yBAC/B;wBACD,WAAW,EAAE;4BACX,UAAU;gCACR,GAAC,wDAAgC,CAAC,uBAAuB,IAAG,0DAAqB,CAAC,GAAG;mCACtF;yBACF;wBACD,EAAE,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AAK,MAAM,EAAE,CAAC;4CACjC,sBAAO;oDACL,IAAI,EAAE,MAAM;oDACZ,OAAO,EAAE,OAAO,IAAI,IAAI;oDACxB,aAAa,EAAE,IAAA,oBAAY,EAAC,OAAO,IAAI,IAAI,CAAC;oDAC5C,KAAK,EAAE,QAAQ;oDACf,cAAc,gBAAA;iDACf,EAAC;wCACJ,CAAC;wCAED,sBAAO;gDACL,IAAI,EAAE,MAAM;gDACZ,OAAO,SAAA;gDACP,KAAK,EAAE,QAAQ;gDACf,cAAc,gBAAA;6CACf,EAAC;;;wCAEF,IAAI,CAAC,SAAS,CAAC,EAAE,IAAI,EAAE,oBAAc,CAAC,KAAK,EAAE,OAAO,EAAG,GAAW,aAAX,GAAC,uBAAD,GAAC,CAAY,OAAO,EAAE,CAAC,CAAC;wCAC/E,MAAM,GAAC,CAAC;;wCAER,IAAI,CAAC,GAAG,EAAE,CAAC;;;;;6BAEd;qBACF,CAAC,EAAA;wBAjLF,sBAAA,SAiLE,EAAA;;;SAAA;AArLJ,CAqLI,CAAC;AA1LM,QAAA,oBAAoB,wBA0L1B"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type OpenAI from 'openai';
|
|
2
|
+
import type { AzureOpenAI } from 'openai';
|
|
3
|
+
import type { CommonIntegrationConfig } from '../types';
|
|
4
|
+
export type OpenAILlmIntegrationConfig<TClient extends OpenAI | AzureOpenAI> = {
|
|
5
|
+
/**
|
|
6
|
+
* Configuration strictly for the model invocation parameters passed to the OpenAI SDK.
|
|
7
|
+
*
|
|
8
|
+
* Common parameters include:
|
|
9
|
+
* - `model`: The model ID (e.g., `gpt-4o`).
|
|
10
|
+
* - `temperature`: Controls randomness.
|
|
11
|
+
* - `max_completion_tokens` or `max_tokens`: Limits the generation length.
|
|
12
|
+
*
|
|
13
|
+
* @default
|
|
14
|
+
* { model: 'gpt-4o', max_completion_tokens: 4096, temperature: 0 }
|
|
15
|
+
*/
|
|
16
|
+
invocationParam?: Pick<Parameters<TClient['chat']['completions']['create']>[0], 'model' | 'temperature' | 'max_tokens' | 'max_completion_tokens'>;
|
|
17
|
+
/**
|
|
18
|
+
* Configuration for distributed tracing attributes.
|
|
19
|
+
*/
|
|
20
|
+
telemetry?: {
|
|
21
|
+
/**
|
|
22
|
+
* The value for the `llm.provider` OpenTelemetry attribute.
|
|
23
|
+
* @default 'openai'
|
|
24
|
+
*/
|
|
25
|
+
modelProvider?: string;
|
|
26
|
+
/**
|
|
27
|
+
* The value for the `llm.system` OpenTelemetry attribute.
|
|
28
|
+
* @default 'openai' (or 'azure_openai' if utilizing Azure)
|
|
29
|
+
*/
|
|
30
|
+
modelSystem?: string;
|
|
31
|
+
};
|
|
32
|
+
} & CommonIntegrationConfig;
|
|
33
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/Integrations/openai/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,QAAQ,CAAC;AACjC,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAC;AAC1C,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,UAAU,CAAC;AAExD,MAAM,MAAM,0BAA0B,CAAC,OAAO,SAAS,MAAM,GAAG,WAAW,IAAI;IAC7E;;;;;;;;;;OAUG;IACH,eAAe,CAAC,EAAE,IAAI,CACpB,UAAU,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,aAAa,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,EACvD,OAAO,GAAG,aAAa,GAAG,YAAY,GAAG,uBAAuB,CACjE,CAAC;IAEF;;OAEG;IACH,SAAS,CAAC,EAAE;QACV;;;WAGG;QACH,aAAa,CAAC,EAAE,MAAM,CAAC;QACvB;;;WAGG;QACH,WAAW,CAAC,EAAE,MAAM,CAAC;KACtB,CAAC;CACH,GAAG,uBAAuB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/Integrations/openai/types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { ChatCompletionMessageParam } from 'openai/resources/index.mjs';
|
|
2
|
+
import type { AgentLLMIntegrationParam } from '../types';
|
|
3
|
+
/**
|
|
4
|
+
* Internal Adapter: Maps Arvo's generic Agent Message format to OpenAI's specific API format.
|
|
5
|
+
*
|
|
6
|
+
* Handles:
|
|
7
|
+
* - System Prompt injection.
|
|
8
|
+
* - Mapping Tool Results to their originating Tool Call IDs.
|
|
9
|
+
* - Multimodal Content (converting Arvo media objects to OpenAI Image/File URLs).
|
|
10
|
+
* - Reconstructs the specific message ordering OpenAI expects (User -> Assistant(ToolCall) -> Tool(Result)).
|
|
11
|
+
*/
|
|
12
|
+
export declare const formatMessagesForOpenAI: (messages: AgentLLMIntegrationParam["messages"], systemPrompt: string | null) => ChatCompletionMessageParam[];
|
|
13
|
+
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/Integrations/openai/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,4BAA4B,CAAC;AAE7E,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,UAAU,CAAC;AAEzD;;;;;;;;GAQG;AACH,eAAO,MAAM,uBAAuB,GAClC,UAAU,wBAAwB,CAAC,UAAU,CAAC,EAC9C,cAAc,MAAM,GAAG,IAAI,KAC1B,0BAA0B,EAyF5B,CAAC"}
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __values = (this && this.__values) || function(o) {
|
|
3
|
+
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
4
|
+
if (m) return m.call(o);
|
|
5
|
+
if (o && typeof o.length === "number") return {
|
|
6
|
+
next: function () {
|
|
7
|
+
if (o && i >= o.length) o = void 0;
|
|
8
|
+
return { value: o && o[i++], done: !o };
|
|
9
|
+
}
|
|
10
|
+
};
|
|
11
|
+
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
12
|
+
};
|
|
13
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
+
exports.formatMessagesForOpenAI = void 0;
|
|
15
|
+
/**
|
|
16
|
+
* Internal Adapter: Maps Arvo's generic Agent Message format to OpenAI's specific API format.
|
|
17
|
+
*
|
|
18
|
+
* Handles:
|
|
19
|
+
* - System Prompt injection.
|
|
20
|
+
* - Mapping Tool Results to their originating Tool Call IDs.
|
|
21
|
+
* - Multimodal Content (converting Arvo media objects to OpenAI Image/File URLs).
|
|
22
|
+
* - Reconstructs the specific message ordering OpenAI expects (User -> Assistant(ToolCall) -> Tool(Result)).
|
|
23
|
+
*/
|
|
24
|
+
var formatMessagesForOpenAI = function (messages, systemPrompt) {
|
|
25
|
+
var e_1, _a, e_2, _b;
|
|
26
|
+
var _c;
|
|
27
|
+
var formattedMessages = [];
|
|
28
|
+
if (systemPrompt) {
|
|
29
|
+
formattedMessages.push({
|
|
30
|
+
role: 'system',
|
|
31
|
+
content: systemPrompt,
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
var toolResponseMap = {};
|
|
35
|
+
try {
|
|
36
|
+
for (var messages_1 = __values(messages), messages_1_1 = messages_1.next(); !messages_1_1.done; messages_1_1 = messages_1.next()) {
|
|
37
|
+
var message = messages_1_1.value;
|
|
38
|
+
if (message.role === 'user' && message.content.type === 'tool_result') {
|
|
39
|
+
toolResponseMap[message.content.toolUseId] = message.content;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
44
|
+
finally {
|
|
45
|
+
try {
|
|
46
|
+
if (messages_1_1 && !messages_1_1.done && (_a = messages_1.return)) _a.call(messages_1);
|
|
47
|
+
}
|
|
48
|
+
finally { if (e_1) throw e_1.error; }
|
|
49
|
+
}
|
|
50
|
+
try {
|
|
51
|
+
for (var messages_2 = __values(messages), messages_2_1 = messages_2.next(); !messages_2_1.done; messages_2_1 = messages_2.next()) {
|
|
52
|
+
var message = messages_2_1.value;
|
|
53
|
+
if (message.role === 'user') {
|
|
54
|
+
if (message.content.type === 'text') {
|
|
55
|
+
formattedMessages.push({
|
|
56
|
+
role: 'user',
|
|
57
|
+
content: message.content.content,
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
else if (message.content.type === 'media' &&
|
|
61
|
+
message.content.contentType.type === 'image' &&
|
|
62
|
+
message.content.contentType.format === 'base64') {
|
|
63
|
+
formattedMessages.push({
|
|
64
|
+
role: 'user',
|
|
65
|
+
content: [
|
|
66
|
+
{
|
|
67
|
+
type: 'image_url',
|
|
68
|
+
image_url: {
|
|
69
|
+
url: message.content.content,
|
|
70
|
+
},
|
|
71
|
+
},
|
|
72
|
+
],
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
else if (message.content.type === 'media' &&
|
|
76
|
+
message.content.contentType.type === 'file' &&
|
|
77
|
+
message.content.contentType.format === 'base64') {
|
|
78
|
+
formattedMessages.push({
|
|
79
|
+
role: 'user',
|
|
80
|
+
content: [
|
|
81
|
+
{
|
|
82
|
+
type: 'file',
|
|
83
|
+
file: {
|
|
84
|
+
filename: message.content.contentType.name,
|
|
85
|
+
file_data: message.content.content,
|
|
86
|
+
},
|
|
87
|
+
},
|
|
88
|
+
],
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
else if (message.role === 'assistant') {
|
|
93
|
+
if (message.content.type === 'text') {
|
|
94
|
+
formattedMessages.push({
|
|
95
|
+
role: 'assistant',
|
|
96
|
+
content: message.content.content,
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
else if (message.content.type === 'tool_use') {
|
|
100
|
+
formattedMessages.push({
|
|
101
|
+
role: 'assistant',
|
|
102
|
+
tool_calls: [
|
|
103
|
+
{
|
|
104
|
+
type: 'function',
|
|
105
|
+
id: message.content.toolUseId,
|
|
106
|
+
function: {
|
|
107
|
+
name: message.content.name,
|
|
108
|
+
arguments: JSON.stringify(message.content.input),
|
|
109
|
+
},
|
|
110
|
+
},
|
|
111
|
+
],
|
|
112
|
+
});
|
|
113
|
+
var toolResult = toolResponseMap[message.content.toolUseId];
|
|
114
|
+
formattedMessages.push({
|
|
115
|
+
role: 'tool',
|
|
116
|
+
tool_call_id: message.content.toolUseId,
|
|
117
|
+
content: (_c = toolResult === null || toolResult === void 0 ? void 0 : toolResult.content) !== null && _c !== void 0 ? _c : JSON.stringify({ error: 'No tool response' }),
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
124
|
+
finally {
|
|
125
|
+
try {
|
|
126
|
+
if (messages_2_1 && !messages_2_1.done && (_b = messages_2.return)) _b.call(messages_2);
|
|
127
|
+
}
|
|
128
|
+
finally { if (e_2) throw e_2.error; }
|
|
129
|
+
}
|
|
130
|
+
return formattedMessages;
|
|
131
|
+
};
|
|
132
|
+
exports.formatMessagesForOpenAI = formatMessagesForOpenAI;
|
|
133
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/Integrations/openai/utils.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAIA;;;;;;;;GAQG;AACI,IAAM,uBAAuB,GAAG,UACrC,QAA8C,EAC9C,YAA2B;;;IAE3B,IAAM,iBAAiB,GAAiC,EAAE,CAAC;IAE3D,IAAI,YAAY,EAAE,CAAC;QACjB,iBAAiB,CAAC,IAAI,CAAC;YACrB,IAAI,EAAE,QAAQ;YACd,OAAO,EAAE,YAAY;SACtB,CAAC,CAAC;IACL,CAAC;IAED,IAAM,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S;wBACvC,OAAO,EAAE,MAAA,UAAU,aAAV,UAAU,uBAAV,UAAU,CAAE,OAAO,mCAAI,IAAI,CAAC,SAAS,CAAC,EAAE,KAAK,EAAE,kBAAkB,EAAE,CAAC;qBAC9E,CAAC,CAAC;gBACL,CAAC;YACH,CAAC;QACH,CAAC;;;;;;;;;IAED,OAAO,iBAAiB,CAAC;AAC3B,CAAC,CAAC;AA5FW,QAAA,uBAAuB,2BA4FlC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prompts.d.ts","sourceRoot":"","sources":["../../src/Integrations/prompts.ts"],"names":[],"mappings":"AAEA;;;;;GAKG;AACH,eAAO,MAAM,yBAAyB,QAOpC,CAAC"}
|
|
1
|
+
{"version":3,"file":"prompts.d.ts","sourceRoot":"","sources":["../../src/Integrations/prompts.ts"],"names":[],"mappings":"AAEA;;;;;GAKG;AACH,eAAO,MAAM,yBAAyB,QAOpC,CAAC;AAEH,eAAO,MAAM,UAAU,GAAI,QAAQ,MAAM,WAmCvC,CAAC"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.DEFAULT_TOOL_LIMIT_PROMPT = void 0;
|
|
3
|
+
exports.jsonPrompt = exports.DEFAULT_TOOL_LIMIT_PROMPT = void 0;
|
|
4
4
|
var arvo_core_1 = require("arvo-core");
|
|
5
5
|
/**
|
|
6
6
|
* Standard System Instruction injected when the Agent reaches its `maxToolInteractions` limit.
|
|
@@ -9,4 +9,8 @@ var arvo_core_1 = require("arvo-core");
|
|
|
9
9
|
* synthesize a final response based on whatever partial data it has managed to collect so far.
|
|
10
10
|
*/
|
|
11
11
|
exports.DEFAULT_TOOL_LIMIT_PROMPT = (0, arvo_core_1.cleanString)("\n **CRITICAL WARNING: You have reached your tool interaction limit!**\n You must answer the original question using all the data available to you. \n You have run out of tool call budget. No more tool calls are allowed any more.\n If you cannot answer the query well. Then mention what you have done briefly, what\n can you answer based on the collected data, what data is missing and why you cannot \n answer any further. \n");
|
|
12
|
+
var jsonPrompt = function (schema) {
|
|
13
|
+
return (0, arvo_core_1.cleanString)("\n # Critical JSON Output Requirements\n You must return ONLY a valid JSON object with no additional text, explanations, or formatting outside the required JSON structure.\n\n ## Mandatory Compliance Rules\n 1. The entire response must be a single, parseable JSON object\n 2. Use double quotes for all keys and string values\n 3. No text, commentary, or explanations before or after the JSON\n 4. No markdown code fences (```json or ```) - return raw JSON only\n 5. Properly escape special characters: \\n for newlines, \\\" for quotes, \\\\ for backslashes\n 6. Use literal values: true, false, and null (lowercase, never as strings)\n 7. Numbers must not be enclosed in quotes\n 8. No comments (// or /* */) or trailing commas anywhere in the JSON\n 9. Arrays must use square brackets [], objects must use curly braces {}\n 10. All required fields in the schema MUST be present\n 11. Do not include fields not defined in the schema\n 12. When a field is optional and you have no value, omit it entirely (do not use null unless the schema explicitly allows it)\n\n ## Schema Specification\n The response must conform exactly to this JSON Schema (Draft-07) structure:\n ```json\n ".concat(schema, "\n ```\n\n ## Output Format\n Return ONLY the raw JSON object starting with { and ending with }.\n The output will be parsed directly using JSON.parse(), so any non-compliant formatting will cause a fatal error.\n\n ## Common Mistakes to Avoid\n - Do NOT wrap the JSON in markdown code blocks\n - Do NOT include any preamble like \"Here is the JSON:\"\n - Do NOT include any explanation after the JSON\n - Do NOT use single quotes instead of double quotes\n - Do NOT leave trailing commas after the last item in arrays or objects\n"));
|
|
14
|
+
};
|
|
15
|
+
exports.jsonPrompt = jsonPrompt;
|
|
12
16
|
//# sourceMappingURL=prompts.js.map
|