@arvo-tools/agentic 0.2.0 → 0.3.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.
@@ -0,0 +1,28 @@
1
+ import type { ArvoSemanticVersion } from 'arvo-core';
2
+ import z from 'zod';
3
+ import type { AgentContextBuilder, AgentInternalTool, AgentOutputBuilder, AgentServiceContract, AnyArvoOrchestratorContract, PromiseLike } from './types.js';
4
+ export declare const AgentDefaults: {
5
+ readonly INIT_SCHEMA: z.ZodObject<{
6
+ message: z.ZodString;
7
+ imageBase64: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
8
+ pdfBase64: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
9
+ }, "strip", z.ZodTypeAny, {
10
+ message: string;
11
+ imageBase64?: string[] | undefined;
12
+ pdfBase64?: string[] | undefined;
13
+ }, {
14
+ message: string;
15
+ imageBase64?: string[] | undefined;
16
+ pdfBase64?: string[] | undefined;
17
+ }>;
18
+ readonly COMPLETE_SCHEMA: z.ZodObject<{
19
+ response: z.ZodString;
20
+ }, "strip", z.ZodTypeAny, {
21
+ response: string;
22
+ }, {
23
+ response: string;
24
+ }>;
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]) => PromiseLike<string>) => AgentContextBuilder<T, V, TServiceContract, TTools>;
26
+ readonly OUTPUT_BUILDER: AgentOutputBuilder;
27
+ };
28
+ //# sourceMappingURL=AgentDefaults.d.ts.map
@@ -0,0 +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,EACnB,iBAAiB,EAEjB,kBAAkB,EAClB,oBAAoB,EACpB,2BAA2B,EAC3B,WAAW,EACZ,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;6BAoDlD,kBAAkB;CAChB,CAAC"}
@@ -0,0 +1,154 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __generator = (this && this.__generator) || function (thisArg, body) {
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
13
+ return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
+ function verb(n) { return function (v) { return step([n, v]); }; }
15
+ function step(op) {
16
+ if (f) throw new TypeError("Generator is already executing.");
17
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
18
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
+ if (y = 0, t) op = [op[0] & 2, t.value];
20
+ switch (op[0]) {
21
+ case 0: case 1: t = op; break;
22
+ case 4: _.label++; return { value: op[1], done: false };
23
+ case 5: _.label++; y = op[1]; op = [0]; continue;
24
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
+ default:
26
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
+ if (t[2]) _.ops.pop();
31
+ _.trys.pop(); continue;
32
+ }
33
+ op = body.call(thisArg, _);
34
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
+ }
37
+ };
38
+ var __values = (this && this.__values) || function(o) {
39
+ var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
40
+ if (m) return m.call(o);
41
+ if (o && typeof o.length === "number") return {
42
+ next: function () {
43
+ if (o && i >= o.length) o = void 0;
44
+ return { value: o && o[i++], done: !o };
45
+ }
46
+ };
47
+ throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
48
+ };
49
+ var __importDefault = (this && this.__importDefault) || function (mod) {
50
+ return (mod && mod.__esModule) ? mod : { "default": mod };
51
+ };
52
+ Object.defineProperty(exports, "__esModule", { value: true });
53
+ exports.AgentDefaults = void 0;
54
+ var uuid_1 = require("uuid");
55
+ var zod_1 = __importDefault(require("zod"));
56
+ exports.AgentDefaults = {
57
+ INIT_SCHEMA: zod_1.default.object({
58
+ message: zod_1.default.string().describe('The input message to the agent'),
59
+ imageBase64: zod_1.default
60
+ .string()
61
+ .array()
62
+ .optional()
63
+ .describe('An optional list of base64 image strings to read. Must not be added by an AI Agent'),
64
+ pdfBase64: zod_1.default
65
+ .string()
66
+ .array()
67
+ .optional()
68
+ .describe('An optional list of base64 pngs to read. Must not be added by an AI Agent'),
69
+ }),
70
+ COMPLETE_SCHEMA: zod_1.default.object({
71
+ response: zod_1.default.string().describe('The output response of the agent'),
72
+ }),
73
+ CONTEXT_BUILDER: function (systemPromptBuilder) {
74
+ return function (param) { return __awaiter(void 0, void 0, void 0, function () {
75
+ var messages, _a, _b, item, _c, _d, item;
76
+ var e_1, _e, e_2, _f, _g;
77
+ var _h, _j, _k;
78
+ return __generator(this, function (_l) {
79
+ switch (_l.label) {
80
+ case 0:
81
+ messages = [
82
+ {
83
+ role: 'user',
84
+ content: { type: 'text', content: param.input.data.message },
85
+ },
86
+ ];
87
+ try {
88
+ for (_a = __values((_h = param.input.data.pdfBase64) !== null && _h !== void 0 ? _h : []), _b = _a.next(); !_b.done; _b = _a.next()) {
89
+ item = _b.value;
90
+ messages.push({
91
+ role: 'user',
92
+ content: {
93
+ type: 'media',
94
+ content: item,
95
+ contentType: {
96
+ format: 'base64',
97
+ type: 'file',
98
+ filename: "".concat((0, uuid_1.v4)(), ".pdf"),
99
+ filetype: 'pdf',
100
+ },
101
+ },
102
+ });
103
+ }
104
+ }
105
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
106
+ finally {
107
+ try {
108
+ if (_b && !_b.done && (_e = _a.return)) _e.call(_a);
109
+ }
110
+ finally { if (e_1) throw e_1.error; }
111
+ }
112
+ try {
113
+ for (_c = __values((_j = param.input.data.imageBase64) !== null && _j !== void 0 ? _j : []), _d = _c.next(); !_d.done; _d = _c.next()) {
114
+ item = _d.value;
115
+ messages.push({
116
+ role: 'user',
117
+ content: {
118
+ type: 'media',
119
+ content: item,
120
+ contentType: {
121
+ format: 'base64',
122
+ type: 'image',
123
+ filename: "".concat((0, uuid_1.v4)(), ".png"),
124
+ filetype: 'png',
125
+ },
126
+ },
127
+ });
128
+ }
129
+ }
130
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
131
+ finally {
132
+ try {
133
+ if (_d && !_d.done && (_f = _c.return)) _f.call(_c);
134
+ }
135
+ finally { if (e_2) throw e_2.error; }
136
+ }
137
+ _g = {};
138
+ return [4 /*yield*/, (systemPromptBuilder === null || systemPromptBuilder === void 0 ? void 0 : systemPromptBuilder(param))];
139
+ case 1: return [2 /*return*/, (_g.system = (_k = (_l.sent())) !== null && _k !== void 0 ? _k : null,
140
+ _g.messages = messages,
141
+ _g)];
142
+ }
143
+ });
144
+ }); };
145
+ },
146
+ OUTPUT_BUILDER: (function (param) {
147
+ return {
148
+ data: {
149
+ response: param.content,
150
+ },
151
+ };
152
+ }),
153
+ };
154
+ //# sourceMappingURL=AgentDefaults.js.map
@@ -0,0 +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,CAAC,gCAAgC,CAAC;QAC9D,WAAW,EAAE,aAAC;aACX,MAAM,EAAE;aACR,KAAK,EAAE;aACP,QAAQ,EAAE;aACV,QAAQ,CACP,oFAAoF,CACrF;QACH,SAAS,EAAE,aAAC;aACT,MAAM,EAAE;aACR,KAAK,EAAE;aACP,QAAQ,EAAE;aACV,QAAQ,CAAC,2EAA2E,CAAC;KAC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;iCACF,CAAC,CAAC;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;IA5CD,CA4CC;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"}
@@ -0,0 +1,109 @@
1
+ import type z from 'zod';
2
+ import type { IMCPClient } from '../interfaces.mcp.js';
3
+ import type { OtelInfoType } from '../types.js';
4
+ import type { AgentLLMIntegration, AgentLLMIntegrationParam, AgentMessage, AgentOutputBuilder, AgentToolDefinition, CreateArvoAgentParam } from './types.js';
5
+ export declare const agentLoop: (param: {
6
+ initLifecycle: AgentLLMIntegrationParam["lifecycle"];
7
+ system: string | null;
8
+ messages: AgentMessage[];
9
+ tools: AgentToolDefinition[];
10
+ outputFormat: z.ZodTypeAny;
11
+ outputBuilder: AgentOutputBuilder;
12
+ llmResponseType: NonNullable<CreateArvoAgentParam["llmResponseType"]>;
13
+ llm: AgentLLMIntegration;
14
+ mcp: IMCPClient | null;
15
+ toolInteraction: {
16
+ current: number;
17
+ max: number;
18
+ };
19
+ currentTotalExecutionUnits: number;
20
+ }, config: {
21
+ otelInfo: OtelInfoType;
22
+ }) => Promise<{
23
+ messages: {
24
+ content: {
25
+ type: "text";
26
+ content: string;
27
+ } | {
28
+ type: "media";
29
+ content: string;
30
+ contentType: {
31
+ type: "image";
32
+ filename: string;
33
+ filetype: string;
34
+ format: "base64";
35
+ } | {
36
+ type: "file";
37
+ filename: string;
38
+ filetype: string;
39
+ format: "base64";
40
+ };
41
+ } | {
42
+ type: "tool_result";
43
+ content: string;
44
+ toolUseId: string;
45
+ } | {
46
+ type: "tool_use";
47
+ toolUseId: string;
48
+ name: string;
49
+ input: Record<string, any>;
50
+ };
51
+ role: "user" | "assistant";
52
+ }[];
53
+ toolCalls: {
54
+ type: "tool_use";
55
+ toolUseId: string;
56
+ name: string;
57
+ input: Record<string, any>;
58
+ }[];
59
+ toolInteractions: {
60
+ current: number;
61
+ max: number;
62
+ };
63
+ executionUnits: number;
64
+ output?: undefined;
65
+ } | {
66
+ messages: {
67
+ content: {
68
+ type: "text";
69
+ content: string;
70
+ } | {
71
+ type: "media";
72
+ content: string;
73
+ contentType: {
74
+ type: "image";
75
+ filename: string;
76
+ filetype: string;
77
+ format: "base64";
78
+ } | {
79
+ type: "file";
80
+ filename: string;
81
+ filetype: string;
82
+ format: "base64";
83
+ };
84
+ } | {
85
+ type: "tool_result";
86
+ content: string;
87
+ toolUseId: string;
88
+ } | {
89
+ type: "tool_use";
90
+ toolUseId: string;
91
+ name: string;
92
+ input: Record<string, any>;
93
+ };
94
+ role: "user" | "assistant";
95
+ }[];
96
+ output: {
97
+ [x: string]: any;
98
+ } & {
99
+ __id?: import("arvo-core").CreateArvoEvent<Record<string, unknown>, string>["id"];
100
+ __executionunits?: import("arvo-core").CreateArvoEvent<Record<string, unknown>, string>["executionunits"];
101
+ };
102
+ toolInteractions: {
103
+ current: number;
104
+ max: number;
105
+ };
106
+ executionUnits: number;
107
+ toolCalls?: undefined;
108
+ }>;
109
+ //# sourceMappingURL=agentLoop.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"agentLoop.d.ts","sourceRoot":"","sources":["../../src/Agent/agentLoop.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,CAAC,MAAM,KAAK,CAAC;AACzB,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,KAAK,EAEV,mBAAmB,EACnB,wBAAwB,EACxB,YAAY,EACZ,kBAAkB,EAElB,mBAAmB,EAGnB,oBAAoB,EACrB,MAAM,YAAY,CAAC;AAGpB,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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAiPhC,CAAC"}