@botonic/plugin-ai-agents 0.43.0-beta.0 → 0.43.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cjs/agent-builder.d.ts +14 -3
- package/lib/cjs/agent-builder.js +44 -13
- package/lib/cjs/agent-builder.js.map +1 -1
- package/lib/cjs/constants.d.ts +3 -0
- package/lib/cjs/constants.js +6 -1
- package/lib/cjs/constants.js.map +1 -1
- package/lib/cjs/guardrails/input.js.map +1 -1
- package/lib/cjs/hubtype-api-client.js +9 -15
- package/lib/cjs/hubtype-api-client.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 -2
- 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 -3
- package/lib/esm/agent-builder.d.ts +14 -3
- package/lib/esm/agent-builder.js +45 -14
- 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/hubtype-api-client.js +9 -15
- package/lib/esm/hubtype-api-client.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 -2
- 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 -3
- package/package.json +4 -4
- package/src/agent-builder.ts +80 -26
- package/src/constants.ts +7 -0
- package/src/guardrails/input.ts +1 -1
- package/src/hubtype-api-client.ts +21 -14
- package/src/index.ts +9 -8
- package/src/openai.ts +19 -3
- package/src/runner.ts +15 -6
- package/src/tools/retrieve-knowledge.ts +3 -2
- package/src/types.ts +4 -3
|
@@ -74,21 +74,15 @@ export class HubtypeApiClient {
|
|
|
74
74
|
'Content-Type': 'application/json',
|
|
75
75
|
Authorization: `Bearer ${this.authToken}`,
|
|
76
76
|
};
|
|
77
|
-
const params = {
|
|
78
|
-
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
}
|
|
86
|
-
if (options.maxFullToolResults !== undefined) {
|
|
87
|
-
params.max_full_tool_results = options.maxFullToolResults;
|
|
88
|
-
}
|
|
89
|
-
if (options.debugMode !== undefined) {
|
|
90
|
-
params.debug_mode = options.debugMode;
|
|
91
|
-
}
|
|
77
|
+
const params = Object.assign(Object.assign(Object.assign(Object.assign({ last_message_id: request.input.message_id }, (options.maxMessages !== undefined && {
|
|
78
|
+
max_messages: options.maxMessages,
|
|
79
|
+
})), (options.includeToolCalls !== undefined && {
|
|
80
|
+
include_tool_calls: options.includeToolCalls,
|
|
81
|
+
})), (options.maxFullToolResults !== undefined && {
|
|
82
|
+
max_full_tool_results: options.maxFullToolResults,
|
|
83
|
+
})), (options.debugMode !== undefined && {
|
|
84
|
+
debug_mode: options.debugMode,
|
|
85
|
+
}));
|
|
92
86
|
try {
|
|
93
87
|
const response = yield axios.get(url, {
|
|
94
88
|
headers,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hubtype-api-client.js","sourceRoot":"","sources":["../../src/hubtype-api-client.ts"],"names":[],"mappings":";AAEA,OAAO,KAAK,MAAM,OAAO,CAAA;AAEzB,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;
|
|
1
|
+
{"version":3,"file":"hubtype-api-client.js","sourceRoot":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C/D,iEAAiE;gBACjE,gDAAgD;gBAChD,MAAM,WAAW,GAAG,OAA+B,CAAA;gBACnD,OAAO;oBACL,IAAI,EAAE,MAAM;oBACZ,YAAY,EAAE,WAAW,CAAC,YAAY;oBACtC,OAAO,EAAE,MAAA,WAAW,CAAC,OAAO,mCAAI,EAAE;iBACD,CAAA;aACpC;YACD,KAAK,QAAQ;gBACX,OAAO;oBACL,IAAI,EAAE,QAAQ;oBACd,OAAO,EAAE,MAAA,OAAO,CAAC,OAAO,mCAAI,EAAE;iBAC/B,CAAA;YACH;gBACE,MAAM,IAAI,KAAK,CACb,yBAA0B,OAA4B,CAAC,IAAI,EAAE,CAC9D,CAAA;SACJ;IACH,CAAC;IAEO,aAAa,CAAC,OAAuB;QAC3C,IAAI,OAAO,CAAC,IAAI,KAAK,MAAM,EAAE;YAC3B,OAAO;gBACL,OAAO,EAAE,OAAO,CAAC,OAAO;gBACxB,IAAI,EAAE,MAAM;aACb,CAAA;SACF;aAAM,IAAI,OAAO,CAAC,IAAI,KAAK,WAAW,EAAE;YACvC,OAAO;gBACL,IAAI,EAAE,WAAW;gBACjB,OAAO,EAAE;oBACP;wBACE,IAAI,EAAE,aAAa;wBACnB,IAAI,EAAE,OAAO,CAAC,OAAO;qBACtB;iBACF;gBACD,MAAM,EAAE,WAAW;aACpB,CAAA;SACF;aAAM;YACL,MAAM,IAAI,KAAK,CAAC,sBAAsB,CAAC,CAAA;SACxC;IACH,CAAC;CACF"}
|
package/lib/esm/index.js
CHANGED
|
@@ -23,7 +23,7 @@ export default class BotonicPluginAiAgents {
|
|
|
23
23
|
return;
|
|
24
24
|
}
|
|
25
25
|
getInference(request, aiAgentArgs) {
|
|
26
|
-
var _a;
|
|
26
|
+
var _a, _b;
|
|
27
27
|
return __awaiter(this, void 0, void 0, function* () {
|
|
28
28
|
try {
|
|
29
29
|
const authToken = isProd ? request.session._access_token : this.authToken;
|
|
@@ -31,7 +31,15 @@ export default class BotonicPluginAiAgents {
|
|
|
31
31
|
throw new Error('Auth token is required');
|
|
32
32
|
}
|
|
33
33
|
const tools = this.buildTools(((_a = aiAgentArgs.activeTools) === null || _a === void 0 ? void 0 : _a.map(tool => tool.name)) || []);
|
|
34
|
-
const agent = new AIAgentBuilder(
|
|
34
|
+
const agent = new AIAgentBuilder({
|
|
35
|
+
name: aiAgentArgs.name,
|
|
36
|
+
instructions: aiAgentArgs.instructions,
|
|
37
|
+
tools: tools,
|
|
38
|
+
contactInfo: request.session.user.contact_info || [],
|
|
39
|
+
inputGuardrailRules: aiAgentArgs.inputGuardrailRules || [],
|
|
40
|
+
sourceIds: aiAgentArgs.sourceIds || [],
|
|
41
|
+
campaignContext: (_b = request.input.context) === null || _b === void 0 ? void 0 : _b.campaign_v2,
|
|
42
|
+
}).build();
|
|
35
43
|
const messages = yield this.getMessages(request, authToken, MAX_MEMORY_LENGTH);
|
|
36
44
|
const context = {
|
|
37
45
|
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;AAYxC,MAAM,CAAC,OAAO,OAAO,qBAAqB;IAUxC,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;QAElD,IAAI,CAA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AAG,CAAC,cAAc,CAAC,EAAE;YACzC,OAAO,IAAI,CAA0C;gBACnD,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;AAED,cAAc,SAAS,CAAA"}
|
package/lib/esm/openai.js
CHANGED
|
@@ -1,18 +1,32 @@
|
|
|
1
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';
|
|
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
|
@@ -8,12 +8,15 @@ export class AIAgentRunner {
|
|
|
8
8
|
run(messages, context) {
|
|
9
9
|
var _a;
|
|
10
10
|
return __awaiter(this, void 0, void 0, function* () {
|
|
11
|
-
console.log('Running agent with messages', JSON.stringify(messages, null, 2));
|
|
12
11
|
try {
|
|
13
12
|
const runner = new Runner({
|
|
14
13
|
modelSettings: { temperature: 0 },
|
|
15
14
|
});
|
|
16
|
-
|
|
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
|
+
}));
|
|
17
20
|
const outputMessages = ((_a = result.finalOutput) === null || _a === void 0 ? void 0 : _a.messages) || [];
|
|
18
21
|
const hasExit = outputMessages.length === 0 ||
|
|
19
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,OAAO,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,MAAM,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;iBACR,CAAC,CAAwB,CAAA;gBAE1B,MAAM,cAAc,GAAG,CAAA,MAAA,MAAM,CAAC,WAAW,0CAAE,QAAQ,KAAI,EAAE,CAAA;gBACzD,MAAM,OAAO,GACX,cAAc,CAAC,MAAM,KAAK,CAAC;oBAC3B,cAAc,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC,OAAO,CAAC,IAAI,KAAK,MAAM,CAAC,CAAA;gBACzD,MAAM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AAE;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,iBAAiB,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"}
|
|
@@ -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":";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,CAAC;IACpC,IAAI,EAAE,oBAAoB;IAC1B,WAAW,EACT,kIAAkI;IACpI,UAAU,EAAE,CAAC,CAAC,MAAM,CAAC;QACnB,KAAK,EAAE,CAAC,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,gBAAgB,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/esm/types.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { AgenticOutputMessage, AiAgentArgs, BotContext, GuardrailRule, InferenceResponse, ResolvedPlugins, RunResult } from '@botonic/core';
|
|
2
|
-
import { Agent, AgentInputItem, RunContext as OpenAIRunContext, Tool as OpenAITool } from '@openai/agents';
|
|
2
|
+
import { Agent, AgentInputItem, AgentOutputType, RunContext as OpenAIRunContext, Tool as OpenAITool } from '@openai/agents';
|
|
3
3
|
import { ZodSchema } from 'zod';
|
|
4
4
|
import { OutputSchema } from './structured-output';
|
|
5
5
|
export interface Context<TPlugins extends ResolvedPlugins = ResolvedPlugins, TExtraData = any> {
|
|
@@ -24,9 +24,8 @@ export interface Chunk {
|
|
|
24
24
|
id: string;
|
|
25
25
|
text: string;
|
|
26
26
|
}
|
|
27
|
-
export type ContactInfo = Record<string, string>;
|
|
28
27
|
export type Tool<TPlugins extends ResolvedPlugins = ResolvedPlugins, TExtraData = any> = OpenAITool<Context<TPlugins, TExtraData>>;
|
|
29
|
-
export type AIAgent<TPlugins extends ResolvedPlugins = ResolvedPlugins, TExtraData = any> = Agent<Context<TPlugins, TExtraData>, typeof OutputSchema
|
|
28
|
+
export type AIAgent<TPlugins extends ResolvedPlugins = ResolvedPlugins, TExtraData = any> = Agent<Context<TPlugins, TExtraData>, AgentOutputType<typeof OutputSchema>>;
|
|
30
29
|
export type MessageHistoryApiVersion = 'v1' | 'v2';
|
|
31
30
|
export interface MemoryOptions {
|
|
32
31
|
maxMessages?: number;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@botonic/plugin-ai-agents",
|
|
3
|
-
"version": "0.43.0
|
|
3
|
+
"version": "0.43.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,9 +13,9 @@
|
|
|
13
13
|
"lint_core": "../../node_modules/.bin/eslint_d --cache --quiet 'src/**/*.ts*'"
|
|
14
14
|
},
|
|
15
15
|
"dependencies": {
|
|
16
|
-
"@botonic/core": "^0.
|
|
16
|
+
"@botonic/core": "^0.43.0",
|
|
17
17
|
"@openai/agents": "^0.1.11",
|
|
18
|
-
"axios": "^1.
|
|
18
|
+
"axios": "^1.13.2",
|
|
19
19
|
"openai": "^5.23.2",
|
|
20
20
|
"uuid": "^10.0.0",
|
|
21
21
|
"zod": "3.25.76"
|
|
@@ -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, ContactInfo, ResolvedPlugins } from '@botonic/core'
|
|
2
|
+
import {
|
|
3
|
+
Agent,
|
|
4
|
+
AgentOutputType,
|
|
5
|
+
InputGuardrail,
|
|
6
|
+
ModelSettings,
|
|
7
|
+
} from '@openai/agents'
|
|
3
8
|
|
|
9
|
+
import { OPENAI_MODEL, OPENAI_PROVIDER } from './constants'
|
|
4
10
|
import { createInputGuardrail } from './guardrails'
|
|
5
11
|
import { OutputSchema } from './structured-output'
|
|
6
12
|
import { mandatoryTools, retrieveKnowledge } from './tools'
|
|
7
|
-
import { AIAgent,
|
|
13
|
+
import { AIAgent, Context, GuardrailRule, Tool } from './types'
|
|
14
|
+
|
|
15
|
+
interface AIAgentBuilderOptions<
|
|
16
|
+
TPlugins extends ResolvedPlugins = ResolvedPlugins,
|
|
17
|
+
TExtraData = any,
|
|
18
|
+
> {
|
|
19
|
+
name: string
|
|
20
|
+
instructions: string
|
|
21
|
+
tools: Tool<TPlugins, TExtraData>[]
|
|
22
|
+
campaignContext?: CampaignV2
|
|
23
|
+
contactInfo: ContactInfo[]
|
|
24
|
+
inputGuardrailRules: GuardrailRule[]
|
|
25
|
+
sourceIds: string[]
|
|
26
|
+
}
|
|
8
27
|
|
|
9
28
|
export class AIAgentBuilder<
|
|
10
29
|
TPlugins extends ResolvedPlugins = ResolvedPlugins,
|
|
@@ -15,33 +34,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,20 +86,34 @@ 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
|
-
private getContactInfoInstructions(contactInfo: ContactInfo): string {
|
|
66
|
-
const structuredContactInfo =
|
|
67
|
-
.map(
|
|
100
|
+
private getContactInfoInstructions(contactInfo: ContactInfo[]): string {
|
|
101
|
+
const structuredContactInfo = contactInfo
|
|
102
|
+
.map(
|
|
103
|
+
info =>
|
|
104
|
+
` <contact_info>
|
|
105
|
+
<name>${info.name}</name>
|
|
106
|
+
<value>${info.value}</value>
|
|
107
|
+
<type>${info.type}</type>
|
|
108
|
+
${
|
|
109
|
+
info.description
|
|
110
|
+
? `<description>${info.description}</description>`
|
|
111
|
+
: ''
|
|
112
|
+
}
|
|
113
|
+
</contact_info>`
|
|
114
|
+
)
|
|
68
115
|
.join('\n')
|
|
69
|
-
return `<
|
|
116
|
+
return `<contact_info_fields>\n${structuredContactInfo}</contact_info_fields>`
|
|
70
117
|
}
|
|
71
118
|
|
|
72
119
|
private getMetadataInstructions(): string {
|
|
@@ -74,6 +121,13 @@ export class AIAgentBuilder<
|
|
|
74
121
|
return `<metadata>\n${metadata}\n</metadata>`
|
|
75
122
|
}
|
|
76
123
|
|
|
124
|
+
private getCampaignInstructions(campaignContext?: CampaignV2): string {
|
|
125
|
+
if (!campaignContext || !campaignContext.agent_context) {
|
|
126
|
+
return ''
|
|
127
|
+
}
|
|
128
|
+
return `<campaign_context>\n${campaignContext.agent_context}\n</campaign_context>`
|
|
129
|
+
}
|
|
130
|
+
|
|
77
131
|
private getOutputInstructions(): string {
|
|
78
132
|
const example = {
|
|
79
133
|
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
|
}
|
|
@@ -74,6 +74,14 @@ export interface GetMessagesV2Result {
|
|
|
74
74
|
truncated: boolean
|
|
75
75
|
}
|
|
76
76
|
|
|
77
|
+
interface MessageHistoryV2Params {
|
|
78
|
+
last_message_id: string
|
|
79
|
+
max_messages?: number
|
|
80
|
+
include_tool_calls?: boolean
|
|
81
|
+
max_full_tool_results?: number
|
|
82
|
+
debug_mode?: boolean
|
|
83
|
+
}
|
|
84
|
+
|
|
77
85
|
export class HubtypeApiClient {
|
|
78
86
|
private readonly authToken: string
|
|
79
87
|
|
|
@@ -158,21 +166,20 @@ export class HubtypeApiClient {
|
|
|
158
166
|
'Content-Type': 'application/json',
|
|
159
167
|
Authorization: `Bearer ${this.authToken}`,
|
|
160
168
|
}
|
|
161
|
-
const params:
|
|
169
|
+
const params: MessageHistoryV2Params = {
|
|
162
170
|
last_message_id: request.input.message_id,
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
params.debug_mode = options.debugMode
|
|
171
|
+
...(options.maxMessages !== undefined && {
|
|
172
|
+
max_messages: options.maxMessages,
|
|
173
|
+
}),
|
|
174
|
+
...(options.includeToolCalls !== undefined && {
|
|
175
|
+
include_tool_calls: options.includeToolCalls,
|
|
176
|
+
}),
|
|
177
|
+
...(options.maxFullToolResults !== undefined && {
|
|
178
|
+
max_full_tool_results: options.maxFullToolResults,
|
|
179
|
+
}),
|
|
180
|
+
...(options.debugMode !== undefined && {
|
|
181
|
+
debug_mode: options.debugMode,
|
|
182
|
+
}),
|
|
176
183
|
}
|
|
177
184
|
|
|
178
185
|
try {
|
package/src/index.ts
CHANGED
|
@@ -60,14 +60,15 @@ export default class BotonicPluginAiAgents<
|
|
|
60
60
|
const tools = this.buildTools(
|
|
61
61
|
aiAgentArgs.activeTools?.map(tool => tool.name) || []
|
|
62
62
|
)
|
|
63
|
-
const agent = new AIAgentBuilder<TPlugins, TExtraData>(
|
|
64
|
-
aiAgentArgs.name,
|
|
65
|
-
aiAgentArgs.instructions,
|
|
66
|
-
tools,
|
|
67
|
-
request.session.user.contact_info ||
|
|
68
|
-
aiAgentArgs.inputGuardrailRules || [],
|
|
69
|
-
aiAgentArgs.sourceIds || []
|
|
70
|
-
|
|
63
|
+
const agent = new AIAgentBuilder<TPlugins, TExtraData>({
|
|
64
|
+
name: aiAgentArgs.name,
|
|
65
|
+
instructions: aiAgentArgs.instructions,
|
|
66
|
+
tools: tools,
|
|
67
|
+
contactInfo: request.session.user.contact_info || [],
|
|
68
|
+
inputGuardrailRules: aiAgentArgs.inputGuardrailRules || [],
|
|
69
|
+
sourceIds: aiAgentArgs.sourceIds || [],
|
|
70
|
+
campaignContext: request.input.context?.campaign_v2,
|
|
71
|
+
}).build()
|
|
71
72
|
|
|
72
73
|
const messages = await this.getMessages(
|
|
73
74
|
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,
|
|
@@ -28,15 +37,15 @@ export class AIAgentRunner<
|
|
|
28
37
|
messages: AgenticInputMessage[],
|
|
29
38
|
context: Context<TPlugins, TExtraData>
|
|
30
39
|
): Promise<RunResult> {
|
|
31
|
-
console.log(
|
|
32
|
-
'Running agent with messages',
|
|
33
|
-
JSON.stringify(messages, null, 2)
|
|
34
|
-
)
|
|
35
40
|
try {
|
|
36
41
|
const runner = new Runner({
|
|
37
42
|
modelSettings: { temperature: 0 },
|
|
38
43
|
})
|
|
39
|
-
|
|
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
|
|
40
49
|
|
|
41
50
|
const outputMessages = result.finalOutput?.messages || []
|
|
42
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
|
}
|