@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/cjs/index.js
CHANGED
|
@@ -9,79 +9,80 @@ const openai_1 = require("./openai");
|
|
|
9
9
|
const runner_1 = require("./runner");
|
|
10
10
|
class BotonicPluginAiAgents {
|
|
11
11
|
constructor(options) {
|
|
12
|
-
var _a, _b;
|
|
13
12
|
this.toolDefinitions = [];
|
|
14
|
-
(0, openai_1.setUpOpenAI)(options
|
|
15
|
-
if (
|
|
13
|
+
(0, openai_1.setUpOpenAI)(options?.maxRetries, options?.timeout);
|
|
14
|
+
if (options?.messageHistoryApiVersion === 'v1' && options?.memory) {
|
|
16
15
|
throw new Error('Cannot use memory when messageHistoryApiVersion is "v1". ' +
|
|
17
16
|
'Either set messageHistoryApiVersion to "v2" or remove memory.');
|
|
18
17
|
}
|
|
19
|
-
this.authToken = options
|
|
20
|
-
this.toolDefinitions =
|
|
21
|
-
this.messageHistoryApiVersion =
|
|
22
|
-
this.memory =
|
|
18
|
+
this.authToken = options?.authToken;
|
|
19
|
+
this.toolDefinitions = options?.customTools || [];
|
|
20
|
+
this.messageHistoryApiVersion = options?.messageHistoryApiVersion ?? 'v2';
|
|
21
|
+
this.memory = options?.memory ?? {};
|
|
23
22
|
}
|
|
24
23
|
pre() {
|
|
25
24
|
return;
|
|
26
25
|
}
|
|
27
|
-
getInference(request, aiAgentArgs) {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
if (!authToken) {
|
|
33
|
-
throw new Error('Auth token is required');
|
|
34
|
-
}
|
|
35
|
-
const tools = this.buildTools(((_a = aiAgentArgs.activeTools) === null || _a === void 0 ? void 0 : _a.map(tool => tool.name)) || []);
|
|
36
|
-
const agent = new agent_builder_1.AIAgentBuilder(aiAgentArgs.name, aiAgentArgs.instructions, tools, request.session.user.contact_info || {}, aiAgentArgs.inputGuardrailRules || [], aiAgentArgs.sourceIds || []).build();
|
|
37
|
-
const messages = yield this.getMessages(request, authToken, constants_1.MAX_MEMORY_LENGTH);
|
|
38
|
-
const context = {
|
|
39
|
-
authToken,
|
|
40
|
-
sourceIds: aiAgentArgs.sourceIds || [],
|
|
41
|
-
knowledgeUsed: {
|
|
42
|
-
query: '',
|
|
43
|
-
sourceIds: [],
|
|
44
|
-
chunksIds: [],
|
|
45
|
-
chunkTexts: [],
|
|
46
|
-
},
|
|
47
|
-
request,
|
|
48
|
-
};
|
|
49
|
-
const runner = new runner_1.AIAgentRunner(agent);
|
|
50
|
-
return yield runner.run(messages, context);
|
|
26
|
+
async getInference(request, aiAgentArgs) {
|
|
27
|
+
try {
|
|
28
|
+
const authToken = constants_1.isProd ? request.session._access_token : this.authToken;
|
|
29
|
+
if (!authToken) {
|
|
30
|
+
throw new Error('Auth token is required');
|
|
51
31
|
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
32
|
+
const tools = this.buildTools(aiAgentArgs.activeTools?.map(tool => tool.name) || []);
|
|
33
|
+
const agent = new agent_builder_1.AIAgentBuilder({
|
|
34
|
+
name: aiAgentArgs.name,
|
|
35
|
+
instructions: aiAgentArgs.instructions,
|
|
36
|
+
tools: tools,
|
|
37
|
+
contactInfo: request.session.user.contact_info || [],
|
|
38
|
+
inputGuardrailRules: aiAgentArgs.inputGuardrailRules || [],
|
|
39
|
+
sourceIds: aiAgentArgs.sourceIds || [],
|
|
40
|
+
campaignContext: request.input.context?.campaign_v2,
|
|
41
|
+
}).build();
|
|
42
|
+
const messages = await this.getMessages(request, authToken, constants_1.MAX_MEMORY_LENGTH);
|
|
43
|
+
const context = {
|
|
44
|
+
authToken,
|
|
45
|
+
sourceIds: aiAgentArgs.sourceIds || [],
|
|
46
|
+
knowledgeUsed: {
|
|
47
|
+
query: '',
|
|
48
|
+
sourceIds: [],
|
|
49
|
+
chunksIds: [],
|
|
50
|
+
chunkTexts: [],
|
|
51
|
+
},
|
|
52
|
+
request,
|
|
53
|
+
};
|
|
54
|
+
const runner = new runner_1.AIAgentRunner(agent);
|
|
55
|
+
return await runner.run(messages, context);
|
|
56
|
+
}
|
|
57
|
+
catch (error) {
|
|
58
|
+
console.error('error plugin returns undefined', error);
|
|
59
|
+
return {
|
|
60
|
+
messages: [],
|
|
61
|
+
toolsExecuted: [],
|
|
62
|
+
memoryLength: 0,
|
|
63
|
+
exit: true,
|
|
64
|
+
error: true,
|
|
65
|
+
inputGuardrailsTriggered: [],
|
|
66
|
+
outputGuardrailsTriggered: [],
|
|
67
|
+
};
|
|
68
|
+
}
|
|
65
69
|
}
|
|
66
|
-
getMessages(request, authToken, memoryLength) {
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
maxFullToolResults: (_c = this.memory.maxFullToolResults) !== null && _c !== void 0 ? _c : 1,
|
|
81
|
-
debugMode: (_d = this.memory.debugMode) !== null && _d !== void 0 ? _d : false,
|
|
82
|
-
});
|
|
83
|
-
return result.messages;
|
|
70
|
+
async getMessages(request, authToken, memoryLength) {
|
|
71
|
+
const hubtypeClient = new hubtype_api_client_1.HubtypeApiClient(authToken);
|
|
72
|
+
if (!constants_1.isProd) {
|
|
73
|
+
return await hubtypeClient.getLocalMessages(memoryLength);
|
|
74
|
+
}
|
|
75
|
+
if (this.messageHistoryApiVersion === 'v1') {
|
|
76
|
+
return await hubtypeClient.getMessages(request, memoryLength);
|
|
77
|
+
}
|
|
78
|
+
// Default to V2
|
|
79
|
+
const result = await hubtypeClient.getMessagesV2(request, {
|
|
80
|
+
maxMessages: this.memory.maxMessages ?? memoryLength,
|
|
81
|
+
includeToolCalls: this.memory.includeToolCalls ?? true,
|
|
82
|
+
maxFullToolResults: this.memory.maxFullToolResults ?? 1,
|
|
83
|
+
debugMode: this.memory.debugMode ?? false,
|
|
84
84
|
});
|
|
85
|
+
return result.messages;
|
|
85
86
|
}
|
|
86
87
|
buildTools(activeToolNames) {
|
|
87
88
|
const availableTools = this.toolDefinitions.filter(tool => activeToolNames.includes(tool.name));
|
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;AAYxC,MAAqB,qBAAqB;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;AACA,2CAAqC;AAErC,mDAAgD;AAChD,2CAAuD;AACvD,6DAAuD;AACvD,qCAAsC;AACtC,qCAA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
|
+
exports.setUpOpenAI = setUpOpenAI;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
4
5
|
const agents_1 = require("@openai/agents");
|
|
5
|
-
const openai_1 = require("openai");
|
|
6
|
+
const openai_1 = tslib_1.__importStar(require("openai"));
|
|
6
7
|
const constants_1 = require("./constants");
|
|
7
8
|
function setUpOpenAI(maxRetries, timeout) {
|
|
8
|
-
|
|
9
|
+
if (constants_1.OPENAI_PROVIDER === 'azure') {
|
|
10
|
+
setAzureOpenAIClient(maxRetries, timeout);
|
|
11
|
+
}
|
|
12
|
+
else {
|
|
13
|
+
setOpenAIClient(maxRetries, timeout);
|
|
14
|
+
}
|
|
9
15
|
(0, agents_1.setOpenAIAPI)('chat_completions');
|
|
10
16
|
(0, agents_1.setTracingDisabled)(true);
|
|
11
17
|
}
|
|
12
|
-
|
|
18
|
+
function setOpenAIClient(maxRetries, timeout) {
|
|
19
|
+
const client = new openai_1.default({
|
|
20
|
+
apiKey: constants_1.OPENAI_API_KEY,
|
|
21
|
+
timeout: timeout || 16000, // 16 seconds
|
|
22
|
+
maxRetries: maxRetries || 2,
|
|
23
|
+
dangerouslyAllowBrowser: !constants_1.isProd,
|
|
24
|
+
});
|
|
25
|
+
(0, agents_1.setDefaultOpenAIClient)(client);
|
|
26
|
+
}
|
|
13
27
|
function setAzureOpenAIClient(maxRetries, timeout) {
|
|
14
28
|
const client = new openai_1.AzureOpenAI({
|
|
15
29
|
apiKey: constants_1.AZURE_OPENAI_API_KEY,
|
|
16
30
|
apiVersion: constants_1.AZURE_OPENAI_API_VERSION,
|
|
17
31
|
deployment: constants_1.AZURE_OPENAI_API_DEPLOYMENT_NAME,
|
|
18
32
|
baseURL: constants_1.AZURE_OPENAI_API_BASE,
|
|
19
|
-
timeout: timeout ||
|
|
33
|
+
timeout: timeout || 16000, // 16 seconds
|
|
20
34
|
maxRetries: maxRetries || 2,
|
|
21
35
|
dangerouslyAllowBrowser: !constants_1.isProd,
|
|
22
36
|
});
|
package/lib/cjs/openai.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"openai.js","sourceRoot":"","sources":["../../src/openai.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"openai.js","sourceRoot":"","sources":["../../src/openai.ts"],"names":[],"mappings":";;AAiBA,kCAQC;;AAzBD,2CAIuB;AACvB,yDAA4C;AAE5C,2CAQoB;AAEpB,SAAgB,WAAW,CAAC,UAAmB,EAAE,OAAgB;IAC/D,IAAI,2BAAe,KAAK,OAAO,EAAE,CAAC;QAChC,oBAAoB,CAAC,UAAU,EAAE,OAAO,CAAC,CAAA;IAC3C,CAAC;SAAM,CAAC;QACN,eAAe,CAAC,UAAU,EAAE,OAAO,CAAC,CAAA;IACtC,CAAC;IACD,IAAA,qBAAY,EAAC,kBAAkB,CAAC,CAAA;IAChC,IAAA,2BAAkB,EAAC,IAAI,CAAC,CAAA;AAC1B,CAAC;AAED,SAAS,eAAe,CAAC,UAAmB,EAAE,OAAgB;IAC5D,MAAM,MAAM,GAAG,IAAI,gBAAM,CAAC;QACxB,MAAM,EAAE,0BAAc;QACtB,OAAO,EAAE,OAAO,IAAI,KAAK,EAAE,aAAa;QACxC,UAAU,EAAE,UAAU,IAAI,CAAC;QAC3B,uBAAuB,EAAE,CAAC,kBAAM;KACjC,CAAC,CAAA;IACF,IAAA,+BAAsB,EAAC,MAAM,CAAC,CAAA;AAChC,CAAC;AAED,SAAS,oBAAoB,CAAC,UAAmB,EAAE,OAAgB;IACjE,MAAM,MAAM,GAAG,IAAI,oBAAW,CAAC;QAC7B,MAAM,EAAE,gCAAoB;QAC5B,UAAU,EAAE,oCAAwB;QACpC,UAAU,EAAE,4CAAgC;QAC5C,OAAO,EAAE,iCAAqB;QAC9B,OAAO,EAAE,OAAO,IAAI,KAAK,EAAE,aAAa;QACxC,UAAU,EAAE,UAAU,IAAI,CAAC;QAC3B,uBAAuB,EAAE,CAAC,kBAAM;KACjC,CAAC,CAAA;IACF,IAAA,+BAAsB,EAAC,MAAM,CAAC,CAAA;AAChC,CAAC"}
|
package/lib/cjs/runner.js
CHANGED
|
@@ -1,57 +1,58 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.AIAgentRunner = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
4
|
const agents_1 = require("@openai/agents");
|
|
6
5
|
const tools_1 = require("./tools");
|
|
7
6
|
class AIAgentRunner {
|
|
8
7
|
constructor(agent) {
|
|
9
8
|
this.agent = agent;
|
|
10
9
|
}
|
|
11
|
-
run(messages, context) {
|
|
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') {
|
package/lib/cjs/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.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O;YACL,QAAQ;YACR,aAAa;SACd,CAAA;IACH,CAAC;IAEO,oBAAoB,CAAC,gBAAwB;QACnD,IAAI,CAAC;YACH,OAAO,IAAI,CAAC,KAAK,CAAC,gBAAgB,CAAC,CAAA;QACrC,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO,EAAE,CAAA;QACX,CAAC;IACH,CAAC;CACF;AA9GD,sCA8GC"}
|
|
@@ -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,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.retrieveKnowledge = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
4
|
const agents_1 = require("@openai/agents");
|
|
6
5
|
const zod_1 = require("zod");
|
|
7
6
|
const hubtype_api_client_1 = require("../hubtype-api-client");
|
|
@@ -11,14 +10,15 @@ exports.retrieveKnowledge = (0, agents_1.tool)({
|
|
|
11
10
|
parameters: zod_1.z.object({
|
|
12
11
|
query: zod_1.z.string().describe('The query to search the knowledge base for'),
|
|
13
12
|
}),
|
|
14
|
-
execute: (
|
|
15
|
-
const context = runContext
|
|
13
|
+
execute: async (input, runContext) => {
|
|
14
|
+
const context = runContext?.context;
|
|
15
|
+
const query = input.query;
|
|
16
16
|
if (!context) {
|
|
17
17
|
throw new Error('Context is required');
|
|
18
18
|
}
|
|
19
19
|
const sourceIds = context.sourceIds;
|
|
20
20
|
const client = new hubtype_api_client_1.HubtypeApiClient(context.authToken);
|
|
21
|
-
const chunks =
|
|
21
|
+
const chunks = await client.retrieveSimilarChunks(query, sourceIds);
|
|
22
22
|
const chunkTexts = chunks.map(chunk => chunk.text);
|
|
23
23
|
context.knowledgeUsed = {
|
|
24
24
|
query,
|
|
@@ -27,6 +27,6 @@ exports.retrieveKnowledge = (0, agents_1.tool)({
|
|
|
27
27
|
chunkTexts,
|
|
28
28
|
};
|
|
29
29
|
return chunkTexts;
|
|
30
|
-
}
|
|
30
|
+
},
|
|
31
31
|
});
|
|
32
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/cjs/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;
|
|
@@ -1,15 +1,26 @@
|
|
|
1
|
-
import { ResolvedPlugins } from '@botonic/core';
|
|
2
|
-
import { AIAgent,
|
|
1
|
+
import { CampaignV2, ContactInfo, ResolvedPlugins } from '@botonic/core';
|
|
2
|
+
import { AIAgent, GuardrailRule, Tool } from './types';
|
|
3
|
+
interface AIAgentBuilderOptions<TPlugins extends ResolvedPlugins = ResolvedPlugins, TExtraData = any> {
|
|
4
|
+
name: string;
|
|
5
|
+
instructions: string;
|
|
6
|
+
tools: Tool<TPlugins, TExtraData>[];
|
|
7
|
+
campaignContext?: CampaignV2;
|
|
8
|
+
contactInfo: ContactInfo[];
|
|
9
|
+
inputGuardrailRules: GuardrailRule[];
|
|
10
|
+
sourceIds: string[];
|
|
11
|
+
}
|
|
3
12
|
export declare class AIAgentBuilder<TPlugins extends ResolvedPlugins = ResolvedPlugins, TExtraData = any> {
|
|
4
13
|
private name;
|
|
5
14
|
private instructions;
|
|
6
15
|
private tools;
|
|
7
16
|
private inputGuardrails;
|
|
8
|
-
constructor(
|
|
17
|
+
constructor(options: AIAgentBuilderOptions<TPlugins, TExtraData>);
|
|
9
18
|
build(): AIAgent<TPlugins, TExtraData>;
|
|
10
19
|
private addExtraInstructions;
|
|
11
20
|
private getContactInfoInstructions;
|
|
12
21
|
private getMetadataInstructions;
|
|
22
|
+
private getCampaignInstructions;
|
|
13
23
|
private getOutputInstructions;
|
|
14
24
|
private addHubtypeTools;
|
|
15
25
|
}
|
|
26
|
+
export {};
|
package/lib/esm/agent-builder.js
CHANGED
|
@@ -1,50 +1,83 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AIAgentBuilder = void 0;
|
|
4
|
+
const agents_1 = require("@openai/agents");
|
|
5
|
+
const constants_1 = require("./constants");
|
|
6
|
+
const guardrails_1 = require("./guardrails");
|
|
7
|
+
const structured_output_1 = require("./structured-output");
|
|
8
|
+
const tools_1 = require("./tools");
|
|
9
|
+
class AIAgentBuilder {
|
|
10
|
+
constructor(options) {
|
|
11
|
+
this.name = options.name;
|
|
12
|
+
this.instructions = this.addExtraInstructions(options.instructions, options.contactInfo, options.campaignContext);
|
|
13
|
+
this.tools = this.addHubtypeTools(options.tools, options.sourceIds);
|
|
10
14
|
this.inputGuardrails = [];
|
|
11
|
-
if (inputGuardrailRules.length > 0) {
|
|
12
|
-
const inputGuardrail = createInputGuardrail(inputGuardrailRules);
|
|
15
|
+
if (options.inputGuardrailRules.length > 0) {
|
|
16
|
+
const inputGuardrail = (0, guardrails_1.createInputGuardrail)(options.inputGuardrailRules);
|
|
13
17
|
this.inputGuardrails.push(inputGuardrail);
|
|
14
18
|
}
|
|
15
19
|
}
|
|
16
20
|
build() {
|
|
17
21
|
const modelSettings = {};
|
|
18
|
-
if (
|
|
19
|
-
modelSettings.
|
|
22
|
+
if (constants_1.OPENAI_PROVIDER === 'openai') {
|
|
23
|
+
modelSettings.reasoning = { effort: 'none' };
|
|
24
|
+
modelSettings.text = { verbosity: 'medium' };
|
|
20
25
|
}
|
|
21
|
-
|
|
26
|
+
if (this.tools.includes(tools_1.retrieveKnowledge) && constants_1.OPENAI_PROVIDER === 'azure') {
|
|
27
|
+
modelSettings.toolChoice = tools_1.retrieveKnowledge.name;
|
|
28
|
+
}
|
|
29
|
+
// When using standard OpenAI API, we need to specify the model
|
|
30
|
+
// Azure OpenAI uses deployment name instead
|
|
31
|
+
const model = constants_1.OPENAI_PROVIDER === 'openai' ? constants_1.OPENAI_MODEL : undefined;
|
|
32
|
+
// TODO: Improve type safety - replace AgentOutputType<any> with AgentOutputType<typeof OutputSchema>
|
|
33
|
+
// Currently using explicit type parameters to avoid type inference issues where Agent constructor
|
|
34
|
+
// infers ZodObject instead of AgentOutputType<typeof OutputSchema>. The explicit type parameters
|
|
35
|
+
// ensure compatibility with AIAgent type definition. Future improvements:
|
|
36
|
+
// 1. Update @openai/agents package to properly infer AgentOutputType from outputType parameter
|
|
37
|
+
// 2. Replace AgentOutputType<any> with AgentOutputType<typeof OutputSchema> once type system allows
|
|
38
|
+
// 3. Consider updating AIAgent type definition if @openai/agents types change significantly
|
|
39
|
+
return new agents_1.Agent({
|
|
22
40
|
name: this.name,
|
|
41
|
+
model,
|
|
23
42
|
instructions: this.instructions,
|
|
24
43
|
tools: this.tools,
|
|
25
|
-
outputType: OutputSchema,
|
|
44
|
+
outputType: structured_output_1.OutputSchema,
|
|
26
45
|
inputGuardrails: this.inputGuardrails,
|
|
27
46
|
outputGuardrails: [],
|
|
28
47
|
modelSettings,
|
|
29
48
|
});
|
|
30
49
|
}
|
|
31
|
-
addExtraInstructions(initialInstructions, contactInfo) {
|
|
32
|
-
const instructions = `<instructions>\n${initialInstructions}\n</instructions>`;
|
|
50
|
+
addExtraInstructions(initialInstructions, contactInfo, campaignContext) {
|
|
51
|
+
const instructions = `<instructions>\n${initialInstructions.trim()}\n</instructions>`;
|
|
33
52
|
const metadataInstructions = this.getMetadataInstructions();
|
|
34
53
|
const contactInfoInstructions = this.getContactInfoInstructions(contactInfo);
|
|
54
|
+
const campaignInstructions = this.getCampaignInstructions(campaignContext);
|
|
35
55
|
const outputInstructions = this.getOutputInstructions();
|
|
36
|
-
return `${instructions}\n\n${metadataInstructions}\n\n${contactInfoInstructions}\n\n${outputInstructions}`;
|
|
56
|
+
return `${instructions}\n\n${metadataInstructions}\n\n${contactInfoInstructions}\n\n${campaignInstructions}\n\n${outputInstructions}`;
|
|
37
57
|
}
|
|
38
58
|
getContactInfoInstructions(contactInfo) {
|
|
39
|
-
const structuredContactInfo =
|
|
40
|
-
.map(
|
|
59
|
+
const structuredContactInfo = contactInfo
|
|
60
|
+
.map(info => ` <contact_info>
|
|
61
|
+
<name>${info.name}</name>
|
|
62
|
+
<value>${info.value}</value>
|
|
63
|
+
<type>${info.type}</type>
|
|
64
|
+
${info.description
|
|
65
|
+
? `<description>${info.description}</description>`
|
|
66
|
+
: ''}
|
|
67
|
+
</contact_info>`)
|
|
41
68
|
.join('\n');
|
|
42
|
-
return `<
|
|
69
|
+
return `<contact_info_fields>\n${structuredContactInfo}</contact_info_fields>`;
|
|
43
70
|
}
|
|
44
71
|
getMetadataInstructions() {
|
|
45
72
|
const metadata = `Current Date: ${new Date().toISOString()}`;
|
|
46
73
|
return `<metadata>\n${metadata}\n</metadata>`;
|
|
47
74
|
}
|
|
75
|
+
getCampaignInstructions(campaignContext) {
|
|
76
|
+
if (!campaignContext || !campaignContext.agent_context) {
|
|
77
|
+
return '';
|
|
78
|
+
}
|
|
79
|
+
return `<campaign_context>\n${campaignContext.agent_context}\n</campaign_context>`;
|
|
80
|
+
}
|
|
48
81
|
getOutputInstructions() {
|
|
49
82
|
const example = {
|
|
50
83
|
messages: [
|
|
@@ -60,11 +93,12 @@ export class AIAgentBuilder {
|
|
|
60
93
|
return `<output>\n${output}\n</output>`;
|
|
61
94
|
}
|
|
62
95
|
addHubtypeTools(tools, sourceIds) {
|
|
63
|
-
const hubtypeTools = [...mandatoryTools];
|
|
96
|
+
const hubtypeTools = [...tools_1.mandatoryTools];
|
|
64
97
|
if (sourceIds.length > 0) {
|
|
65
|
-
hubtypeTools.push(retrieveKnowledge);
|
|
98
|
+
hubtypeTools.push(tools_1.retrieveKnowledge);
|
|
66
99
|
}
|
|
67
100
|
return [...hubtypeTools, ...tools];
|
|
68
101
|
}
|
|
69
102
|
}
|
|
103
|
+
exports.AIAgentBuilder = AIAgentBuilder;
|
|
70
104
|
//# sourceMappingURL=agent-builder.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agent-builder.js","sourceRoot":"","sources":["../../src/agent-builder.ts"],"names":[],"mappings":"AACA,
|
|
1
|
+
{"version":3,"file":"agent-builder.js","sourceRoot":"","sources":["../../src/agent-builder.ts"],"names":[],"mappings":";;;AACA,2CAKuB;AAEvB,2CAA2D;AAC3D,6CAAmD;AACnD,2DAAkD;AAClD,mCAA2D;AAgB3D,MAAa,cAAc;IASzB,YAAY,OAAoD;QAC9D,IAAI,CAAC,IAAI,GAAG,OAAO,CAAC,IAAI,CAAA;QACxB,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC,oBAAoB,CAC3C,OAAO,CAAC,YAAY,EACpB,OAAO,CAAC,WAAW,EACnB,OAAO,CAAC,eAAe,CACxB,CAAA;QACD,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,eAAe,CAAC,OAAO,CAAC,KAAK,EAAE,OAAO,CAAC,SAAS,CAAC,CAAA;QACnE,IAAI,CAAC,eAAe,GAAG,EAAE,CAAA;QACzB,IAAI,OAAO,CAAC,mBAAmB,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YAC3C,MAAM,cAAc,GAAG,IAAA,iCAAoB,EAAC,OAAO,CAAC,mBAAmB,CAAC,CAAA;YACxE,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,cAAc,CAAC,CAAA;QAC3C,CAAC;IACH,CAAC;IAED,KAAK;QACH,MAAM,aAAa,GAAkB,EAAmB,CAAA;QACxD,IAAI,2BAAe,KAAK,QAAQ,EAAE,CAAC;YACjC,aAAa,CAAC,SAAS,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,CAAA;YAC5C,aAAa,CAAC,IAAI,GAAG,EAAE,SAAS,EAAE,QAAQ,EAAE,CAAA;QAC9C,CAAC;QAED,IAAI,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,yBAAiB,CAAC,IAAI,2BAAe,KAAK,OAAO,EAAE,CAAC;YAC1E,aAAa,CAAC,UAAU,GAAG,yBAAiB,CAAC,IA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_API_KEY: string | undefined;
|
|
3
|
+
export declare const OPENAI_MODEL: string;
|
|
4
|
+
export declare const OPENAI_PROVIDER: 'openai' | 'azure';
|
|
2
5
|
export declare const AZURE_OPENAI_API_KEY: string | undefined;
|
|
3
6
|
export declare const AZURE_OPENAI_API_BASE: string | undefined;
|
|
4
7
|
export declare const AZURE_OPENAI_API_DEPLOYMENT_NAME: string;
|
package/lib/esm/constants.js
CHANGED
|
@@ -1,8 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MAX_MEMORY_LENGTH = exports.isProd = exports.AZURE_OPENAI_API_VERSION = exports.AZURE_OPENAI_API_DEPLOYMENT_NAME = exports.AZURE_OPENAI_API_BASE = exports.AZURE_OPENAI_API_KEY = exports.OPENAI_PROVIDER = exports.OPENAI_MODEL = exports.OPENAI_API_KEY = exports.HUBTYPE_API_URL = void 0;
|
|
4
|
+
exports.HUBTYPE_API_URL = process.env.HUBTYPE_API_URL || 'https://api.hubtype.com';
|
|
5
|
+
// OpenAI Provider Configuration
|
|
6
|
+
exports.OPENAI_API_KEY = process.env.OPENAI_API_KEY; // pragma: allowlist secret
|
|
7
|
+
exports.OPENAI_MODEL = process.env.OPENAI_MODEL || 'gpt-4.1-mini';
|
|
8
|
+
exports.OPENAI_PROVIDER = process.env.OPENAI_PROVIDER || 'azure';
|
|
9
|
+
// Azure OpenAI Configuration
|
|
10
|
+
exports.AZURE_OPENAI_API_KEY = process.env.AZURE_OPENAI_API_KEY; // pragma: allowlist secret
|
|
11
|
+
exports.AZURE_OPENAI_API_BASE = process.env.AZURE_OPENAI_API_BASE;
|
|
12
|
+
exports.AZURE_OPENAI_API_DEPLOYMENT_NAME = process.env.AZURE_OPENAI_API_DEPLOYMENT_NAME || 'gpt-41-mini_p1';
|
|
13
|
+
exports.AZURE_OPENAI_API_VERSION = process.env.AZURE_OPENAI_API_VERSION || '2025-01-01-preview';
|
|
14
|
+
exports.isProd = process.env.NODE_ENV === 'production';
|
|
15
|
+
exports.MAX_MEMORY_LENGTH = 25;
|
|
8
16
|
//# sourceMappingURL=constants.js.map
|
package/lib/esm/constants.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":";;;AAAa,QAAA,eAAe,GAC1B,OAAO,CAAC,GAAG,CAAC,eAAe,IAAI,yBAAyB,CAAA;AAE1D,gCAAgC;AACnB,QAAA,cAAc,GAAG,OAAO,CAAC,GAAG,CAAC,cAAc,CAAA,CAAC,2BAA2B;AACvE,QAAA,YAAY,GAAG,OAAO,CAAC,GAAG,CAAC,YAAY,IAAI,cAAc,CAAA;AACzD,QAAA,eAAe,GACzB,OAAO,CAAC,GAAG,CAAC,eAAsC,IAAI,OAAO,CAAA;AAEhE,6BAA6B;AAChB,QAAA,oBAAoB,GAAG,OAAO,CAAC,GAAG,CAAC,oBAAoB,CAAA,CAAC,2BAA2B;AACnF,QAAA,qBAAqB,GAAG,OAAO,CAAC,GAAG,CAAC,qBAAqB,CAAA;AACzD,QAAA,gCAAgC,GAC3C,OAAO,CAAC,GAAG,CAAC,gCAAgC,IAAI,gBAAgB,CAAA;AACrD,QAAA,wBAAwB,GACnC,OAAO,CAAC,GAAG,CAAC,wBAAwB,IAAI,oBAAoB,CAAA;AAEjD,QAAA,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,YAAY,CAAA;AAE9C,QAAA,iBAAiB,GAAG,EAAE,CAAA"}
|