@botonic/plugin-ai-agents 0.42.4 → 0.43.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 +13 -2
- package/lib/cjs/agent-builder.js +34 -10
- 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.map +1 -1
- package/lib/cjs/index.js +10 -2
- package/lib/cjs/index.js.map +1 -1
- package/lib/cjs/openai.js +18 -3
- package/lib/cjs/openai.js.map +1 -1
- package/lib/cjs/runner.js +5 -1
- 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 +2 -1
- package/lib/cjs/tools/retrieve-knowledge.js.map +1 -1
- package/lib/cjs/types.d.ts +2 -2
- package/lib/esm/agent-builder.d.ts +13 -2
- package/lib/esm/agent-builder.js +35 -11
- package/lib/esm/agent-builder.js.map +1 -1
- package/lib/esm/constants.d.ts +3 -0
- package/lib/esm/constants.js +5 -0
- package/lib/esm/constants.js.map +1 -1
- package/lib/esm/guardrails/input.js.map +1 -1
- package/lib/esm/index.js +10 -2
- package/lib/esm/index.js.map +1 -1
- package/lib/esm/openai.js +18 -4
- package/lib/esm/openai.js.map +1 -1
- package/lib/esm/runner.js +5 -1
- package/lib/esm/runner.js.map +1 -1
- package/lib/esm/tools/retrieve-knowledge.d.ts +8 -1
- package/lib/esm/tools/retrieve-knowledge.js +2 -1
- package/lib/esm/tools/retrieve-knowledge.js.map +1 -1
- package/lib/esm/types.d.ts +2 -2
- package/package.json +3 -3
- package/src/agent-builder.ts +64 -22
- package/src/constants.ts +7 -0
- package/src/guardrails/input.ts +1 -1
- package/src/index.ts +9 -8
- package/src/openai.ts +19 -3
- package/src/runner.ts +15 -2
- package/src/tools/retrieve-knowledge.ts +3 -2
- package/src/types.ts +2 -1
|
@@ -1,15 +1,26 @@
|
|
|
1
|
-
import { ResolvedPlugins } from '@botonic/core';
|
|
1
|
+
import { CampaignV2, ResolvedPlugins } from '@botonic/core';
|
|
2
2
|
import { AIAgent, ContactInfo, 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/cjs/agent-builder.js
CHANGED
|
@@ -2,27 +2,44 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.AIAgentBuilder = void 0;
|
|
4
4
|
const agents_1 = require("@openai/agents");
|
|
5
|
+
const constants_1 = require("./constants");
|
|
5
6
|
const guardrails_1 = require("./guardrails");
|
|
6
7
|
const structured_output_1 = require("./structured-output");
|
|
7
8
|
const tools_1 = require("./tools");
|
|
8
9
|
class AIAgentBuilder {
|
|
9
|
-
constructor(
|
|
10
|
-
this.name = name;
|
|
11
|
-
this.instructions = this.addExtraInstructions(instructions, contactInfo);
|
|
12
|
-
this.tools = this.addHubtypeTools(tools, sourceIds);
|
|
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);
|
|
13
14
|
this.inputGuardrails = [];
|
|
14
|
-
if (inputGuardrailRules.length > 0) {
|
|
15
|
-
const inputGuardrail = (0, guardrails_1.createInputGuardrail)(inputGuardrailRules);
|
|
15
|
+
if (options.inputGuardrailRules.length > 0) {
|
|
16
|
+
const inputGuardrail = (0, guardrails_1.createInputGuardrail)(options.inputGuardrailRules);
|
|
16
17
|
this.inputGuardrails.push(inputGuardrail);
|
|
17
18
|
}
|
|
18
19
|
}
|
|
19
20
|
build() {
|
|
20
21
|
const modelSettings = {};
|
|
21
|
-
if (
|
|
22
|
+
if (constants_1.OPENAI_PROVIDER === 'openai') {
|
|
23
|
+
// @ts-expect-error - reasoning.effort is valid but we need to update openai and typescript dependencies
|
|
24
|
+
modelSettings.reasoning = { effort: 'none' };
|
|
25
|
+
modelSettings.text = { verbosity: 'medium' };
|
|
26
|
+
}
|
|
27
|
+
if (this.tools.includes(tools_1.retrieveKnowledge) && constants_1.OPENAI_PROVIDER === 'azure') {
|
|
22
28
|
modelSettings.toolChoice = tools_1.retrieveKnowledge.name;
|
|
23
29
|
}
|
|
30
|
+
// When using standard OpenAI API, we need to specify the model
|
|
31
|
+
// Azure OpenAI uses deployment name instead
|
|
32
|
+
const model = constants_1.OPENAI_PROVIDER === 'openai' ? constants_1.OPENAI_MODEL : undefined;
|
|
33
|
+
// TODO: Improve type safety - replace AgentOutputType<any> with AgentOutputType<typeof OutputSchema>
|
|
34
|
+
// Currently using explicit type parameters to avoid type inference issues where Agent constructor
|
|
35
|
+
// infers ZodObject instead of AgentOutputType<typeof OutputSchema>. The explicit type parameters
|
|
36
|
+
// ensure compatibility with AIAgent type definition. Future improvements:
|
|
37
|
+
// 1. Update @openai/agents package to properly infer AgentOutputType from outputType parameter
|
|
38
|
+
// 2. Replace AgentOutputType<any> with AgentOutputType<typeof OutputSchema> once type system allows
|
|
39
|
+
// 3. Consider updating AIAgent type definition if @openai/agents types change significantly
|
|
24
40
|
return new agents_1.Agent({
|
|
25
41
|
name: this.name,
|
|
42
|
+
model,
|
|
26
43
|
instructions: this.instructions,
|
|
27
44
|
tools: this.tools,
|
|
28
45
|
outputType: structured_output_1.OutputSchema,
|
|
@@ -31,12 +48,13 @@ class AIAgentBuilder {
|
|
|
31
48
|
modelSettings,
|
|
32
49
|
});
|
|
33
50
|
}
|
|
34
|
-
addExtraInstructions(initialInstructions, contactInfo) {
|
|
35
|
-
const instructions = `<instructions>\n${initialInstructions}\n</instructions>`;
|
|
51
|
+
addExtraInstructions(initialInstructions, contactInfo, campaignContext) {
|
|
52
|
+
const instructions = `<instructions>\n${initialInstructions.trim()}\n</instructions>`;
|
|
36
53
|
const metadataInstructions = this.getMetadataInstructions();
|
|
37
54
|
const contactInfoInstructions = this.getContactInfoInstructions(contactInfo);
|
|
55
|
+
const campaignInstructions = this.getCampaignInstructions(campaignContext);
|
|
38
56
|
const outputInstructions = this.getOutputInstructions();
|
|
39
|
-
return `${instructions}\n\n${metadataInstructions}\n\n${contactInfoInstructions}\n\n${outputInstructions}`;
|
|
57
|
+
return `${instructions}\n\n${metadataInstructions}\n\n${contactInfoInstructions}\n\n${campaignInstructions}\n\n${outputInstructions}`;
|
|
40
58
|
}
|
|
41
59
|
getContactInfoInstructions(contactInfo) {
|
|
42
60
|
const structuredContactInfo = Object.entries(contactInfo)
|
|
@@ -48,6 +66,12 @@ class AIAgentBuilder {
|
|
|
48
66
|
const metadata = `Current Date: ${new Date().toISOString()}`;
|
|
49
67
|
return `<metadata>\n${metadata}\n</metadata>`;
|
|
50
68
|
}
|
|
69
|
+
getCampaignInstructions(campaignContext) {
|
|
70
|
+
if (!campaignContext || !campaignContext.agent_context) {
|
|
71
|
+
return '';
|
|
72
|
+
}
|
|
73
|
+
return `<campaign_context>\n${campaignContext.agent_context}\n</campaign_context>`;
|
|
74
|
+
}
|
|
51
75
|
getOutputInstructions() {
|
|
52
76
|
const example = {
|
|
53
77
|
messages: [
|
|
@@ -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;YAC1C,MAAM,cAAc,GAAG,IAAA,iCAAoB,EAAC,OAAO,CAAC,mBAAmB,CAAC,CAAA;YACxE,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,cAAc,CAAC,CAAA;SAC1C;IACH,CAAC;IAED,KAAK;QACH,MAAM,aAAa,GAAkB,EAAmB,CAAA;QACxD,IAAI,2BAAe,KAAK,QAAQ,EAAE;YAChC,wGAAwG;YACxG,aAAa,CAAC,SAAS,GAAG,EA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ACF;AApHD,wCAoHC"}
|
package/lib/cjs/constants.d.ts
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
export declare const HUBTYPE_API_URL: string;
|
|
2
|
+
export declare const OPENAI_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/cjs/constants.js
CHANGED
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
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.HUBTYPE_API_URL = void 0;
|
|
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
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
|
|
5
10
|
exports.AZURE_OPENAI_API_KEY = process.env.AZURE_OPENAI_API_KEY; // pragma: allowlist secret
|
|
6
11
|
exports.AZURE_OPENAI_API_BASE = process.env.AZURE_OPENAI_API_BASE;
|
|
7
12
|
exports.AZURE_OPENAI_API_DEPLOYMENT_NAME = process.env.AZURE_OPENAI_API_DEPLOYMENT_NAME || 'gpt-41-mini_p1';
|
package/lib/cjs/constants.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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;
|
|
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"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"input.js","sourceRoot":"","sources":["../../../src/guardrails/input.ts"],"names":[],"mappings":";;;;AAAA,2CAA4E;AAC5E,6BAAuB;AAIvB,SAAgB,oBAAoB,CAAC,KAAsB;IACzD,MAAM,UAAU,GAAG,OAAC,CAAC,MAAM,CACzB,MAAM,CAAC,WAAW,CAChB,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,EAAE,OAAC,CAAC,OAAO,EAAE,CAAC,QAAQ,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC,CACvE,CACF,CAAA;IAED,MAAM,KAAK,GAAG,IAAI,cAAK,CAAC;QACtB,IAAI,EAAE,gBAAgB;QACtB,YAAY,EACV,8DAA8D;QAChE,UAAU;KACX,CAAC,CAAA;IAEF,OAAO;QACL,IAAI,EAAE,gBAAgB;QACtB,OAAO,EAAE,CAAO,EAAE,KAAK,EAAE,OAAO,EAAE,EAAE,EAAE;YACpC,MAAM,WAAW,GAAG,KAAK,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAoB,CAAA;YAC9D,MAAM,MAAM,GAAG,MAAM,IAAA,YAAG,EAAC,KAAK,EAAE,CAAC,WAAW,CAAC,EAAE,EAAE,OAAO,EAAE,CAAC,CAAA;YAC3D,MAAM,WAAW,GAAG,MAAM,CAAC,
|
|
1
|
+
{"version":3,"file":"input.js","sourceRoot":"","sources":["../../../src/guardrails/input.ts"],"names":[],"mappings":";;;;AAAA,2CAA4E;AAC5E,6BAAuB;AAIvB,SAAgB,oBAAoB,CAAC,KAAsB;IACzD,MAAM,UAAU,GAAG,OAAC,CAAC,MAAM,CACzB,MAAM,CAAC,WAAW,CAChB,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,EAAE,OAAC,CAAC,OAAO,EAAE,CAAC,QAAQ,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC,CACvE,CACF,CAAA;IAED,MAAM,KAAK,GAAG,IAAI,cAAK,CAAC;QACtB,IAAI,EAAE,gBAAgB;QACtB,YAAY,EACV,8DAA8D;QAChE,UAAU;KACX,CAAC,CAAA;IAEF,OAAO;QACL,IAAI,EAAE,gBAAgB;QACtB,OAAO,EAAE,CAAO,EAAE,KAAK,EAAE,OAAO,EAAE,EAAE,EAAE;YACpC,MAAM,WAAW,GAAG,KAAK,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAoB,CAAA;YAC9D,MAAM,MAAM,GAAG,MAAM,IAAA,YAAG,EAAC,KAAK,EAAE,CAAC,WAAW,CAAC,EAAE,EAAE,OAAO,EAAE,CAAC,CAAA;YAC3D,MAAM,WAAW,GAAG,MAAM,CAAC,WAAsC,CAAA;YACjE,IAAI,WAAW,KAAK,SAAS,EAAE;gBAC7B,MAAM,IAAI,KAAK,CAAC,0CAA0C,CAAC,CAAA;aAC5D;YACD,MAAM,SAAS,GAAG,MAAM,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,KAAK,KAAK,IAAI,CAAC,CAAA;YAC1E,MAAM,mBAAmB,GAAG,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,MAAM,CACzD,GAAG,CAAC,EAAE,CAAC,WAAW,CAAC,GAAG,CAAC,KAAK,IAAI,CACjC,CAAA;YACD,OAAO;gBACL,UAAU,EAAE,mBAAmB;gBAC/B,iBAAiB,EAAE,SAAS;aAC7B,CAAA;QACH,CAAC,CAAA;KACF,CAAA;AACH,CAAC;AAjCD,oDAiCC"}
|
package/lib/cjs/index.js
CHANGED
|
@@ -18,7 +18,7 @@ class BotonicPluginAiAgents {
|
|
|
18
18
|
return;
|
|
19
19
|
}
|
|
20
20
|
getInference(request, aiAgentArgs) {
|
|
21
|
-
var _a;
|
|
21
|
+
var _a, _b;
|
|
22
22
|
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
23
23
|
try {
|
|
24
24
|
const authToken = constants_1.isProd ? request.session._access_token : this.authToken;
|
|
@@ -26,7 +26,15 @@ 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(
|
|
29
|
+
const agent = new agent_builder_1.AIAgentBuilder({
|
|
30
|
+
name: aiAgentArgs.name,
|
|
31
|
+
instructions: aiAgentArgs.instructions,
|
|
32
|
+
tools: tools,
|
|
33
|
+
contactInfo: request.session.user.contact_info || {},
|
|
34
|
+
inputGuardrailRules: aiAgentArgs.inputGuardrailRules || [],
|
|
35
|
+
sourceIds: aiAgentArgs.sourceIds || [],
|
|
36
|
+
campaignContext: (_b = request.input.context) === null || _b === void 0 ? void 0 : _b.campaign_v2,
|
|
37
|
+
}).build();
|
|
30
38
|
const messages = yield this.getMessages(request, authToken, constants_1.MAX_MEMORY_LENGTH);
|
|
31
39
|
const context = {
|
|
32
40
|
authToken,
|
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;AAUxC,MAAqB,qBAAqB;IAQxC,YAAY,OAAoD;QAFzD,oBAAe,GAAuC,EAAE,CAAA;QAG7D,IAAA,oBAAW,EAAC,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,UAAU,EAAE,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,OAAO,CAAC,CAAA;QAClD,IAAI,CAAC,SAAS,GAAG,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,SAAS,CAAA;QACnC,IAAI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"}
|
package/lib/cjs/openai.js
CHANGED
|
@@ -1,22 +1,37 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.setUpOpenAI = void 0;
|
|
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
|
exports.setUpOpenAI = setUpOpenAI;
|
|
19
|
+
function setOpenAIClient(maxRetries, timeout) {
|
|
20
|
+
const client = new openai_1.default({
|
|
21
|
+
apiKey: constants_1.OPENAI_API_KEY,
|
|
22
|
+
timeout: timeout || 16000,
|
|
23
|
+
maxRetries: maxRetries || 2,
|
|
24
|
+
dangerouslyAllowBrowser: !constants_1.isProd,
|
|
25
|
+
});
|
|
26
|
+
(0, agents_1.setDefaultOpenAIClient)(client);
|
|
27
|
+
}
|
|
13
28
|
function setAzureOpenAIClient(maxRetries, timeout) {
|
|
14
29
|
const client = new openai_1.AzureOpenAI({
|
|
15
30
|
apiKey: constants_1.AZURE_OPENAI_API_KEY,
|
|
16
31
|
apiVersion: constants_1.AZURE_OPENAI_API_VERSION,
|
|
17
32
|
deployment: constants_1.AZURE_OPENAI_API_DEPLOYMENT_NAME,
|
|
18
33
|
baseURL: constants_1.AZURE_OPENAI_API_BASE,
|
|
19
|
-
timeout: timeout ||
|
|
34
|
+
timeout: timeout || 16000,
|
|
20
35
|
maxRetries: maxRetries || 2,
|
|
21
36
|
dangerouslyAllowBrowser: !constants_1.isProd,
|
|
22
37
|
});
|
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":";;;;AAAA,2CAIuB;AACvB,yDAA4C;AAE5C,2CAQoB;AAEpB,SAAgB,WAAW,CAAC,UAAmB,EAAE,OAAgB;IAC/D,IAAI,2BAAe,KAAK,OAAO,EAAE;QAC/B,oBAAoB,CAAC,UAAU,EAAE,OAAO,CAAC,CAAA;KAC1C;SAAM;QACL,eAAe,CAAC,UAAU,EAAE,OAAO,CAAC,CAAA;KACrC;IACD,IAAA,qBAAY,EAAC,kBAAkB,CAAC,CAAA;IAChC,IAAA,2BAAkB,EAAC,IAAI,CAAC,CAAA;AAC1B,CAAC;AARD,kCAQC;AAED,SAAS,eAAe,CAAC,UAAmB,EAAE,OAAgB;IAC5D,MAAM,MAAM,GAAG,IAAI,gBAAM,CAAC;QACxB,MAAM,EAAE,0BAAc;QACtB,OAAO,EAAE,OAAO,IAAI,KAAK;QACzB,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;QACzB,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
|
@@ -15,7 +15,11 @@ class AIAgentRunner {
|
|
|
15
15
|
const runner = new agents_1.Runner({
|
|
16
16
|
modelSettings: { temperature: 0 },
|
|
17
17
|
});
|
|
18
|
-
|
|
18
|
+
// Type assertion to bypass strict type checking - the actual return type from runner.run()
|
|
19
|
+
// doesn't perfectly match our interface, but the properties we access are compatible
|
|
20
|
+
const result = (yield runner.run(this.agent, messages, {
|
|
21
|
+
context,
|
|
22
|
+
}));
|
|
19
23
|
const outputMessages = ((_a = result.finalOutput) === null || _a === void 0 ? void 0 : _a.messages) || [];
|
|
20
24
|
const hasExit = outputMessages.length === 0 ||
|
|
21
25
|
outputMessages.some(message => message.type === 'exit');
|
package/lib/cjs/runner.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runner.js","sourceRoot":"","sources":["../../src/runner.ts"],"names":[],"mappings":";;;;AACA,2CAIuB;AAEvB,mCAA2C;
|
|
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;IAEK,GAAG,CACP,QAA+B,EAC/B,OAAsC;;;YAEtC,IAAI;gBACF,MAAM,MAAM,GAAG,IAAI,eAAM,CAAC;oBACxB,aAAa,EAAE,EAAE,WAAW,EAAE,CAAC,EAAE;iBAClC,CAAC,CAAA;gBACF,2FAA2F;gBAC3F,qFAAqF;gBACrF,MAAM,MAAM,GAAG,CAAC,MAAM,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,EAAE,QAAQ,EAAE;oBACrD,OAAO;iB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CAC7B,IAAI,CAAC,oBAAoB,CAAC,IAAuB,EAAE,OAAO,CAAC,EAE5D,MAAM,CACL,CAAC,aAA4B,EAAE,EAAE,CAAC,aAAa,CAAC,QAAQ,KAAK,EAAE,CAChE,KAAI,EAAE,CACV,CAAA;IACH,CAAC;IAEO,oBAAoB,CAC1B,IAAqB,EACrB,OAAsC;QAEtC,IAAI,IAAI,CAAC,OAAO,CAAC,IAAI,KAAK,eAAe,EAAE;YACzC,OAAO;gBACL,QAAQ,EAAE,EAAE;gBACZ,aAAa,EAAE,EAAE;aAClB,CAAA;SACF;QACD,MAAM,QAAQ,GAAG,IAAI,CAAC,OAAO,CAAC,IAAI,CAAA;QAClC,MAAM,aAAa,GAAG,IAAI,CAAC,oBAAoB,CAAC,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,CAAA;QAEvE,IAAI,QAAQ,KAAK,yBAAiB,CAAC,IAAI,EAAE;YACvC,OAAO;gBACL,QAAQ;gBACR,aAAa;gBACb,uBAAuB,EAAE,OAAO,CAAC,aAAa,CAAC,SAAS;gBACxD,sBAAsB,EAAE,OAAO,CAAC,aAAa,CAAC,SAAS;aACxD,CAAA;SACF;QAED,OAAO;YACL,QAAQ;YACR,aAAa;SACd,CAAA;IACH,CAAC;IAEO,oBAAoB,CAAC,gBAAwB;QACnD,IAAI;YACF,OAAO,IAAI,CAAC,KAAK,CAAC,gBAAgB,CAAC,CAAA;SACpC;QAAC,OAAO,KAAK,EAAE;YACd,OAAO,EAAE,CAAA;SACV;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>;
|
|
@@ -11,8 +11,9 @@ exports.retrieveKnowledge = (0, agents_1.tool)({
|
|
|
11
11
|
parameters: zod_1.z.object({
|
|
12
12
|
query: zod_1.z.string().describe('The query to search the knowledge base for'),
|
|
13
13
|
}),
|
|
14
|
-
execute: (
|
|
14
|
+
execute: (input, runContext) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
15
15
|
const context = runContext === null || runContext === void 0 ? void 0 : runContext.context;
|
|
16
|
+
const query = input.query;
|
|
16
17
|
if (!context) {
|
|
17
18
|
throw new Error('Context is required');
|
|
18
19
|
}
|
|
@@ -1 +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,
|
|
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,CACP,KAAwB,EACxB,UAAgC,EACb,EAAE;QACrB,MAAM,OAAO,GAAG,UAAU,aAAV,UAAU,uBAAV,UAAU,CAAE,OAAO,CAAA;QACnC,MAAM,KAAK,GAAG,KAAK,CAAC,KAAK,CAAA;QACzB,IAAI,CAAC,OAAO,EAAE;YACZ,MAAM,IAAI,KAAK,CAAC,qBAAqB,CAAC,CAAA;SACvC;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,CAAA;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> {
|
|
@@ -26,7 +26,7 @@ export interface Chunk {
|
|
|
26
26
|
}
|
|
27
27
|
export type ContactInfo = Record<string, string>;
|
|
28
28
|
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
|
|
29
|
+
export type AIAgent<TPlugins extends ResolvedPlugins = ResolvedPlugins, TExtraData = any> = Agent<Context<TPlugins, TExtraData>, AgentOutputType<typeof OutputSchema>>;
|
|
30
30
|
export interface PluginAiAgentOptions<TPlugins extends ResolvedPlugins = ResolvedPlugins, TExtraData = any> {
|
|
31
31
|
authToken?: string;
|
|
32
32
|
customTools?: CustomTool<TPlugins, TExtraData>[];
|
|
@@ -1,15 +1,26 @@
|
|
|
1
|
-
import { ResolvedPlugins } from '@botonic/core';
|
|
1
|
+
import { CampaignV2, ResolvedPlugins } from '@botonic/core';
|
|
2
2
|
import { AIAgent, ContactInfo, 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,25 +1,42 @@
|
|
|
1
|
-
import { Agent } from '@openai/agents';
|
|
1
|
+
import { Agent, } from '@openai/agents';
|
|
2
|
+
import { OPENAI_MODEL, OPENAI_PROVIDER } from './constants';
|
|
2
3
|
import { createInputGuardrail } from './guardrails';
|
|
3
4
|
import { OutputSchema } from './structured-output';
|
|
4
5
|
import { mandatoryTools, retrieveKnowledge } from './tools';
|
|
5
6
|
export class AIAgentBuilder {
|
|
6
|
-
constructor(
|
|
7
|
-
this.name = name;
|
|
8
|
-
this.instructions = this.addExtraInstructions(instructions, contactInfo);
|
|
9
|
-
this.tools = this.addHubtypeTools(tools, sourceIds);
|
|
7
|
+
constructor(options) {
|
|
8
|
+
this.name = options.name;
|
|
9
|
+
this.instructions = this.addExtraInstructions(options.instructions, options.contactInfo, options.campaignContext);
|
|
10
|
+
this.tools = this.addHubtypeTools(options.tools, options.sourceIds);
|
|
10
11
|
this.inputGuardrails = [];
|
|
11
|
-
if (inputGuardrailRules.length > 0) {
|
|
12
|
-
const inputGuardrail = createInputGuardrail(inputGuardrailRules);
|
|
12
|
+
if (options.inputGuardrailRules.length > 0) {
|
|
13
|
+
const inputGuardrail = createInputGuardrail(options.inputGuardrailRules);
|
|
13
14
|
this.inputGuardrails.push(inputGuardrail);
|
|
14
15
|
}
|
|
15
16
|
}
|
|
16
17
|
build() {
|
|
17
18
|
const modelSettings = {};
|
|
18
|
-
if (
|
|
19
|
+
if (OPENAI_PROVIDER === 'openai') {
|
|
20
|
+
// @ts-expect-error - reasoning.effort is valid but we need to update openai and typescript dependencies
|
|
21
|
+
modelSettings.reasoning = { effort: 'none' };
|
|
22
|
+
modelSettings.text = { verbosity: 'medium' };
|
|
23
|
+
}
|
|
24
|
+
if (this.tools.includes(retrieveKnowledge) && OPENAI_PROVIDER === 'azure') {
|
|
19
25
|
modelSettings.toolChoice = retrieveKnowledge.name;
|
|
20
26
|
}
|
|
27
|
+
// When using standard OpenAI API, we need to specify the model
|
|
28
|
+
// Azure OpenAI uses deployment name instead
|
|
29
|
+
const model = OPENAI_PROVIDER === 'openai' ? OPENAI_MODEL : undefined;
|
|
30
|
+
// TODO: Improve type safety - replace AgentOutputType<any> with AgentOutputType<typeof OutputSchema>
|
|
31
|
+
// Currently using explicit type parameters to avoid type inference issues where Agent constructor
|
|
32
|
+
// infers ZodObject instead of AgentOutputType<typeof OutputSchema>. The explicit type parameters
|
|
33
|
+
// ensure compatibility with AIAgent type definition. Future improvements:
|
|
34
|
+
// 1. Update @openai/agents package to properly infer AgentOutputType from outputType parameter
|
|
35
|
+
// 2. Replace AgentOutputType<any> with AgentOutputType<typeof OutputSchema> once type system allows
|
|
36
|
+
// 3. Consider updating AIAgent type definition if @openai/agents types change significantly
|
|
21
37
|
return new Agent({
|
|
22
38
|
name: this.name,
|
|
39
|
+
model,
|
|
23
40
|
instructions: this.instructions,
|
|
24
41
|
tools: this.tools,
|
|
25
42
|
outputType: OutputSchema,
|
|
@@ -28,12 +45,13 @@ export class AIAgentBuilder {
|
|
|
28
45
|
modelSettings,
|
|
29
46
|
});
|
|
30
47
|
}
|
|
31
|
-
addExtraInstructions(initialInstructions, contactInfo) {
|
|
32
|
-
const instructions = `<instructions>\n${initialInstructions}\n</instructions>`;
|
|
48
|
+
addExtraInstructions(initialInstructions, contactInfo, campaignContext) {
|
|
49
|
+
const instructions = `<instructions>\n${initialInstructions.trim()}\n</instructions>`;
|
|
33
50
|
const metadataInstructions = this.getMetadataInstructions();
|
|
34
51
|
const contactInfoInstructions = this.getContactInfoInstructions(contactInfo);
|
|
52
|
+
const campaignInstructions = this.getCampaignInstructions(campaignContext);
|
|
35
53
|
const outputInstructions = this.getOutputInstructions();
|
|
36
|
-
return `${instructions}\n\n${metadataInstructions}\n\n${contactInfoInstructions}\n\n${outputInstructions}`;
|
|
54
|
+
return `${instructions}\n\n${metadataInstructions}\n\n${contactInfoInstructions}\n\n${campaignInstructions}\n\n${outputInstructions}`;
|
|
37
55
|
}
|
|
38
56
|
getContactInfoInstructions(contactInfo) {
|
|
39
57
|
const structuredContactInfo = Object.entries(contactInfo)
|
|
@@ -45,6 +63,12 @@ export class AIAgentBuilder {
|
|
|
45
63
|
const metadata = `Current Date: ${new Date().toISOString()}`;
|
|
46
64
|
return `<metadata>\n${metadata}\n</metadata>`;
|
|
47
65
|
}
|
|
66
|
+
getCampaignInstructions(campaignContext) {
|
|
67
|
+
if (!campaignContext || !campaignContext.agent_context) {
|
|
68
|
+
return '';
|
|
69
|
+
}
|
|
70
|
+
return `<campaign_context>\n${campaignContext.agent_context}\n</campaign_context>`;
|
|
71
|
+
}
|
|
48
72
|
getOutputInstructions() {
|
|
49
73
|
const example = {
|
|
50
74
|
messages: [
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agent-builder.js","sourceRoot":"","sources":["../../src/agent-builder.ts"],"names":[],"mappings":"AACA,OAAO,
|
|
1
|
+
{"version":3,"file":"agent-builder.js","sourceRoot":"","sources":["../../src/agent-builder.ts"],"names":[],"mappings":"AACA,OAAO,EACL,KAAK,GAIN,MAAM,gBAAgB,CAAA;AAEvB,OAAO,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAC3D,OAAO,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAA;AACnD,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAA;AAClD,OAAO,EAAE,cAAc,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAA;AAgB3D,MAAM,OAAO,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,KA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iBACF;aACF;SACF,CAAA;QACD,MAAM,MAAM,GAAG,yIAAyI,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,cAAc,CAAA;QAC7L,OAAO,aAAa,MAAM,aAAa,CAAA;IACzC,CAAC;IAEO,eAAe,CACrB,KAAmC,EACnC,SAAmB;QAEnB,MAAM,YAAY,GAAW,CAAC,GAAG,cAAc,CAAC,CAAA;QAChD,IAAI,SAAS,CAAC,MAAM,GAAG,CAAC,EAAE;YACxB,YAAY,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAA;SACrC;QACD,OAAO,CAAC,GAAG,YAAY,EAAE,GAAG,KAAK,CAAC,CAAA;IACpC,CAAC;CACF"}
|
package/lib/esm/constants.d.ts
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
export declare const HUBTYPE_API_URL: string;
|
|
2
|
+
export declare const OPENAI_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,4 +1,9 @@
|
|
|
1
1
|
export const HUBTYPE_API_URL = process.env.HUBTYPE_API_URL || 'https://api.hubtype.com';
|
|
2
|
+
// OpenAI Provider Configuration
|
|
3
|
+
export const OPENAI_API_KEY = process.env.OPENAI_API_KEY; // pragma: allowlist secret
|
|
4
|
+
export const OPENAI_MODEL = process.env.OPENAI_MODEL || 'gpt-4.1-mini';
|
|
5
|
+
export const OPENAI_PROVIDER = process.env.OPENAI_PROVIDER || 'azure';
|
|
6
|
+
// Azure OpenAI Configuration
|
|
2
7
|
export const AZURE_OPENAI_API_KEY = process.env.AZURE_OPENAI_API_KEY; // pragma: allowlist secret
|
|
3
8
|
export const AZURE_OPENAI_API_BASE = process.env.AZURE_OPENAI_API_BASE;
|
|
4
9
|
export const AZURE_OPENAI_API_DEPLOYMENT_NAME = process.env.AZURE_OPENAI_API_DEPLOYMENT_NAME || 'gpt-41-mini_p1';
|
package/lib/esm/constants.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,eAAe,GAC1B,OAAO,CAAC,GAAG,CAAC,eAAe,IAAI,yBAAyB,CAAA;AAE1D,MAAM,CAAC,MAAM,oBAAoB,GAAG,OAAO,CAAC,GAAG,CAAC,oBAAoB,CAAA,CAAC,2BAA2B;AAChG,MAAM,CAAC,MAAM,qBAAqB,GAAG,OAAO,CAAC,GAAG,CAAC,qBAAqB,CAAA;AACtE,MAAM,CAAC,MAAM,gCAAgC,GAC3C,OAAO,CAAC,GAAG,CAAC,gCAAgC,IAAI,gBAAgB,CAAA;AAClE,MAAM,CAAC,MAAM,wBAAwB,GACnC,OAAO,CAAC,GAAG,CAAC,wBAAwB,IAAI,oBAAoB,CAAA;AAE9D,MAAM,CAAC,MAAM,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,YAAY,CAAA;AAE3D,MAAM,CAAC,MAAM,iBAAiB,GAAG,EAAE,CAAA"}
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,eAAe,GAC1B,OAAO,CAAC,GAAG,CAAC,eAAe,IAAI,yBAAyB,CAAA;AAE1D,gCAAgC;AAChC,MAAM,CAAC,MAAM,cAAc,GAAG,OAAO,CAAC,GAAG,CAAC,cAAc,CAAA,CAAC,2BAA2B;AACpF,MAAM,CAAC,MAAM,YAAY,GAAG,OAAO,CAAC,GAAG,CAAC,YAAY,IAAI,cAAc,CAAA;AACtE,MAAM,CAAC,MAAM,eAAe,GACzB,OAA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WAAW,KAAK,SAAS,EAAE;gBAC7B,MAAM,IAAI,KAAK,CAAC,0CAA0C,CAAC,CAAA;aAC5D;YACD,MAAM,SAAS,GAAG,MAAM,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,KAAK,KAAK,IAAI,CAAC,CAAA;YAC1E,MAAM,mBAAmB,GAAG,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,MAAM,CACzD,GAAG,CAAC,EAAE,CAAC,WAAW,CAAC,GAAG,CAAC,KAAK,IAAI,CACjC,CAAA;YACD,OAAO;gBACL,UAAU,EAAE,mBAAmB;gBAC/B,iBAAiB,EAAE,SAAS;aAC7B,CAAA;QACH,CAAC,CAAA;KACF,CAAA;AACH,CAAC"}
|
package/lib/esm/index.js
CHANGED
|
@@ -16,7 +16,7 @@ export default class BotonicPluginAiAgents {
|
|
|
16
16
|
return;
|
|
17
17
|
}
|
|
18
18
|
getInference(request, aiAgentArgs) {
|
|
19
|
-
var _a;
|
|
19
|
+
var _a, _b;
|
|
20
20
|
return __awaiter(this, void 0, void 0, function* () {
|
|
21
21
|
try {
|
|
22
22
|
const authToken = isProd ? request.session._access_token : this.authToken;
|
|
@@ -24,7 +24,15 @@ export default class BotonicPluginAiAgents {
|
|
|
24
24
|
throw new Error('Auth token is required');
|
|
25
25
|
}
|
|
26
26
|
const tools = this.buildTools(((_a = aiAgentArgs.activeTools) === null || _a === void 0 ? void 0 : _a.map(tool => tool.name)) || []);
|
|
27
|
-
const agent = new AIAgentBuilder(
|
|
27
|
+
const agent = new AIAgentBuilder({
|
|
28
|
+
name: aiAgentArgs.name,
|
|
29
|
+
instructions: aiAgentArgs.instructions,
|
|
30
|
+
tools: tools,
|
|
31
|
+
contactInfo: request.session.user.contact_info || {},
|
|
32
|
+
inputGuardrailRules: aiAgentArgs.inputGuardrailRules || [],
|
|
33
|
+
sourceIds: aiAgentArgs.sourceIds || [],
|
|
34
|
+
campaignContext: (_b = request.input.context) === null || _b === void 0 ? void 0 : _b.campaign_v2,
|
|
35
|
+
}).build();
|
|
28
36
|
const messages = yield this.getMessages(request, authToken, MAX_MEMORY_LENGTH);
|
|
29
37
|
const context = {
|
|
30
38
|
authToken,
|
package/lib/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAA;AAErC,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAA;AAChD,OAAO,EAAE,MAAM,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAA;AACvD,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAA;AACvD,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAA;AACtC,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAA;AAUxC,MAAM,CAAC,OAAO,OAAO,qBAAqB;IAQxC,YAAY,OAAoD;QAFzD,oBAAe,GAAuC,EAAE,CAAA;QAG7D,WAAW,CAAC,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,UAAU,EAAE,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,OAAO,CAAC,CAAA;QAClD,IAAI,CAAC,SAAS,GAAG,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,SAAS,CAAA;QACnC,IAAI,CAAC,eAAe,GAAG,CAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,WAAW,KAAI,EAAE,CAAA;IACnD,CAAC;IAED,GAAG;QACD,OAAM;IACR,CAAC;IAEK,YAAY,CAChB,OAAyC,EACzC,WAAwB;;;YAExB,IAAI;gBACF,MAAM,SAAS,GAAG,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAA;gBACzE,IAAI,CAAC,SAAS,EAAE;oBACd,MAA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
import { AzureOpenAI } from 'openai';
|
|
3
|
-
import { AZURE_OPENAI_API_BASE, AZURE_OPENAI_API_DEPLOYMENT_NAME, AZURE_OPENAI_API_KEY, AZURE_OPENAI_API_VERSION, isProd, } from './constants';
|
|
2
|
+
import OpenAI, { AzureOpenAI } from 'openai';
|
|
3
|
+
import { AZURE_OPENAI_API_BASE, AZURE_OPENAI_API_DEPLOYMENT_NAME, AZURE_OPENAI_API_KEY, AZURE_OPENAI_API_VERSION, isProd, OPENAI_API_KEY, OPENAI_PROVIDER, } from './constants';
|
|
4
4
|
export function setUpOpenAI(maxRetries, timeout) {
|
|
5
|
-
|
|
5
|
+
if (OPENAI_PROVIDER === 'azure') {
|
|
6
|
+
setAzureOpenAIClient(maxRetries, timeout);
|
|
7
|
+
}
|
|
8
|
+
else {
|
|
9
|
+
setOpenAIClient(maxRetries, timeout);
|
|
10
|
+
}
|
|
6
11
|
setOpenAIAPI('chat_completions');
|
|
7
12
|
setTracingDisabled(true);
|
|
8
13
|
}
|
|
14
|
+
function setOpenAIClient(maxRetries, timeout) {
|
|
15
|
+
const client = new OpenAI({
|
|
16
|
+
apiKey: OPENAI_API_KEY,
|
|
17
|
+
timeout: timeout || 16000,
|
|
18
|
+
maxRetries: maxRetries || 2,
|
|
19
|
+
dangerouslyAllowBrowser: !isProd,
|
|
20
|
+
});
|
|
21
|
+
setDefaultOpenAIClient(client);
|
|
22
|
+
}
|
|
9
23
|
function setAzureOpenAIClient(maxRetries, timeout) {
|
|
10
24
|
const client = new AzureOpenAI({
|
|
11
25
|
apiKey: AZURE_OPENAI_API_KEY,
|
|
12
26
|
apiVersion: AZURE_OPENAI_API_VERSION,
|
|
13
27
|
deployment: AZURE_OPENAI_API_DEPLOYMENT_NAME,
|
|
14
28
|
baseURL: AZURE_OPENAI_API_BASE,
|
|
15
|
-
timeout: timeout ||
|
|
29
|
+
timeout: timeout || 16000,
|
|
16
30
|
maxRetries: maxRetries || 2,
|
|
17
31
|
dangerouslyAllowBrowser: !isProd,
|
|
18
32
|
});
|
package/lib/esm/openai.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"openai.js","sourceRoot":"","sources":["../../src/openai.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,sBAAsB,EACtB,YAAY,EACZ,kBAAkB,GACnB,MAAM,gBAAgB,CAAA;AACvB,OAAO,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAA;
|
|
1
|
+
{"version":3,"file":"openai.js","sourceRoot":"","sources":["../../src/openai.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,sBAAsB,EACtB,YAAY,EACZ,kBAAkB,GACnB,MAAM,gBAAgB,CAAA;AACvB,OAAO,MAAM,EAAE,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAA;AAE5C,OAAO,EACL,qBAAqB,EACrB,gCAAgC,EAChC,oBAAoB,EACpB,wBAAwB,EACxB,MAAM,EACN,cAAc,EACd,eAAe,GAChB,MAAM,aAAa,CAAA;AAEpB,MAAM,UAAU,WAAW,CAAC,UAAmB,EAAE,OAAgB;IAC/D,IAAI,eAAe,KAAK,OAAO,EAAE;QAC/B,oBAAoB,CAAC,UAAU,EAAE,OAAO,CAAC,CAAA;KAC1C;SAAM;QACL,eAAe,CAAC,UAAU,EAAE,OAAO,CAAC,CAAA;KACrC;IACD,YAAY,CAAC,kBAAkB,CAAC,CAAA;IAChC,kBAAkB,CAAC,IAAI,CAAC,CAAA;AAC1B,CAAC;AAED,SAAS,eAAe,CAAC,UAAmB,EAAE,OAAgB;IAC5D,MAAM,MAAM,GAAG,IAAI,MAAM,CAAC;QACxB,MAAM,EAAE,cAAc;QACtB,OAAO,EAAE,OAAO,IAAI,KAAK;QACzB,UAAU,EAAE,UAAU,IAAI,CAAC;QAC3B,uBAAuB,EAAE,CAAC,MAAM;KACjC,CAAC,CAAA;IACF,sBAAsB,CAAC,MAAM,CAAC,CAAA;AAChC,CAAC;AAED,SAAS,oBAAoB,CAAC,UAAmB,EAAE,OAAgB;IACjE,MAAM,MAAM,GAAG,IAAI,WAAW,CAAC;QAC7B,MAAM,EAAE,oBAAoB;QAC5B,UAAU,EAAE,wBAAwB;QACpC,UAAU,EAAE,gCAAgC;QAC5C,OAAO,EAAE,qBAAqB;QAC9B,OAAO,EAAE,OAAO,IAAI,KAAK;QACzB,UAAU,EAAE,UAAU,IAAI,CAAC;QAC3B,uBAAuB,EAAE,CAAC,MAAM;KACjC,CAAC,CAAA;IACF,sBAAsB,CAAC,MAAM,CAAC,CAAA;AAChC,CAAC"}
|
package/lib/esm/runner.js
CHANGED
|
@@ -12,7 +12,11 @@ export class AIAgentRunner {
|
|
|
12
12
|
const runner = new Runner({
|
|
13
13
|
modelSettings: { temperature: 0 },
|
|
14
14
|
});
|
|
15
|
-
|
|
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 = (yield runner.run(this.agent, messages, {
|
|
18
|
+
context,
|
|
19
|
+
}));
|
|
16
20
|
const outputMessages = ((_a = result.finalOutput) === null || _a === void 0 ? void 0 : _a.messages) || [];
|
|
17
21
|
const hasExit = outputMessages.length === 0 ||
|
|
18
22
|
outputMessages.some(message => message.type === 'exit');
|
package/lib/esm/runner.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runner.js","sourceRoot":"","sources":["../../src/runner.ts"],"names":[],"mappings":";AACA,OAAO,EACL,+BAA+B,EAC/B,MAAM,EACN,eAAe,GAChB,MAAM,gBAAgB,CAAA;AAEvB,OAAO,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAA;
|
|
1
|
+
{"version":3,"file":"runner.js","sourceRoot":"","sources":["../../src/runner.ts"],"names":[],"mappings":";AACA,OAAO,EACL,+BAA+B,EAC/B,MAAM,EACN,eAAe,GAChB,MAAM,gBAAgB,CAAA;AAEvB,OAAO,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAA;AAkB3C,MAAM,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I,CAAC,KAAK,CAAC,gBAAgB,CAAC,CAAA;SACpC;QAAC,OAAO,KAAK,EAAE;YACd,OAAO,EAAE,CAAA;SACV;IACH,CAAC;CACF"}
|
|
@@ -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>;
|
|
@@ -8,8 +8,9 @@ export const retrieveKnowledge = tool({
|
|
|
8
8
|
parameters: z.object({
|
|
9
9
|
query: z.string().describe('The query to search the knowledge base for'),
|
|
10
10
|
}),
|
|
11
|
-
execute: (
|
|
11
|
+
execute: (input, runContext) => __awaiter(void 0, void 0, void 0, function* () {
|
|
12
12
|
const context = runContext === null || runContext === void 0 ? void 0 : runContext.context;
|
|
13
|
+
const query = input.query;
|
|
13
14
|
if (!context) {
|
|
14
15
|
throw new Error('Context is required');
|
|
15
16
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"retrieve-knowledge.js","sourceRoot":"","sources":["../../../src/tools/retrieve-knowledge.ts"],"names":[],"mappings":";AAAA,OAAO,EAAc,IAAI,EAAE,MAAM,gBAAgB,CAAA;AACjD,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAEvB,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAA;AAGxD,MAAM,CAAC,MAAM,iBAAiB,GAAG,IAAI,
|
|
1
|
+
{"version":3,"file":"retrieve-knowledge.js","sourceRoot":"","sources":["../../../src/tools/retrieve-knowledge.ts"],"names":[],"mappings":";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
|
|
|
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> {
|
|
@@ -26,7 +26,7 @@ export interface Chunk {
|
|
|
26
26
|
}
|
|
27
27
|
export type ContactInfo = Record<string, string>;
|
|
28
28
|
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
|
|
29
|
+
export type AIAgent<TPlugins extends ResolvedPlugins = ResolvedPlugins, TExtraData = any> = Agent<Context<TPlugins, TExtraData>, AgentOutputType<typeof OutputSchema>>;
|
|
30
30
|
export interface PluginAiAgentOptions<TPlugins extends ResolvedPlugins = ResolvedPlugins, TExtraData = any> {
|
|
31
31
|
authToken?: string;
|
|
32
32
|
customTools?: CustomTool<TPlugins, TExtraData>[];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@botonic/plugin-ai-agents",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.43.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,7 +13,7 @@
|
|
|
13
13
|
"lint_core": "../../node_modules/.bin/eslint_d --cache --quiet 'src/**/*.ts*'"
|
|
14
14
|
},
|
|
15
15
|
"dependencies": {
|
|
16
|
-
"@botonic/core": "
|
|
16
|
+
"@botonic/core": "0.43.0-alpha.0",
|
|
17
17
|
"@openai/agents": "^0.1.11",
|
|
18
18
|
"axios": "^1.12.2",
|
|
19
19
|
"openai": "^5.23.2",
|
|
@@ -45,4 +45,4 @@
|
|
|
45
45
|
"javascript"
|
|
46
46
|
],
|
|
47
47
|
"author": ""
|
|
48
|
-
}
|
|
48
|
+
}
|
package/src/agent-builder.ts
CHANGED
|
@@ -1,10 +1,29 @@
|
|
|
1
|
-
import { ResolvedPlugins } from '@botonic/core'
|
|
2
|
-
import {
|
|
1
|
+
import { CampaignV2, 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, ContactInfo, GuardrailRule, Tool } from './types'
|
|
13
|
+
import { AIAgent, ContactInfo, 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,47 @@ 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
|
+
// @ts-expect-error - reasoning.effort is valid but we need to update openai and typescript dependencies
|
|
56
|
+
modelSettings.reasoning = { effort: 'none' }
|
|
57
|
+
modelSettings.text = { verbosity: 'medium' }
|
|
58
|
+
}
|
|
38
59
|
|
|
39
|
-
if (this.tools.includes(retrieveKnowledge)) {
|
|
60
|
+
if (this.tools.includes(retrieveKnowledge) && OPENAI_PROVIDER === 'azure') {
|
|
40
61
|
modelSettings.toolChoice = retrieveKnowledge.name
|
|
41
62
|
}
|
|
42
63
|
|
|
43
|
-
|
|
64
|
+
// When using standard OpenAI API, we need to specify the model
|
|
65
|
+
// Azure OpenAI uses deployment name instead
|
|
66
|
+
const model = OPENAI_PROVIDER === 'openai' ? OPENAI_MODEL : undefined
|
|
67
|
+
|
|
68
|
+
// TODO: Improve type safety - replace AgentOutputType<any> with AgentOutputType<typeof OutputSchema>
|
|
69
|
+
// Currently using explicit type parameters to avoid type inference issues where Agent constructor
|
|
70
|
+
// infers ZodObject instead of AgentOutputType<typeof OutputSchema>. The explicit type parameters
|
|
71
|
+
// ensure compatibility with AIAgent type definition. Future improvements:
|
|
72
|
+
// 1. Update @openai/agents package to properly infer AgentOutputType from outputType parameter
|
|
73
|
+
// 2. Replace AgentOutputType<any> with AgentOutputType<typeof OutputSchema> once type system allows
|
|
74
|
+
// 3. Consider updating AIAgent type definition if @openai/agents types change significantly
|
|
75
|
+
return new Agent<Context<TPlugins, TExtraData>, AgentOutputType<any>>({
|
|
44
76
|
name: this.name,
|
|
77
|
+
model,
|
|
45
78
|
instructions: this.instructions,
|
|
46
79
|
tools: this.tools,
|
|
47
80
|
outputType: OutputSchema,
|
|
@@ -53,13 +86,15 @@ export class AIAgentBuilder<
|
|
|
53
86
|
|
|
54
87
|
private addExtraInstructions(
|
|
55
88
|
initialInstructions: string,
|
|
56
|
-
contactInfo: ContactInfo
|
|
89
|
+
contactInfo: ContactInfo,
|
|
90
|
+
campaignContext?: CampaignV2
|
|
57
91
|
): string {
|
|
58
|
-
const instructions = `<instructions>\n${initialInstructions}\n</instructions>`
|
|
92
|
+
const instructions = `<instructions>\n${initialInstructions.trim()}\n</instructions>`
|
|
59
93
|
const metadataInstructions = this.getMetadataInstructions()
|
|
60
94
|
const contactInfoInstructions = this.getContactInfoInstructions(contactInfo)
|
|
95
|
+
const campaignInstructions = this.getCampaignInstructions(campaignContext)
|
|
61
96
|
const outputInstructions = this.getOutputInstructions()
|
|
62
|
-
return `${instructions}\n\n${metadataInstructions}\n\n${contactInfoInstructions}\n\n${outputInstructions}`
|
|
97
|
+
return `${instructions}\n\n${metadataInstructions}\n\n${contactInfoInstructions}\n\n${campaignInstructions}\n\n${outputInstructions}`
|
|
63
98
|
}
|
|
64
99
|
|
|
65
100
|
private getContactInfoInstructions(contactInfo: ContactInfo): string {
|
|
@@ -74,6 +109,13 @@ export class AIAgentBuilder<
|
|
|
74
109
|
return `<metadata>\n${metadata}\n</metadata>`
|
|
75
110
|
}
|
|
76
111
|
|
|
112
|
+
private getCampaignInstructions(campaignContext?: CampaignV2): string {
|
|
113
|
+
if (!campaignContext || !campaignContext.agent_context) {
|
|
114
|
+
return ''
|
|
115
|
+
}
|
|
116
|
+
return `<campaign_context>\n${campaignContext.agent_context}\n</campaign_context>`
|
|
117
|
+
}
|
|
118
|
+
|
|
77
119
|
private getOutputInstructions(): string {
|
|
78
120
|
const example = {
|
|
79
121
|
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
|
}
|
package/src/index.ts
CHANGED
|
@@ -46,14 +46,15 @@ export default class BotonicPluginAiAgents<
|
|
|
46
46
|
const tools = this.buildTools(
|
|
47
47
|
aiAgentArgs.activeTools?.map(tool => tool.name) || []
|
|
48
48
|
)
|
|
49
|
-
const agent = new AIAgentBuilder<TPlugins, TExtraData>(
|
|
50
|
-
aiAgentArgs.name,
|
|
51
|
-
aiAgentArgs.instructions,
|
|
52
|
-
tools,
|
|
53
|
-
request.session.user.contact_info || {},
|
|
54
|
-
aiAgentArgs.inputGuardrailRules || [],
|
|
55
|
-
aiAgentArgs.sourceIds || []
|
|
56
|
-
|
|
49
|
+
const agent = new AIAgentBuilder<TPlugins, TExtraData>({
|
|
50
|
+
name: aiAgentArgs.name,
|
|
51
|
+
instructions: aiAgentArgs.instructions,
|
|
52
|
+
tools: tools,
|
|
53
|
+
contactInfo: request.session.user.contact_info || {},
|
|
54
|
+
inputGuardrailRules: aiAgentArgs.inputGuardrailRules || [],
|
|
55
|
+
sourceIds: aiAgentArgs.sourceIds || [],
|
|
56
|
+
campaignContext: request.input.context?.campaign_v2,
|
|
57
|
+
}).build()
|
|
57
58
|
|
|
58
59
|
const messages = await this.getMessages(
|
|
59
60
|
request,
|
package/src/openai.ts
CHANGED
|
@@ -3,7 +3,7 @@ import {
|
|
|
3
3
|
setOpenAIAPI,
|
|
4
4
|
setTracingDisabled,
|
|
5
5
|
} from '@openai/agents'
|
|
6
|
-
import { AzureOpenAI } from 'openai'
|
|
6
|
+
import OpenAI, { AzureOpenAI } from 'openai'
|
|
7
7
|
|
|
8
8
|
import {
|
|
9
9
|
AZURE_OPENAI_API_BASE,
|
|
@@ -11,21 +11,37 @@ import {
|
|
|
11
11
|
AZURE_OPENAI_API_KEY,
|
|
12
12
|
AZURE_OPENAI_API_VERSION,
|
|
13
13
|
isProd,
|
|
14
|
+
OPENAI_API_KEY,
|
|
15
|
+
OPENAI_PROVIDER,
|
|
14
16
|
} from './constants'
|
|
15
17
|
|
|
16
18
|
export function setUpOpenAI(maxRetries?: number, timeout?: number) {
|
|
17
|
-
|
|
19
|
+
if (OPENAI_PROVIDER === 'azure') {
|
|
20
|
+
setAzureOpenAIClient(maxRetries, timeout)
|
|
21
|
+
} else {
|
|
22
|
+
setOpenAIClient(maxRetries, timeout)
|
|
23
|
+
}
|
|
18
24
|
setOpenAIAPI('chat_completions')
|
|
19
25
|
setTracingDisabled(true)
|
|
20
26
|
}
|
|
21
27
|
|
|
28
|
+
function setOpenAIClient(maxRetries?: number, timeout?: number) {
|
|
29
|
+
const client = new OpenAI({
|
|
30
|
+
apiKey: OPENAI_API_KEY,
|
|
31
|
+
timeout: timeout || 16000, // 16 seconds
|
|
32
|
+
maxRetries: maxRetries || 2,
|
|
33
|
+
dangerouslyAllowBrowser: !isProd,
|
|
34
|
+
})
|
|
35
|
+
setDefaultOpenAIClient(client)
|
|
36
|
+
}
|
|
37
|
+
|
|
22
38
|
function setAzureOpenAIClient(maxRetries?: number, timeout?: number) {
|
|
23
39
|
const client = new AzureOpenAI({
|
|
24
40
|
apiKey: AZURE_OPENAI_API_KEY,
|
|
25
41
|
apiVersion: AZURE_OPENAI_API_VERSION,
|
|
26
42
|
deployment: AZURE_OPENAI_API_DEPLOYMENT_NAME,
|
|
27
43
|
baseURL: AZURE_OPENAI_API_BASE,
|
|
28
|
-
timeout: timeout ||
|
|
44
|
+
timeout: timeout || 16000, // 16 seconds
|
|
29
45
|
maxRetries: maxRetries || 2,
|
|
30
46
|
dangerouslyAllowBrowser: !isProd,
|
|
31
47
|
})
|
package/src/runner.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ResolvedPlugins, ToolExecution } from '@botonic/core'
|
|
1
|
+
import { OutputMessage, ResolvedPlugins, ToolExecution } from '@botonic/core'
|
|
2
2
|
import {
|
|
3
3
|
InputGuardrailTripwireTriggered,
|
|
4
4
|
Runner,
|
|
@@ -14,6 +14,15 @@ import {
|
|
|
14
14
|
RunResult,
|
|
15
15
|
} from './types'
|
|
16
16
|
|
|
17
|
+
// Minimal interface matching the properties we actually use from Runner.run() result
|
|
18
|
+
// This bypasses strict type checking while maintaining type safety for accessed properties
|
|
19
|
+
interface AIAgentRunnerResult {
|
|
20
|
+
finalOutput?: {
|
|
21
|
+
messages?: OutputMessage[]
|
|
22
|
+
}
|
|
23
|
+
newItems?: RunToolCallItem[]
|
|
24
|
+
}
|
|
25
|
+
|
|
17
26
|
export class AIAgentRunner<
|
|
18
27
|
TPlugins extends ResolvedPlugins = ResolvedPlugins,
|
|
19
28
|
TExtraData = any,
|
|
@@ -32,7 +41,11 @@ export class AIAgentRunner<
|
|
|
32
41
|
const runner = new Runner({
|
|
33
42
|
modelSettings: { temperature: 0 },
|
|
34
43
|
})
|
|
35
|
-
|
|
44
|
+
// Type assertion to bypass strict type checking - the actual return type from runner.run()
|
|
45
|
+
// doesn't perfectly match our interface, but the properties we access are compatible
|
|
46
|
+
const result = (await runner.run(this.agent, messages, {
|
|
47
|
+
context,
|
|
48
|
+
})) as AIAgentRunnerResult
|
|
36
49
|
|
|
37
50
|
const outputMessages = result.finalOutput?.messages || []
|
|
38
51
|
const hasExit =
|
|
@@ -4,7 +4,7 @@ import { z } from 'zod'
|
|
|
4
4
|
import { HubtypeApiClient } from '../hubtype-api-client'
|
|
5
5
|
import { Context } from '../types'
|
|
6
6
|
|
|
7
|
-
export const retrieveKnowledge = tool
|
|
7
|
+
export const retrieveKnowledge = tool({
|
|
8
8
|
name: 'retrieve_knowledge',
|
|
9
9
|
description:
|
|
10
10
|
'Consult the knowledge base for information before answering. Use this tool to make sure the information you provide is faithful.',
|
|
@@ -12,10 +12,11 @@ export const retrieveKnowledge = tool<any, Context, any>({
|
|
|
12
12
|
query: z.string().describe('The query to search the knowledge base for'),
|
|
13
13
|
}),
|
|
14
14
|
execute: async (
|
|
15
|
-
|
|
15
|
+
input: { query: string },
|
|
16
16
|
runContext?: RunContext<Context>
|
|
17
17
|
): Promise<string[]> => {
|
|
18
18
|
const context = runContext?.context
|
|
19
|
+
const query = input.query
|
|
19
20
|
if (!context) {
|
|
20
21
|
throw new Error('Context is required')
|
|
21
22
|
}
|
package/src/types.ts
CHANGED
|
@@ -10,6 +10,7 @@ import {
|
|
|
10
10
|
import {
|
|
11
11
|
Agent,
|
|
12
12
|
AgentInputItem,
|
|
13
|
+
AgentOutputType,
|
|
13
14
|
RunContext as OpenAIRunContext,
|
|
14
15
|
Tool as OpenAITool,
|
|
15
16
|
} from '@openai/agents'
|
|
@@ -64,7 +65,7 @@ export type Tool<
|
|
|
64
65
|
export type AIAgent<
|
|
65
66
|
TPlugins extends ResolvedPlugins = ResolvedPlugins,
|
|
66
67
|
TExtraData = any,
|
|
67
|
-
> = Agent<Context<TPlugins, TExtraData>, typeof OutputSchema
|
|
68
|
+
> = Agent<Context<TPlugins, TExtraData>, AgentOutputType<typeof OutputSchema>>
|
|
68
69
|
export interface PluginAiAgentOptions<
|
|
69
70
|
TPlugins extends ResolvedPlugins = ResolvedPlugins,
|
|
70
71
|
TExtraData = any,
|