@arvo-tools/agentic 0.4.1 → 1.0.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/Agent/AgentDefaults.d.ts +4 -2
- package/dist/Agent/AgentDefaults.d.ts.map +1 -1
- package/dist/Agent/AgentDefaults.js +3 -0
- package/dist/Agent/AgentDefaults.js.map +1 -1
- package/dist/Agent/agentLoop.d.ts +22 -1
- package/dist/Agent/agentLoop.d.ts.map +1 -1
- package/dist/Agent/agentLoop.js +39 -4
- package/dist/Agent/agentLoop.js.map +1 -1
- package/dist/Agent/index.d.ts +76 -3
- package/dist/Agent/index.d.ts.map +1 -1
- package/dist/Agent/index.js +77 -2
- package/dist/Agent/index.js.map +1 -1
- package/dist/Agent/schema.d.ts +9 -0
- package/dist/Agent/schema.d.ts.map +1 -1
- package/dist/Agent/schema.js +7 -0
- package/dist/Agent/schema.js.map +1 -1
- package/dist/Agent/types.d.ts +214 -58
- package/dist/Agent/types.d.ts.map +1 -1
- package/dist/Agent/utils.d.ts +46 -1
- package/dist/Agent/utils.d.ts.map +1 -1
- package/dist/Agent/utils.js +43 -0
- package/dist/Agent/utils.js.map +1 -1
- package/dist/{Agent/agentTool.d.ts → AgentTool/index.d.ts} +3 -3
- package/dist/AgentTool/index.d.ts.map +1 -0
- package/dist/{Agent/agentTool.js → AgentTool/index.js} +1 -1
- package/dist/AgentTool/index.js.map +1 -0
- package/dist/AgentTool/types.d.ts +21 -0
- package/dist/AgentTool/types.d.ts.map +1 -0
- package/dist/AgentTool/types.js +3 -0
- package/dist/AgentTool/types.js.map +1 -0
- package/dist/Integrations/MCPClient.d.ts +62 -29
- package/dist/Integrations/MCPClient.d.ts.map +1 -1
- package/dist/Integrations/MCPClient.js +60 -29
- package/dist/Integrations/MCPClient.js.map +1 -1
- package/dist/Integrations/openai/index.d.ts +25 -0
- package/dist/Integrations/openai/index.d.ts.map +1 -0
- package/dist/Integrations/{openai.js → openai/index.js} +64 -28
- package/dist/Integrations/openai/index.js.map +1 -0
- package/dist/Integrations/prompts.d.ts +8 -0
- package/dist/Integrations/prompts.d.ts.map +1 -0
- package/dist/Integrations/prompts.js +12 -0
- package/dist/Integrations/prompts.js.map +1 -0
- package/dist/Integrations/types.d.ts +101 -0
- package/dist/Integrations/types.d.ts.map +1 -0
- package/dist/Integrations/types.js +3 -0
- package/dist/Integrations/types.js.map +1 -0
- package/dist/index.d.ts +7 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -3
- package/dist/index.js.map +1 -1
- package/dist/interfaces.mcp.d.ts +29 -0
- package/dist/interfaces.mcp.d.ts.map +1 -1
- package/dist/types.d.ts +13 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +1 -1
- package/dist/Agent/agentTool.d.ts.map +0 -1
- package/dist/Agent/agentTool.js.map +0 -1
- package/dist/Integrations/openai.d.ts +0 -10
- package/dist/Integrations/openai.d.ts.map +0 -1
- package/dist/Integrations/openai.js.map +0 -1
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import type { ArvoSemanticVersion } from 'arvo-core';
|
|
2
2
|
import z from 'zod';
|
|
3
|
-
import type {
|
|
3
|
+
import type { AgentInternalTool } from '../AgentTool/types.js';
|
|
4
|
+
import type { PromiseAble } from '../types.js';
|
|
5
|
+
import type { AgentContextBuilder, AgentOutputBuilder, AgentServiceContract, AnyArvoOrchestratorContract } from './types.js';
|
|
4
6
|
export declare const AgentDefaults: {
|
|
5
7
|
readonly INIT_SCHEMA: z.ZodObject<{
|
|
6
8
|
message: z.ZodString;
|
|
@@ -22,7 +24,7 @@ export declare const AgentDefaults: {
|
|
|
22
24
|
}, {
|
|
23
25
|
response: string;
|
|
24
26
|
}>;
|
|
25
|
-
readonly CONTEXT_BUILDER: <T extends AnyArvoOrchestratorContract, V extends ArvoSemanticVersion, TServiceContract extends Record<string, AgentServiceContract>, TTools extends Record<string, AgentInternalTool>>(systemPromptBuilder?: (param: Parameters<AgentContextBuilder<T, V, TServiceContract, TTools>>[0]) =>
|
|
27
|
+
readonly CONTEXT_BUILDER: <T extends AnyArvoOrchestratorContract, V extends ArvoSemanticVersion, TServiceContract extends Record<string, AgentServiceContract>, TTools extends Record<string, AgentInternalTool>>(systemPromptBuilder?: (param: Parameters<AgentContextBuilder<T, V, TServiceContract, TTools>>[0]) => PromiseAble<string>) => AgentContextBuilder<T, V, TServiceContract, TTools>;
|
|
26
28
|
readonly OUTPUT_BUILDER: AgentOutputBuilder;
|
|
27
29
|
};
|
|
28
30
|
//# sourceMappingURL=AgentDefaults.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AgentDefaults.d.ts","sourceRoot":"","sources":["../../src/Agent/AgentDefaults.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAC;AAErD,OAAO,CAAC,MAAM,KAAK,CAAC;AACpB,OAAO,KAAK,EACV,mBAAmB,
|
|
1
|
+
{"version":3,"file":"AgentDefaults.d.ts","sourceRoot":"","sources":["../../src/Agent/AgentDefaults.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAC;AAErD,OAAO,CAAC,MAAM,KAAK,CAAC;AACpB,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAC/D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,KAAK,EACV,mBAAmB,EAEnB,kBAAkB,EAClB,oBAAoB,EACpB,2BAA2B,EAC5B,MAAM,YAAY,CAAC;AAEpB,eAAO,MAAM,aAAa;;;;;;;;;;;;;;;;;;;;;+BAqBpB,CAAC,SAAS,2BAA2B,EACrC,CAAC,SAAS,mBAAmB,EAC7B,gBAAgB,SAAS,MAAM,CAAC,MAAM,EAAE,oBAAoB,CAAC,EAC7D,MAAM,SAAS,MAAM,CAAC,MAAM,EAAE,iBAAiB,CAAC,wBAE1B,CACpB,KAAK,EAAE,UAAU,CAAC,mBAAmB,CAAC,CAAC,EAAE,CAAC,EAAE,gBAAgB,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,KACtE,WAAW,CAAC,MAAM,CAAC,KACvB,mBAAmB,CAAC,CAAC,EAAE,CAAC,EAAE,gBAAgB,EAAE,MAAM,CAAC;6BAuDlD,kBAAkB;CAChB,CAAC"}
|
|
@@ -82,12 +82,14 @@ exports.AgentDefaults = {
|
|
|
82
82
|
{
|
|
83
83
|
role: 'user',
|
|
84
84
|
content: { type: 'text', content: param.input.data.message },
|
|
85
|
+
seenCount: 0,
|
|
85
86
|
},
|
|
86
87
|
];
|
|
87
88
|
try {
|
|
88
89
|
for (_a = __values((_h = param.input.data.pdfBase64) !== null && _h !== void 0 ? _h : []), _b = _a.next(); !_b.done; _b = _a.next()) {
|
|
89
90
|
item = _b.value;
|
|
90
91
|
messages.push({
|
|
92
|
+
seenCount: 0,
|
|
91
93
|
role: 'user',
|
|
92
94
|
content: {
|
|
93
95
|
type: 'media',
|
|
@@ -113,6 +115,7 @@ exports.AgentDefaults = {
|
|
|
113
115
|
for (_c = __values((_j = param.input.data.imageBase64) !== null && _j !== void 0 ? _j : []), _d = _c.next(); !_d.done; _d = _c.next()) {
|
|
114
116
|
item = _d.value;
|
|
115
117
|
messages.push({
|
|
118
|
+
seenCount: 0,
|
|
116
119
|
role: 'user',
|
|
117
120
|
content: {
|
|
118
121
|
type: 'media',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AgentDefaults.js","sourceRoot":"","sources":["../../src/Agent/AgentDefaults.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,6BAA0B;AAC1B,4CAAoB;AAWP,QAAA,aAAa,GAAG;IAC3B,WAAW,EAAE,aAAC,CAAC,MAAM,CAAC;QACpB,OAAO,EAAE,aAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAA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AC;4BACL,CAAC;;;;;;;;;;wBAGU,qBAAM,CAAA,mBAAmB,aAAnB,mBAAmB,uBAAnB,mBAAmB,CAAG,KAAK,CAAC,CAAA,EAAA;4BAD7C,uBACE,SAAM,GAAE,MAAA,CAAC,SAAkC,CAAC,mCAAI,IAAI;4BACpD,WAAQ,WAAA;iCACR;;;aACH;IA/CD,CA+CC;IACH,cAAc,EAAE,CAAC,UAAC,KAAK;QACrB,OAAO;YACL,IAAI,EAAE;gBACJ,QAAQ,EAAE,KAAK,CAAC,OAAO;aACxB;SACF,CAAC;IACJ,CAAC,CAAuB;CAChB,CAAC"}
|
|
@@ -1,7 +1,26 @@
|
|
|
1
1
|
import type z from 'zod';
|
|
2
|
+
import type { AgentLLMIntegration, AgentLLMIntegrationParam } from '../Integrations/types.js';
|
|
2
3
|
import type { IMCPClient } from '../interfaces.mcp.js';
|
|
3
4
|
import type { OtelInfoType } from '../types.js';
|
|
4
|
-
import type {
|
|
5
|
+
import type { AgentMessage, AgentOutputBuilder, AgentToolDefinition, CreateArvoAgentParam } from './types.js';
|
|
6
|
+
/**
|
|
7
|
+
* The Core Cognitive Loop of the Arvo Agent.
|
|
8
|
+
*
|
|
9
|
+
* This function implements the **ReAct (Reason + Act)** pattern, orchestrating the interactive
|
|
10
|
+
* session between the Large Language Model (LLM) and the available Tool ecosystem.
|
|
11
|
+
*
|
|
12
|
+
* @remarks
|
|
13
|
+
* **Hybrid Execution Strategy:**
|
|
14
|
+
* The loop handles two types of tool executions differently:
|
|
15
|
+
* 1. **Synchronous Tools (Internal & MCP):** These are executed **immediately** within the loop.
|
|
16
|
+
* The results are added to the history, and the LLM is called again in the same tick.
|
|
17
|
+
* 2. **Asynchronous Tools (Arvo Services):** These interrupt the loop. The function returns
|
|
18
|
+
* the tool call definition, signaling the parent `ArvoResumable` to **emit an event and suspend**.
|
|
19
|
+
*
|
|
20
|
+
* **Self-Correction:**
|
|
21
|
+
* If the LLM's final output fails the Contract's Output Schema validation (via `outputBuilder`),
|
|
22
|
+
* the loop catches the error and feeds it back to the LLM for auto-correction.
|
|
23
|
+
*/
|
|
5
24
|
export declare const agentLoop: (param: {
|
|
6
25
|
initLifecycle: AgentLLMIntegrationParam["lifecycle"];
|
|
7
26
|
system: string | null;
|
|
@@ -49,6 +68,7 @@ export declare const agentLoop: (param: {
|
|
|
49
68
|
input: Record<string, any>;
|
|
50
69
|
};
|
|
51
70
|
role: "user" | "assistant";
|
|
71
|
+
seenCount: number;
|
|
52
72
|
}[];
|
|
53
73
|
toolCalls: {
|
|
54
74
|
type: "tool_use";
|
|
@@ -92,6 +112,7 @@ export declare const agentLoop: (param: {
|
|
|
92
112
|
input: Record<string, any>;
|
|
93
113
|
};
|
|
94
114
|
role: "user" | "assistant";
|
|
115
|
+
seenCount: number;
|
|
95
116
|
}[];
|
|
96
117
|
output: {
|
|
97
118
|
[x: string]: any;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agentLoop.d.ts","sourceRoot":"","sources":["../../src/Agent/agentLoop.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,CAAC,MAAM,KAAK,CAAC;
|
|
1
|
+
{"version":3,"file":"agentLoop.d.ts","sourceRoot":"","sources":["../../src/Agent/agentLoop.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,CAAC,MAAM,KAAK,CAAC;AAEzB,OAAO,KAAK,EAAE,mBAAmB,EAAE,wBAAwB,EAAE,MAAM,0BAA0B,CAAC;AAC9F,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,KAAK,EACV,YAAY,EACZ,kBAAkB,EAElB,mBAAmB,EAGnB,oBAAoB,EACrB,MAAM,YAAY,CAAC;AAGpB;;;;;;;;;;;;;;;;;GAiBG;AACH,eAAO,MAAM,SAAS,GACpB,OAAO;IACL,aAAa,EAAE,wBAAwB,CAAC,WAAW,CAAC,CAAC;IACrD,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,QAAQ,EAAE,YAAY,EAAE,CAAC;IACzB,KAAK,EAAE,mBAAmB,EAAE,CAAC;IAC7B,YAAY,EAAE,CAAC,CAAC,UAAU,CAAC;IAC3B,aAAa,EAAE,kBAAkB,CAAC;IAClC,eAAe,EAAE,WAAW,CAAC,oBAAoB,CAAC,iBAAiB,CAAC,CAAC,CAAC;IACtE,GAAG,EAAE,mBAAmB,CAAC;IACzB,GAAG,EAAE,UAAU,GAAG,IAAI,CAAC;IACvB,eAAe,EAAE;QACf,OAAO,EAAE,MAAM,CAAC;QAChB,GAAG,EAAE,MAAM,CAAC;KACb,CAAC;IACF,0BAA0B,EAAE,MAAM,CAAC;CACpC,EACD,QAAQ;IAAE,QAAQ,EAAE,YAAY,CAAA;CAAE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAqQhC,CAAC"}
|
package/dist/Agent/agentLoop.js
CHANGED
|
@@ -87,6 +87,24 @@ exports.agentLoop = void 0;
|
|
|
87
87
|
var openinference_semantic_conventions_1 = require("@arizeai/openinference-semantic-conventions");
|
|
88
88
|
var arvo_core_1 = require("arvo-core");
|
|
89
89
|
var utils_1 = require("./utils");
|
|
90
|
+
/**
|
|
91
|
+
* The Core Cognitive Loop of the Arvo Agent.
|
|
92
|
+
*
|
|
93
|
+
* This function implements the **ReAct (Reason + Act)** pattern, orchestrating the interactive
|
|
94
|
+
* session between the Large Language Model (LLM) and the available Tool ecosystem.
|
|
95
|
+
*
|
|
96
|
+
* @remarks
|
|
97
|
+
* **Hybrid Execution Strategy:**
|
|
98
|
+
* The loop handles two types of tool executions differently:
|
|
99
|
+
* 1. **Synchronous Tools (Internal & MCP):** These are executed **immediately** within the loop.
|
|
100
|
+
* The results are added to the history, and the LLM is called again in the same tick.
|
|
101
|
+
* 2. **Asynchronous Tools (Arvo Services):** These interrupt the loop. The function returns
|
|
102
|
+
* the tool call definition, signaling the parent `ArvoResumable` to **emit an event and suspend**.
|
|
103
|
+
*
|
|
104
|
+
* **Self-Correction:**
|
|
105
|
+
* If the LLM's final output fails the Contract's Output Schema validation (via `outputBuilder`),
|
|
106
|
+
* the loop catches the error and feeds it back to the LLM for auto-correction.
|
|
107
|
+
*/
|
|
90
108
|
var agentLoop = function (param, config) { return __awaiter(void 0, void 0, void 0, function () {
|
|
91
109
|
var _a;
|
|
92
110
|
return __generator(this, function (_b) {
|
|
@@ -104,7 +122,7 @@ var agentLoop = function (param, config) { return __awaiter(void 0, void 0, void
|
|
|
104
122
|
_a),
|
|
105
123
|
},
|
|
106
124
|
fn: function (span) { return __awaiter(void 0, void 0, void 0, function () {
|
|
107
|
-
var otelInfo, nameToToolMap, lifecycle, executionUnits, currentToolInteractionCount, messages, toolQuotaExhausted, response, arvoToolCalls, mcpToolResultPromises, internalToolResultPromises, _loop_1, _a, _b, item, _c, _d, item, e_1_1, _e, _f, item, e_2_1, outputResult;
|
|
125
|
+
var otelInfo, nameToToolMap, lifecycle, executionUnits, currentToolInteractionCount, messages, toolQuotaExhausted, response, i, arvoToolCalls, mcpToolResultPromises, internalToolResultPromises, _loop_1, _a, _b, item, _c, _d, item, e_1_1, _e, _f, item, e_2_1, outputResult;
|
|
108
126
|
var e_3, _g, e_1, _h, e_2, _j;
|
|
109
127
|
var _k, _l, _m;
|
|
110
128
|
return __generator(this, function (_o) {
|
|
@@ -145,6 +163,11 @@ var agentLoop = function (param, config) { return __awaiter(void 0, void 0, void
|
|
|
145
163
|
response = _o.sent();
|
|
146
164
|
currentToolInteractionCount++;
|
|
147
165
|
executionUnits += response.executionUnits;
|
|
166
|
+
// Update the message seen count by one for all the
|
|
167
|
+
// messages which the LLM has seen
|
|
168
|
+
for (i = 0; i < messages.length; i++) {
|
|
169
|
+
messages[i].seenCount += 1;
|
|
170
|
+
}
|
|
148
171
|
if (!(response.type === 'tool_call')) return [3 /*break*/, 19];
|
|
149
172
|
arvoToolCalls = [];
|
|
150
173
|
mcpToolResultPromises = [];
|
|
@@ -156,7 +179,12 @@ var agentLoop = function (param, config) { return __awaiter(void 0, void 0, void
|
|
|
156
179
|
name: item.name,
|
|
157
180
|
input: item.input,
|
|
158
181
|
};
|
|
159
|
-
messages.push({
|
|
182
|
+
messages.push({
|
|
183
|
+
role: 'assistant',
|
|
184
|
+
content: toolCallContent,
|
|
185
|
+
// This has been viewed by the LLM as it was generated by it
|
|
186
|
+
seenCount: 1,
|
|
187
|
+
});
|
|
160
188
|
var resolvedToolDef = nameToToolMap[item.name];
|
|
161
189
|
if (!resolvedToolDef) {
|
|
162
190
|
messages.push({
|
|
@@ -166,6 +194,7 @@ var agentLoop = function (param, config) { return __awaiter(void 0, void 0, void
|
|
|
166
194
|
toolUseId: item.toolUseId,
|
|
167
195
|
content: "The tool ".concat(item.name, " does not exist. Please check if you are using the correct tool and don't call this tool again till you have confirmed the existance of the correct tool"),
|
|
168
196
|
},
|
|
197
|
+
seenCount: 0,
|
|
169
198
|
});
|
|
170
199
|
return "continue";
|
|
171
200
|
}
|
|
@@ -243,6 +272,7 @@ var agentLoop = function (param, config) { return __awaiter(void 0, void 0, void
|
|
|
243
272
|
message: zodParseResult.error.message,
|
|
244
273
|
}),
|
|
245
274
|
},
|
|
275
|
+
seenCount: 0,
|
|
246
276
|
});
|
|
247
277
|
}
|
|
248
278
|
else {
|
|
@@ -274,7 +304,7 @@ var agentLoop = function (param, config) { return __awaiter(void 0, void 0, void
|
|
|
274
304
|
case 6:
|
|
275
305
|
if (!!_d.done) return [3 /*break*/, 8];
|
|
276
306
|
item = _d.value;
|
|
277
|
-
messages.push({ role: 'user', content: item });
|
|
307
|
+
messages.push({ role: 'user', content: item, seenCount: 0 });
|
|
278
308
|
_o.label = 7;
|
|
279
309
|
case 7:
|
|
280
310
|
_d = _c.next();
|
|
@@ -300,7 +330,7 @@ var agentLoop = function (param, config) { return __awaiter(void 0, void 0, void
|
|
|
300
330
|
case 13:
|
|
301
331
|
if (!!_f.done) return [3 /*break*/, 15];
|
|
302
332
|
item = _f.value;
|
|
303
|
-
messages.push({ role: 'user', content: item });
|
|
333
|
+
messages.push({ role: 'user', content: item, seenCount: 0 });
|
|
304
334
|
_o.label = 14;
|
|
305
335
|
case 14:
|
|
306
336
|
_f = _e.next();
|
|
@@ -340,6 +370,8 @@ var agentLoop = function (param, config) { return __awaiter(void 0, void 0, void
|
|
|
340
370
|
type: 'text',
|
|
341
371
|
content: 'content' in response && response.content ? response.content : 'No response',
|
|
342
372
|
},
|
|
373
|
+
// This has been viewed by the LLM as it was generated by it
|
|
374
|
+
seenCount: 1,
|
|
343
375
|
});
|
|
344
376
|
messages.push({
|
|
345
377
|
role: 'user',
|
|
@@ -351,6 +383,7 @@ var agentLoop = function (param, config) { return __awaiter(void 0, void 0, void
|
|
|
351
383
|
message: outputResult.error.message,
|
|
352
384
|
}),
|
|
353
385
|
},
|
|
386
|
+
seenCount: 0,
|
|
354
387
|
});
|
|
355
388
|
lifecycle = 'output_error_feedback';
|
|
356
389
|
return [3 /*break*/, 2];
|
|
@@ -362,6 +395,8 @@ var agentLoop = function (param, config) { return __awaiter(void 0, void 0, void
|
|
|
362
395
|
type: 'text',
|
|
363
396
|
content: JSON.stringify(outputResult.data),
|
|
364
397
|
},
|
|
398
|
+
// This has been viewed by the LLM as it was generated by it
|
|
399
|
+
seenCount: 1,
|
|
365
400
|
});
|
|
366
401
|
return [2 /*return*/, {
|
|
367
402
|
messages: messages,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agentLoop.js","sourceRoot":"","sources":["../../src/Agent/agentLoop.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,kGAGqD;AACrD,uCAKmB;
|
|
1
|
+
{"version":3,"file":"agentLoop.js","sourceRoot":"","sources":["../../src/Agent/ag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AAC;wCACH,SAAS,GAAG,uBAAuB,CAAC;wCACpC,wBAAS;oCACX,CAAC;oCAED,IAAI,MAAM,IAAI,YAAY,IAAI,YAAY,CAAC,IAAI,EAAE,CAAC;wCAChD,QAAQ,CAAC,IAAI,CAAC;4CACZ,IAAI,EAAE,WAAW;4CACjB,OAAO,EAAE;gDACP,IAAI,EAAE,MAAM;gDACZ,OAAO,EAAE,IAAI,CAAC,SAAS,CAAC,YAAY,CAAC,IAAI,CAAC;6CAC3C;4CACD,4DAA4D;4CAC5D,SAAS,EAAE,CAAC;yCACb,CAAC,CAAC;wCAEH,sBAAO;gDACL,QAAQ,UAAA;gDACR,MAAM,EAAE,YAAY,CAAC,IAAI;gDACzB,gBAAgB,EAAE;oDAChB,OAAO,EAAE,2BAA2B;oDACpC,GAAG,EAAE,KAAK,CAAC,eAAe,CAAC,GAAG;iDAC/B;gDACD,cAAc,gBAAA;6CACf,EAAC;oCACJ,CAAC;;yCAEH,MAAM,IAAI,KAAK,CAAC,8CAAuC,2BAA2B,CAAE,CAAC,CAAC;;oCAEtF,IAAI,CAAC,GAAG,EAAE,CAAC;;;;;yBAEd;iBACF,CAAC,EAAA;oBAnQF,sBAAA,SAmQE,EAAA;;;KAAA,CAAC;AAtRQ,QAAA,SAAS,aAsRjB"}
|
package/dist/Agent/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import type { AgentInternalTool
|
|
2
|
-
type
|
|
1
|
+
import type { AgentInternalTool } from '../AgentTool/types.js';
|
|
2
|
+
import type { AgentMessage, AgentServiceContract, AnyArvoOrchestratorContract, CreateArvoAgentParam } from './types.js';
|
|
3
|
+
export type AgentState = {
|
|
3
4
|
currentSubject: string;
|
|
4
5
|
system: string | null;
|
|
5
6
|
messages: AgentMessage[];
|
|
@@ -13,6 +14,78 @@ type AgentState = {
|
|
|
13
14
|
}>;
|
|
14
15
|
totalExecutionUnits: number;
|
|
15
16
|
};
|
|
17
|
+
/**
|
|
18
|
+
* Creates a fully-featured AI Agent implemented as an Arvo Resumable Event Handler.
|
|
19
|
+
*
|
|
20
|
+
* This factory transforms a standard Large Language Model (LLM) into a stateful, event-driven
|
|
21
|
+
* participant in your system. Unlike standard chatbots, this Agent can interact with:
|
|
22
|
+
* 1. **Local Tools**: Async/Sync JavaScript functions executed immediately.
|
|
23
|
+
* 2. **MCP Servers**: External data sources via the Model Context Protocol.
|
|
24
|
+
* 3. **Arvo Services**: Other Event Handlers in your Arvo distributed system (Async/Distributed tools).
|
|
25
|
+
*
|
|
26
|
+
* @remarks
|
|
27
|
+
* **The Execution Model:**
|
|
28
|
+
* The Agent operates on a **Start-Stop-Resume** cycle:
|
|
29
|
+
* 1. **Init**: Receives an event -> Builds Context -> Calls LLM.
|
|
30
|
+
* 2. **Action**:
|
|
31
|
+
* - If the LLM chooses a `tool` or `mcp`, it executes immediately and loops back.
|
|
32
|
+
* - If the LLM chooses a `service`, the Agent **emits an event** and **suspends execution**.
|
|
33
|
+
* - The LLM can choose a mix all three modalities at the same time.
|
|
34
|
+
* 3. **Resume**: When the Service replies with an event, the Agent wakes up, restores state from `memory`,
|
|
35
|
+
* adds the result to its history, and calls the LLM again.
|
|
36
|
+
*
|
|
37
|
+
* **Strict Versioning Compliance:**
|
|
38
|
+
* Arvo enforces that your Agent implementation matches your Contract versions.
|
|
39
|
+
* If your `self` contract defines versions `'1.0.0'` and `'2.0.0'`, you must
|
|
40
|
+
* provide specific `context` (A context builder function which runs at init of the agent
|
|
41
|
+
* execution and is reponsible for building the context of the agent i.e. system promot
|
|
42
|
+
* and messages list, both are optional) and `output` builder, which takes the LLM output
|
|
43
|
+
* and converts it into yor contract compliant structure,for *all* versions
|
|
44
|
+
* in the `handler` parameter.
|
|
45
|
+
*
|
|
46
|
+
* This allows you to:
|
|
47
|
+
* - Safely evolve prompt engineering strategies (e.g., v1 uses GPT-3.5, v2 uses GPT-4).
|
|
48
|
+
* - Run different tests on Agent behavior within the same deployment.
|
|
49
|
+
* - Retire old Agent behaviors gradually without breaking existing clients.
|
|
50
|
+
*
|
|
51
|
+
* @param param - Configuration object for the Agent.
|
|
52
|
+
*
|
|
53
|
+
* @returns An `ArvoResumable` instance specialised to run as an AI Agent.
|
|
54
|
+
*
|
|
55
|
+
* @example
|
|
56
|
+
* ```typescript
|
|
57
|
+
* export const supportAgent = ({ memory }) => createArvoAgent({
|
|
58
|
+
* contracts: {
|
|
59
|
+
* self: supportAgentContract, // The interface for this agent
|
|
60
|
+
* services: {
|
|
61
|
+
* // The Agent can "call" this service by emitting an event
|
|
62
|
+
* // and going to sleep until the billing service replies.
|
|
63
|
+
* billing: { contract: billingServiceContract.version('1.0.0') }
|
|
64
|
+
* }
|
|
65
|
+
* },
|
|
66
|
+
* tools: {
|
|
67
|
+
* // The Agent can execute this immediately in-memory
|
|
68
|
+
* checkTime: createAgentTool({
|
|
69
|
+
* name: 'check_time',
|
|
70
|
+
* description: 'Checks current server time',
|
|
71
|
+
* input: z.object({}),
|
|
72
|
+
* output: z.object({ time: z.string() }),
|
|
73
|
+
* fn: async () => ({ time: new Date().toISOString() })
|
|
74
|
+
* })
|
|
75
|
+
* },
|
|
76
|
+
* llm: openaiLLMIntegration(new OpenAI(), { model: 'gpt-4o' }),
|
|
77
|
+
* memory: memory, // Persists chat history during async calls
|
|
78
|
+
* handler: {
|
|
79
|
+
* '1.0.0': {
|
|
80
|
+
* // Dynamic System Prompt Building
|
|
81
|
+
* context: AgentDefaults.CONTEXT_BUILDER(async ({ tools }) =>
|
|
82
|
+
* `You are a support agent. You have access to billing data via the ${tools.services.billing.name} tool.`
|
|
83
|
+
* ),
|
|
84
|
+
* output: AgentDefaults.OUTPUT_BUILDER
|
|
85
|
+
* }
|
|
86
|
+
* }
|
|
87
|
+
* });
|
|
88
|
+
* ```
|
|
89
|
+
*/
|
|
16
90
|
export declare const createArvoAgent: <TSelfContract extends AnyArvoOrchestratorContract, TServiceContract extends Record<string, AgentServiceContract>, TTools extends Record<string, AgentInternalTool>>({ contracts, memory, handler, llm, mcp, maxToolInteractions, llmResponseType, tools, }: CreateArvoAgentParam<TSelfContract, TServiceContract, TTools>) => import("arvo-event-handler").ArvoResumable<AgentState, TSelfContract, { [K in keyof TServiceContract & string]: TServiceContract[K]["contract"]; }>;
|
|
17
|
-
export {};
|
|
18
91
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/Agent/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/Agent/index.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAG/D,OAAO,KAAK,EACV,YAAY,EACZ,oBAAoB,EACpB,2BAA2B,EAC3B,oBAAoB,EACrB,MAAM,YAAY,CAAC;AAOpB,MAAM,MAAM,UAAU,GAAG;IACvB,cAAc,EAAE,MAAM,CAAC;IACvB,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,QAAQ,EAAE,YAAY,EAAE,CAAC;IACzB,gBAAgB,EAAE;QAChB,GAAG,EAAE,MAAM,CAAC;QACZ,OAAO,EAAE,MAAM,CAAC;KACjB,CAAC;IACF,iBAAiB,EAAE,MAAM,CAAC,MAAM,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAAA;KAAE,CAAC,CAAC;IAC1F,mBAAmB,EAAE,MAAM,CAAC;CAC7B,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwEG;AACH,eAAO,MAAM,eAAe,GAC1B,aAAa,SAAS,2BAA2B,EACjD,gBAAgB,SAAS,MAAM,CAAC,MAAM,EAAE,oBAAoB,CAAC,EAC7D,MAAM,SAAS,MAAM,CAAC,MAAM,EAAE,iBAAiB,CAAC,EAChD,wFASC,oBAAoB,CAAC,aAAa,EAAE,gBAAgB,EAAE,MAAM,CAAC,8EAGtD,CAAC,yEA0NV,CAAC"}
|
package/dist/Agent/index.js
CHANGED
|
@@ -99,6 +99,79 @@ var arvo_core_1 = require("arvo-core");
|
|
|
99
99
|
var arvo_event_handler_1 = require("arvo-event-handler");
|
|
100
100
|
var agentLoop_js_1 = require("./agentLoop.js");
|
|
101
101
|
var utils_js_1 = require("./utils.js");
|
|
102
|
+
/**
|
|
103
|
+
* Creates a fully-featured AI Agent implemented as an Arvo Resumable Event Handler.
|
|
104
|
+
*
|
|
105
|
+
* This factory transforms a standard Large Language Model (LLM) into a stateful, event-driven
|
|
106
|
+
* participant in your system. Unlike standard chatbots, this Agent can interact with:
|
|
107
|
+
* 1. **Local Tools**: Async/Sync JavaScript functions executed immediately.
|
|
108
|
+
* 2. **MCP Servers**: External data sources via the Model Context Protocol.
|
|
109
|
+
* 3. **Arvo Services**: Other Event Handlers in your Arvo distributed system (Async/Distributed tools).
|
|
110
|
+
*
|
|
111
|
+
* @remarks
|
|
112
|
+
* **The Execution Model:**
|
|
113
|
+
* The Agent operates on a **Start-Stop-Resume** cycle:
|
|
114
|
+
* 1. **Init**: Receives an event -> Builds Context -> Calls LLM.
|
|
115
|
+
* 2. **Action**:
|
|
116
|
+
* - If the LLM chooses a `tool` or `mcp`, it executes immediately and loops back.
|
|
117
|
+
* - If the LLM chooses a `service`, the Agent **emits an event** and **suspends execution**.
|
|
118
|
+
* - The LLM can choose a mix all three modalities at the same time.
|
|
119
|
+
* 3. **Resume**: When the Service replies with an event, the Agent wakes up, restores state from `memory`,
|
|
120
|
+
* adds the result to its history, and calls the LLM again.
|
|
121
|
+
*
|
|
122
|
+
* **Strict Versioning Compliance:**
|
|
123
|
+
* Arvo enforces that your Agent implementation matches your Contract versions.
|
|
124
|
+
* If your `self` contract defines versions `'1.0.0'` and `'2.0.0'`, you must
|
|
125
|
+
* provide specific `context` (A context builder function which runs at init of the agent
|
|
126
|
+
* execution and is reponsible for building the context of the agent i.e. system promot
|
|
127
|
+
* and messages list, both are optional) and `output` builder, which takes the LLM output
|
|
128
|
+
* and converts it into yor contract compliant structure,for *all* versions
|
|
129
|
+
* in the `handler` parameter.
|
|
130
|
+
*
|
|
131
|
+
* This allows you to:
|
|
132
|
+
* - Safely evolve prompt engineering strategies (e.g., v1 uses GPT-3.5, v2 uses GPT-4).
|
|
133
|
+
* - Run different tests on Agent behavior within the same deployment.
|
|
134
|
+
* - Retire old Agent behaviors gradually without breaking existing clients.
|
|
135
|
+
*
|
|
136
|
+
* @param param - Configuration object for the Agent.
|
|
137
|
+
*
|
|
138
|
+
* @returns An `ArvoResumable` instance specialised to run as an AI Agent.
|
|
139
|
+
*
|
|
140
|
+
* @example
|
|
141
|
+
* ```typescript
|
|
142
|
+
* export const supportAgent = ({ memory }) => createArvoAgent({
|
|
143
|
+
* contracts: {
|
|
144
|
+
* self: supportAgentContract, // The interface for this agent
|
|
145
|
+
* services: {
|
|
146
|
+
* // The Agent can "call" this service by emitting an event
|
|
147
|
+
* // and going to sleep until the billing service replies.
|
|
148
|
+
* billing: { contract: billingServiceContract.version('1.0.0') }
|
|
149
|
+
* }
|
|
150
|
+
* },
|
|
151
|
+
* tools: {
|
|
152
|
+
* // The Agent can execute this immediately in-memory
|
|
153
|
+
* checkTime: createAgentTool({
|
|
154
|
+
* name: 'check_time',
|
|
155
|
+
* description: 'Checks current server time',
|
|
156
|
+
* input: z.object({}),
|
|
157
|
+
* output: z.object({ time: z.string() }),
|
|
158
|
+
* fn: async () => ({ time: new Date().toISOString() })
|
|
159
|
+
* })
|
|
160
|
+
* },
|
|
161
|
+
* llm: openaiLLMIntegration(new OpenAI(), { model: 'gpt-4o' }),
|
|
162
|
+
* memory: memory, // Persists chat history during async calls
|
|
163
|
+
* handler: {
|
|
164
|
+
* '1.0.0': {
|
|
165
|
+
* // Dynamic System Prompt Building
|
|
166
|
+
* context: AgentDefaults.CONTEXT_BUILDER(async ({ tools }) =>
|
|
167
|
+
* `You are a support agent. You have access to billing data via the ${tools.services.billing.name} tool.`
|
|
168
|
+
* ),
|
|
169
|
+
* output: AgentDefaults.OUTPUT_BUILDER
|
|
170
|
+
* }
|
|
171
|
+
* }
|
|
172
|
+
* });
|
|
173
|
+
* ```
|
|
174
|
+
*/
|
|
102
175
|
var createArvoAgent = function (_a) {
|
|
103
176
|
var contracts = _a.contracts, memory = _a.memory, handler = _a.handler, llm = _a.llm, mcp = _a.mcp, _b = _a.maxToolInteractions, maxToolInteractions = _b === void 0 ? 5 : _b, _c = _a.llmResponseType, llmResponseType = _c === void 0 ? 'text' : _c, tools = _a.tools;
|
|
104
177
|
var serviceContracts = Object.fromEntries(Object.entries(contracts.services).map(function (_a) {
|
|
@@ -164,14 +237,15 @@ var createArvoAgent = function (_a) {
|
|
|
164
237
|
return [4 /*yield*/, (0, agentLoop_js_1.agentLoop)({
|
|
165
238
|
initLifecycle: 'init',
|
|
166
239
|
system: (_m = llmContext === null || llmContext === void 0 ? void 0 : llmContext.system) !== null && _m !== void 0 ? _m : null,
|
|
167
|
-
messages: ((_o = llmContext === null || llmContext === void 0 ? void 0 : llmContext.messages) === null || _o === void 0 ? void 0 : _o.length)
|
|
240
|
+
messages: (((_o = llmContext === null || llmContext === void 0 ? void 0 : llmContext.messages) === null || _o === void 0 ? void 0 : _o.length)
|
|
168
241
|
? llmContext.messages
|
|
169
242
|
: [
|
|
170
243
|
{
|
|
171
244
|
role: 'user',
|
|
172
245
|
content: { type: 'text', content: JSON.stringify(inputData) },
|
|
246
|
+
seenCount: 0,
|
|
173
247
|
},
|
|
174
|
-
],
|
|
248
|
+
]).map(function (item) { var _a; return (__assign(__assign({}, item), { seenCount: (_a = item.seenCount) !== null && _a !== void 0 ? _a : 0 })); }),
|
|
175
249
|
tools: Object.values(__assign(__assign(__assign({}, mcpTools), serviceTools), internalTools)),
|
|
176
250
|
outputFormat: outputFormat,
|
|
177
251
|
outputBuilder: outputBuilder,
|
|
@@ -233,6 +307,7 @@ var createArvoAgent = function (_a) {
|
|
|
233
307
|
toolUseId: toolUseId,
|
|
234
308
|
content: JSON.stringify(data !== null && data !== void 0 ? data : {}),
|
|
235
309
|
},
|
|
310
|
+
seenCount: 0,
|
|
236
311
|
});
|
|
237
312
|
}
|
|
238
313
|
}
|
package/dist/Agent/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/Agent/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,uCAA4E;AAC5E,yDAI4B;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/Agent/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,uCAA4E;AAC5E,yDAI4B;AAG5B,+CAA2C;AAO3C,uCAIoB;AAcpB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwEG;AACI,IAAM,eAAe,GAAG,UAI7B,EAS8D;QAR9D,SAAS,eAAA,EACT,MAAM,YAAA,EACN,OAAO,aAAA,EACP,GAAG,SAAA,EACH,GAAG,SAAA,EACH,2BAAuB,EAAvB,mBAAmB,mBAAG,CAAC,KAAA,EACvB,uBAAwB,EAAxB,eAAe,mBAAG,MAAM,KAAA,EACxB,KAAK,WAAA;IAEL,IAAM,gBAAgB,GAAG,MAAM,CAAC,WAAW,CACzC,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC,GAAG,CAAC,UAAC,EAAmB;YAAnB,KAAA,aAAmB,EAAlB,GAAG,Q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A;;4BAAzD,SAAyD,CAAC;;;;;iBAE7D,CAIqB;SACvB,EAhMiD,CAgMjD,CAAC,CAKH;KACF,CAAC,CAAC;AACL,CAAC,CAAC;AA1OW,QAAA,eAAe,mBA0O1B"}
|
package/dist/Agent/schema.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import z from 'zod';
|
|
2
|
+
/** Zod schema for standard text content within a message. */
|
|
2
3
|
export declare const AgentTextContentSchema: z.ZodObject<{
|
|
3
4
|
type: z.ZodLiteral<"text">;
|
|
4
5
|
content: z.ZodString;
|
|
@@ -9,6 +10,7 @@ export declare const AgentTextContentSchema: z.ZodObject<{
|
|
|
9
10
|
type: "text";
|
|
10
11
|
content: string;
|
|
11
12
|
}>;
|
|
13
|
+
/** Zod schema for multimodal inputs (Images, PDFs, Files) encoded as Base64. */
|
|
12
14
|
export declare const AgentMediaContentSchema: z.ZodObject<{
|
|
13
15
|
type: z.ZodLiteral<"media">;
|
|
14
16
|
content: z.ZodString;
|
|
@@ -72,6 +74,7 @@ export declare const AgentMediaContentSchema: z.ZodObject<{
|
|
|
72
74
|
format: "base64";
|
|
73
75
|
};
|
|
74
76
|
}>;
|
|
77
|
+
/** Zod schema for the output of a tool execution, correlated by ID to a specific tool call. */
|
|
75
78
|
export declare const AgentToolResultContentSchema: z.ZodObject<{
|
|
76
79
|
type: z.ZodLiteral<"tool_result">;
|
|
77
80
|
toolUseId: z.ZodString;
|
|
@@ -85,6 +88,7 @@ export declare const AgentToolResultContentSchema: z.ZodObject<{
|
|
|
85
88
|
content: string;
|
|
86
89
|
toolUseId: string;
|
|
87
90
|
}>;
|
|
91
|
+
/** Zod schema representing an LLM's request to execute a named tool with specific arguments. */
|
|
88
92
|
export declare const AgentToolCallContentSchema: z.ZodObject<{
|
|
89
93
|
type: z.ZodLiteral<"tool_use">;
|
|
90
94
|
toolUseId: z.ZodString;
|
|
@@ -101,6 +105,7 @@ export declare const AgentToolCallContentSchema: z.ZodObject<{
|
|
|
101
105
|
name: string;
|
|
102
106
|
input: Record<string, any>;
|
|
103
107
|
}>;
|
|
108
|
+
/** Discriminated union of all valid payload types (Text, Media, Tool Calls, and Results). */
|
|
104
109
|
export declare const AgentMessageContentSchema: z.ZodDiscriminatedUnion<"type", [z.ZodObject<{
|
|
105
110
|
type: z.ZodLiteral<"text">;
|
|
106
111
|
content: z.ZodString;
|
|
@@ -200,6 +205,7 @@ export declare const AgentMessageContentSchema: z.ZodDiscriminatedUnion<"type",
|
|
|
200
205
|
name: string;
|
|
201
206
|
input: Record<string, any>;
|
|
202
207
|
}>]>;
|
|
208
|
+
/** The primary data structure representing a single turn in the Agent's conversation history. */
|
|
203
209
|
export declare const AgentMessageSchema: z.ZodObject<{
|
|
204
210
|
role: z.ZodEnum<["user", "assistant"]>;
|
|
205
211
|
content: z.ZodDiscriminatedUnion<"type", [z.ZodObject<{
|
|
@@ -301,6 +307,7 @@ export declare const AgentMessageSchema: z.ZodObject<{
|
|
|
301
307
|
name: string;
|
|
302
308
|
input: Record<string, any>;
|
|
303
309
|
}>]>;
|
|
310
|
+
seenCount: z.ZodNumber;
|
|
304
311
|
}, "strip", z.ZodTypeAny, {
|
|
305
312
|
content: {
|
|
306
313
|
type: "text";
|
|
@@ -330,6 +337,7 @@ export declare const AgentMessageSchema: z.ZodObject<{
|
|
|
330
337
|
input: Record<string, any>;
|
|
331
338
|
};
|
|
332
339
|
role: "user" | "assistant";
|
|
340
|
+
seenCount: number;
|
|
333
341
|
}, {
|
|
334
342
|
content: {
|
|
335
343
|
type: "text";
|
|
@@ -359,5 +367,6 @@ export declare const AgentMessageSchema: z.ZodObject<{
|
|
|
359
367
|
input: Record<string, any>;
|
|
360
368
|
};
|
|
361
369
|
role: "user" | "assistant";
|
|
370
|
+
seenCount: number;
|
|
362
371
|
}>;
|
|
363
372
|
//# sourceMappingURL=schema.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../src/Ag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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAI7B,CAAC"}
|
package/dist/Agent/schema.js
CHANGED
|
@@ -5,10 +5,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.AgentMessageSchema = exports.AgentMessageContentSchema = exports.AgentToolCallContentSchema = exports.AgentToolResultContentSchema = exports.AgentMediaContentSchema = exports.AgentTextContentSchema = void 0;
|
|
7
7
|
var zod_1 = __importDefault(require("zod"));
|
|
8
|
+
/** Zod schema for standard text content within a message. */
|
|
8
9
|
exports.AgentTextContentSchema = zod_1.default.object({
|
|
9
10
|
type: zod_1.default.literal('text'),
|
|
10
11
|
content: zod_1.default.string(),
|
|
11
12
|
});
|
|
13
|
+
/** Zod schema for multimodal inputs (Images, PDFs, Files) encoded as Base64. */
|
|
12
14
|
exports.AgentMediaContentSchema = zod_1.default.object({
|
|
13
15
|
type: zod_1.default.literal('media'),
|
|
14
16
|
content: zod_1.default.string(),
|
|
@@ -27,25 +29,30 @@ exports.AgentMediaContentSchema = zod_1.default.object({
|
|
|
27
29
|
}),
|
|
28
30
|
]),
|
|
29
31
|
});
|
|
32
|
+
/** Zod schema for the output of a tool execution, correlated by ID to a specific tool call. */
|
|
30
33
|
exports.AgentToolResultContentSchema = zod_1.default.object({
|
|
31
34
|
type: zod_1.default.literal('tool_result'),
|
|
32
35
|
toolUseId: zod_1.default.string(),
|
|
33
36
|
content: zod_1.default.string(),
|
|
34
37
|
});
|
|
38
|
+
/** Zod schema representing an LLM's request to execute a named tool with specific arguments. */
|
|
35
39
|
exports.AgentToolCallContentSchema = zod_1.default.object({
|
|
36
40
|
type: zod_1.default.literal('tool_use'),
|
|
37
41
|
toolUseId: zod_1.default.string(),
|
|
38
42
|
name: zod_1.default.string(),
|
|
39
43
|
input: zod_1.default.record(zod_1.default.string(), zod_1.default.any()),
|
|
40
44
|
});
|
|
45
|
+
/** Discriminated union of all valid payload types (Text, Media, Tool Calls, and Results). */
|
|
41
46
|
exports.AgentMessageContentSchema = zod_1.default.discriminatedUnion('type', [
|
|
42
47
|
exports.AgentTextContentSchema,
|
|
43
48
|
exports.AgentMediaContentSchema,
|
|
44
49
|
exports.AgentToolResultContentSchema,
|
|
45
50
|
exports.AgentToolCallContentSchema,
|
|
46
51
|
]);
|
|
52
|
+
/** The primary data structure representing a single turn in the Agent's conversation history. */
|
|
47
53
|
exports.AgentMessageSchema = zod_1.default.object({
|
|
48
54
|
role: zod_1.default.enum(['user', 'assistant']),
|
|
49
55
|
content: exports.AgentMessageContentSchema,
|
|
56
|
+
seenCount: zod_1.default.number().describe('Then number of time the LLM integration has seen this message'),
|
|
50
57
|
});
|
|
51
58
|
//# sourceMappingURL=schema.js.map
|