@botonic/plugin-ai-agents 0.43.0 → 0.44.0-alpha.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/lib/cjs/agent-builder.d.ts +1 -1
- package/lib/cjs/agent-builder.js +8 -7
- package/lib/cjs/agent-builder.js.map +1 -1
- package/lib/cjs/guardrails/input.js +4 -6
- package/lib/cjs/guardrails/input.js.map +1 -1
- package/lib/cjs/hubtype-api-client.js +94 -97
- package/lib/cjs/hubtype-api-client.js.map +1 -1
- package/lib/cjs/index.js +63 -70
- package/lib/cjs/index.js.map +1 -1
- package/lib/cjs/openai.js +3 -4
- package/lib/cjs/openai.js.map +1 -1
- package/lib/cjs/runner.js +39 -41
- package/lib/cjs/runner.js.map +1 -1
- package/lib/cjs/tools/retrieve-knowledge.js +4 -5
- package/lib/cjs/tools/retrieve-knowledge.js.map +1 -1
- package/lib/esm/agent-builder.d.ts +1 -1
- package/lib/esm/agent-builder.js +27 -22
- package/lib/esm/agent-builder.js.map +1 -1
- package/lib/esm/constants.js +13 -10
- package/lib/esm/constants.js.map +1 -1
- package/lib/esm/guardrails/index.js +4 -1
- package/lib/esm/guardrails/index.js.map +1 -1
- package/lib/esm/guardrails/input.js +11 -9
- package/lib/esm/guardrails/input.js.map +1 -1
- package/lib/esm/hubtype-api-client.js +102 -101
- package/lib/esm/hubtype-api-client.js.map +1 -1
- package/lib/esm/index.js +76 -80
- package/lib/esm/index.js.map +1 -1
- package/lib/esm/openai.js +24 -20
- package/lib/esm/openai.js.map +1 -1
- package/lib/esm/runner.js +47 -45
- package/lib/esm/runner.js.map +1 -1
- package/lib/esm/structured-output/carousel.js +15 -12
- package/lib/esm/structured-output/carousel.js.map +1 -1
- package/lib/esm/structured-output/exit.js +7 -3
- package/lib/esm/structured-output/exit.js.map +1 -1
- package/lib/esm/structured-output/index.js +10 -7
- package/lib/esm/structured-output/index.js.map +1 -1
- package/lib/esm/structured-output/text-with-buttons.js +12 -8
- package/lib/esm/structured-output/text-with-buttons.js.map +1 -1
- package/lib/esm/structured-output/text.js +8 -5
- package/lib/esm/structured-output/text.js.map +1 -1
- package/lib/esm/tools/index.js +6 -2
- package/lib/esm/tools/index.js.map +1 -1
- package/lib/esm/tools/retrieve-knowledge.js +14 -12
- package/lib/esm/tools/retrieve-knowledge.js.map +1 -1
- package/lib/esm/types.js +2 -1
- package/package.json +5 -5
- package/src/agent-builder.ts +12 -8
- package/src/index.ts +2 -3
package/lib/esm/runner.js
CHANGED
|
@@ -1,57 +1,58 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AIAgentRunner = void 0;
|
|
4
|
+
const agents_1 = require("@openai/agents");
|
|
5
|
+
const tools_1 = require("./tools");
|
|
6
|
+
class AIAgentRunner {
|
|
5
7
|
constructor(agent) {
|
|
6
8
|
this.agent = agent;
|
|
7
9
|
}
|
|
8
|
-
run(messages, context) {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
10
|
+
async run(messages, context) {
|
|
11
|
+
try {
|
|
12
|
+
const runner = new agents_1.Runner({
|
|
13
|
+
modelSettings: { temperature: 0 },
|
|
14
|
+
});
|
|
15
|
+
// Type assertion to bypass strict type checking - the actual return type from runner.run()
|
|
16
|
+
// doesn't perfectly match our interface, but the properties we access are compatible
|
|
17
|
+
const result = (await runner.run(this.agent, messages, {
|
|
18
|
+
context,
|
|
19
|
+
}));
|
|
20
|
+
const outputMessages = result.finalOutput?.messages || [];
|
|
21
|
+
const hasExit = outputMessages.length === 0 ||
|
|
22
|
+
outputMessages.some(message => message.type === 'exit');
|
|
23
|
+
const toolsExecuted = this.getToolsExecuted(result, context);
|
|
24
|
+
return {
|
|
25
|
+
messages: hasExit
|
|
26
|
+
? []
|
|
27
|
+
: outputMessages.filter(message => message.type !== 'exit'),
|
|
28
|
+
toolsExecuted,
|
|
29
|
+
exit: hasExit,
|
|
30
|
+
memoryLength: messages.length,
|
|
31
|
+
error: false,
|
|
32
|
+
inputGuardrailsTriggered: [],
|
|
33
|
+
outputGuardrailsTriggered: [],
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
catch (error) {
|
|
37
|
+
if (error instanceof agents_1.InputGuardrailTripwireTriggered) {
|
|
24
38
|
return {
|
|
25
|
-
messages:
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
exit: hasExit,
|
|
30
|
-
memoryLength: messages.length,
|
|
39
|
+
messages: [],
|
|
40
|
+
memoryLength: 0,
|
|
41
|
+
toolsExecuted: [],
|
|
42
|
+
exit: true,
|
|
31
43
|
error: false,
|
|
32
|
-
inputGuardrailsTriggered:
|
|
44
|
+
inputGuardrailsTriggered: error.result.output.outputInfo,
|
|
33
45
|
outputGuardrailsTriggered: [],
|
|
34
46
|
};
|
|
35
47
|
}
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
return {
|
|
39
|
-
messages: [],
|
|
40
|
-
memoryLength: 0,
|
|
41
|
-
toolsExecuted: [],
|
|
42
|
-
exit: true,
|
|
43
|
-
error: false,
|
|
44
|
-
inputGuardrailsTriggered: error.result.output.outputInfo,
|
|
45
|
-
outputGuardrailsTriggered: [],
|
|
46
|
-
};
|
|
47
|
-
}
|
|
48
|
-
throw error;
|
|
49
|
-
}
|
|
50
|
-
});
|
|
48
|
+
throw error;
|
|
49
|
+
}
|
|
51
50
|
}
|
|
52
51
|
getToolsExecuted(result, context) {
|
|
53
|
-
|
|
54
|
-
|
|
52
|
+
return (result.newItems
|
|
53
|
+
?.filter(item => item instanceof agents_1.RunToolCallItem)
|
|
54
|
+
.map((item) => this.getToolExecutionInfo(item, context))
|
|
55
|
+
.filter((toolExecution) => toolExecution.toolName !== '') || []);
|
|
55
56
|
}
|
|
56
57
|
getToolExecutionInfo(item, context) {
|
|
57
58
|
if (item.rawItem.type !== 'function_call') {
|
|
@@ -62,7 +63,7 @@ export class AIAgentRunner {
|
|
|
62
63
|
}
|
|
63
64
|
const toolName = item.rawItem.name;
|
|
64
65
|
const toolArguments = this.getSafeToolArguments(item.rawItem.arguments);
|
|
65
|
-
if (toolName === retrieveKnowledge.name) {
|
|
66
|
+
if (toolName === tools_1.retrieveKnowledge.name) {
|
|
66
67
|
return {
|
|
67
68
|
toolName,
|
|
68
69
|
toolArguments,
|
|
@@ -84,4 +85,5 @@ export class AIAgentRunner {
|
|
|
84
85
|
}
|
|
85
86
|
}
|
|
86
87
|
}
|
|
88
|
+
exports.AIAgentRunner = AIAgentRunner;
|
|
87
89
|
//# sourceMappingURL=runner.js.map
|
package/lib/esm/runner.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runner.js","sourceRoot":"","sources":["../../src/runner.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"runner.js","sourceRoot":"","sources":["../../src/runner.ts"],"names":[],"mappings":"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"}
|
|
@@ -1,16 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CarouselSchema = void 0;
|
|
4
|
+
const zod_1 = require("zod");
|
|
5
|
+
exports.CarouselSchema = zod_1.z
|
|
3
6
|
.object({
|
|
4
|
-
type: z.enum(['carousel']),
|
|
5
|
-
content: z.object({
|
|
6
|
-
text: z.string().nullable().optional(),
|
|
7
|
-
elements: z.array(z.object({
|
|
8
|
-
title: z.string(),
|
|
9
|
-
subtitle: z.string(),
|
|
10
|
-
image: z.string(),
|
|
11
|
-
button: z.object({
|
|
12
|
-
text: z.string(),
|
|
13
|
-
url: z.string().nullable().optional(),
|
|
7
|
+
type: zod_1.z.enum(['carousel']),
|
|
8
|
+
content: zod_1.z.object({
|
|
9
|
+
text: zod_1.z.string().nullable().optional(),
|
|
10
|
+
elements: zod_1.z.array(zod_1.z.object({
|
|
11
|
+
title: zod_1.z.string(),
|
|
12
|
+
subtitle: zod_1.z.string(),
|
|
13
|
+
image: zod_1.z.string(),
|
|
14
|
+
button: zod_1.z.object({
|
|
15
|
+
text: zod_1.z.string(),
|
|
16
|
+
url: zod_1.z.string().nullable().optional(),
|
|
14
17
|
}),
|
|
15
18
|
})),
|
|
16
19
|
}),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"carousel.js","sourceRoot":"","sources":["../../../src/structured-output/carousel.ts"],"names":[],"mappings":"AACA,
|
|
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,IAAI,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE,CAAC,QAAQ,EAAE;QACtC,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"}
|
|
@@ -1,7 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ExitSchema = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const zod_1 = tslib_1.__importDefault(require("zod"));
|
|
6
|
+
exports.ExitSchema = zod_1.default
|
|
3
7
|
.object({
|
|
4
|
-
type:
|
|
8
|
+
type: zod_1.default.enum(['exit']),
|
|
5
9
|
})
|
|
6
10
|
.describe('An exit message. This message should only be used to exit the agent due to out of context or the user asking to exit the conversation');
|
|
7
11
|
//# sourceMappingURL=exit.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"exit.js","sourceRoot":"","sources":["../../../src/structured-output/exit.ts"],"names":[],"mappings":"AACA,
|
|
1
|
+
{"version":3,"file":"exit.js","sourceRoot":"","sources":["../../../src/structured-output/exit.ts"],"names":[],"mappings":";;;;AACA,sDAAmB;AAIN,QAAA,UAAU,GAAG,aAAC;KACxB,MAAM,CAAC;IACN,IAAI,EAAE,aAAC,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,CAAC;CACvB,CAAC;KACD,QAAQ,CACP,uIAAuI,CACxI,CAAA"}
|
|
@@ -1,11 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.OutputSchema = void 0;
|
|
4
|
+
const zod_1 = require("zod");
|
|
5
|
+
const carousel_1 = require("./carousel");
|
|
6
|
+
const exit_1 = require("./exit");
|
|
7
|
+
const text_1 = require("./text");
|
|
8
|
+
const text_with_buttons_1 = require("./text-with-buttons");
|
|
9
|
+
exports.OutputSchema = zod_1.z
|
|
7
10
|
.object({
|
|
8
|
-
messages: z.array(z.union([TextSchema, TextWithButtonsSchema, CarouselSchema, ExitSchema])),
|
|
11
|
+
messages: zod_1.z.array(zod_1.z.union([text_1.TextSchema, text_with_buttons_1.TextWithButtonsSchema, carousel_1.CarouselSchema, exit_1.ExitSchema])),
|
|
9
12
|
})
|
|
10
13
|
.describe('The messages to be sent to the user');
|
|
11
14
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/structured-output/index.ts"],"names":[],"mappings":"AACA,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/structured-output/index.ts"],"names":[],"mappings":";;;AACA,6BAAuB;AAEvB,yCAA2C;AAC3C,iCAAmC;AACnC,iCAAmC;AACnC,2DAA2D;AAM9C,QAAA,YAAY,GAAG,OAAC;KAC1B,MAAM,CAAC;IACN,QAAQ,EAAE,OAAC,CAAC,KAAK,CACf,OAAC,CAAC,KAAK,CAAC,CAAC,iBAAU,EAAE,yCAAqB,EAAE,yBAAc,EAAE,iBAAU,CAAC,CAAC,CACzE;CACF,CAAC;KACD,QAAQ,CAAC,qCAAqC,CAAC,CAAA"}
|
|
@@ -1,12 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TextWithButtonsSchema = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const zod_1 = tslib_1.__importDefault(require("zod"));
|
|
6
|
+
exports.TextWithButtonsSchema = zod_1.default
|
|
3
7
|
.object({
|
|
4
|
-
type:
|
|
5
|
-
content:
|
|
6
|
-
text:
|
|
7
|
-
buttons:
|
|
8
|
-
text:
|
|
9
|
-
url:
|
|
8
|
+
type: zod_1.default.enum(['textWithButtons']),
|
|
9
|
+
content: zod_1.default.object({
|
|
10
|
+
text: zod_1.default.string(),
|
|
11
|
+
buttons: zod_1.default.array(zod_1.default.object({
|
|
12
|
+
text: zod_1.default.string(),
|
|
13
|
+
url: zod_1.default.string().nullable().optional(),
|
|
10
14
|
})),
|
|
11
15
|
}),
|
|
12
16
|
})
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"text-with-buttons.js","sourceRoot":"","sources":["../../../src/structured-output/text-with-buttons.ts"],"names":[],"mappings":"AACA,
|
|
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;YAChB,GAAG,EAAE,aAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE,CAAC,QAAQ,EAAE;SACtC,CAAC,CACH;KACF,CAAC;CACH,CAAC;KACD,QAAQ,CACP,oEAAoE,CACrE,CAAA"}
|
|
@@ -1,9 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TextSchema = void 0;
|
|
4
|
+
const zod_1 = require("zod");
|
|
5
|
+
exports.TextSchema = zod_1.z
|
|
3
6
|
.object({
|
|
4
|
-
type: z.enum(['text']),
|
|
5
|
-
content: z.object({
|
|
6
|
-
text: z.string(),
|
|
7
|
+
type: zod_1.z.enum(['text']),
|
|
8
|
+
content: zod_1.z.object({
|
|
9
|
+
text: zod_1.z.string(),
|
|
7
10
|
}),
|
|
8
11
|
})
|
|
9
12
|
.describe('A text message');
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"text.js","sourceRoot":"","sources":["../../../src/structured-output/text.ts"],"names":[],"mappings":"AACA,
|
|
1
|
+
{"version":3,"file":"text.js","sourceRoot":"","sources":["../../../src/structured-output/text.ts"],"names":[],"mappings":";;;AACA,6BAAuB;AAIV,QAAA,UAAU,GAAG,OAAC;KACxB,MAAM,CAAC;IACN,IAAI,EAAE,OAAC,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,CAAC;IACtB,OAAO,EAAE,OAAC,CAAC,MAAM,CAAC;QAChB,IAAI,EAAE,OAAC,CAAC,MAAM,EAAE;KACjB,CAAC;CACH,CAAC;KACD,QAAQ,CAAC,gBAAgB,CAAC,CAAA"}
|
package/lib/esm/tools/index.js
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
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; } });
|
|
6
|
+
exports.mandatoryTools = [];
|
|
3
7
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/tools/index.ts"],"names":[],"mappings":"AACA,
|
|
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"}
|
|
@@ -1,22 +1,24 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.retrieveKnowledge = void 0;
|
|
4
|
+
const agents_1 = require("@openai/agents");
|
|
5
|
+
const zod_1 = require("zod");
|
|
6
|
+
const hubtype_api_client_1 = require("../hubtype-api-client");
|
|
7
|
+
exports.retrieveKnowledge = (0, agents_1.tool)({
|
|
6
8
|
name: 'retrieve_knowledge',
|
|
7
9
|
description: 'Consult the knowledge base for information before answering. Use this tool to make sure the information you provide is faithful.',
|
|
8
|
-
parameters: z.object({
|
|
9
|
-
query: z.string().describe('The query to search the knowledge base for'),
|
|
10
|
+
parameters: zod_1.z.object({
|
|
11
|
+
query: zod_1.z.string().describe('The query to search the knowledge base for'),
|
|
10
12
|
}),
|
|
11
|
-
execute: (input, runContext) =>
|
|
12
|
-
const context = runContext
|
|
13
|
+
execute: async (input, runContext) => {
|
|
14
|
+
const context = runContext?.context;
|
|
13
15
|
const query = input.query;
|
|
14
16
|
if (!context) {
|
|
15
17
|
throw new Error('Context is required');
|
|
16
18
|
}
|
|
17
19
|
const sourceIds = context.sourceIds;
|
|
18
|
-
const client = new HubtypeApiClient(context.authToken);
|
|
19
|
-
const chunks =
|
|
20
|
+
const client = new hubtype_api_client_1.HubtypeApiClient(context.authToken);
|
|
21
|
+
const chunks = await client.retrieveSimilarChunks(query, sourceIds);
|
|
20
22
|
const chunkTexts = chunks.map(chunk => chunk.text);
|
|
21
23
|
context.knowledgeUsed = {
|
|
22
24
|
query,
|
|
@@ -25,6 +27,6 @@ export const retrieveKnowledge = tool({
|
|
|
25
27
|
chunkTexts,
|
|
26
28
|
};
|
|
27
29
|
return chunkTexts;
|
|
28
|
-
}
|
|
30
|
+
},
|
|
29
31
|
});
|
|
30
32
|
//# sourceMappingURL=retrieve-knowledge.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"retrieve-knowledge.js","sourceRoot":"","sources":["../../../src/tools/retrieve-knowledge.ts"],"names":[],"mappings":"
|
|
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,EAAC;IACpC,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,KAAK,EACZ,KAAwB,EACxB,UAAgC,EACb,EAAE;QACrB,MAAM,OAAO,GAAG,UAAU,EAAE,OAAO,CAAA;QACnC,MAAM,KAAK,GAAG,KAAK,CAAC,KAAK,CAAA;QACzB,IAAI,CAAC,OAAO,EAAE,CAAC;YACb,MAAM,IAAI,KAAK,CAAC,qBAAqB,CAAC,CAAA;QACxC,CAAC;QACD,MAAM,SAAS,GAAG,OAAO,CAAC,SAAS,CAAA;QACnC,MAAM,MAAM,GAAG,IAAI,qCAAgB,CAAC,OAAO,CAAC,SAAS,CAAC,CAAA;QACtD,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,qBAAqB,CAAC,KAAK,EAAE,SAAS,CAAC,CAAA;QACnE,MAAM,UAAU,GAAG,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,CAAA;QAElD,OAAO,CAAC,aAAa,GAAG;YACtB,KAAK;YACL,SAAS;YACT,SAAS,EAAE,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC,KAAK,CAAC,EAAE,CAAC;YACxC,UAAU;SACX,CAAA;QAED,OAAO,UAAU,CAAA;IACnB,CAAC;CACF,CAAC,CAAA"}
|
package/lib/esm/types.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@botonic/plugin-ai-agents",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.44.0-alpha.1",
|
|
4
4
|
"main": "./lib/cjs/index.js",
|
|
5
5
|
"module": "./lib/esm/index.js",
|
|
6
6
|
"description": "Use AI Agents to generate your contents",
|
|
@@ -13,10 +13,10 @@
|
|
|
13
13
|
"lint_core": "../../node_modules/.bin/eslint_d --cache --quiet 'src/**/*.ts*'"
|
|
14
14
|
},
|
|
15
15
|
"dependencies": {
|
|
16
|
-
"@botonic/core": "^0.
|
|
17
|
-
"@openai/agents": "^0.
|
|
16
|
+
"@botonic/core": "^0.44.0-alpha.1",
|
|
17
|
+
"@openai/agents": "^0.3.9",
|
|
18
18
|
"axios": "^1.13.2",
|
|
19
|
-
"openai": "^
|
|
19
|
+
"openai": "^6.0.0",
|
|
20
20
|
"uuid": "^10.0.0",
|
|
21
21
|
"zod": "3.25.76"
|
|
22
22
|
},
|
|
@@ -45,4 +45,4 @@
|
|
|
45
45
|
"javascript"
|
|
46
46
|
],
|
|
47
47
|
"author": ""
|
|
48
|
-
}
|
|
48
|
+
}
|
package/src/agent-builder.ts
CHANGED
|
@@ -19,7 +19,7 @@ interface AIAgentBuilderOptions<
|
|
|
19
19
|
name: string
|
|
20
20
|
instructions: string
|
|
21
21
|
tools: Tool<TPlugins, TExtraData>[]
|
|
22
|
-
|
|
22
|
+
campaignsContext?: CampaignV2[]
|
|
23
23
|
contactInfo: ContactInfo[]
|
|
24
24
|
inputGuardrailRules: GuardrailRule[]
|
|
25
25
|
sourceIds: string[]
|
|
@@ -39,7 +39,7 @@ export class AIAgentBuilder<
|
|
|
39
39
|
this.instructions = this.addExtraInstructions(
|
|
40
40
|
options.instructions,
|
|
41
41
|
options.contactInfo,
|
|
42
|
-
options.
|
|
42
|
+
options.campaignsContext
|
|
43
43
|
)
|
|
44
44
|
this.tools = this.addHubtypeTools(options.tools, options.sourceIds)
|
|
45
45
|
this.inputGuardrails = []
|
|
@@ -52,7 +52,6 @@ export class AIAgentBuilder<
|
|
|
52
52
|
build(): AIAgent<TPlugins, TExtraData> {
|
|
53
53
|
const modelSettings: ModelSettings = {} as ModelSettings
|
|
54
54
|
if (OPENAI_PROVIDER === 'openai') {
|
|
55
|
-
// @ts-expect-error - reasoning.effort is valid but we need to update openai and typescript dependencies
|
|
56
55
|
modelSettings.reasoning = { effort: 'none' }
|
|
57
56
|
modelSettings.text = { verbosity: 'medium' }
|
|
58
57
|
}
|
|
@@ -87,12 +86,12 @@ export class AIAgentBuilder<
|
|
|
87
86
|
private addExtraInstructions(
|
|
88
87
|
initialInstructions: string,
|
|
89
88
|
contactInfo: ContactInfo[],
|
|
90
|
-
|
|
89
|
+
campaignsContext?: CampaignV2[]
|
|
91
90
|
): string {
|
|
92
91
|
const instructions = `<instructions>\n${initialInstructions.trim()}\n</instructions>`
|
|
93
92
|
const metadataInstructions = this.getMetadataInstructions()
|
|
94
93
|
const contactInfoInstructions = this.getContactInfoInstructions(contactInfo)
|
|
95
|
-
const campaignInstructions = this.getCampaignInstructions(
|
|
94
|
+
const campaignInstructions = this.getCampaignInstructions(campaignsContext)
|
|
96
95
|
const outputInstructions = this.getOutputInstructions()
|
|
97
96
|
return `${instructions}\n\n${metadataInstructions}\n\n${contactInfoInstructions}\n\n${campaignInstructions}\n\n${outputInstructions}`
|
|
98
97
|
}
|
|
@@ -121,11 +120,16 @@ export class AIAgentBuilder<
|
|
|
121
120
|
return `<metadata>\n${metadata}\n</metadata>`
|
|
122
121
|
}
|
|
123
122
|
|
|
124
|
-
private getCampaignInstructions(
|
|
125
|
-
if (!
|
|
123
|
+
private getCampaignInstructions(campaignsContext?: CampaignV2[]): string {
|
|
124
|
+
if (!campaignsContext || campaignsContext.length === 0) {
|
|
126
125
|
return ''
|
|
127
126
|
}
|
|
128
|
-
return
|
|
127
|
+
return campaignsContext
|
|
128
|
+
.map(
|
|
129
|
+
(campaign, index) =>
|
|
130
|
+
`<campaign_context${index + 1}>\n${campaign.agent_context}\n</campaign_context${index + 1}>`
|
|
131
|
+
)
|
|
132
|
+
.join('\n')
|
|
129
133
|
}
|
|
130
134
|
|
|
131
135
|
private getOutputInstructions(): string {
|
package/src/index.ts
CHANGED
|
@@ -20,8 +20,7 @@ import {
|
|
|
20
20
|
export default class BotonicPluginAiAgents<
|
|
21
21
|
TPlugins extends ResolvedPlugins = ResolvedPlugins,
|
|
22
22
|
TExtraData = any,
|
|
23
|
-
> implements Plugin
|
|
24
|
-
{
|
|
23
|
+
> implements Plugin {
|
|
25
24
|
private readonly authToken?: string
|
|
26
25
|
private readonly messageHistoryApiVersion: MessageHistoryApiVersion
|
|
27
26
|
private readonly memory: MemoryOptions
|
|
@@ -67,7 +66,7 @@ export default class BotonicPluginAiAgents<
|
|
|
67
66
|
contactInfo: request.session.user.contact_info || [],
|
|
68
67
|
inputGuardrailRules: aiAgentArgs.inputGuardrailRules || [],
|
|
69
68
|
sourceIds: aiAgentArgs.sourceIds || [],
|
|
70
|
-
|
|
69
|
+
campaignsContext: request.input.context?.campaigns_v2,
|
|
71
70
|
}).build()
|
|
72
71
|
|
|
73
72
|
const messages = await this.getMessages(
|