@botonic/plugin-ai-agents 0.36.0-alpha.8 → 0.36.0-alpha.9
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 +10 -0
- package/lib/cjs/agent-builder.js +43 -0
- package/lib/cjs/agent-builder.js.map +1 -0
- package/lib/cjs/index.d.ts +2 -2
- package/lib/cjs/index.js +20 -14
- package/lib/cjs/index.js.map +1 -1
- package/lib/cjs/openai.d.ts +1 -0
- package/lib/cjs/openai.js +23 -0
- package/lib/cjs/openai.js.map +1 -0
- package/lib/cjs/runner.d.ts +3 -6
- package/lib/cjs/runner.js +7 -47
- package/lib/cjs/runner.js.map +1 -1
- package/lib/cjs/tools/index.d.ts +2 -0
- package/lib/cjs/tools/index.js +5 -0
- package/lib/cjs/tools/index.js.map +1 -0
- package/lib/cjs/types.d.ts +11 -6
- package/lib/esm/agent-builder.d.ts +10 -0
- package/lib/esm/agent-builder.js +39 -0
- package/lib/esm/agent-builder.js.map +1 -0
- package/lib/esm/index.d.ts +2 -2
- package/lib/esm/index.js +20 -14
- package/lib/esm/index.js.map +1 -1
- package/lib/esm/openai.d.ts +1 -0
- package/lib/esm/openai.js +19 -0
- package/lib/esm/openai.js.map +1 -0
- package/lib/esm/runner.d.ts +3 -6
- package/lib/esm/runner.js +8 -48
- package/lib/esm/runner.js.map +1 -1
- package/lib/esm/tools/index.d.ts +2 -0
- package/lib/esm/tools/index.js +2 -0
- package/lib/esm/tools/index.js.map +1 -0
- package/lib/esm/types.d.ts +11 -6
- package/package.json +1 -1
- package/src/agent-builder.ts +48 -0
- package/src/index.ts +28 -19
- package/src/openai.ts +30 -0
- package/src/runner.ts +16 -70
- package/src/tools/index.ts +3 -0
- package/src/types.ts +19 -6
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { AIAgent, Tool } from './types';
|
|
2
|
+
export declare class AIAgentBuilder {
|
|
3
|
+
private name;
|
|
4
|
+
private instructions;
|
|
5
|
+
private tools;
|
|
6
|
+
constructor(name: string, instructions: string, tools: Tool[]);
|
|
7
|
+
build(): AIAgent;
|
|
8
|
+
private addExtraInstructions;
|
|
9
|
+
private addHubtypeTools;
|
|
10
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AIAgentBuilder = void 0;
|
|
4
|
+
const agents_1 = require("@openai/agents");
|
|
5
|
+
const structured_output_1 = require("./structured-output");
|
|
6
|
+
const tools_1 = require("./tools");
|
|
7
|
+
class AIAgentBuilder {
|
|
8
|
+
constructor(name, instructions, tools) {
|
|
9
|
+
this.name = name;
|
|
10
|
+
this.instructions = this.addExtraInstructions(instructions);
|
|
11
|
+
this.tools = this.addHubtypeTools(tools);
|
|
12
|
+
}
|
|
13
|
+
build() {
|
|
14
|
+
return new agents_1.Agent({
|
|
15
|
+
name: this.name,
|
|
16
|
+
instructions: this.instructions,
|
|
17
|
+
tools: this.tools,
|
|
18
|
+
outputType: structured_output_1.OutputSchema,
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
addExtraInstructions(instructions) {
|
|
22
|
+
const metadata = `Current Date: ${new Date().toISOString()}`;
|
|
23
|
+
const example = {
|
|
24
|
+
messages: [
|
|
25
|
+
{
|
|
26
|
+
type: 'text',
|
|
27
|
+
content: {
|
|
28
|
+
text: 'Hello, how can I help you today?',
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
],
|
|
32
|
+
numMessages: 1,
|
|
33
|
+
};
|
|
34
|
+
const output = `Return a JSON that follows the output schema provided. Never return multiple output schemas concatenated by a line break.\n<example>\n${JSON.stringify(example)}\n</example>`;
|
|
35
|
+
return `<instructions>\n${instructions}\n</instructions>\n\n<metadata>\n${metadata}\n</metadata>\n\n<output>\n${output}\n</output>`;
|
|
36
|
+
}
|
|
37
|
+
addHubtypeTools(tools) {
|
|
38
|
+
const hubtypeTools = [...tools_1.mandatoryTools];
|
|
39
|
+
return [...hubtypeTools, ...tools];
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
exports.AIAgentBuilder = AIAgentBuilder;
|
|
43
|
+
//# sourceMappingURL=agent-builder.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agent-builder.js","sourceRoot":"","sources":["../../src/agent-builder.ts"],"names":[],"mappings":";;;AAAA,2CAAsC;AAEtC,2DAAkD;AAClD,mCAAwC;AAGxC,MAAa,cAAc;IAKzB,YAAY,IAAY,EAAE,YAAoB,EAAE,KAAa;QAC3D,IAAI,CAAC,IAAI,GAAG,IAAI,CAAA;QAChB,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC,oBAAoB,CAAC,YAAY,CAAC,CAAA;QAC3D,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,eAAe,CAAC,KAAK,CAAC,CAAA;IAC1C,CAAC;IAED,KAAK;QACH,OAAO,IAAI,cAAK,CAAC;YACf,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,YAAY,EAAE,IAAI,CAAC,YAAY;YAC/B,KAAK,EAAE,IAAI,CAAC,KAAK;YACjB,UAAU,EAAE,gCAAY;SACzB,CAAC,CAAA;IACJ,CAAC;IAEO,oBAAoB,CAAC,YAAoB;QAC/C,MAAM,QAAQ,GAAG,iBAAiB,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,EAAE,CAAA;QAC5D,MAAM,OAAO,GAAG;YACd,QAAQ,EAAE;gBACR;oBACE,IAAI,EAAE,MAAM;oBACZ,OAAO,EAAE;wBACP,IAAI,EAAE,kCAAkC;qBACzC;iBACF;aACF;YACD,WAAW,EAAE,CAAC;SACf,CAAA;QACD,MAAM,MAAM,GAAG,yIAAyI,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,cAAc,CAAA;QAC7L,OAAO,mBAAmB,YAAY,oCAAoC,QAAQ,8BAA8B,MAAM,aAAa,CAAA;IACrI,CAAC;IAEO,eAAe,CAAC,KAAa;QACnC,MAAM,YAAY,GAAW,CAAC,GAAG,sBAAc,CAAC,CAAA;QAChD,OAAO,CAAC,GAAG,YAAY,EAAE,GAAG,KAAK,CAAC,CAAA;IACpC,CAAC;CACF;AAzCD,wCAyCC"}
|
package/lib/cjs/index.d.ts
CHANGED
|
@@ -2,11 +2,11 @@ import { BotContext, Plugin } from '@botonic/core';
|
|
|
2
2
|
import { AgenticOutputMessage, AiAgentArgs, CustomTool, PluginAiAgentOptions } from './types';
|
|
3
3
|
export default class BotonicPluginAiAgents implements Plugin {
|
|
4
4
|
private readonly authToken?;
|
|
5
|
-
|
|
5
|
+
toolDefinitions: CustomTool[];
|
|
6
6
|
constructor(options?: PluginAiAgentOptions);
|
|
7
7
|
pre(): void;
|
|
8
8
|
getInference(request: BotContext, aiAgentArgs: AiAgentArgs): Promise<AgenticOutputMessage[] | undefined>;
|
|
9
9
|
private getMessages;
|
|
10
|
-
private
|
|
10
|
+
private buildTools;
|
|
11
11
|
}
|
|
12
12
|
export * from './types';
|
package/lib/cjs/index.js
CHANGED
|
@@ -2,32 +2,37 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const tslib_1 = require("tslib");
|
|
4
4
|
const agents_1 = require("@openai/agents");
|
|
5
|
+
const agent_builder_1 = require("./agent-builder");
|
|
5
6
|
const constants_1 = require("./constants");
|
|
6
7
|
const hubtype_api_client_1 = require("./hubtype-api-client");
|
|
8
|
+
const openai_1 = require("./openai");
|
|
7
9
|
const runner_1 = require("./runner");
|
|
8
10
|
class BotonicPluginAiAgents {
|
|
9
11
|
constructor(options) {
|
|
10
|
-
this.
|
|
12
|
+
this.toolDefinitions = [];
|
|
13
|
+
(0, openai_1.setUpOpenAI)();
|
|
11
14
|
this.authToken = options === null || options === void 0 ? void 0 : options.authToken;
|
|
12
|
-
this.
|
|
15
|
+
this.toolDefinitions = (options === null || options === void 0 ? void 0 : options.customTools) || [];
|
|
13
16
|
}
|
|
14
17
|
pre() {
|
|
15
18
|
return;
|
|
16
19
|
}
|
|
17
20
|
getInference(request, aiAgentArgs) {
|
|
21
|
+
var _a;
|
|
18
22
|
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
19
23
|
try {
|
|
20
24
|
const authToken = constants_1.isProd ? request.session._access_token : this.authToken;
|
|
21
25
|
if (!authToken) {
|
|
22
26
|
throw new Error('Auth token is required');
|
|
23
27
|
}
|
|
28
|
+
const tools = this.buildTools(((_a = aiAgentArgs.activeTools) === null || _a === void 0 ? void 0 : _a.map(tool => tool.name)) || []);
|
|
29
|
+
const agent = new agent_builder_1.AIAgentBuilder(aiAgentArgs.name, aiAgentArgs.instructions, tools).build();
|
|
24
30
|
const messages = yield this.getMessages(request, authToken, 10);
|
|
25
|
-
const
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
const
|
|
29
|
-
|
|
30
|
-
return output;
|
|
31
|
+
const context = {
|
|
32
|
+
authToken,
|
|
33
|
+
};
|
|
34
|
+
const runner = new runner_1.AIAgentRunner(agent);
|
|
35
|
+
return yield runner.run(messages, context);
|
|
31
36
|
}
|
|
32
37
|
catch (error) {
|
|
33
38
|
console.error('error plugin returns undefined', error);
|
|
@@ -45,13 +50,14 @@ class BotonicPluginAiAgents {
|
|
|
45
50
|
return yield hubtypeClient.getLocalMessages(memoryLength);
|
|
46
51
|
});
|
|
47
52
|
}
|
|
48
|
-
|
|
49
|
-
|
|
53
|
+
buildTools(activeToolNames) {
|
|
54
|
+
const availableTools = this.toolDefinitions.filter(tool => activeToolNames.includes(tool.name));
|
|
55
|
+
return availableTools.map(toolDefinition => {
|
|
50
56
|
return (0, agents_1.tool)({
|
|
51
|
-
name:
|
|
52
|
-
description:
|
|
53
|
-
parameters:
|
|
54
|
-
execute:
|
|
57
|
+
name: toolDefinition.name,
|
|
58
|
+
description: toolDefinition.description,
|
|
59
|
+
parameters: toolDefinition.schema,
|
|
60
|
+
execute: toolDefinition.func,
|
|
55
61
|
});
|
|
56
62
|
});
|
|
57
63
|
}
|
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,2CAAoC;AACpC,6DAAuD;AACvD,qCAAwC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;AACA,2CAAqC;AAErC,mDAAgD;AAChD,2CAAoC;AACpC,6DAAuD;AACvD,qCAAsC;AACtC,qCAAwC;AAWxC,MAAqB,qBAAqB;IAIxC,YAAY,OAA8B;QAFnC,oBAAe,GAAiB,EAAE,CAAA;QAGvC,IAAA,oBAAW,GAAE,CAAA;QACb,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,OAAmB,EACnB,WAAwB;;;YAExB,IAAI;gBACF,MAAM,SAAS,GAAG,kBAAM,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAA;gBACzE,IAAI,CAAC,SAAS,EAAE;oBACd,MAAM,IAAI,KAAK,CAAC,wBAAwB,CAAC,CAAA;iBAC1C;gBAED,MAAM,KAAK,GAAG,IAAI,CAAC,UAAU,CAC3B,CAAA,MAAA,WAAW,CAAC,WAAW,0CAAE,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,KAAI,EAAE,CACtD,CAAA;gBACD,MAAM,KAAK,GAAG,IAAI,8BAAc,CAC9B,WAAW,CAAC,IAAI,EAChB,WAAW,CAAC,YAAY,EACxB,KAAK,CACN,CAAC,KAAK,EAAE,CAAA;gBAET,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,WAAW,CAAC,OAAO,EAAE,SAAS,EAAE,EAAE,CAAC,CAAA;gBAC/D,MAAM,OAAO,GAAY;oBACvB,SAAS;iBACV,CAAA;gBAED,MAAM,MAAM,GAAG,IAAI,sBAAa,CAAC,KAAK,CAAC,CAAA;gBACvC,OAAO,MAAM,MAAM,CAAC,GAAG,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAA;aAC3C;YAAC,OAAO,KAAK,EAAE;gBACd,OAAO,CAAC,KAAK,CAAC,gCAAgC,EAAE,KAAK,CAAC,CAAA;gBACtD,OAAO,SAAS,CAAA;aACjB;;KACF;IAEa,WAAW,CACvB,OAAmB,EACnB,SAAiB,EACjB,YAAoB;;YAEpB,IAAI,kBAAM,EAAE;gBACV,MAAM,aAAa,GAAG,IAAI,qCAAgB,CAAC,SAAS,CAAC,CAAA;gBACrD,OAAO,MAAM,aAAa,CAAC,WAAW,CAAC,OAAO,EAAE,YAAY,CAAC,CAAA;aAC9D;YACD,MAAM,aAAa,GAAG,IAAI,qCAAgB,CAAC,SAAS,CAAC,CAAA;YACrD,OAAO,MAAM,aAAa,CAAC,gBAAgB,CAAC,YAAY,CAAC,CAAA;QAC3D,CAAC;KAAA;IAEO,UAAU,CAAC,eAAyB;QAC1C,MAAM,cAAc,GAAG,IAAI,CAAC,eAAe,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,CACxD,eAAe,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CACpC,CAAA;QACD,OAAO,cAAc,CAAC,GAAG,CAAC,cAAc,CAAC,EAAE;YACzC,OAAO,IAAA,aAAI,EAAoB;gBAC7B,IAAI,EAAE,cAAc,CAAC,IAAI;gBACzB,WAAW,EAAE,cAAc,CAAC,WAAW;gBACvC,UAAU,EAAE,cAAc,CAAC,MAAM;gBACjC,OAAO,EAAE,cAAc,CAAC,IAAI;aAC7B,CAAC,CAAA;QACJ,CAAC,CAAC,CAAA;IACJ,CAAC;CACF;AAxED,wCAwEC;AAED,kDAAuB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function setUpOpenAI(): void;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.setUpOpenAI = void 0;
|
|
4
|
+
const agents_1 = require("@openai/agents");
|
|
5
|
+
const openai_1 = require("openai");
|
|
6
|
+
const constants_1 = require("./constants");
|
|
7
|
+
function setUpOpenAI() {
|
|
8
|
+
setAzureOpenAIClient();
|
|
9
|
+
(0, agents_1.setOpenAIAPI)('chat_completions');
|
|
10
|
+
(0, agents_1.setTracingDisabled)(true);
|
|
11
|
+
}
|
|
12
|
+
exports.setUpOpenAI = setUpOpenAI;
|
|
13
|
+
function setAzureOpenAIClient() {
|
|
14
|
+
const client = new openai_1.AzureOpenAI({
|
|
15
|
+
apiKey: constants_1.AZURE_OPENAI_API_KEY,
|
|
16
|
+
apiVersion: constants_1.AZURE_OPENAI_API_VERSION,
|
|
17
|
+
deployment: constants_1.AZURE_OPENAI_API_DEPLOYMENT_NAME,
|
|
18
|
+
baseURL: constants_1.AZURE_OPENAI_API_BASE,
|
|
19
|
+
dangerouslyAllowBrowser: !constants_1.isProd,
|
|
20
|
+
});
|
|
21
|
+
(0, agents_1.setDefaultOpenAIClient)(client);
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=openai.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"openai.js","sourceRoot":"","sources":["../../src/openai.ts"],"names":[],"mappings":";;;AAAA,2CAIuB;AACvB,mCAAoC;AACpC,2CAMoB;AAEpB,SAAgB,WAAW;IACzB,oBAAoB,EAAE,CAAA;IACtB,IAAA,qBAAY,EAAC,kBAAkB,CAAC,CAAA;IAChC,IAAA,2BAAkB,EAAC,IAAI,CAAC,CAAA;AAC1B,CAAC;AAJD,kCAIC;AAED,SAAS,oBAAoB;IAC3B,MAAM,MAAM,GAAG,IAAI,oBAAW,CAAC;QAC7B,MAAM,EAAE,gCAAoB;QAC5B,UAAU,EAAE,oCAAwB;QACpC,UAAU,EAAE,4CAAgC;QAC5C,OAAO,EAAE,iCAAqB;QAC9B,uBAAuB,EAAE,CAAC,kBAAM;KACjC,CAAC,CAAA;IACF,IAAA,+BAAsB,EAAC,MAAM,CAAC,CAAA;AAChC,CAAC"}
|
package/lib/cjs/runner.d.ts
CHANGED
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { OutputMessage } from './structured-output';
|
|
3
|
-
import { AgenticInputMessage } from './types';
|
|
1
|
+
import { AIAgent, AgenticInputMessage, AgenticOutputMessage, Context } from './types';
|
|
4
2
|
export declare class AIAgentRunner {
|
|
5
3
|
private agent;
|
|
6
|
-
constructor(
|
|
7
|
-
run(messages: AgenticInputMessage[], maxRetries?: number): Promise<
|
|
4
|
+
constructor(agent: AIAgent);
|
|
5
|
+
run(messages: AgenticInputMessage[], context: Context, maxRetries?: number): Promise<AgenticOutputMessage[]>;
|
|
8
6
|
private runWithRetry;
|
|
9
|
-
private addExtraInstructions;
|
|
10
7
|
}
|
package/lib/cjs/runner.js
CHANGED
|
@@ -3,73 +3,33 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.AIAgentRunner = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const agents_1 = require("@openai/agents");
|
|
6
|
-
const openai_1 = require("openai");
|
|
7
|
-
const constants_1 = require("./constants");
|
|
8
|
-
const structured_output_1 = require("./structured-output");
|
|
9
6
|
class AIAgentRunner {
|
|
10
|
-
constructor(
|
|
11
|
-
|
|
12
|
-
const client = new openai_1.AzureOpenAI({
|
|
13
|
-
apiKey: constants_1.AZURE_OPENAI_API_KEY,
|
|
14
|
-
apiVersion: constants_1.AZURE_OPENAI_API_VERSION,
|
|
15
|
-
deployment: constants_1.AZURE_OPENAI_API_DEPLOYMENT_NAME,
|
|
16
|
-
baseURL: constants_1.AZURE_OPENAI_API_BASE,
|
|
17
|
-
dangerouslyAllowBrowser: !constants_1.isProd,
|
|
18
|
-
});
|
|
19
|
-
(0, agents_1.setDefaultOpenAIClient)(client);
|
|
20
|
-
(0, agents_1.setOpenAIAPI)('chat_completions');
|
|
21
|
-
(0, agents_1.setTracingDisabled)(true);
|
|
22
|
-
}
|
|
23
|
-
this.agent = new agents_1.Agent({
|
|
24
|
-
name: name,
|
|
25
|
-
instructions: this.addExtraInstructions(instructions),
|
|
26
|
-
tools: tools,
|
|
27
|
-
outputType: structured_output_1.OutputSchema,
|
|
28
|
-
});
|
|
7
|
+
constructor(agent) {
|
|
8
|
+
this.agent = agent;
|
|
29
9
|
}
|
|
30
|
-
run(messages, maxRetries = 1) {
|
|
10
|
+
run(messages, context, maxRetries = 1) {
|
|
31
11
|
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
32
|
-
return this.runWithRetry(messages, maxRetries, 1);
|
|
12
|
+
return this.runWithRetry(messages, context, maxRetries, 1);
|
|
33
13
|
});
|
|
34
14
|
}
|
|
35
|
-
runWithRetry(messages, maxRetries, attempt) {
|
|
15
|
+
runWithRetry(messages, context, maxRetries, attempt) {
|
|
36
16
|
var _a;
|
|
37
17
|
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
38
18
|
try {
|
|
39
19
|
const runner = new agents_1.Runner({
|
|
40
20
|
modelSettings: { temperature: 0 },
|
|
41
21
|
});
|
|
42
|
-
const result = yield runner.run(this.agent, messages);
|
|
22
|
+
const result = yield runner.run(this.agent, messages, { context });
|
|
43
23
|
return ((_a = result.finalOutput) === null || _a === void 0 ? void 0 : _a.messages) || [];
|
|
44
24
|
}
|
|
45
25
|
catch (error) {
|
|
46
|
-
if (!(error instanceof agents_1.ModelBehaviorError)) {
|
|
47
|
-
throw error;
|
|
48
|
-
}
|
|
49
26
|
if (attempt > maxRetries) {
|
|
50
27
|
throw error;
|
|
51
28
|
}
|
|
52
|
-
|
|
53
|
-
return this.runWithRetry(messages, maxRetries, attempt + 1);
|
|
29
|
+
return this.runWithRetry(messages, context, maxRetries, attempt + 1);
|
|
54
30
|
}
|
|
55
31
|
});
|
|
56
32
|
}
|
|
57
|
-
addExtraInstructions(instructions) {
|
|
58
|
-
const metadata = `Current Date: ${new Date().toISOString()}`;
|
|
59
|
-
const outputExample = JSON.stringify({
|
|
60
|
-
messages: [
|
|
61
|
-
{
|
|
62
|
-
type: 'text',
|
|
63
|
-
content: {
|
|
64
|
-
text: 'Hello, how can I help you today?',
|
|
65
|
-
},
|
|
66
|
-
},
|
|
67
|
-
],
|
|
68
|
-
numMessages: 1,
|
|
69
|
-
});
|
|
70
|
-
const output = `Return a JSON that follows the output schema provided. Never return multiple output schemas concatenated by a line break.\n<example>\n${outputExample}\n</example>`;
|
|
71
|
-
return `<instructions>\n${instructions}\n</instructions>\n\n<metadata>\n${metadata}\n</metadata>\n\n<output>\n${output}\n</output>`;
|
|
72
|
-
}
|
|
73
33
|
}
|
|
74
34
|
exports.AIAgentRunner = AIAgentRunner;
|
|
75
35
|
//# sourceMappingURL=runner.js.map
|
package/lib/cjs/runner.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runner.js","sourceRoot":"","sources":["../../src/runner.ts"],"names":[],"mappings":";;;;AAAA,
|
|
1
|
+
{"version":3,"file":"runner.js","sourceRoot":"","sources":["../../src/runner.ts"],"names":[],"mappings":";;;;AAAA,2CAAuC;AAQvC,MAAa,aAAa;IAGxB,YAAY,KAAc;QACxB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAA;IACpB,CAAC;IAEK,GAAG,CACP,QAA+B,EAC/B,OAAgB,EAChB,aAAqB,CAAC;;YAEtB,OAAO,IAAI,CAAC,YAAY,CAAC,QAAQ,EAAE,OAAO,EAAE,UAAU,EAAE,CAAC,CAAC,CAAA;QAC5D,CAAC;KAAA;IAEa,YAAY,CACxB,QAA+B,EAC/B,OAAgB,EAChB,UAAkB,EAClB,OAAe;;;YAEf,IAAI;gBACF,MAAM,MAAM,GAAG,IAAI,eAAM,CAAC;oBACxB,aAAa,EAAE,EAAE,WAAW,EAAE,CAAC,EAAE;iBAClC,CAAC,CAAA;gBACF,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,EAAE,QAAQ,EAAE,EAAE,OAAO,EAAE,CAAC,CAAA;gBAClE,OAAO,CAAA,MAAA,MAAM,CAAC,WAAW,0CAAE,QAAQ,KAAI,EAAE,CAAA;aAC1C;YAAC,OAAO,KAAK,EAAE;gBACd,IAAI,OAAO,GAAG,UAAU,EAAE;oBACxB,MAAM,KAAK,CAAA;iBACZ;gBACD,OAAO,IAAI,CAAC,YAAY,CAAC,QAAQ,EAAE,OAAO,EAAE,UAAU,EAAE,OAAO,GAAG,CAAC,CAAC,CAAA;aACrE;;KACF;CACF;AAlCD,sCAkCC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/tools/index.ts"],"names":[],"mappings":";;;AAEa,QAAA,cAAc,GAAW,EAAE,CAAA"}
|
package/lib/cjs/types.d.ts
CHANGED
|
@@ -1,15 +1,20 @@
|
|
|
1
|
-
import { AgentInputItem } from '@openai/agents';
|
|
1
|
+
import { Agent, AgentInputItem, RunContext, Tool as OpenAITool } from '@openai/agents';
|
|
2
2
|
import { ZodObject } from 'zod';
|
|
3
|
-
import { OutputMessage } from './structured-output';
|
|
4
|
-
export interface
|
|
5
|
-
authToken
|
|
6
|
-
customTools?: CustomTool[];
|
|
3
|
+
import { OutputMessage, OutputSchema } from './structured-output';
|
|
4
|
+
export interface Context {
|
|
5
|
+
authToken: string;
|
|
7
6
|
}
|
|
8
7
|
export interface CustomTool {
|
|
9
8
|
name: string;
|
|
10
9
|
description: string;
|
|
11
10
|
schema: ZodObject<any>;
|
|
12
|
-
func: (input?: any) => Promise<any>;
|
|
11
|
+
func: (input?: any, runContext?: RunContext<Context>) => Promise<any>;
|
|
12
|
+
}
|
|
13
|
+
export type Tool = OpenAITool<Context>;
|
|
14
|
+
export type AIAgent = Agent<Context, typeof OutputSchema>;
|
|
15
|
+
export interface PluginAiAgentOptions {
|
|
16
|
+
authToken?: string;
|
|
17
|
+
customTools?: CustomTool[];
|
|
13
18
|
}
|
|
14
19
|
export interface AiAgentArgs {
|
|
15
20
|
name: string;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { AIAgent, Tool } from './types';
|
|
2
|
+
export declare class AIAgentBuilder {
|
|
3
|
+
private name;
|
|
4
|
+
private instructions;
|
|
5
|
+
private tools;
|
|
6
|
+
constructor(name: string, instructions: string, tools: Tool[]);
|
|
7
|
+
build(): AIAgent;
|
|
8
|
+
private addExtraInstructions;
|
|
9
|
+
private addHubtypeTools;
|
|
10
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { Agent } from '@openai/agents';
|
|
2
|
+
import { OutputSchema } from './structured-output';
|
|
3
|
+
import { mandatoryTools } from './tools';
|
|
4
|
+
export class AIAgentBuilder {
|
|
5
|
+
constructor(name, instructions, tools) {
|
|
6
|
+
this.name = name;
|
|
7
|
+
this.instructions = this.addExtraInstructions(instructions);
|
|
8
|
+
this.tools = this.addHubtypeTools(tools);
|
|
9
|
+
}
|
|
10
|
+
build() {
|
|
11
|
+
return new Agent({
|
|
12
|
+
name: this.name,
|
|
13
|
+
instructions: this.instructions,
|
|
14
|
+
tools: this.tools,
|
|
15
|
+
outputType: OutputSchema,
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
addExtraInstructions(instructions) {
|
|
19
|
+
const metadata = `Current Date: ${new Date().toISOString()}`;
|
|
20
|
+
const example = {
|
|
21
|
+
messages: [
|
|
22
|
+
{
|
|
23
|
+
type: 'text',
|
|
24
|
+
content: {
|
|
25
|
+
text: 'Hello, how can I help you today?',
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
],
|
|
29
|
+
numMessages: 1,
|
|
30
|
+
};
|
|
31
|
+
const output = `Return a JSON that follows the output schema provided. Never return multiple output schemas concatenated by a line break.\n<example>\n${JSON.stringify(example)}\n</example>`;
|
|
32
|
+
return `<instructions>\n${instructions}\n</instructions>\n\n<metadata>\n${metadata}\n</metadata>\n\n<output>\n${output}\n</output>`;
|
|
33
|
+
}
|
|
34
|
+
addHubtypeTools(tools) {
|
|
35
|
+
const hubtypeTools = [...mandatoryTools];
|
|
36
|
+
return [...hubtypeTools, ...tools];
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
//# sourceMappingURL=agent-builder.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agent-builder.js","sourceRoot":"","sources":["../../src/agent-builder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAA;AAEtC,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAA;AAClD,OAAO,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AAGxC,MAAM,OAAO,cAAc;IAKzB,YAAY,IAAY,EAAE,YAAoB,EAAE,KAAa;QAC3D,IAAI,CAAC,IAAI,GAAG,IAAI,CAAA;QAChB,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC,oBAAoB,CAAC,YAAY,CAAC,CAAA;QAC3D,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,eAAe,CAAC,KAAK,CAAC,CAAA;IAC1C,CAAC;IAED,KAAK;QACH,OAAO,IAAI,KAAK,CAAC;YACf,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,YAAY,EAAE,IAAI,CAAC,YAAY;YAC/B,KAAK,EAAE,IAAI,CAAC,KAAK;YACjB,UAAU,EAAE,YAAY;SACzB,CAAC,CAAA;IACJ,CAAC;IAEO,oBAAoB,CAAC,YAAoB;QAC/C,MAAM,QAAQ,GAAG,iBAAiB,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,EAAE,CAAA;QAC5D,MAAM,OAAO,GAAG;YACd,QAAQ,EAAE;gBACR;oBACE,IAAI,EAAE,MAAM;oBACZ,OAAO,EAAE;wBACP,IAAI,EAAE,kCAAkC;qBACzC;iBACF;aACF;YACD,WAAW,EAAE,CAAC;SACf,CAAA;QACD,MAAM,MAAM,GAAG,yIAAyI,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,cAAc,CAAA;QAC7L,OAAO,mBAAmB,YAAY,oCAAoC,QAAQ,8BAA8B,MAAM,aAAa,CAAA;IACrI,CAAC;IAEO,eAAe,CAAC,KAAa;QACnC,MAAM,YAAY,GAAW,CAAC,GAAG,cAAc,CAAC,CAAA;QAChD,OAAO,CAAC,GAAG,YAAY,EAAE,GAAG,KAAK,CAAC,CAAA;IACpC,CAAC;CACF"}
|
package/lib/esm/index.d.ts
CHANGED
|
@@ -2,11 +2,11 @@ import { BotContext, Plugin } from '@botonic/core';
|
|
|
2
2
|
import { AgenticOutputMessage, AiAgentArgs, CustomTool, PluginAiAgentOptions } from './types';
|
|
3
3
|
export default class BotonicPluginAiAgents implements Plugin {
|
|
4
4
|
private readonly authToken?;
|
|
5
|
-
|
|
5
|
+
toolDefinitions: CustomTool[];
|
|
6
6
|
constructor(options?: PluginAiAgentOptions);
|
|
7
7
|
pre(): void;
|
|
8
8
|
getInference(request: BotContext, aiAgentArgs: AiAgentArgs): Promise<AgenticOutputMessage[] | undefined>;
|
|
9
9
|
private getMessages;
|
|
10
|
-
private
|
|
10
|
+
private buildTools;
|
|
11
11
|
}
|
|
12
12
|
export * from './types';
|
package/lib/esm/index.js
CHANGED
|
@@ -1,31 +1,36 @@
|
|
|
1
1
|
import { __awaiter } from "tslib";
|
|
2
2
|
import { tool } from '@openai/agents';
|
|
3
|
+
import { AIAgentBuilder } from './agent-builder';
|
|
3
4
|
import { isProd } from './constants';
|
|
4
5
|
import { HubtypeApiClient } from './hubtype-api-client';
|
|
6
|
+
import { setUpOpenAI } from './openai';
|
|
5
7
|
import { AIAgentRunner } from './runner';
|
|
6
8
|
export default class BotonicPluginAiAgents {
|
|
7
9
|
constructor(options) {
|
|
8
|
-
this.
|
|
10
|
+
this.toolDefinitions = [];
|
|
11
|
+
setUpOpenAI();
|
|
9
12
|
this.authToken = options === null || options === void 0 ? void 0 : options.authToken;
|
|
10
|
-
this.
|
|
13
|
+
this.toolDefinitions = (options === null || options === void 0 ? void 0 : options.customTools) || [];
|
|
11
14
|
}
|
|
12
15
|
pre() {
|
|
13
16
|
return;
|
|
14
17
|
}
|
|
15
18
|
getInference(request, aiAgentArgs) {
|
|
19
|
+
var _a;
|
|
16
20
|
return __awaiter(this, void 0, void 0, function* () {
|
|
17
21
|
try {
|
|
18
22
|
const authToken = isProd ? request.session._access_token : this.authToken;
|
|
19
23
|
if (!authToken) {
|
|
20
24
|
throw new Error('Auth token is required');
|
|
21
25
|
}
|
|
26
|
+
const tools = this.buildTools(((_a = aiAgentArgs.activeTools) === null || _a === void 0 ? void 0 : _a.map(tool => tool.name)) || []);
|
|
27
|
+
const agent = new AIAgentBuilder(aiAgentArgs.name, aiAgentArgs.instructions, tools).build();
|
|
22
28
|
const messages = yield this.getMessages(request, authToken, 10);
|
|
23
|
-
const
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
const
|
|
27
|
-
|
|
28
|
-
return output;
|
|
29
|
+
const context = {
|
|
30
|
+
authToken,
|
|
31
|
+
};
|
|
32
|
+
const runner = new AIAgentRunner(agent);
|
|
33
|
+
return yield runner.run(messages, context);
|
|
29
34
|
}
|
|
30
35
|
catch (error) {
|
|
31
36
|
console.error('error plugin returns undefined', error);
|
|
@@ -43,13 +48,14 @@ export default class BotonicPluginAiAgents {
|
|
|
43
48
|
return yield hubtypeClient.getLocalMessages(memoryLength);
|
|
44
49
|
});
|
|
45
50
|
}
|
|
46
|
-
|
|
47
|
-
|
|
51
|
+
buildTools(activeToolNames) {
|
|
52
|
+
const availableTools = this.toolDefinitions.filter(tool => activeToolNames.includes(tool.name));
|
|
53
|
+
return availableTools.map(toolDefinition => {
|
|
48
54
|
return tool({
|
|
49
|
-
name:
|
|
50
|
-
description:
|
|
51
|
-
parameters:
|
|
52
|
-
execute:
|
|
55
|
+
name: toolDefinition.name,
|
|
56
|
+
description: toolDefinition.description,
|
|
57
|
+
parameters: toolDefinition.schema,
|
|
58
|
+
execute: toolDefinition.func,
|
|
53
59
|
});
|
|
54
60
|
});
|
|
55
61
|
}
|
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,MAAM,EAAE,MAAM,aAAa,CAAA;AACpC,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAA;AACvD,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAA;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function setUpOpenAI(): void;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { setDefaultOpenAIClient, setOpenAIAPI, setTracingDisabled, } from '@openai/agents';
|
|
2
|
+
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';
|
|
4
|
+
export function setUpOpenAI() {
|
|
5
|
+
setAzureOpenAIClient();
|
|
6
|
+
setOpenAIAPI('chat_completions');
|
|
7
|
+
setTracingDisabled(true);
|
|
8
|
+
}
|
|
9
|
+
function setAzureOpenAIClient() {
|
|
10
|
+
const client = new AzureOpenAI({
|
|
11
|
+
apiKey: AZURE_OPENAI_API_KEY,
|
|
12
|
+
apiVersion: AZURE_OPENAI_API_VERSION,
|
|
13
|
+
deployment: AZURE_OPENAI_API_DEPLOYMENT_NAME,
|
|
14
|
+
baseURL: AZURE_OPENAI_API_BASE,
|
|
15
|
+
dangerouslyAllowBrowser: !isProd,
|
|
16
|
+
});
|
|
17
|
+
setDefaultOpenAIClient(client);
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=openai.js.map
|
|
@@ -0,0 +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;AACpC,OAAO,EACL,qBAAqB,EACrB,gCAAgC,EAChC,oBAAoB,EACpB,wBAAwB,EACxB,MAAM,GACP,MAAM,aAAa,CAAA;AAEpB,MAAM,UAAU,WAAW;IACzB,oBAAoB,EAAE,CAAA;IACtB,YAAY,CAAC,kBAAkB,CAAC,CAAA;IAChC,kBAAkB,CAAC,IAAI,CAAC,CAAA;AAC1B,CAAC;AAED,SAAS,oBAAoB;IAC3B,MAAM,MAAM,GAAG,IAAI,WAAW,CAAC;QAC7B,MAAM,EAAE,oBAAoB;QAC5B,UAAU,EAAE,wBAAwB;QACpC,UAAU,EAAE,gCAAgC;QAC5C,OAAO,EAAE,qBAAqB;QAC9B,uBAAuB,EAAE,CAAC,MAAM;KACjC,CAAC,CAAA;IACF,sBAAsB,CAAC,MAAM,CAAC,CAAA;AAChC,CAAC"}
|
package/lib/esm/runner.d.ts
CHANGED
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { OutputMessage } from './structured-output';
|
|
3
|
-
import { AgenticInputMessage } from './types';
|
|
1
|
+
import { AIAgent, AgenticInputMessage, AgenticOutputMessage, Context } from './types';
|
|
4
2
|
export declare class AIAgentRunner {
|
|
5
3
|
private agent;
|
|
6
|
-
constructor(
|
|
7
|
-
run(messages: AgenticInputMessage[], maxRetries?: number): Promise<
|
|
4
|
+
constructor(agent: AIAgent);
|
|
5
|
+
run(messages: AgenticInputMessage[], context: Context, maxRetries?: number): Promise<AgenticOutputMessage[]>;
|
|
8
6
|
private runWithRetry;
|
|
9
|
-
private addExtraInstructions;
|
|
10
7
|
}
|
package/lib/esm/runner.js
CHANGED
|
@@ -1,71 +1,31 @@
|
|
|
1
1
|
import { __awaiter } from "tslib";
|
|
2
|
-
import {
|
|
3
|
-
import { AzureOpenAI } from 'openai';
|
|
4
|
-
import { AZURE_OPENAI_API_BASE, AZURE_OPENAI_API_DEPLOYMENT_NAME, AZURE_OPENAI_API_KEY, AZURE_OPENAI_API_VERSION, isProd, } from './constants';
|
|
5
|
-
import { OutputSchema } from './structured-output';
|
|
2
|
+
import { Runner } from '@openai/agents';
|
|
6
3
|
export class AIAgentRunner {
|
|
7
|
-
constructor(
|
|
8
|
-
|
|
9
|
-
const client = new AzureOpenAI({
|
|
10
|
-
apiKey: AZURE_OPENAI_API_KEY,
|
|
11
|
-
apiVersion: AZURE_OPENAI_API_VERSION,
|
|
12
|
-
deployment: AZURE_OPENAI_API_DEPLOYMENT_NAME,
|
|
13
|
-
baseURL: AZURE_OPENAI_API_BASE,
|
|
14
|
-
dangerouslyAllowBrowser: !isProd,
|
|
15
|
-
});
|
|
16
|
-
setDefaultOpenAIClient(client);
|
|
17
|
-
setOpenAIAPI('chat_completions');
|
|
18
|
-
setTracingDisabled(true);
|
|
19
|
-
}
|
|
20
|
-
this.agent = new Agent({
|
|
21
|
-
name: name,
|
|
22
|
-
instructions: this.addExtraInstructions(instructions),
|
|
23
|
-
tools: tools,
|
|
24
|
-
outputType: OutputSchema,
|
|
25
|
-
});
|
|
4
|
+
constructor(agent) {
|
|
5
|
+
this.agent = agent;
|
|
26
6
|
}
|
|
27
|
-
run(messages, maxRetries = 1) {
|
|
7
|
+
run(messages, context, maxRetries = 1) {
|
|
28
8
|
return __awaiter(this, void 0, void 0, function* () {
|
|
29
|
-
return this.runWithRetry(messages, maxRetries, 1);
|
|
9
|
+
return this.runWithRetry(messages, context, maxRetries, 1);
|
|
30
10
|
});
|
|
31
11
|
}
|
|
32
|
-
runWithRetry(messages, maxRetries, attempt) {
|
|
12
|
+
runWithRetry(messages, context, maxRetries, attempt) {
|
|
33
13
|
var _a;
|
|
34
14
|
return __awaiter(this, void 0, void 0, function* () {
|
|
35
15
|
try {
|
|
36
16
|
const runner = new Runner({
|
|
37
17
|
modelSettings: { temperature: 0 },
|
|
38
18
|
});
|
|
39
|
-
const result = yield runner.run(this.agent, messages);
|
|
19
|
+
const result = yield runner.run(this.agent, messages, { context });
|
|
40
20
|
return ((_a = result.finalOutput) === null || _a === void 0 ? void 0 : _a.messages) || [];
|
|
41
21
|
}
|
|
42
22
|
catch (error) {
|
|
43
|
-
if (!(error instanceof ModelBehaviorError)) {
|
|
44
|
-
throw error;
|
|
45
|
-
}
|
|
46
23
|
if (attempt > maxRetries) {
|
|
47
24
|
throw error;
|
|
48
25
|
}
|
|
49
|
-
|
|
50
|
-
return this.runWithRetry(messages, maxRetries, attempt + 1);
|
|
26
|
+
return this.runWithRetry(messages, context, maxRetries, attempt + 1);
|
|
51
27
|
}
|
|
52
28
|
});
|
|
53
29
|
}
|
|
54
|
-
addExtraInstructions(instructions) {
|
|
55
|
-
const metadata = `Current Date: ${new Date().toISOString()}`;
|
|
56
|
-
const outputExample = JSON.stringify({
|
|
57
|
-
messages: [
|
|
58
|
-
{
|
|
59
|
-
type: 'text',
|
|
60
|
-
content: {
|
|
61
|
-
text: 'Hello, how can I help you today?',
|
|
62
|
-
},
|
|
63
|
-
},
|
|
64
|
-
],
|
|
65
|
-
numMessages: 1,
|
|
66
|
-
});
|
|
67
|
-
const output = `Return a JSON that follows the output schema provided. Never return multiple output schemas concatenated by a line break.\n<example>\n${outputExample}\n</example>`;
|
|
68
|
-
return `<instructions>\n${instructions}\n</instructions>\n\n<metadata>\n${metadata}\n</metadata>\n\n<output>\n${output}\n</output>`;
|
|
69
|
-
}
|
|
70
30
|
}
|
|
71
31
|
//# 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":";AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"runner.js","sourceRoot":"","sources":["../../src/runner.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAA;AAQvC,MAAM,OAAO,aAAa;IAGxB,YAAY,KAAc;QACxB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAA;IACpB,CAAC;IAEK,GAAG,CACP,QAA+B,EAC/B,OAAgB,EAChB,aAAqB,CAAC;;YAEtB,OAAO,IAAI,CAAC,YAAY,CAAC,QAAQ,EAAE,OAAO,EAAE,UAAU,EAAE,CAAC,CAAC,CAAA;QAC5D,CAAC;KAAA;IAEa,YAAY,CACxB,QAA+B,EAC/B,OAAgB,EAChB,UAAkB,EAClB,OAAe;;;YAEf,IAAI;gBACF,MAAM,MAAM,GAAG,IAAI,MAAM,CAAC;oBACxB,aAAa,EAAE,EAAE,WAAW,EAAE,CAAC,EAAE;iBAClC,CAAC,CAAA;gBACF,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,EAAE,QAAQ,EAAE,EAAE,OAAO,EAAE,CAAC,CAAA;gBAClE,OAAO,CAAA,MAAA,MAAM,CAAC,WAAW,0CAAE,QAAQ,KAAI,EAAE,CAAA;aAC1C;YAAC,OAAO,KAAK,EAAE;gBACd,IAAI,OAAO,GAAG,UAAU,EAAE;oBACxB,MAAM,KAAK,CAAA;iBACZ;gBACD,OAAO,IAAI,CAAC,YAAY,CAAC,QAAQ,EAAE,OAAO,EAAE,UAAU,EAAE,OAAO,GAAG,CAAC,CAAC,CAAA;aACrE;;KACF;CACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/tools/index.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,cAAc,GAAW,EAAE,CAAA"}
|
package/lib/esm/types.d.ts
CHANGED
|
@@ -1,15 +1,20 @@
|
|
|
1
|
-
import { AgentInputItem } from '@openai/agents';
|
|
1
|
+
import { Agent, AgentInputItem, RunContext, Tool as OpenAITool } from '@openai/agents';
|
|
2
2
|
import { ZodObject } from 'zod';
|
|
3
|
-
import { OutputMessage } from './structured-output';
|
|
4
|
-
export interface
|
|
5
|
-
authToken
|
|
6
|
-
customTools?: CustomTool[];
|
|
3
|
+
import { OutputMessage, OutputSchema } from './structured-output';
|
|
4
|
+
export interface Context {
|
|
5
|
+
authToken: string;
|
|
7
6
|
}
|
|
8
7
|
export interface CustomTool {
|
|
9
8
|
name: string;
|
|
10
9
|
description: string;
|
|
11
10
|
schema: ZodObject<any>;
|
|
12
|
-
func: (input?: any) => Promise<any>;
|
|
11
|
+
func: (input?: any, runContext?: RunContext<Context>) => Promise<any>;
|
|
12
|
+
}
|
|
13
|
+
export type Tool = OpenAITool<Context>;
|
|
14
|
+
export type AIAgent = Agent<Context, typeof OutputSchema>;
|
|
15
|
+
export interface PluginAiAgentOptions {
|
|
16
|
+
authToken?: string;
|
|
17
|
+
customTools?: CustomTool[];
|
|
13
18
|
}
|
|
14
19
|
export interface AiAgentArgs {
|
|
15
20
|
name: string;
|
package/package.json
CHANGED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { Agent } from '@openai/agents'
|
|
2
|
+
|
|
3
|
+
import { OutputSchema } from './structured-output'
|
|
4
|
+
import { mandatoryTools } from './tools'
|
|
5
|
+
import { AIAgent, Tool } from './types'
|
|
6
|
+
|
|
7
|
+
export class AIAgentBuilder {
|
|
8
|
+
private name: string
|
|
9
|
+
private instructions: string
|
|
10
|
+
private tools: Tool[]
|
|
11
|
+
|
|
12
|
+
constructor(name: string, instructions: string, tools: Tool[]) {
|
|
13
|
+
this.name = name
|
|
14
|
+
this.instructions = this.addExtraInstructions(instructions)
|
|
15
|
+
this.tools = this.addHubtypeTools(tools)
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
build(): AIAgent {
|
|
19
|
+
return new Agent({
|
|
20
|
+
name: this.name,
|
|
21
|
+
instructions: this.instructions,
|
|
22
|
+
tools: this.tools,
|
|
23
|
+
outputType: OutputSchema,
|
|
24
|
+
})
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
private addExtraInstructions(instructions: string): string {
|
|
28
|
+
const metadata = `Current Date: ${new Date().toISOString()}`
|
|
29
|
+
const example = {
|
|
30
|
+
messages: [
|
|
31
|
+
{
|
|
32
|
+
type: 'text',
|
|
33
|
+
content: {
|
|
34
|
+
text: 'Hello, how can I help you today?',
|
|
35
|
+
},
|
|
36
|
+
},
|
|
37
|
+
],
|
|
38
|
+
numMessages: 1,
|
|
39
|
+
}
|
|
40
|
+
const output = `Return a JSON that follows the output schema provided. Never return multiple output schemas concatenated by a line break.\n<example>\n${JSON.stringify(example)}\n</example>`
|
|
41
|
+
return `<instructions>\n${instructions}\n</instructions>\n\n<metadata>\n${metadata}\n</metadata>\n\n<output>\n${output}\n</output>`
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
private addHubtypeTools(tools: Tool[]): Tool[] {
|
|
45
|
+
const hubtypeTools: Tool[] = [...mandatoryTools]
|
|
46
|
+
return [...hubtypeTools, ...tools]
|
|
47
|
+
}
|
|
48
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -1,24 +1,29 @@
|
|
|
1
1
|
import { BotContext, Plugin } from '@botonic/core'
|
|
2
2
|
import { tool } from '@openai/agents'
|
|
3
3
|
|
|
4
|
+
import { AIAgentBuilder } from './agent-builder'
|
|
4
5
|
import { isProd } from './constants'
|
|
5
6
|
import { HubtypeApiClient } from './hubtype-api-client'
|
|
7
|
+
import { setUpOpenAI } from './openai'
|
|
6
8
|
import { AIAgentRunner } from './runner'
|
|
7
9
|
import {
|
|
8
10
|
AgenticInputMessage,
|
|
9
11
|
AgenticOutputMessage,
|
|
10
12
|
AiAgentArgs,
|
|
13
|
+
Context,
|
|
11
14
|
CustomTool,
|
|
12
15
|
PluginAiAgentOptions,
|
|
16
|
+
Tool,
|
|
13
17
|
} from './types'
|
|
14
18
|
|
|
15
19
|
export default class BotonicPluginAiAgents implements Plugin {
|
|
16
20
|
private readonly authToken?: string
|
|
17
|
-
public
|
|
21
|
+
public toolDefinitions: CustomTool[] = []
|
|
18
22
|
|
|
19
23
|
constructor(options?: PluginAiAgentOptions) {
|
|
24
|
+
setUpOpenAI()
|
|
20
25
|
this.authToken = options?.authToken
|
|
21
|
-
this.
|
|
26
|
+
this.toolDefinitions = options?.customTools || []
|
|
22
27
|
}
|
|
23
28
|
|
|
24
29
|
pre(): void {
|
|
@@ -35,21 +40,22 @@ export default class BotonicPluginAiAgents implements Plugin {
|
|
|
35
40
|
throw new Error('Auth token is required')
|
|
36
41
|
}
|
|
37
42
|
|
|
38
|
-
const
|
|
39
|
-
|
|
40
|
-
aiAgentArgs.activeTools?.map(tool => tool.name).includes(tool.name)
|
|
43
|
+
const tools = this.buildTools(
|
|
44
|
+
aiAgentArgs.activeTools?.map(tool => tool.name) || []
|
|
41
45
|
)
|
|
42
|
-
const
|
|
43
|
-
|
|
44
|
-
const runner = new AIAgentRunner(
|
|
46
|
+
const agent = new AIAgentBuilder(
|
|
45
47
|
aiAgentArgs.name,
|
|
46
48
|
aiAgentArgs.instructions,
|
|
47
49
|
tools
|
|
48
|
-
)
|
|
49
|
-
|
|
50
|
-
|
|
50
|
+
).build()
|
|
51
|
+
|
|
52
|
+
const messages = await this.getMessages(request, authToken, 10)
|
|
53
|
+
const context: Context = {
|
|
54
|
+
authToken,
|
|
55
|
+
}
|
|
51
56
|
|
|
52
|
-
|
|
57
|
+
const runner = new AIAgentRunner(agent)
|
|
58
|
+
return await runner.run(messages, context)
|
|
53
59
|
} catch (error) {
|
|
54
60
|
console.error('error plugin returns undefined', error)
|
|
55
61
|
return undefined
|
|
@@ -69,13 +75,16 @@ export default class BotonicPluginAiAgents implements Plugin {
|
|
|
69
75
|
return await hubtypeClient.getLocalMessages(memoryLength)
|
|
70
76
|
}
|
|
71
77
|
|
|
72
|
-
private
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
78
|
+
private buildTools(activeToolNames: string[]): Tool[] {
|
|
79
|
+
const availableTools = this.toolDefinitions.filter(tool =>
|
|
80
|
+
activeToolNames.includes(tool.name)
|
|
81
|
+
)
|
|
82
|
+
return availableTools.map(toolDefinition => {
|
|
83
|
+
return tool<any, Context, any>({
|
|
84
|
+
name: toolDefinition.name,
|
|
85
|
+
description: toolDefinition.description,
|
|
86
|
+
parameters: toolDefinition.schema,
|
|
87
|
+
execute: toolDefinition.func,
|
|
79
88
|
})
|
|
80
89
|
})
|
|
81
90
|
}
|
package/src/openai.ts
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import {
|
|
2
|
+
setDefaultOpenAIClient,
|
|
3
|
+
setOpenAIAPI,
|
|
4
|
+
setTracingDisabled,
|
|
5
|
+
} from '@openai/agents'
|
|
6
|
+
import { AzureOpenAI } from 'openai'
|
|
7
|
+
import {
|
|
8
|
+
AZURE_OPENAI_API_BASE,
|
|
9
|
+
AZURE_OPENAI_API_DEPLOYMENT_NAME,
|
|
10
|
+
AZURE_OPENAI_API_KEY,
|
|
11
|
+
AZURE_OPENAI_API_VERSION,
|
|
12
|
+
isProd,
|
|
13
|
+
} from './constants'
|
|
14
|
+
|
|
15
|
+
export function setUpOpenAI() {
|
|
16
|
+
setAzureOpenAIClient()
|
|
17
|
+
setOpenAIAPI('chat_completions')
|
|
18
|
+
setTracingDisabled(true)
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function setAzureOpenAIClient() {
|
|
22
|
+
const client = new AzureOpenAI({
|
|
23
|
+
apiKey: AZURE_OPENAI_API_KEY,
|
|
24
|
+
apiVersion: AZURE_OPENAI_API_VERSION,
|
|
25
|
+
deployment: AZURE_OPENAI_API_DEPLOYMENT_NAME,
|
|
26
|
+
baseURL: AZURE_OPENAI_API_BASE,
|
|
27
|
+
dangerouslyAllowBrowser: !isProd,
|
|
28
|
+
})
|
|
29
|
+
setDefaultOpenAIClient(client)
|
|
30
|
+
}
|
package/src/runner.ts
CHANGED
|
@@ -1,97 +1,43 @@
|
|
|
1
|
+
import { Runner } from '@openai/agents'
|
|
1
2
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
setTracingDisabled,
|
|
8
|
-
Tool,
|
|
9
|
-
} from '@openai/agents'
|
|
10
|
-
import { AzureOpenAI } from 'openai'
|
|
11
|
-
|
|
12
|
-
import {
|
|
13
|
-
AZURE_OPENAI_API_BASE,
|
|
14
|
-
AZURE_OPENAI_API_DEPLOYMENT_NAME,
|
|
15
|
-
AZURE_OPENAI_API_KEY,
|
|
16
|
-
AZURE_OPENAI_API_VERSION,
|
|
17
|
-
isProd,
|
|
18
|
-
} from './constants'
|
|
19
|
-
import { OutputMessage, OutputSchema } from './structured-output'
|
|
20
|
-
import { AgenticInputMessage } from './types'
|
|
3
|
+
AIAgent,
|
|
4
|
+
AgenticInputMessage,
|
|
5
|
+
AgenticOutputMessage,
|
|
6
|
+
Context,
|
|
7
|
+
} from './types'
|
|
21
8
|
|
|
22
9
|
export class AIAgentRunner {
|
|
23
|
-
private agent:
|
|
24
|
-
|
|
25
|
-
constructor(name: string, instructions: string, tools: Tool[]) {
|
|
26
|
-
if (AZURE_OPENAI_API_KEY) {
|
|
27
|
-
const client = new AzureOpenAI({
|
|
28
|
-
apiKey: AZURE_OPENAI_API_KEY,
|
|
29
|
-
apiVersion: AZURE_OPENAI_API_VERSION,
|
|
30
|
-
deployment: AZURE_OPENAI_API_DEPLOYMENT_NAME,
|
|
31
|
-
baseURL: AZURE_OPENAI_API_BASE,
|
|
32
|
-
dangerouslyAllowBrowser: !isProd,
|
|
33
|
-
})
|
|
34
|
-
setDefaultOpenAIClient(client as any)
|
|
35
|
-
setOpenAIAPI('chat_completions')
|
|
36
|
-
setTracingDisabled(true)
|
|
37
|
-
}
|
|
10
|
+
private agent: AIAgent
|
|
38
11
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
instructions: this.addExtraInstructions(instructions),
|
|
42
|
-
tools: tools,
|
|
43
|
-
outputType: OutputSchema,
|
|
44
|
-
})
|
|
12
|
+
constructor(agent: AIAgent) {
|
|
13
|
+
this.agent = agent
|
|
45
14
|
}
|
|
46
15
|
|
|
47
16
|
async run(
|
|
48
17
|
messages: AgenticInputMessage[],
|
|
18
|
+
context: Context,
|
|
49
19
|
maxRetries: number = 1
|
|
50
|
-
): Promise<
|
|
51
|
-
return this.runWithRetry(messages, maxRetries, 1)
|
|
20
|
+
): Promise<AgenticOutputMessage[]> {
|
|
21
|
+
return this.runWithRetry(messages, context, maxRetries, 1)
|
|
52
22
|
}
|
|
53
23
|
|
|
54
24
|
private async runWithRetry(
|
|
55
25
|
messages: AgenticInputMessage[],
|
|
26
|
+
context: Context,
|
|
56
27
|
maxRetries: number,
|
|
57
28
|
attempt: number
|
|
58
|
-
): Promise<
|
|
29
|
+
): Promise<AgenticOutputMessage[]> {
|
|
59
30
|
try {
|
|
60
31
|
const runner = new Runner({
|
|
61
32
|
modelSettings: { temperature: 0 },
|
|
62
33
|
})
|
|
63
|
-
const result = await runner.run(this.agent, messages)
|
|
34
|
+
const result = await runner.run(this.agent, messages, { context })
|
|
64
35
|
return result.finalOutput?.messages || []
|
|
65
36
|
} catch (error) {
|
|
66
|
-
if (!(error instanceof ModelBehaviorError)) {
|
|
67
|
-
throw error
|
|
68
|
-
}
|
|
69
37
|
if (attempt > maxRetries) {
|
|
70
38
|
throw error
|
|
71
39
|
}
|
|
72
|
-
|
|
73
|
-
`AI Agent execution failed due to ModelBehaviorError. Retrying... (Attempt ${attempt}/${maxRetries})`
|
|
74
|
-
)
|
|
75
|
-
return this.runWithRetry(messages, maxRetries, attempt + 1)
|
|
40
|
+
return this.runWithRetry(messages, context, maxRetries, attempt + 1)
|
|
76
41
|
}
|
|
77
42
|
}
|
|
78
|
-
|
|
79
|
-
private addExtraInstructions(instructions: string): string {
|
|
80
|
-
const metadata = `Current Date: ${new Date().toISOString()}`
|
|
81
|
-
|
|
82
|
-
const outputExample = JSON.stringify({
|
|
83
|
-
messages: [
|
|
84
|
-
{
|
|
85
|
-
type: 'text',
|
|
86
|
-
content: {
|
|
87
|
-
text: 'Hello, how can I help you today?',
|
|
88
|
-
},
|
|
89
|
-
},
|
|
90
|
-
],
|
|
91
|
-
numMessages: 1,
|
|
92
|
-
})
|
|
93
|
-
const output = `Return a JSON that follows the output schema provided. Never return multiple output schemas concatenated by a line break.\n<example>\n${outputExample}\n</example>`
|
|
94
|
-
|
|
95
|
-
return `<instructions>\n${instructions}\n</instructions>\n\n<metadata>\n${metadata}\n</metadata>\n\n<output>\n${output}\n</output>`
|
|
96
|
-
}
|
|
97
43
|
}
|
package/src/types.ts
CHANGED
|
@@ -1,17 +1,30 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
Agent,
|
|
3
|
+
AgentInputItem,
|
|
4
|
+
RunContext,
|
|
5
|
+
Tool as OpenAITool,
|
|
6
|
+
} from '@openai/agents'
|
|
2
7
|
import { ZodObject } from 'zod'
|
|
3
8
|
|
|
4
|
-
import { OutputMessage } from './structured-output'
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
9
|
+
import { OutputMessage, OutputSchema } from './structured-output'
|
|
10
|
+
|
|
11
|
+
export interface Context {
|
|
12
|
+
authToken: string
|
|
8
13
|
}
|
|
9
14
|
|
|
10
15
|
export interface CustomTool {
|
|
11
16
|
name: string
|
|
12
17
|
description: string
|
|
13
18
|
schema: ZodObject<any>
|
|
14
|
-
func: (input?: any) => Promise<any>
|
|
19
|
+
func: (input?: any, runContext?: RunContext<Context>) => Promise<any>
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export type Tool = OpenAITool<Context>
|
|
23
|
+
export type AIAgent = Agent<Context, typeof OutputSchema>
|
|
24
|
+
|
|
25
|
+
export interface PluginAiAgentOptions {
|
|
26
|
+
authToken?: string
|
|
27
|
+
customTools?: CustomTool[]
|
|
15
28
|
}
|
|
16
29
|
|
|
17
30
|
export interface AiAgentArgs {
|