@botonic/plugin-ai-agents 0.43.0-beta.0 → 0.44.0-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 +14 -3
- package/lib/cjs/agent-builder.js +43 -13
- package/lib/cjs/agent-builder.js.map +1 -1
- package/lib/cjs/constants.d.ts +3 -0
- package/lib/cjs/constants.js +6 -1
- package/lib/cjs/constants.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 +97 -106
- package/lib/cjs/hubtype-api-client.js.map +1 -1
- package/lib/cjs/index.js +63 -62
- package/lib/cjs/index.js.map +1 -1
- package/lib/cjs/openai.js +19 -5
- package/lib/cjs/openai.js.map +1 -1
- package/lib/cjs/runner.js +39 -38
- package/lib/cjs/runner.js.map +1 -1
- package/lib/cjs/tools/retrieve-knowledge.d.ts +8 -1
- package/lib/cjs/tools/retrieve-knowledge.js +5 -5
- package/lib/cjs/tools/retrieve-knowledge.js.map +1 -1
- package/lib/cjs/types.d.ts +2 -3
- package/lib/esm/agent-builder.d.ts +14 -3
- package/lib/esm/agent-builder.js +57 -23
- package/lib/esm/agent-builder.js.map +1 -1
- package/lib/esm/constants.d.ts +3 -0
- package/lib/esm/constants.js +15 -7
- 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 +105 -110
- package/lib/esm/hubtype-api-client.js.map +1 -1
- package/lib/esm/index.js +76 -72
- package/lib/esm/index.js.map +1 -1
- package/lib/esm/openai.js +33 -15
- package/lib/esm/openai.js.map +1 -1
- package/lib/esm/runner.js +47 -42
- 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.d.ts +8 -1
- package/lib/esm/tools/retrieve-knowledge.js +15 -12
- package/lib/esm/tools/retrieve-knowledge.js.map +1 -1
- package/lib/esm/types.d.ts +2 -3
- package/lib/esm/types.js +2 -1
- package/package.json +5 -5
- package/src/agent-builder.ts +79 -26
- package/src/constants.ts +7 -0
- package/src/guardrails/input.ts +1 -1
- package/src/hubtype-api-client.ts +21 -14
- package/src/index.ts +10 -10
- package/src/openai.ts +19 -3
- package/src/runner.ts +15 -6
- package/src/tools/retrieve-knowledge.ts +3 -2
- package/src/types.ts +4 -3
package/lib/esm/runner.js
CHANGED
|
@@ -1,54 +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
|
-
|
|
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) {
|
|
21
38
|
return {
|
|
22
|
-
messages:
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
exit: hasExit,
|
|
27
|
-
memoryLength: messages.length,
|
|
39
|
+
messages: [],
|
|
40
|
+
memoryLength: 0,
|
|
41
|
+
toolsExecuted: [],
|
|
42
|
+
exit: true,
|
|
28
43
|
error: false,
|
|
29
|
-
inputGuardrailsTriggered:
|
|
44
|
+
inputGuardrailsTriggered: error.result.output.outputInfo,
|
|
30
45
|
outputGuardrailsTriggered: [],
|
|
31
46
|
};
|
|
32
47
|
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
return {
|
|
36
|
-
messages: [],
|
|
37
|
-
memoryLength: 0,
|
|
38
|
-
toolsExecuted: [],
|
|
39
|
-
exit: true,
|
|
40
|
-
error: false,
|
|
41
|
-
inputGuardrailsTriggered: error.result.output.outputInfo,
|
|
42
|
-
outputGuardrailsTriggered: [],
|
|
43
|
-
};
|
|
44
|
-
}
|
|
45
|
-
throw error;
|
|
46
|
-
}
|
|
47
|
-
});
|
|
48
|
+
throw error;
|
|
49
|
+
}
|
|
48
50
|
}
|
|
49
51
|
getToolsExecuted(result, context) {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
+
return (result.newItems
|
|
53
|
+
?.filter(item => item instanceof agents_1.RunToolCallItem)
|
|
54
|
+
.map((item) => this.getToolExecutionInfo(item, context))
|
|
55
|
+
.filter((toolExecution) => toolExecution.toolName !== '') || []);
|
|
52
56
|
}
|
|
53
57
|
getToolExecutionInfo(item, context) {
|
|
54
58
|
if (item.rawItem.type !== 'function_call') {
|
|
@@ -59,7 +63,7 @@ export class AIAgentRunner {
|
|
|
59
63
|
}
|
|
60
64
|
const toolName = item.rawItem.name;
|
|
61
65
|
const toolArguments = this.getSafeToolArguments(item.rawItem.arguments);
|
|
62
|
-
if (toolName === retrieveKnowledge.name) {
|
|
66
|
+
if (toolName === tools_1.retrieveKnowledge.name) {
|
|
63
67
|
return {
|
|
64
68
|
toolName,
|
|
65
69
|
toolArguments,
|
|
@@ -81,4 +85,5 @@ export class AIAgentRunner {
|
|
|
81
85
|
}
|
|
82
86
|
}
|
|
83
87
|
}
|
|
88
|
+
exports.AIAgentRunner = AIAgentRunner;
|
|
84
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":";;;AACA,2CAIuB;AAEvB,mCAA2C;AAkB3C,MAAa,aAAa;IAMxB,YAAY,KAAoC;QAC9C,IAAI,CAAC,KAAK,GAAG,KAAK,CAAA;IACpB,CAAC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CAAA;QACrC,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO,EAAE,CAAA;QACX,CAAC;IACH,CAAC;CACF;AA9GD,sCA8GC"}
|
|
@@ -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,2 +1,9 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
1
2
|
import { Context } from '../types';
|
|
2
|
-
export declare const retrieveKnowledge: import("@openai/agents").FunctionTool<Context<import("@botonic/core").ResolvedPlugins, any>,
|
|
3
|
+
export declare const retrieveKnowledge: import("@openai/agents").FunctionTool<Context<import("@botonic/core").ResolvedPlugins, any>, z.ZodObject<{
|
|
4
|
+
query: z.ZodString;
|
|
5
|
+
}, "strip", z.ZodTypeAny, {
|
|
6
|
+
query: string;
|
|
7
|
+
}, {
|
|
8
|
+
query: string;
|
|
9
|
+
}>, string>;
|
|
@@ -1,21 +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: (
|
|
12
|
-
const context = runContext
|
|
13
|
+
execute: async (input, runContext) => {
|
|
14
|
+
const context = runContext?.context;
|
|
15
|
+
const query = input.query;
|
|
13
16
|
if (!context) {
|
|
14
17
|
throw new Error('Context is required');
|
|
15
18
|
}
|
|
16
19
|
const sourceIds = context.sourceIds;
|
|
17
|
-
const client = new HubtypeApiClient(context.authToken);
|
|
18
|
-
const chunks =
|
|
20
|
+
const client = new hubtype_api_client_1.HubtypeApiClient(context.authToken);
|
|
21
|
+
const chunks = await client.retrieveSimilarChunks(query, sourceIds);
|
|
19
22
|
const chunkTexts = chunks.map(chunk => chunk.text);
|
|
20
23
|
context.knowledgeUsed = {
|
|
21
24
|
query,
|
|
@@ -24,6 +27,6 @@ export const retrieveKnowledge = tool({
|
|
|
24
27
|
chunkTexts,
|
|
25
28
|
};
|
|
26
29
|
return chunkTexts;
|
|
27
|
-
}
|
|
30
|
+
},
|
|
28
31
|
});
|
|
29
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.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { AgenticOutputMessage, AiAgentArgs, BotContext, GuardrailRule, InferenceResponse, ResolvedPlugins, RunResult } from '@botonic/core';
|
|
2
|
-
import { Agent, AgentInputItem, RunContext as OpenAIRunContext, Tool as OpenAITool } from '@openai/agents';
|
|
2
|
+
import { Agent, AgentInputItem, AgentOutputType, RunContext as OpenAIRunContext, Tool as OpenAITool } from '@openai/agents';
|
|
3
3
|
import { ZodSchema } from 'zod';
|
|
4
4
|
import { OutputSchema } from './structured-output';
|
|
5
5
|
export interface Context<TPlugins extends ResolvedPlugins = ResolvedPlugins, TExtraData = any> {
|
|
@@ -24,9 +24,8 @@ export interface Chunk {
|
|
|
24
24
|
id: string;
|
|
25
25
|
text: string;
|
|
26
26
|
}
|
|
27
|
-
export type ContactInfo = Record<string, string>;
|
|
28
27
|
export type Tool<TPlugins extends ResolvedPlugins = ResolvedPlugins, TExtraData = any> = OpenAITool<Context<TPlugins, TExtraData>>;
|
|
29
|
-
export type AIAgent<TPlugins extends ResolvedPlugins = ResolvedPlugins, TExtraData = any> = Agent<Context<TPlugins, TExtraData>, typeof OutputSchema
|
|
28
|
+
export type AIAgent<TPlugins extends ResolvedPlugins = ResolvedPlugins, TExtraData = any> = Agent<Context<TPlugins, TExtraData>, AgentOutputType<typeof OutputSchema>>;
|
|
30
29
|
export type MessageHistoryApiVersion = 'v1' | 'v2';
|
|
31
30
|
export interface MemoryOptions {
|
|
32
31
|
maxMessages?: number;
|
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.0",
|
|
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.
|
|
18
|
-
"axios": "^1.
|
|
19
|
-
"openai": "^
|
|
16
|
+
"@botonic/core": "^0.44.0-alpha.0",
|
|
17
|
+
"@openai/agents": "^0.3.9",
|
|
18
|
+
"axios": "^1.13.2",
|
|
19
|
+
"openai": "^6.0.0",
|
|
20
20
|
"uuid": "^10.0.0",
|
|
21
21
|
"zod": "3.25.76"
|
|
22
22
|
},
|
package/src/agent-builder.ts
CHANGED
|
@@ -1,10 +1,29 @@
|
|
|
1
|
-
import { ResolvedPlugins } from '@botonic/core'
|
|
2
|
-
import {
|
|
1
|
+
import { CampaignV2, ContactInfo, ResolvedPlugins } from '@botonic/core'
|
|
2
|
+
import {
|
|
3
|
+
Agent,
|
|
4
|
+
AgentOutputType,
|
|
5
|
+
InputGuardrail,
|
|
6
|
+
ModelSettings,
|
|
7
|
+
} from '@openai/agents'
|
|
3
8
|
|
|
9
|
+
import { OPENAI_MODEL, OPENAI_PROVIDER } from './constants'
|
|
4
10
|
import { createInputGuardrail } from './guardrails'
|
|
5
11
|
import { OutputSchema } from './structured-output'
|
|
6
12
|
import { mandatoryTools, retrieveKnowledge } from './tools'
|
|
7
|
-
import { AIAgent,
|
|
13
|
+
import { AIAgent, Context, GuardrailRule, Tool } from './types'
|
|
14
|
+
|
|
15
|
+
interface AIAgentBuilderOptions<
|
|
16
|
+
TPlugins extends ResolvedPlugins = ResolvedPlugins,
|
|
17
|
+
TExtraData = any,
|
|
18
|
+
> {
|
|
19
|
+
name: string
|
|
20
|
+
instructions: string
|
|
21
|
+
tools: Tool<TPlugins, TExtraData>[]
|
|
22
|
+
campaignContext?: CampaignV2
|
|
23
|
+
contactInfo: ContactInfo[]
|
|
24
|
+
inputGuardrailRules: GuardrailRule[]
|
|
25
|
+
sourceIds: string[]
|
|
26
|
+
}
|
|
8
27
|
|
|
9
28
|
export class AIAgentBuilder<
|
|
10
29
|
TPlugins extends ResolvedPlugins = ResolvedPlugins,
|
|
@@ -15,33 +34,46 @@ export class AIAgentBuilder<
|
|
|
15
34
|
private tools: Tool<TPlugins, TExtraData>[]
|
|
16
35
|
private inputGuardrails: InputGuardrail[]
|
|
17
36
|
|
|
18
|
-
constructor(
|
|
19
|
-
name
|
|
20
|
-
instructions
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
this.name = name
|
|
27
|
-
this.instructions = this.addExtraInstructions(instructions, contactInfo)
|
|
28
|
-
this.tools = this.addHubtypeTools(tools, sourceIds)
|
|
37
|
+
constructor(options: AIAgentBuilderOptions<TPlugins, TExtraData>) {
|
|
38
|
+
this.name = options.name
|
|
39
|
+
this.instructions = this.addExtraInstructions(
|
|
40
|
+
options.instructions,
|
|
41
|
+
options.contactInfo,
|
|
42
|
+
options.campaignContext
|
|
43
|
+
)
|
|
44
|
+
this.tools = this.addHubtypeTools(options.tools, options.sourceIds)
|
|
29
45
|
this.inputGuardrails = []
|
|
30
|
-
if (inputGuardrailRules.length > 0) {
|
|
31
|
-
const inputGuardrail = createInputGuardrail(inputGuardrailRules)
|
|
46
|
+
if (options.inputGuardrailRules.length > 0) {
|
|
47
|
+
const inputGuardrail = createInputGuardrail(options.inputGuardrailRules)
|
|
32
48
|
this.inputGuardrails.push(inputGuardrail)
|
|
33
49
|
}
|
|
34
50
|
}
|
|
35
51
|
|
|
36
52
|
build(): AIAgent<TPlugins, TExtraData> {
|
|
37
|
-
const modelSettings: ModelSettings = {}
|
|
53
|
+
const modelSettings: ModelSettings = {} as ModelSettings
|
|
54
|
+
if (OPENAI_PROVIDER === 'openai') {
|
|
55
|
+
modelSettings.reasoning = { effort: 'none' }
|
|
56
|
+
modelSettings.text = { verbosity: 'medium' }
|
|
57
|
+
}
|
|
38
58
|
|
|
39
|
-
if (this.tools.includes(retrieveKnowledge)) {
|
|
59
|
+
if (this.tools.includes(retrieveKnowledge) && OPENAI_PROVIDER === 'azure') {
|
|
40
60
|
modelSettings.toolChoice = retrieveKnowledge.name
|
|
41
61
|
}
|
|
42
62
|
|
|
43
|
-
|
|
63
|
+
// When using standard OpenAI API, we need to specify the model
|
|
64
|
+
// Azure OpenAI uses deployment name instead
|
|
65
|
+
const model = OPENAI_PROVIDER === 'openai' ? OPENAI_MODEL : undefined
|
|
66
|
+
|
|
67
|
+
// TODO: Improve type safety - replace AgentOutputType<any> with AgentOutputType<typeof OutputSchema>
|
|
68
|
+
// Currently using explicit type parameters to avoid type inference issues where Agent constructor
|
|
69
|
+
// infers ZodObject instead of AgentOutputType<typeof OutputSchema>. The explicit type parameters
|
|
70
|
+
// ensure compatibility with AIAgent type definition. Future improvements:
|
|
71
|
+
// 1. Update @openai/agents package to properly infer AgentOutputType from outputType parameter
|
|
72
|
+
// 2. Replace AgentOutputType<any> with AgentOutputType<typeof OutputSchema> once type system allows
|
|
73
|
+
// 3. Consider updating AIAgent type definition if @openai/agents types change significantly
|
|
74
|
+
return new Agent<Context<TPlugins, TExtraData>, AgentOutputType<any>>({
|
|
44
75
|
name: this.name,
|
|
76
|
+
model,
|
|
45
77
|
instructions: this.instructions,
|
|
46
78
|
tools: this.tools,
|
|
47
79
|
outputType: OutputSchema,
|
|
@@ -53,20 +85,34 @@ export class AIAgentBuilder<
|
|
|
53
85
|
|
|
54
86
|
private addExtraInstructions(
|
|
55
87
|
initialInstructions: string,
|
|
56
|
-
contactInfo: ContactInfo
|
|
88
|
+
contactInfo: ContactInfo[],
|
|
89
|
+
campaignContext?: CampaignV2
|
|
57
90
|
): string {
|
|
58
|
-
const instructions = `<instructions>\n${initialInstructions}\n</instructions>`
|
|
91
|
+
const instructions = `<instructions>\n${initialInstructions.trim()}\n</instructions>`
|
|
59
92
|
const metadataInstructions = this.getMetadataInstructions()
|
|
60
93
|
const contactInfoInstructions = this.getContactInfoInstructions(contactInfo)
|
|
94
|
+
const campaignInstructions = this.getCampaignInstructions(campaignContext)
|
|
61
95
|
const outputInstructions = this.getOutputInstructions()
|
|
62
|
-
return `${instructions}\n\n${metadataInstructions}\n\n${contactInfoInstructions}\n\n${outputInstructions}`
|
|
96
|
+
return `${instructions}\n\n${metadataInstructions}\n\n${contactInfoInstructions}\n\n${campaignInstructions}\n\n${outputInstructions}`
|
|
63
97
|
}
|
|
64
98
|
|
|
65
|
-
private getContactInfoInstructions(contactInfo: ContactInfo): string {
|
|
66
|
-
const structuredContactInfo =
|
|
67
|
-
.map(
|
|
99
|
+
private getContactInfoInstructions(contactInfo: ContactInfo[]): string {
|
|
100
|
+
const structuredContactInfo = contactInfo
|
|
101
|
+
.map(
|
|
102
|
+
info =>
|
|
103
|
+
` <contact_info>
|
|
104
|
+
<name>${info.name}</name>
|
|
105
|
+
<value>${info.value}</value>
|
|
106
|
+
<type>${info.type}</type>
|
|
107
|
+
${
|
|
108
|
+
info.description
|
|
109
|
+
? `<description>${info.description}</description>`
|
|
110
|
+
: ''
|
|
111
|
+
}
|
|
112
|
+
</contact_info>`
|
|
113
|
+
)
|
|
68
114
|
.join('\n')
|
|
69
|
-
return `<
|
|
115
|
+
return `<contact_info_fields>\n${structuredContactInfo}</contact_info_fields>`
|
|
70
116
|
}
|
|
71
117
|
|
|
72
118
|
private getMetadataInstructions(): string {
|
|
@@ -74,6 +120,13 @@ export class AIAgentBuilder<
|
|
|
74
120
|
return `<metadata>\n${metadata}\n</metadata>`
|
|
75
121
|
}
|
|
76
122
|
|
|
123
|
+
private getCampaignInstructions(campaignContext?: CampaignV2): string {
|
|
124
|
+
if (!campaignContext || !campaignContext.agent_context) {
|
|
125
|
+
return ''
|
|
126
|
+
}
|
|
127
|
+
return `<campaign_context>\n${campaignContext.agent_context}\n</campaign_context>`
|
|
128
|
+
}
|
|
129
|
+
|
|
77
130
|
private getOutputInstructions(): string {
|
|
78
131
|
const example = {
|
|
79
132
|
messages: [
|
package/src/constants.ts
CHANGED
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
export const HUBTYPE_API_URL =
|
|
2
2
|
process.env.HUBTYPE_API_URL || 'https://api.hubtype.com'
|
|
3
3
|
|
|
4
|
+
// OpenAI Provider Configuration
|
|
5
|
+
export const OPENAI_API_KEY = process.env.OPENAI_API_KEY // pragma: allowlist secret
|
|
6
|
+
export const OPENAI_MODEL = process.env.OPENAI_MODEL || 'gpt-4.1-mini'
|
|
7
|
+
export const OPENAI_PROVIDER: 'openai' | 'azure' =
|
|
8
|
+
(process.env.OPENAI_PROVIDER as 'openai' | 'azure') || 'azure'
|
|
9
|
+
|
|
10
|
+
// Azure OpenAI Configuration
|
|
4
11
|
export const AZURE_OPENAI_API_KEY = process.env.AZURE_OPENAI_API_KEY // pragma: allowlist secret
|
|
5
12
|
export const AZURE_OPENAI_API_BASE = process.env.AZURE_OPENAI_API_BASE
|
|
6
13
|
export const AZURE_OPENAI_API_DEPLOYMENT_NAME =
|
package/src/guardrails/input.ts
CHANGED
|
@@ -22,7 +22,7 @@ export function createInputGuardrail(rules: GuardrailRule[]): InputGuardrail {
|
|
|
22
22
|
execute: async ({ input, context }) => {
|
|
23
23
|
const lastMessage = input[input.length - 1] as UserMessageItem
|
|
24
24
|
const result = await run(agent, [lastMessage], { context })
|
|
25
|
-
const finalOutput = result.finalOutput
|
|
25
|
+
const finalOutput = result.finalOutput as Record<string, boolean>
|
|
26
26
|
if (finalOutput === undefined) {
|
|
27
27
|
throw new Error('Guardrail agent failed to produce output')
|
|
28
28
|
}
|