@botonic/plugin-ai-agents 0.40.0-alpha.1 → 0.40.1-alpha.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/lib/cjs/agent-builder.d.ts +1 -1
- package/lib/cjs/agent-builder.js +13 -3
- package/lib/cjs/agent-builder.js.map +1 -1
- package/lib/cjs/hubtype-api-client.d.ts +1 -0
- package/lib/cjs/hubtype-api-client.js +19 -1
- package/lib/cjs/hubtype-api-client.js.map +1 -1
- package/lib/cjs/index.d.ts +2 -2
- package/lib/cjs/index.js +3 -1
- package/lib/cjs/index.js.map +1 -1
- package/lib/cjs/structured-output/carousel.d.ts +9 -9
- package/lib/cjs/structured-output/carousel.js +1 -1
- package/lib/cjs/structured-output/carousel.js.map +1 -1
- package/lib/cjs/structured-output/index.d.ts +36 -18
- package/lib/cjs/structured-output/text-with-buttons.d.ts +19 -5
- package/lib/cjs/structured-output/text-with-buttons.js +3 -1
- package/lib/cjs/structured-output/text-with-buttons.js.map +1 -1
- package/lib/cjs/tools/index.d.ts +1 -0
- package/lib/cjs/tools/index.js +3 -1
- package/lib/cjs/tools/index.js.map +1 -1
- package/lib/cjs/tools/retrieve-knowledge.d.ts +2 -0
- package/lib/cjs/tools/retrieve-knowledge.js +25 -0
- package/lib/cjs/tools/retrieve-knowledge.js.map +1 -0
- package/lib/cjs/types.d.ts +7 -17
- package/lib/esm/agent-builder.d.ts +1 -1
- package/lib/esm/agent-builder.js +14 -4
- package/lib/esm/agent-builder.js.map +1 -1
- package/lib/esm/hubtype-api-client.d.ts +1 -0
- package/lib/esm/hubtype-api-client.js +19 -1
- package/lib/esm/hubtype-api-client.js.map +1 -1
- package/lib/esm/index.d.ts +2 -2
- package/lib/esm/index.js +3 -1
- package/lib/esm/index.js.map +1 -1
- package/lib/esm/structured-output/carousel.d.ts +9 -9
- package/lib/esm/structured-output/carousel.js +1 -1
- package/lib/esm/structured-output/carousel.js.map +1 -1
- package/lib/esm/structured-output/index.d.ts +36 -18
- package/lib/esm/structured-output/text-with-buttons.d.ts +19 -5
- package/lib/esm/structured-output/text-with-buttons.js +3 -1
- package/lib/esm/structured-output/text-with-buttons.js.map +1 -1
- package/lib/esm/tools/index.d.ts +1 -0
- package/lib/esm/tools/index.js +1 -0
- package/lib/esm/tools/index.js.map +1 -1
- package/lib/esm/tools/retrieve-knowledge.d.ts +2 -0
- package/lib/esm/tools/retrieve-knowledge.js +22 -0
- package/lib/esm/tools/retrieve-knowledge.js.map +1 -0
- package/lib/esm/types.d.ts +7 -17
- package/package.json +4 -4
- package/src/agent-builder.ts +23 -5
- package/src/hubtype-api-client.ts +22 -1
- package/src/index.ts +5 -3
- package/src/structured-output/carousel.ts +1 -1
- package/src/structured-output/text-with-buttons.ts +5 -1
- package/src/tools/index.ts +1 -0
- package/src/tools/retrieve-knowledge.ts +28 -0
- package/src/types.ts +25 -16
|
@@ -4,7 +4,7 @@ export declare class AIAgentBuilder {
|
|
|
4
4
|
private instructions;
|
|
5
5
|
private tools;
|
|
6
6
|
private inputGuardrails;
|
|
7
|
-
constructor(name: string, instructions: string, tools: Tool[], contactInfo: ContactInfo, inputGuardrailRules: GuardrailRule[]);
|
|
7
|
+
constructor(name: string, instructions: string, tools: Tool[], contactInfo: ContactInfo, inputGuardrailRules: GuardrailRule[], sourceIds: string[]);
|
|
8
8
|
build(): AIAgent;
|
|
9
9
|
private addExtraInstructions;
|
|
10
10
|
private getContactInfoInstructions;
|
package/lib/cjs/agent-builder.js
CHANGED
|
@@ -6,10 +6,10 @@ const guardrails_1 = require("./guardrails");
|
|
|
6
6
|
const structured_output_1 = require("./structured-output");
|
|
7
7
|
const tools_1 = require("./tools");
|
|
8
8
|
class AIAgentBuilder {
|
|
9
|
-
constructor(name, instructions, tools, contactInfo, inputGuardrailRules) {
|
|
9
|
+
constructor(name, instructions, tools, contactInfo, inputGuardrailRules, sourceIds) {
|
|
10
10
|
this.name = name;
|
|
11
11
|
this.instructions = this.addExtraInstructions(instructions, contactInfo);
|
|
12
|
-
this.tools = this.addHubtypeTools(tools);
|
|
12
|
+
this.tools = this.addHubtypeTools(tools, sourceIds);
|
|
13
13
|
this.inputGuardrails = [];
|
|
14
14
|
if (inputGuardrailRules.length > 0) {
|
|
15
15
|
const inputGuardrail = (0, guardrails_1.createInputGuardrail)(inputGuardrailRules);
|
|
@@ -17,6 +17,11 @@ class AIAgentBuilder {
|
|
|
17
17
|
}
|
|
18
18
|
}
|
|
19
19
|
build() {
|
|
20
|
+
const modelSettings = {};
|
|
21
|
+
if (this.tools.includes(tools_1.retrieveKnowledge)) {
|
|
22
|
+
// With this line, we force the agent to use the retrieve_knowledge tool
|
|
23
|
+
modelSettings.toolChoice = tools_1.retrieveKnowledge.name;
|
|
24
|
+
}
|
|
20
25
|
return new agents_1.Agent({
|
|
21
26
|
name: this.name,
|
|
22
27
|
instructions: this.instructions,
|
|
@@ -24,6 +29,7 @@ class AIAgentBuilder {
|
|
|
24
29
|
outputType: structured_output_1.OutputSchema,
|
|
25
30
|
inputGuardrails: this.inputGuardrails,
|
|
26
31
|
outputGuardrails: [],
|
|
32
|
+
modelSettings,
|
|
27
33
|
});
|
|
28
34
|
}
|
|
29
35
|
addExtraInstructions(initialInstructions, contactInfo) {
|
|
@@ -43,6 +49,7 @@ class AIAgentBuilder {
|
|
|
43
49
|
const metadata = `Current Date: ${new Date().toISOString()}`;
|
|
44
50
|
return `<metadata>\n${metadata}\n</metadata>`;
|
|
45
51
|
}
|
|
52
|
+
// TODO: Review in the future if the model works better without this instruction
|
|
46
53
|
getOutputInstructions() {
|
|
47
54
|
const example = {
|
|
48
55
|
messages: [
|
|
@@ -57,8 +64,11 @@ class AIAgentBuilder {
|
|
|
57
64
|
const output = `Return a JSON that follows the output schema provided. Never return multiple output schemas concatenated by a line break.\n<example>\n${JSON.stringify(example)}\n</example>`;
|
|
58
65
|
return `<output>\n${output}\n</output>`;
|
|
59
66
|
}
|
|
60
|
-
addHubtypeTools(tools) {
|
|
67
|
+
addHubtypeTools(tools, sourceIds) {
|
|
61
68
|
const hubtypeTools = [...tools_1.mandatoryTools];
|
|
69
|
+
if (sourceIds.length > 0) {
|
|
70
|
+
hubtypeTools.push(tools_1.retrieveKnowledge);
|
|
71
|
+
}
|
|
62
72
|
return [...hubtypeTools, ...tools];
|
|
63
73
|
}
|
|
64
74
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agent-builder.js","sourceRoot":"","sources":["../../src/agent-builder.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"agent-builder.js","sourceRoot":"","sources":["../../src/agent-builder.ts"],"names":[],"mappings":";;;AAAA,2CAAqE;AAErE,6CAAmD;AACnD,2DAAkD;AAClD,mCAA2D;AAG3D,MAAa,cAAc;IAMzB,YACE,IAAY,EACZ,YAAoB,EACpB,KAAa,EACb,WAAwB,EACxB,mBAAoC,EACpC,SAAmB;QAEnB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAA;QAChB,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC,oBAAoB,CAAC,YAAY,EAAE,WAAW,CAAC,CAAA;QACxE,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,eAAe,CAAC,KAAK,EAAE,SAAS,CAAC,CAAA;QACnD,IAAI,CAAC,eAAe,GAAG,EAAE,CAAA;QACzB,IAAI,mBAAmB,CAAC,MAAM,GAAG,CAAC,EAAE;YAClC,MAAM,cAAc,GAAG,IAAA,iCAAoB,EAAC,mBAAmB,CAAC,CAAA;YAChE,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,cAAc,CAAC,CAAA;SAC1C;IACH,CAAC;IAED,KAAK;QACH,MAAM,aAAa,GAAkB,EAAE,CAAA;QAEvC,IAAI,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,yBAAiB,CAAC,EAAE;YAC1C,wEAAwE;YACxE,aAAa,CAAC,UAAU,GAAG,yBAAiB,CAAC,IAAI,CAAA;SAClD;QAED,OAAO,IAAI,c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aACF;SACF,CAAA;QACD,MAAM,MAAM,GAAG,yIAAyI,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,cAAc,CAAA;QAE7L,OAAO,aAAa,MAAM,aAAa,CAAA;IACzC,CAAC;IAEO,eAAe,CAAC,KAAa,EAAE,SAAmB;QACxD,MAAM,YAAY,GAAW,CAAC,GAAG,sBAAc,CAAC,CAAA;QAChD,IAAI,SAAS,CAAC,MAAM,GAAG,CAAC,EAAE;YACxB,YAAY,CAAC,IAAI,CAAC,yBAAiB,CAAC,CAAA;SACrC;QAED,OAAO,CAAC,GAAG,YAAY,EAAE,GAAG,KAAK,CAAC,CAAA;IACpC,CAAC;CACF;AA9FD,wCA8FC"}
|
|
@@ -3,6 +3,7 @@ import { AgenticInputMessage } from './types';
|
|
|
3
3
|
export declare class HubtypeApiClient {
|
|
4
4
|
private readonly authToken;
|
|
5
5
|
constructor(authToken: string);
|
|
6
|
+
retrieveSimilarChunks(query: string, sources: string[]): Promise<string[]>;
|
|
6
7
|
getLocalMessages(maxMemoryLength: number): Promise<AgenticInputMessage[]>;
|
|
7
8
|
getMessages(request: BotContext, maxMemoryLength: number): Promise<AgenticInputMessage[]>;
|
|
8
9
|
private formatMessage;
|
|
@@ -8,9 +8,27 @@ class HubtypeApiClient {
|
|
|
8
8
|
constructor(authToken) {
|
|
9
9
|
this.authToken = authToken;
|
|
10
10
|
}
|
|
11
|
+
retrieveSimilarChunks(query, sources) {
|
|
12
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
13
|
+
const url = `${constants_1.HUBTYPE_API_URL}/external/v1/ai/knowledge_base/similar_chunks/`;
|
|
14
|
+
const headers = {
|
|
15
|
+
'Content-Type': 'application/json',
|
|
16
|
+
Authorization: `Bearer ${this.authToken}`,
|
|
17
|
+
};
|
|
18
|
+
const params = {
|
|
19
|
+
query,
|
|
20
|
+
source_ids: sources,
|
|
21
|
+
num_chunks: 5,
|
|
22
|
+
};
|
|
23
|
+
const response = yield axios_1.default.post(url, params, { headers });
|
|
24
|
+
return response.data.chunks.map((chunk) => chunk.text);
|
|
25
|
+
});
|
|
26
|
+
}
|
|
11
27
|
getLocalMessages(maxMemoryLength) {
|
|
12
28
|
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
13
|
-
const localBotonicState =
|
|
29
|
+
const localBotonicState = typeof globalThis !== 'undefined' && globalThis.localStorage
|
|
30
|
+
? globalThis.localStorage.getItem('botonicState')
|
|
31
|
+
: null;
|
|
14
32
|
const botonicState = JSON.parse(localBotonicState || '{}');
|
|
15
33
|
const messages = botonicState.messages;
|
|
16
34
|
const filteredMessages = messages
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hubtype-api-client.js","sourceRoot":"","sources":["../../src/hubtype-api-client.ts"],"names":[],"mappings":";;;;AAEA,0DAAyB;AAEzB,2CAA6C;AAe7C,MAAa,gBAAgB;IAG3B,YAAY,SAAiB;QAC3B,IAAI,CAAC,SAAS,GAAG,SAAS,CAAA;IAC5B,CAAC;IAEK,gBAAgB,CACpB,eAAuB;;YAEvB,MAAM,iBAAiB,
|
|
1
|
+
{"version":3,"file":"hubtype-api-client.js","sourceRoot":"","sources":["../../src/hubtype-api-client.ts"],"names":[],"mappings":";;;;AAEA,0DAAyB;AAEzB,2CAA6C;AAe7C,MAAa,gBAAgB;IAG3B,YAAY,SAAiB;QAC3B,IAAI,CAAC,SAAS,GAAG,SAAS,CAAA;IAC5B,CAAC;IAEK,qBAAqB,CACzB,KAAa,EACb,OAAiB;;YAEjB,MAAM,GAAG,GAAG,GAAG,2BAAe,gDAAgD,CAAA;YAC9E,MAAM,OAAO,GAAG;gBACd,cAAc,EAAE,kBAAkB;gBAClC,aAAa,EAAE,UAAU,IAAI,CAAC,SAAS,EAAE;aAC1C,CAAA;YACD,MAAM,MAAM,GAAG;gBACb,KAAK;gBACL,UAAU,EAAE,OAAO;gBACnB,UAAU,EAAE,CAAC;aACd,CAAA;YACD,MAAM,QAAQ,GAAG,MAAM,eAA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SAAS,EAAE;aAC1C,CAAA;YACD,MAAM,MAAM,GAAG;gBACb,eAAe,EAAE,OAAO,CAAC,KAAK,CAAC,UAAU;gBACzC,YAAY,EAAE,eAAe;aAC9B,CAAA;YAED,IAAI;gBACF,MAAM,QAAQ,GAAG,MAAM,eAAK,CAAC,GAAG,CAAiC,GAAG,EAAE;oBACpE,OAAO;oBACP,MAAM;iBACP,CAAC,CAAA;gBACF,MAAM,QAAQ,GAAG,QAAQ,CAAC,IAAI,CAAC,QAAQ,CAAA;gBACvC,OAAO,QAAQ,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE,CAAC,IAAI,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC,CAAA;aAC5D;YAAC,OAAO,KAAK,EAAE;gBACd,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,CAAA;gBACpB,MAAM,IAAI,KAAK,CAAC,qCAAqC,CAAC,CAAA;aACvD;QACH,CAAC;KAAA;IAEO,aAAa,CAAC,OAAuB;QAC3C,IAAI,OAAO,CAAC,IAAI,KAAK,MAAM,EAAE;YAC3B,OAAO;gBACL,OAAO,EAAE,OAAO,CAAC,OAAO;gBACxB,IAAI,EAAE,MAAM;aACb,CAAA;SACF;aAAM,IAAI,OAAO,CAAC,IAAI,KAAK,WAAW,EAAE;YACvC,OAAO;gBACL,IAAI,EAAE,WAAW;gBACjB,OAAO,EAAE;oBACP;wBACE,IAAI,EAAE,aAAa;wBACnB,IAAI,EAAE,OAAO,CAAC,OAAO;qBACtB;iBACF;gBACD,MAAM,EAAE,WAAW;aACpB,CAAA;SACF;aAAM;YACL,MAAM,IAAI,KAAK,CAAC,sBAAsB,CAAC,CAAA;SACxC;IACH,CAAC;CACF;AA5FD,4CA4FC"}
|
package/lib/cjs/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { BotContext, Plugin } from '@botonic/core';
|
|
2
|
-
import {
|
|
1
|
+
import { AiAgentArgs, BotContext, Plugin } from '@botonic/core';
|
|
2
|
+
import { CustomTool, InferenceResponse, PluginAiAgentOptions } from './types';
|
|
3
3
|
export default class BotonicPluginAiAgents implements Plugin {
|
|
4
4
|
private readonly authToken?;
|
|
5
5
|
toolDefinitions: CustomTool[];
|
package/lib/cjs/index.js
CHANGED
|
@@ -26,10 +26,12 @@ class BotonicPluginAiAgents {
|
|
|
26
26
|
throw new Error('Auth token is required');
|
|
27
27
|
}
|
|
28
28
|
const tools = this.buildTools(((_a = aiAgentArgs.activeTools) === null || _a === void 0 ? void 0 : _a.map(tool => tool.name)) || []);
|
|
29
|
-
const agent = new agent_builder_1.AIAgentBuilder(aiAgentArgs.name, aiAgentArgs.instructions, tools, request.session.user.contact_info || {}, aiAgentArgs.inputGuardrailRules || []).build();
|
|
29
|
+
const agent = new agent_builder_1.AIAgentBuilder(aiAgentArgs.name, aiAgentArgs.instructions, tools, request.session.user.contact_info || {}, aiAgentArgs.inputGuardrailRules || [], aiAgentArgs.sourceIds || []).build();
|
|
30
30
|
const messages = yield this.getMessages(request, authToken, constants_1.MAX_MEMORY_LENGTH);
|
|
31
31
|
const context = {
|
|
32
32
|
authToken,
|
|
33
|
+
request,
|
|
34
|
+
sources: aiAgentArgs.sourceIds || [],
|
|
33
35
|
};
|
|
34
36
|
const runner = new runner_1.AIAgentRunner(agent);
|
|
35
37
|
return yield runner.run(messages, context);
|
package/lib/cjs/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;AACA,2CAAqC;AAErC,mDAAgD;AAChD,2CAAuD;AACvD,6DAAuD;AACvD,qCAAsC;AACtC,qCAAwC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;AACA,2CAAqC;AAErC,mDAAgD;AAChD,2CAAuD;AACvD,6DAAuD;AACvD,qCAAsC;AACtC,qCAAwC;AAUxC,MAAqB,qBAAqB;IAIxC,YAAY,O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ACJ,CAAC;CACF;AAzFD,wCAyFC;AAED,kDAAuB"}
|
|
@@ -10,13 +10,13 @@ export declare const CarouselSchema: z.ZodObject<{
|
|
|
10
10
|
image: z.ZodString;
|
|
11
11
|
button: z.ZodObject<{
|
|
12
12
|
text: z.ZodString;
|
|
13
|
-
url: z.ZodString
|
|
13
|
+
url: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
14
14
|
}, "strip", z.ZodTypeAny, {
|
|
15
15
|
text: string;
|
|
16
|
-
url
|
|
16
|
+
url?: string | null | undefined;
|
|
17
17
|
}, {
|
|
18
18
|
text: string;
|
|
19
|
-
url
|
|
19
|
+
url?: string | null | undefined;
|
|
20
20
|
}>;
|
|
21
21
|
}, "strip", z.ZodTypeAny, {
|
|
22
22
|
title: string;
|
|
@@ -24,7 +24,7 @@ export declare const CarouselSchema: z.ZodObject<{
|
|
|
24
24
|
image: string;
|
|
25
25
|
button: {
|
|
26
26
|
text: string;
|
|
27
|
-
url
|
|
27
|
+
url?: string | null | undefined;
|
|
28
28
|
};
|
|
29
29
|
}, {
|
|
30
30
|
title: string;
|
|
@@ -32,7 +32,7 @@ export declare const CarouselSchema: z.ZodObject<{
|
|
|
32
32
|
image: string;
|
|
33
33
|
button: {
|
|
34
34
|
text: string;
|
|
35
|
-
url
|
|
35
|
+
url?: string | null | undefined;
|
|
36
36
|
};
|
|
37
37
|
}>, "many">;
|
|
38
38
|
}, "strip", z.ZodTypeAny, {
|
|
@@ -42,7 +42,7 @@ export declare const CarouselSchema: z.ZodObject<{
|
|
|
42
42
|
image: string;
|
|
43
43
|
button: {
|
|
44
44
|
text: string;
|
|
45
|
-
url
|
|
45
|
+
url?: string | null | undefined;
|
|
46
46
|
};
|
|
47
47
|
}[];
|
|
48
48
|
}, {
|
|
@@ -52,7 +52,7 @@ export declare const CarouselSchema: z.ZodObject<{
|
|
|
52
52
|
image: string;
|
|
53
53
|
button: {
|
|
54
54
|
text: string;
|
|
55
|
-
url
|
|
55
|
+
url?: string | null | undefined;
|
|
56
56
|
};
|
|
57
57
|
}[];
|
|
58
58
|
}>;
|
|
@@ -65,7 +65,7 @@ export declare const CarouselSchema: z.ZodObject<{
|
|
|
65
65
|
image: string;
|
|
66
66
|
button: {
|
|
67
67
|
text: string;
|
|
68
|
-
url
|
|
68
|
+
url?: string | null | undefined;
|
|
69
69
|
};
|
|
70
70
|
}[];
|
|
71
71
|
};
|
|
@@ -78,7 +78,7 @@ export declare const CarouselSchema: z.ZodObject<{
|
|
|
78
78
|
image: string;
|
|
79
79
|
button: {
|
|
80
80
|
text: string;
|
|
81
|
-
url
|
|
81
|
+
url?: string | null | undefined;
|
|
82
82
|
};
|
|
83
83
|
}[];
|
|
84
84
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"carousel.js","sourceRoot":"","sources":["../../../src/structured-output/carousel.ts"],"names":[],"mappings":";;;AACA,6BAAuB;AAIV,QAAA,cAAc,GAAG,OAAC;KAC5B,MAAM,CAAC;IACN,IAAI,EAAE,OAAC,CAAC,IAAI,CAAC,CAAC,UAAU,CAAC,CAAC;IAC1B,OAAO,EAAE,OAAC,CAAC,MAAM,CAAC;QAChB,QAAQ,EAAE,OAAC,CAAC,KAAK,CACf,OAAC,CAAC,MAAM,CAAC;YACP,KAAK,EAAE,OAAC,CAAC,MAAM,EAAE;YACjB,QAAQ,EAAE,OAAC,CAAC,MAAM,EAAE;YACpB,KAAK,EAAE,OAAC,CAAC,MAAM,EAAE;YACjB,MAAM,EAAE,OAAC,CAAC,MAAM,CAAC;gBACf,IAAI,EAAE,OAAC,CAAC,MAAM,EAAE;gBAChB,GAAG,EAAE,OAAC,CAAC,MAAM,EAAE;
|
|
1
|
+
{"version":3,"file":"carousel.js","sourceRoot":"","sources":["../../../src/structured-output/carousel.ts"],"names":[],"mappings":";;;AACA,6BAAuB;AAIV,QAAA,cAAc,GAAG,OAAC;KAC5B,MAAM,CAAC;IACN,IAAI,EAAE,OAAC,CAAC,IAAI,CAAC,CAAC,UAAU,CAAC,CAAC;IAC1B,OAAO,EAAE,OAAC,CAAC,MAAM,CAAC;QAChB,QAAQ,EAAE,OAAC,CAAC,KAAK,CACf,OAAC,CAAC,MAAM,CAAC;YACP,KAAK,EAAE,OAAC,CAAC,MAAM,EAAE;YACjB,QAAQ,EAAE,OAAC,CAAC,MAAM,EAAE;YACpB,KAAK,EAAE,OAAC,CAAC,MAAM,EAAE;YACjB,MAAM,EAAE,OAAC,CAAC,MAAM,CAAC;gBACf,IAAI,EAAE,OAAC,CAAC,MAAM,EAAE;gBAChB,GAAG,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE,CAAC,QAAQ,EAAE;aACtC,CAAC;SACH,CAAC,CACH;KACF,CAAC;CACH,CAAC;KACD,QAAQ,CAAC,kDAAkD,CAAC,CAAA"}
|
|
@@ -27,25 +27,39 @@ export declare const OutputSchema: z.ZodObject<{
|
|
|
27
27
|
type: z.ZodEnum<["textWithButtons"]>;
|
|
28
28
|
content: z.ZodObject<{
|
|
29
29
|
text: z.ZodString;
|
|
30
|
-
buttons: z.ZodArray<z.
|
|
30
|
+
buttons: z.ZodArray<z.ZodObject<{
|
|
31
|
+
text: z.ZodString;
|
|
32
|
+
}, "strip", z.ZodTypeAny, {
|
|
33
|
+
text: string;
|
|
34
|
+
}, {
|
|
35
|
+
text: string;
|
|
36
|
+
}>, "many">;
|
|
31
37
|
}, "strip", z.ZodTypeAny, {
|
|
32
38
|
text: string;
|
|
33
|
-
buttons:
|
|
39
|
+
buttons: {
|
|
40
|
+
text: string;
|
|
41
|
+
}[];
|
|
34
42
|
}, {
|
|
35
43
|
text: string;
|
|
36
|
-
buttons:
|
|
44
|
+
buttons: {
|
|
45
|
+
text: string;
|
|
46
|
+
}[];
|
|
37
47
|
}>;
|
|
38
48
|
}, "strip", z.ZodTypeAny, {
|
|
39
49
|
type: "textWithButtons";
|
|
40
50
|
content: {
|
|
41
51
|
text: string;
|
|
42
|
-
buttons:
|
|
52
|
+
buttons: {
|
|
53
|
+
text: string;
|
|
54
|
+
}[];
|
|
43
55
|
};
|
|
44
56
|
}, {
|
|
45
57
|
type: "textWithButtons";
|
|
46
58
|
content: {
|
|
47
59
|
text: string;
|
|
48
|
-
buttons:
|
|
60
|
+
buttons: {
|
|
61
|
+
text: string;
|
|
62
|
+
}[];
|
|
49
63
|
};
|
|
50
64
|
}>, z.ZodObject<{
|
|
51
65
|
type: z.ZodEnum<["carousel"]>;
|
|
@@ -56,13 +70,13 @@ export declare const OutputSchema: z.ZodObject<{
|
|
|
56
70
|
image: z.ZodString;
|
|
57
71
|
button: z.ZodObject<{
|
|
58
72
|
text: z.ZodString;
|
|
59
|
-
url: z.ZodString
|
|
73
|
+
url: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
60
74
|
}, "strip", z.ZodTypeAny, {
|
|
61
75
|
text: string;
|
|
62
|
-
url
|
|
76
|
+
url?: string | null | undefined;
|
|
63
77
|
}, {
|
|
64
78
|
text: string;
|
|
65
|
-
url
|
|
79
|
+
url?: string | null | undefined;
|
|
66
80
|
}>;
|
|
67
81
|
}, "strip", z.ZodTypeAny, {
|
|
68
82
|
title: string;
|
|
@@ -70,7 +84,7 @@ export declare const OutputSchema: z.ZodObject<{
|
|
|
70
84
|
image: string;
|
|
71
85
|
button: {
|
|
72
86
|
text: string;
|
|
73
|
-
url
|
|
87
|
+
url?: string | null | undefined;
|
|
74
88
|
};
|
|
75
89
|
}, {
|
|
76
90
|
title: string;
|
|
@@ -78,7 +92,7 @@ export declare const OutputSchema: z.ZodObject<{
|
|
|
78
92
|
image: string;
|
|
79
93
|
button: {
|
|
80
94
|
text: string;
|
|
81
|
-
url
|
|
95
|
+
url?: string | null | undefined;
|
|
82
96
|
};
|
|
83
97
|
}>, "many">;
|
|
84
98
|
}, "strip", z.ZodTypeAny, {
|
|
@@ -88,7 +102,7 @@ export declare const OutputSchema: z.ZodObject<{
|
|
|
88
102
|
image: string;
|
|
89
103
|
button: {
|
|
90
104
|
text: string;
|
|
91
|
-
url
|
|
105
|
+
url?: string | null | undefined;
|
|
92
106
|
};
|
|
93
107
|
}[];
|
|
94
108
|
}, {
|
|
@@ -98,7 +112,7 @@ export declare const OutputSchema: z.ZodObject<{
|
|
|
98
112
|
image: string;
|
|
99
113
|
button: {
|
|
100
114
|
text: string;
|
|
101
|
-
url
|
|
115
|
+
url?: string | null | undefined;
|
|
102
116
|
};
|
|
103
117
|
}[];
|
|
104
118
|
}>;
|
|
@@ -111,7 +125,7 @@ export declare const OutputSchema: z.ZodObject<{
|
|
|
111
125
|
image: string;
|
|
112
126
|
button: {
|
|
113
127
|
text: string;
|
|
114
|
-
url
|
|
128
|
+
url?: string | null | undefined;
|
|
115
129
|
};
|
|
116
130
|
}[];
|
|
117
131
|
};
|
|
@@ -124,7 +138,7 @@ export declare const OutputSchema: z.ZodObject<{
|
|
|
124
138
|
image: string;
|
|
125
139
|
button: {
|
|
126
140
|
text: string;
|
|
127
|
-
url
|
|
141
|
+
url?: string | null | undefined;
|
|
128
142
|
};
|
|
129
143
|
}[];
|
|
130
144
|
};
|
|
@@ -145,7 +159,7 @@ export declare const OutputSchema: z.ZodObject<{
|
|
|
145
159
|
image: string;
|
|
146
160
|
button: {
|
|
147
161
|
text: string;
|
|
148
|
-
url
|
|
162
|
+
url?: string | null | undefined;
|
|
149
163
|
};
|
|
150
164
|
}[];
|
|
151
165
|
};
|
|
@@ -160,7 +174,9 @@ export declare const OutputSchema: z.ZodObject<{
|
|
|
160
174
|
type: "textWithButtons";
|
|
161
175
|
content: {
|
|
162
176
|
text: string;
|
|
163
|
-
buttons:
|
|
177
|
+
buttons: {
|
|
178
|
+
text: string;
|
|
179
|
+
}[];
|
|
164
180
|
};
|
|
165
181
|
})[];
|
|
166
182
|
}, {
|
|
@@ -173,7 +189,7 @@ export declare const OutputSchema: z.ZodObject<{
|
|
|
173
189
|
image: string;
|
|
174
190
|
button: {
|
|
175
191
|
text: string;
|
|
176
|
-
url
|
|
192
|
+
url?: string | null | undefined;
|
|
177
193
|
};
|
|
178
194
|
}[];
|
|
179
195
|
};
|
|
@@ -188,7 +204,9 @@ export declare const OutputSchema: z.ZodObject<{
|
|
|
188
204
|
type: "textWithButtons";
|
|
189
205
|
content: {
|
|
190
206
|
text: string;
|
|
191
|
-
buttons:
|
|
207
|
+
buttons: {
|
|
208
|
+
text: string;
|
|
209
|
+
}[];
|
|
192
210
|
};
|
|
193
211
|
})[];
|
|
194
212
|
}>;
|
|
@@ -5,24 +5,38 @@ export declare const TextWithButtonsSchema: z.ZodObject<{
|
|
|
5
5
|
type: z.ZodEnum<["textWithButtons"]>;
|
|
6
6
|
content: z.ZodObject<{
|
|
7
7
|
text: z.ZodString;
|
|
8
|
-
buttons: z.ZodArray<z.
|
|
8
|
+
buttons: z.ZodArray<z.ZodObject<{
|
|
9
|
+
text: z.ZodString;
|
|
10
|
+
}, "strip", z.ZodTypeAny, {
|
|
11
|
+
text: string;
|
|
12
|
+
}, {
|
|
13
|
+
text: string;
|
|
14
|
+
}>, "many">;
|
|
9
15
|
}, "strip", z.ZodTypeAny, {
|
|
10
16
|
text: string;
|
|
11
|
-
buttons:
|
|
17
|
+
buttons: {
|
|
18
|
+
text: string;
|
|
19
|
+
}[];
|
|
12
20
|
}, {
|
|
13
21
|
text: string;
|
|
14
|
-
buttons:
|
|
22
|
+
buttons: {
|
|
23
|
+
text: string;
|
|
24
|
+
}[];
|
|
15
25
|
}>;
|
|
16
26
|
}, "strip", z.ZodTypeAny, {
|
|
17
27
|
type: "textWithButtons";
|
|
18
28
|
content: {
|
|
19
29
|
text: string;
|
|
20
|
-
buttons:
|
|
30
|
+
buttons: {
|
|
31
|
+
text: string;
|
|
32
|
+
}[];
|
|
21
33
|
};
|
|
22
34
|
}, {
|
|
23
35
|
type: "textWithButtons";
|
|
24
36
|
content: {
|
|
25
37
|
text: string;
|
|
26
|
-
buttons:
|
|
38
|
+
buttons: {
|
|
39
|
+
text: string;
|
|
40
|
+
}[];
|
|
27
41
|
};
|
|
28
42
|
}>;
|
|
@@ -8,7 +8,9 @@ exports.TextWithButtonsSchema = zod_1.default
|
|
|
8
8
|
type: zod_1.default.enum(['textWithButtons']),
|
|
9
9
|
content: zod_1.default.object({
|
|
10
10
|
text: zod_1.default.string(),
|
|
11
|
-
buttons: zod_1.default.array(zod_1.default.
|
|
11
|
+
buttons: zod_1.default.array(zod_1.default.object({
|
|
12
|
+
text: zod_1.default.string(),
|
|
13
|
+
})),
|
|
12
14
|
}),
|
|
13
15
|
})
|
|
14
16
|
.describe('A text message with buttons to allow the user to use quick replies');
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"text-with-buttons.js","sourceRoot":"","sources":["../../../src/structured-output/text-with-buttons.ts"],"names":[],"mappings":";;;;AACA,sDAAmB;AAIN,QAAA,qBAAqB,GAAG,aAAC;KACnC,MAAM,CAAC;IACN,IAAI,EAAE,aAAC,CAAC,IAAI,CAAC,CAAC,iBAAiB,CAAC,CAAC;IACjC,OAAO,EAAE,aAAC,CAAC,MAAM,CAAC;QAChB,IAAI,EAAE,aAAC,CAAC,MAAM,EAAE;QAChB,OAAO,EAAE,aAAC,CAAC,KAAK,CAAC,aAAC,CAAC,MAAM,EAAE,CAAC;
|
|
1
|
+
{"version":3,"file":"text-with-buttons.js","sourceRoot":"","sources":["../../../src/structured-output/text-with-buttons.ts"],"names":[],"mappings":";;;;AACA,sDAAmB;AAIN,QAAA,qBAAqB,GAAG,aAAC;KACnC,MAAM,CAAC;IACN,IAAI,EAAE,aAAC,CAAC,IAAI,CAAC,CAAC,iBAAiB,CAAC,CAAC;IACjC,OAAO,EAAE,aAAC,CAAC,MAAM,CAAC;QAChB,IAAI,EAAE,aAAC,CAAC,MAAM,EAAE;QAChB,OAAO,EAAE,aAAC,CAAC,KAAK,CACd,aAAC,CAAC,MAAM,CAAC;YACP,IAAI,EAAE,aAAC,CAAC,MAAM,EAAE;SACjB,CAAC,CACH;KACF,CAAC;CACH,CAAC;KACD,QAAQ,CACP,oEAAoE,CACrE,CAAA"}
|
package/lib/cjs/tools/index.d.ts
CHANGED
package/lib/cjs/tools/index.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.mandatoryTools = void 0;
|
|
3
|
+
exports.mandatoryTools = exports.retrieveKnowledge = void 0;
|
|
4
|
+
var retrieve_knowledge_1 = require("./retrieve-knowledge");
|
|
5
|
+
Object.defineProperty(exports, "retrieveKnowledge", { enumerable: true, get: function () { return retrieve_knowledge_1.retrieveKnowledge; } });
|
|
4
6
|
exports.mandatoryTools = [];
|
|
5
7
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/tools/index.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/tools/index.ts"],"names":[],"mappings":";;;AACA,2DAAwD;AAA/C,uHAAA,iBAAiB,OAAA;AAEb,QAAA,cAAc,GAAW,EAAE,CAAA"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.retrieveKnowledge = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const agents_1 = require("@openai/agents");
|
|
6
|
+
const zod_1 = require("zod");
|
|
7
|
+
const hubtype_api_client_1 = require("../hubtype-api-client");
|
|
8
|
+
exports.retrieveKnowledge = (0, agents_1.tool)({
|
|
9
|
+
name: 'retrieve_knowledge',
|
|
10
|
+
description: 'Consult the knowledge base for information before answering. Use this tool to make sure the information you provide is faithful.',
|
|
11
|
+
parameters: zod_1.z.object({
|
|
12
|
+
query: zod_1.z.string().describe('The query to search the knowledge base for'),
|
|
13
|
+
}),
|
|
14
|
+
execute: ({ query }, runContext) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
15
|
+
const context = runContext === null || runContext === void 0 ? void 0 : runContext.context;
|
|
16
|
+
if (!context) {
|
|
17
|
+
throw new Error('Context is required');
|
|
18
|
+
}
|
|
19
|
+
const sources = context.sources;
|
|
20
|
+
const client = new hubtype_api_client_1.HubtypeApiClient(context.authToken);
|
|
21
|
+
const chunks = yield client.retrieveSimilarChunks(query, sources);
|
|
22
|
+
return chunks;
|
|
23
|
+
}),
|
|
24
|
+
});
|
|
25
|
+
//# sourceMappingURL=retrieve-knowledge.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"retrieve-knowledge.js","sourceRoot":"","sources":["../../../src/tools/retrieve-knowledge.ts"],"names":[],"mappings":";;;;AAAA,2CAAiD;AACjD,6BAAuB;AAEvB,8DAAwD;AAG3C,QAAA,iBAAiB,GAAG,IAAA,aAAI,EAAoB;IACvD,IAAI,EAAE,oBAAoB;IAC1B,WAAW,EACT,kIAAkI;IACpI,UAAU,EAAE,OAAC,CAAC,MAAM,CAAC;QACnB,KAAK,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,4CAA4C,CAAC;KACzE,CAAC;IACF,OAAO,EAAE,CACP,EAAE,KAAK,EAAqB,EAC5B,UAAgC,EACb,EAAE;QACrB,MAAM,OAAO,GAAG,UAAU,aAAV,UAAU,uBAAV,UAAU,CAAE,OAAO,CAAA;QACnC,IAAI,CAAC,OAAO,EAAE;YACZ,MAAM,IAAI,KAAK,CAAC,qBAAqB,CAAC,CAAA;SACvC;QACD,MAAM,OAAO,GAAG,OAAO,CAAC,OAAO,CAAA;QAC/B,MAAM,MAAM,GAAG,IAAI,qCAAgB,CAAC,OAAO,CAAC,SAAS,CAAC,CAAA;QACtD,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,qBAAqB,CAAC,KAAK,EAAE,OAAO,CAAC,CAAA;QAEjE,OAAO,MAAM,CAAA;IACf,CAAC,CAAA;CACF,CAAC,CAAA"}
|
package/lib/cjs/types.d.ts
CHANGED
|
@@ -1,20 +1,18 @@
|
|
|
1
|
-
import { AgenticOutputMessage, InferenceResponse, RunResult } from '@botonic/core';
|
|
1
|
+
import { AgenticOutputMessage, AiAgentArgs, BotContext, GuardrailRule, InferenceResponse, ResolvedPlugins, RunResult } from '@botonic/core';
|
|
2
2
|
import { Agent, AgentInputItem, RunContext as OpenAIRunContext, Tool as OpenAITool } from '@openai/agents';
|
|
3
3
|
import { ZodSchema } from 'zod';
|
|
4
4
|
import { OutputSchema } from './structured-output';
|
|
5
|
-
export interface Context {
|
|
5
|
+
export interface Context<TPlugins extends ResolvedPlugins = ResolvedPlugins, TExtraData = any> {
|
|
6
6
|
authToken: string;
|
|
7
|
+
request: BotContext<TPlugins, TExtraData>;
|
|
8
|
+
sources: string[];
|
|
7
9
|
}
|
|
8
|
-
export type RunContext = OpenAIRunContext<Context
|
|
10
|
+
export type RunContext<TPlugins extends ResolvedPlugins = ResolvedPlugins, TExtraData = any> = OpenAIRunContext<Context<TPlugins, TExtraData>>;
|
|
9
11
|
export interface CustomTool {
|
|
10
12
|
name: string;
|
|
11
13
|
description: string;
|
|
12
14
|
schema: ZodSchema;
|
|
13
|
-
func: (input?: any, runContext?: RunContext) => Promise<any>;
|
|
14
|
-
}
|
|
15
|
-
export interface GuardrailRule {
|
|
16
|
-
name: string;
|
|
17
|
-
description: string;
|
|
15
|
+
func: <TPlugins extends ResolvedPlugins = ResolvedPlugins, TExtraData = any>(input?: any, runContext?: RunContext<TPlugins, TExtraData>) => Promise<any>;
|
|
18
16
|
}
|
|
19
17
|
export type ContactInfo = Record<string, string>;
|
|
20
18
|
export type Tool = OpenAITool<Context>;
|
|
@@ -23,13 +21,5 @@ export interface PluginAiAgentOptions {
|
|
|
23
21
|
authToken?: string;
|
|
24
22
|
customTools?: CustomTool[];
|
|
25
23
|
}
|
|
26
|
-
export interface AiAgentArgs {
|
|
27
|
-
name: string;
|
|
28
|
-
instructions: string;
|
|
29
|
-
activeTools?: {
|
|
30
|
-
name: string;
|
|
31
|
-
}[];
|
|
32
|
-
inputGuardrailRules?: GuardrailRule[];
|
|
33
|
-
}
|
|
34
24
|
export type AgenticInputMessage = AgentInputItem;
|
|
35
|
-
export
|
|
25
|
+
export { AgenticOutputMessage, AiAgentArgs, GuardrailRule, InferenceResponse, RunResult, };
|
|
@@ -4,7 +4,7 @@ export declare class AIAgentBuilder {
|
|
|
4
4
|
private instructions;
|
|
5
5
|
private tools;
|
|
6
6
|
private inputGuardrails;
|
|
7
|
-
constructor(name: string, instructions: string, tools: Tool[], contactInfo: ContactInfo, inputGuardrailRules: GuardrailRule[]);
|
|
7
|
+
constructor(name: string, instructions: string, tools: Tool[], contactInfo: ContactInfo, inputGuardrailRules: GuardrailRule[], sourceIds: string[]);
|
|
8
8
|
build(): AIAgent;
|
|
9
9
|
private addExtraInstructions;
|
|
10
10
|
private getContactInfoInstructions;
|
package/lib/esm/agent-builder.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { Agent } from '@openai/agents';
|
|
2
2
|
import { createInputGuardrail } from './guardrails';
|
|
3
3
|
import { OutputSchema } from './structured-output';
|
|
4
|
-
import { mandatoryTools } from './tools';
|
|
4
|
+
import { mandatoryTools, retrieveKnowledge } from './tools';
|
|
5
5
|
export class AIAgentBuilder {
|
|
6
|
-
constructor(name, instructions, tools, contactInfo, inputGuardrailRules) {
|
|
6
|
+
constructor(name, instructions, tools, contactInfo, inputGuardrailRules, sourceIds) {
|
|
7
7
|
this.name = name;
|
|
8
8
|
this.instructions = this.addExtraInstructions(instructions, contactInfo);
|
|
9
|
-
this.tools = this.addHubtypeTools(tools);
|
|
9
|
+
this.tools = this.addHubtypeTools(tools, sourceIds);
|
|
10
10
|
this.inputGuardrails = [];
|
|
11
11
|
if (inputGuardrailRules.length > 0) {
|
|
12
12
|
const inputGuardrail = createInputGuardrail(inputGuardrailRules);
|
|
@@ -14,6 +14,11 @@ export class AIAgentBuilder {
|
|
|
14
14
|
}
|
|
15
15
|
}
|
|
16
16
|
build() {
|
|
17
|
+
const modelSettings = {};
|
|
18
|
+
if (this.tools.includes(retrieveKnowledge)) {
|
|
19
|
+
// With this line, we force the agent to use the retrieve_knowledge tool
|
|
20
|
+
modelSettings.toolChoice = retrieveKnowledge.name;
|
|
21
|
+
}
|
|
17
22
|
return new Agent({
|
|
18
23
|
name: this.name,
|
|
19
24
|
instructions: this.instructions,
|
|
@@ -21,6 +26,7 @@ export class AIAgentBuilder {
|
|
|
21
26
|
outputType: OutputSchema,
|
|
22
27
|
inputGuardrails: this.inputGuardrails,
|
|
23
28
|
outputGuardrails: [],
|
|
29
|
+
modelSettings,
|
|
24
30
|
});
|
|
25
31
|
}
|
|
26
32
|
addExtraInstructions(initialInstructions, contactInfo) {
|
|
@@ -40,6 +46,7 @@ export class AIAgentBuilder {
|
|
|
40
46
|
const metadata = `Current Date: ${new Date().toISOString()}`;
|
|
41
47
|
return `<metadata>\n${metadata}\n</metadata>`;
|
|
42
48
|
}
|
|
49
|
+
// TODO: Review in the future if the model works better without this instruction
|
|
43
50
|
getOutputInstructions() {
|
|
44
51
|
const example = {
|
|
45
52
|
messages: [
|
|
@@ -54,8 +61,11 @@ export class AIAgentBuilder {
|
|
|
54
61
|
const output = `Return a JSON that follows the output schema provided. Never return multiple output schemas concatenated by a line break.\n<example>\n${JSON.stringify(example)}\n</example>`;
|
|
55
62
|
return `<output>\n${output}\n</output>`;
|
|
56
63
|
}
|
|
57
|
-
addHubtypeTools(tools) {
|
|
64
|
+
addHubtypeTools(tools, sourceIds) {
|
|
58
65
|
const hubtypeTools = [...mandatoryTools];
|
|
66
|
+
if (sourceIds.length > 0) {
|
|
67
|
+
hubtypeTools.push(retrieveKnowledge);
|
|
68
|
+
}
|
|
59
69
|
return [...hubtypeTools, ...tools];
|
|
60
70
|
}
|
|
61
71
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agent-builder.js","sourceRoot":"","sources":["../../src/agent-builder.ts"],"names":[],"mappings":"AAA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