@botonic/plugin-ai-agents 0.49.0-alpha.1 → 0.49.0-alpha.3
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/agents/specialist-agent.js +1 -2
- package/lib/cjs/agents/specialist-agent.js.map +1 -1
- package/lib/cjs/constants.d.ts +9 -3
- package/lib/cjs/constants.js +11 -6
- package/lib/cjs/constants.js.map +1 -1
- package/lib/cjs/debug-logger.js +8 -2
- package/lib/cjs/debug-logger.js.map +1 -1
- package/lib/cjs/guardrails/input.d.ts +1 -1
- package/lib/cjs/guardrails/input.js +1 -3
- package/lib/cjs/guardrails/input.js.map +1 -1
- package/lib/cjs/index.d.ts +2 -2
- package/lib/cjs/index.js +11 -11
- package/lib/cjs/index.js.map +1 -1
- package/lib/cjs/llm-config.d.ts +9 -4
- package/lib/cjs/llm-config.js +43 -25
- package/lib/cjs/llm-config.js.map +1 -1
- package/lib/cjs/runners/base-runner.d.ts +6 -2
- package/lib/cjs/runners/base-runner.js +69 -5
- package/lib/cjs/runners/base-runner.js.map +1 -1
- package/lib/cjs/runners/index.d.ts +1 -1
- package/lib/cjs/runners/index.js +2 -2
- package/lib/cjs/runners/index.js.map +1 -1
- package/lib/cjs/runners/specialist-runner.d.ts +2 -8
- package/lib/cjs/runners/specialist-runner.js +0 -70
- package/lib/cjs/runners/specialist-runner.js.map +1 -1
- package/lib/cjs/services/types.d.ts +1 -1
- package/lib/esm/agents/specialist-agent.js +1 -2
- package/lib/esm/agents/specialist-agent.js.map +1 -1
- package/lib/esm/constants.d.ts +9 -3
- package/lib/esm/constants.js +11 -6
- package/lib/esm/constants.js.map +1 -1
- package/lib/esm/debug-logger.js +8 -2
- package/lib/esm/debug-logger.js.map +1 -1
- package/lib/esm/guardrails/input.d.ts +1 -1
- package/lib/esm/guardrails/input.js +1 -3
- package/lib/esm/guardrails/input.js.map +1 -1
- package/lib/esm/index.d.ts +2 -2
- package/lib/esm/index.js +11 -11
- package/lib/esm/index.js.map +1 -1
- package/lib/esm/llm-config.d.ts +9 -4
- package/lib/esm/llm-config.js +43 -25
- package/lib/esm/llm-config.js.map +1 -1
- package/lib/esm/runners/base-runner.d.ts +6 -2
- package/lib/esm/runners/base-runner.js +69 -5
- package/lib/esm/runners/base-runner.js.map +1 -1
- package/lib/esm/runners/index.d.ts +1 -1
- package/lib/esm/runners/index.js +2 -2
- package/lib/esm/runners/index.js.map +1 -1
- package/lib/esm/runners/specialist-runner.d.ts +2 -8
- package/lib/esm/runners/specialist-runner.js +0 -70
- package/lib/esm/runners/specialist-runner.js.map +1 -1
- package/lib/esm/services/types.d.ts +1 -1
- package/package.json +2 -2
- package/src/agents/specialist-agent.ts +1 -2
- package/src/constants.ts +12 -7
- package/src/debug-logger.ts +8 -2
- package/src/guardrails/input.ts +2 -3
- package/src/index.ts +15 -12
- package/src/llm-config.ts +56 -30
- package/src/runners/base-runner.ts +107 -8
- package/src/runners/index.ts +1 -1
- package/src/runners/specialist-runner.ts +3 -108
- package/src/services/types.ts +1 -1
package/lib/esm/llm-config.js
CHANGED
|
@@ -1,22 +1,33 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.LLMConfig = void 0;
|
|
4
|
-
exports.getApiVersion = getApiVersion;
|
|
5
4
|
const tslib_1 = require("tslib");
|
|
6
5
|
const agents_1 = require("@openai/agents");
|
|
7
6
|
const openai_1 = tslib_1.__importStar(require("openai"));
|
|
8
7
|
const constants_1 = require("./constants");
|
|
9
8
|
class LLMConfig {
|
|
10
|
-
constructor(maxRetries, timeout, modelName, verbosity) {
|
|
9
|
+
constructor(maxRetries, timeout, modelName, verbosity, botContext) {
|
|
11
10
|
this.maxRetries = maxRetries;
|
|
12
11
|
this.timeout = timeout;
|
|
13
|
-
this.
|
|
12
|
+
this.botContext = botContext;
|
|
13
|
+
this.modelName = modelName;
|
|
14
14
|
this.modelProvider = this.getModelProvider();
|
|
15
15
|
this.modelSettings = this.getModelSettings(modelName, verbosity);
|
|
16
16
|
}
|
|
17
17
|
async getModel() {
|
|
18
18
|
return await this.modelProvider.getModel(this.modelName);
|
|
19
19
|
}
|
|
20
|
+
getProviderName() {
|
|
21
|
+
return this.botContext.settings.LITELLM_API_URL
|
|
22
|
+
? constants_1.LLM_PROVIDERS.LITELLM
|
|
23
|
+
: constants_1.LLM_PROVIDERS.AZURE;
|
|
24
|
+
}
|
|
25
|
+
getApiVersion() {
|
|
26
|
+
return this.getProviderName() === constants_1.LLM_PROVIDERS.AZURE
|
|
27
|
+
? this.botContext.settings.AZURE_OPENAI_API_VERSION ||
|
|
28
|
+
constants_1.AZURE_OPENAI_API_VERSION
|
|
29
|
+
: undefined;
|
|
30
|
+
}
|
|
20
31
|
getModelProvider() {
|
|
21
32
|
const client = this.getClient();
|
|
22
33
|
return new agents_1.OpenAIProvider({
|
|
@@ -25,53 +36,60 @@ class LLMConfig {
|
|
|
25
36
|
});
|
|
26
37
|
}
|
|
27
38
|
getClient() {
|
|
28
|
-
if (
|
|
29
|
-
return this.
|
|
39
|
+
if (this.botContext.settings.LITELLM_API_URL) {
|
|
40
|
+
return this.getLiteLLMClient();
|
|
30
41
|
}
|
|
31
42
|
return this.getAzureClient();
|
|
32
43
|
}
|
|
33
|
-
|
|
44
|
+
buildLiteLLMTags() {
|
|
45
|
+
const botId = this.botContext.session.bot.id;
|
|
46
|
+
const orgId = this.botContext.session.organization_id;
|
|
47
|
+
const parts = [];
|
|
48
|
+
if (botId) {
|
|
49
|
+
parts.push(`${constants_1.LITELLM_TAG_KEYS.BOT_ID}:${botId}`);
|
|
50
|
+
}
|
|
51
|
+
if (orgId) {
|
|
52
|
+
parts.push(`${constants_1.LITELLM_TAG_KEYS.ORG_ID}:${orgId}`);
|
|
53
|
+
}
|
|
54
|
+
return parts.length > 0
|
|
55
|
+
? { 'x-litellm-tags': parts.join(constants_1.LITELLM_TAG_KEYS.SEPARATOR) }
|
|
56
|
+
: undefined;
|
|
57
|
+
}
|
|
58
|
+
getLiteLLMClient() {
|
|
34
59
|
return new openai_1.default({
|
|
35
|
-
apiKey:
|
|
60
|
+
apiKey: this.botContext.secrets.LITELLM_API_KEY,
|
|
61
|
+
baseURL: this.botContext.settings.LITELLM_API_URL,
|
|
36
62
|
timeout: this.timeout,
|
|
37
63
|
maxRetries: this.maxRetries,
|
|
38
64
|
dangerouslyAllowBrowser: !constants_1.isProd,
|
|
65
|
+
defaultHeaders: this.buildLiteLLMTags(),
|
|
39
66
|
});
|
|
40
67
|
}
|
|
41
68
|
getAzureClient() {
|
|
42
69
|
return new openai_1.AzureOpenAI({
|
|
43
|
-
apiKey: constants_1.AZURE_OPENAI_API_KEY,
|
|
44
|
-
apiVersion:
|
|
70
|
+
apiKey: this.botContext.secrets.AZURE_OPENAI_API_KEY || constants_1.AZURE_OPENAI_API_KEY,
|
|
71
|
+
apiVersion: this.botContext.settings.AZURE_OPENAI_API_VERSION ||
|
|
72
|
+
constants_1.AZURE_OPENAI_API_VERSION,
|
|
45
73
|
deployment: this.modelName,
|
|
46
|
-
baseURL: constants_1.AZURE_OPENAI_API_BASE,
|
|
74
|
+
baseURL: this.botContext.settings.AZURE_OPENAI_API_BASE || constants_1.AZURE_OPENAI_API_BASE,
|
|
47
75
|
timeout: this.timeout,
|
|
48
76
|
maxRetries: this.maxRetries,
|
|
49
77
|
dangerouslyAllowBrowser: !constants_1.isProd,
|
|
50
78
|
});
|
|
51
79
|
}
|
|
52
80
|
getModelSettings(model, verbosity) {
|
|
53
|
-
if (model.includes('gpt-5')) {
|
|
54
|
-
return {
|
|
55
|
-
reasoning: { effort: 'none' },
|
|
56
|
-
temperature: 1,
|
|
57
|
-
text: { verbosity },
|
|
58
|
-
};
|
|
59
|
-
}
|
|
60
81
|
if (model.includes('gpt-4')) {
|
|
61
82
|
return {
|
|
62
83
|
temperature: 0,
|
|
63
84
|
text: { verbosity: 'medium' },
|
|
64
85
|
};
|
|
65
86
|
}
|
|
66
|
-
|
|
87
|
+
return {
|
|
88
|
+
reasoning: { effort: 'none' },
|
|
89
|
+
temperature: 1,
|
|
90
|
+
text: { verbosity },
|
|
91
|
+
};
|
|
67
92
|
}
|
|
68
93
|
}
|
|
69
94
|
exports.LLMConfig = LLMConfig;
|
|
70
|
-
function getApiVersion() {
|
|
71
|
-
// Return NOT_API_VERSION_FOR_OPENAI_PROVIDER if OPENAI_PROVIDER
|
|
72
|
-
// is not azure to avoid error when tracking in llm_runs endpoint
|
|
73
|
-
return constants_1.OPENAI_PROVIDER === 'azure'
|
|
74
|
-
? constants_1.AZURE_OPENAI_API_VERSION
|
|
75
|
-
: 'NOT_API_VERSION_FOR_OPENAI_PROVIDER';
|
|
76
|
-
}
|
|
77
95
|
//# sourceMappingURL=llm-config.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"llm-config.js","sourceRoot":"","sources":["../../src/llm-config.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"llm-config.js","sourceRoot":"","sources":["../../src/llm-config.ts"],"names":[],"mappings":";;;;AACA,2CAKuB;AACvB,yDAA4C;AAC5C,2CAOoB;AAIpB,MAAa,SAAS;IAQpB,YACE,UAAkB,EAClB,OAAe,EACf,SAAiB,EACjB,SAAyB,EACzB,UAAsB;QAEtB,IAAI,CAAC,UAAU,GAAG,UAAU,CAAA;QAC5B,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA;QACtB,IAAI,CAAC,UAAU,GAAG,UAAU,CAAA;QAC5B,IAAI,CAAC,SAAS,GAAG,SAAS,CAAA;QAC1B,IAAI,CAAC,aAAa,GAAG,IAAI,CAAC,gBAAgB,EAAE,CAAA;QAC5C,IAAI,CAAC,aAAa,GAAG,IAAI,CAAC,gBAAgB,CAAC,SAAS,EAAE,SAAS,CAAC,CAAA;IAClE,CAAC;IAED,KAAK,CAAC,QAAQ;QACZ,OAAO,MAAM,IAAI,CAAC,aAAa,CAAC,QAAQ,CAAC,IAAI,CAAC,SAAS,CAA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AAW,EAAE,CAAC;YACd,IAAI,EAAE,EAAE,SAAS,EAAE;SACpB,CAAA;IACH,CAAC;CACF;AAnHD,8BAmHC"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { OutputMessage, ResolvedPlugins, ToolExecution } from '@botonic/core';
|
|
2
2
|
import type { DebugLogger } from '../debug-logger';
|
|
3
|
-
import {
|
|
3
|
+
import type { LLMConfig } from '../llm-config';
|
|
4
4
|
import type { AgenticInputMessage, AIAgent, Context, ResultRawResponse, RunResult } from '../types';
|
|
5
5
|
export interface RunnerResult {
|
|
6
6
|
finalOutput?: {
|
|
@@ -20,7 +20,11 @@ export declare abstract class BaseRunner<TPlugins extends ResolvedPlugins = Reso
|
|
|
20
20
|
protected logger: DebugLogger;
|
|
21
21
|
constructor(agent: AIAgent<TPlugins, TExtraData>, llmConfig: LLMConfig, inferenceId: string, logger: DebugLogger);
|
|
22
22
|
run(messages: AgenticInputMessage[], context: Context<TPlugins, TExtraData>): Promise<RunResult>;
|
|
23
|
-
protected getToolsExecuted(
|
|
23
|
+
protected getToolsExecuted(result: RunnerResult, context: Context<TPlugins, TExtraData>): ToolExecution[];
|
|
24
|
+
private getToolResultsByCallId;
|
|
25
|
+
private extractToolResult;
|
|
26
|
+
private getToolExecutionInfo;
|
|
27
|
+
private getSafeToolArguments;
|
|
24
28
|
protected buildRunResult(result: RunnerResult, context: Context<TPlugins, TExtraData>, memoryLength: number): RunResult;
|
|
25
29
|
private sendLlmRunTracking;
|
|
26
30
|
}
|
|
@@ -3,9 +3,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.BaseRunner = void 0;
|
|
4
4
|
const agents_1 = require("@openai/agents");
|
|
5
5
|
const constants_1 = require("../constants");
|
|
6
|
-
const llm_config_1 = require("../llm-config");
|
|
7
6
|
const hubtype_api_client_1 = require("../services/hubtype-api-client");
|
|
8
7
|
const types_1 = require("../services/types");
|
|
8
|
+
const tools_1 = require("../tools");
|
|
9
9
|
class BaseRunner {
|
|
10
10
|
constructor(agent, llmConfig, inferenceId, logger) {
|
|
11
11
|
this.agent = agent;
|
|
@@ -52,8 +52,73 @@ class BaseRunner {
|
|
|
52
52
|
throw error;
|
|
53
53
|
}
|
|
54
54
|
}
|
|
55
|
-
getToolsExecuted(
|
|
56
|
-
|
|
55
|
+
getToolsExecuted(result, context) {
|
|
56
|
+
const toolResultsByCallId = this.getToolResultsByCallId(result.newItems);
|
|
57
|
+
return (result.newItems
|
|
58
|
+
?.filter(item => item instanceof agents_1.RunToolCallItem)
|
|
59
|
+
.map((item) => this.getToolExecutionInfo(item, context, toolResultsByCallId))
|
|
60
|
+
.filter((toolExecution) => toolExecution.toolName !== '') || []);
|
|
61
|
+
}
|
|
62
|
+
getToolResultsByCallId(newItems = []) {
|
|
63
|
+
const map = new Map();
|
|
64
|
+
for (const item of newItems) {
|
|
65
|
+
if (!(item instanceof agents_1.RunToolCallOutputItem)) {
|
|
66
|
+
continue;
|
|
67
|
+
}
|
|
68
|
+
const rawItem = item.rawItem;
|
|
69
|
+
const callId = rawItem?.callId;
|
|
70
|
+
const output = rawItem?.output;
|
|
71
|
+
if (callId == null || output == null) {
|
|
72
|
+
continue;
|
|
73
|
+
}
|
|
74
|
+
const text = this.extractToolResult(output);
|
|
75
|
+
if (text != null) {
|
|
76
|
+
map.set(callId, text);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
return map;
|
|
80
|
+
}
|
|
81
|
+
extractToolResult(output) {
|
|
82
|
+
if (typeof output === 'string') {
|
|
83
|
+
return output;
|
|
84
|
+
}
|
|
85
|
+
return output?.type === 'text' && typeof output?.text === 'string'
|
|
86
|
+
? output.text
|
|
87
|
+
: undefined;
|
|
88
|
+
}
|
|
89
|
+
getToolExecutionInfo(item, context, toolResultsByCallId) {
|
|
90
|
+
if (item.rawItem.type !== 'function_call') {
|
|
91
|
+
return {
|
|
92
|
+
toolName: '',
|
|
93
|
+
toolArguments: {},
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
const toolName = item.rawItem.name;
|
|
97
|
+
const toolArguments = this.getSafeToolArguments(item.rawItem.arguments);
|
|
98
|
+
const toolResults = item.rawItem.callId
|
|
99
|
+
? toolResultsByCallId.get(item.rawItem.callId)
|
|
100
|
+
: undefined;
|
|
101
|
+
const toolExecution = {
|
|
102
|
+
toolName,
|
|
103
|
+
toolArguments,
|
|
104
|
+
toolResults,
|
|
105
|
+
};
|
|
106
|
+
if (toolName === tools_1.RETRIEVE_KNOWLEDGE_TOOL_NAME) {
|
|
107
|
+
return {
|
|
108
|
+
...toolExecution,
|
|
109
|
+
knowledgebaseSourcesIds: context.knowledgeUsed.sourceIds,
|
|
110
|
+
knowledgebaseChunksIds: context.knowledgeUsed.chunksIds,
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
return toolExecution;
|
|
114
|
+
}
|
|
115
|
+
getSafeToolArguments(rawToolArguments) {
|
|
116
|
+
try {
|
|
117
|
+
return JSON.parse(rawToolArguments);
|
|
118
|
+
}
|
|
119
|
+
catch (_error) {
|
|
120
|
+
return {};
|
|
121
|
+
}
|
|
57
122
|
}
|
|
58
123
|
buildRunResult(result, context, memoryLength) {
|
|
59
124
|
const outputMessages = result.finalOutput?.messages || [];
|
|
@@ -88,7 +153,6 @@ class BaseRunner {
|
|
|
88
153
|
const totalDuration = endTime - startTime;
|
|
89
154
|
const durationPerCall = Math.round(totalDuration / rawResponses.length);
|
|
90
155
|
const temperature = this.llmConfig.modelSettings.temperature ?? 0;
|
|
91
|
-
const apiVersion = (0, llm_config_1.getApiVersion)();
|
|
92
156
|
const llmRuns = rawResponses.map(response => ({
|
|
93
157
|
inference_id: this.inferenceId,
|
|
94
158
|
is_test: isTest,
|
|
@@ -97,7 +161,7 @@ class BaseRunner {
|
|
|
97
161
|
model_name: response.providerData?.model ??
|
|
98
162
|
this.llmConfig.modelName,
|
|
99
163
|
feature: types_1.TrackFeature.AI_AGENT_RUN,
|
|
100
|
-
api_version:
|
|
164
|
+
api_version: this.llmConfig.getApiVersion(),
|
|
101
165
|
num_prompt_tokens: response.usage.inputTokens,
|
|
102
166
|
num_completion_tokens: response.usage.outputTokens,
|
|
103
167
|
duration_in_milliseconds: durationPerCall,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base-runner.js","sourceRoot":"","sources":["../../../src/runners/base-runner.ts"],"names":[],"mappings":";;;AAKA,
|
|
1
|
+
{"version":3,"file":"base-runner.js","sourceRoot":"","sources":["../../../src/runners/base-runner.ts"],"names":[],"mappings":";;;AAKA,2CAKuB;AACvB,4CAAqC;AAGrC,uEAAiE;AACjE,6CAAkE;AAClE,oCAAuD;AAuBvD,MAAsB,UAAU;IAS9B,YACE,KAAoC,EACpC,SAAoB,EACpB,WAAmB,EACnB,MAAmB;QAEnB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAA;QAClB,IAAI,CAAC,SAAS,GAAG,SAAS,CAAA;QAC1B,IAAI,CAAC,WAAW,GAAG,WAAW,CAAA;QAC9B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;IACtB,CAAC;IAED,KAAK,CAAC,GAAG,CACP,QAA+B,EAC/B,OAAsC;QAEtC,MAAM,SAAS,GAAG,IAAI,CAAC,GAAG,EAAE,CAAA;QAE5B,IAAI,CAAC,MAAM,CAAC,cAAc,CACxB,IAAI,CAAC,SAAS,CAAC,SAAS,EACxB,IAAI,CAAC,SAAS,CAAC,aAAa,CAC7B,CAAA;QAED,IAAI,CAAC;YACH,MAAM,MAAM,GAAG,IAAI,eAAM,CAAC;gBACxB,eAAe,EAAE,IAAI;aACtB,CAAC,CAAA;YACF,MAAM,MAAM,GAAG,CAAC,MAAM,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,EAAE,QAAQ,EAAE;gBACrD,OAAO;aACR,CAAC,CAAiB,CAAA;YACnB,MAAM,OAAO,GAAG,IAAI,CAAC,GAAG,EAAE,CAAA;YAE1B,MAAM,IAAI,CAAC,kBAAkB,CAAC,M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,CAAC,CAAC;YAC5C,YAAY,EAAE,IAAI,CAAC,WAAW;YAC9B,OAAO,EAAE,MAAM;YACf,YAAY,EAAE,wBAAgB,CAAC,QAAQ;YACvC,eAAe,EAAE,IAAI,CAAC,SAAS,CAAC,SAAS;YACzC,UAAU,EACP,QAAQ,CAAC,YAAY,EAAE,KAA4B;gBACpD,IAAI,CAAC,SAAS,CAAC,SAAS;YAC1B,OAAO,EAAE,oBAAY,CAAC,YAAY;YAClC,WAAW,EAAE,IAAI,CAAC,SAAS,CAAC,aAAa,EAAE;YAC3C,iBAAiB,EAAE,QAAQ,CAAC,KAAK,CAAC,WAAW;YAC7C,qBAAqB,EAAE,QAAQ,CAAC,KAAK,CAAC,YAAY;YAClD,wBAAwB,EAAE,eAAe;YACzC,WAAW;YACX,KAAK,EAAE,IAAI;SACZ,CAAC,CAAC,CAAA;QAEH,MAAM,MAAM,GAAG,IAAI,qCAAgB,CAAC,OAAO,CAAC,SAAS,CAAC,CAAA;QACtD,MAAM,MAAM,CAAC,YAAY,CAAC,KAAK,EAAE;YAC/B,QAAQ,EAAE,OAAO;SAClB,CAAC,CAAA;IACJ,CAAC;CACF;AAzPD,gCAyPC"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export { RouterRunner } from './router-runner';
|
|
2
|
-
export { SpecialistRunner
|
|
2
|
+
export { SpecialistRunner } from './specialist-runner';
|
package/lib/esm/runners/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.SpecialistRunner = exports.RouterRunner = void 0;
|
|
4
4
|
var router_runner_1 = require("./router-runner");
|
|
5
5
|
Object.defineProperty(exports, "RouterRunner", { enumerable: true, get: function () { return router_runner_1.RouterRunner; } });
|
|
6
6
|
var specialist_runner_1 = require("./specialist-runner");
|
|
7
|
-
Object.defineProperty(exports, "
|
|
7
|
+
Object.defineProperty(exports, "SpecialistRunner", { enumerable: true, get: function () { return specialist_runner_1.SpecialistRunner; } });
|
|
8
8
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/runners/index.ts"],"names":[],"mappings":";;;AAAA,iDAA8C;AAArC,6GAAA,YAAY,OAAA;AACrB,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/runners/index.ts"],"names":[],"mappings":";;;AAAA,iDAA8C;AAArC,6GAAA,YAAY,OAAA;AACrB,yDAAsD;AAA7C,qHAAA,gBAAgB,OAAA"}
|
|
@@ -1,10 +1,4 @@
|
|
|
1
|
-
import type { ResolvedPlugins
|
|
2
|
-
import
|
|
3
|
-
import { BaseRunner, type RunnerResult } from './base-runner';
|
|
1
|
+
import type { ResolvedPlugins } from '@botonic/core';
|
|
2
|
+
import { BaseRunner } from './base-runner';
|
|
4
3
|
export declare class SpecialistRunner<TPlugins extends ResolvedPlugins = ResolvedPlugins, TExtraData = unknown> extends BaseRunner<TPlugins, TExtraData> {
|
|
5
|
-
protected getToolsExecuted(result: RunnerResult, context: Context<TPlugins, TExtraData>): ToolExecution[];
|
|
6
|
-
private getToolResultsByCallId;
|
|
7
|
-
private extractToolResult;
|
|
8
|
-
private getToolExecutionInfo;
|
|
9
|
-
private getSafeToolArguments;
|
|
10
4
|
}
|
|
@@ -1,78 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.SpecialistRunner = void 0;
|
|
4
|
-
const agents_1 = require("@openai/agents");
|
|
5
|
-
const tools_1 = require("../tools");
|
|
6
4
|
const base_runner_1 = require("./base-runner");
|
|
7
5
|
class SpecialistRunner extends base_runner_1.BaseRunner {
|
|
8
|
-
getToolsExecuted(result, context) {
|
|
9
|
-
const toolResultsByCallId = this.getToolResultsByCallId(result.newItems);
|
|
10
|
-
return (result.newItems
|
|
11
|
-
?.filter(item => item instanceof agents_1.RunToolCallItem)
|
|
12
|
-
.map((item) => this.getToolExecutionInfo(item, context, toolResultsByCallId))
|
|
13
|
-
.filter((toolExecution) => toolExecution.toolName !== '') || []);
|
|
14
|
-
}
|
|
15
|
-
getToolResultsByCallId(newItems = []) {
|
|
16
|
-
const map = new Map();
|
|
17
|
-
for (const item of newItems) {
|
|
18
|
-
if (!(item instanceof agents_1.RunToolCallOutputItem)) {
|
|
19
|
-
continue;
|
|
20
|
-
}
|
|
21
|
-
const rawItem = item.rawItem;
|
|
22
|
-
const callId = rawItem?.callId;
|
|
23
|
-
const output = rawItem?.output;
|
|
24
|
-
if (callId == null || output == null) {
|
|
25
|
-
continue;
|
|
26
|
-
}
|
|
27
|
-
const text = this.extractToolResult(output);
|
|
28
|
-
if (text != null) {
|
|
29
|
-
map.set(callId, text);
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
return map;
|
|
33
|
-
}
|
|
34
|
-
extractToolResult(output) {
|
|
35
|
-
if (typeof output === 'string') {
|
|
36
|
-
return output;
|
|
37
|
-
}
|
|
38
|
-
return output?.type === 'text' && typeof output?.text === 'string'
|
|
39
|
-
? output.text
|
|
40
|
-
: undefined;
|
|
41
|
-
}
|
|
42
|
-
getToolExecutionInfo(item, context, toolResultsByCallId) {
|
|
43
|
-
if (item.rawItem.type !== 'function_call') {
|
|
44
|
-
return {
|
|
45
|
-
toolName: '',
|
|
46
|
-
toolArguments: {},
|
|
47
|
-
};
|
|
48
|
-
}
|
|
49
|
-
const toolName = item.rawItem.name;
|
|
50
|
-
const toolArguments = this.getSafeToolArguments(item.rawItem.arguments);
|
|
51
|
-
const toolResults = item.rawItem.callId
|
|
52
|
-
? toolResultsByCallId.get(item.rawItem.callId)
|
|
53
|
-
: undefined;
|
|
54
|
-
const toolExecution = {
|
|
55
|
-
toolName,
|
|
56
|
-
toolArguments,
|
|
57
|
-
toolResults,
|
|
58
|
-
};
|
|
59
|
-
if (toolName === tools_1.RETRIEVE_KNOWLEDGE_TOOL_NAME) {
|
|
60
|
-
return {
|
|
61
|
-
...toolExecution,
|
|
62
|
-
knowledgebaseSourcesIds: context.knowledgeUsed.sourceIds,
|
|
63
|
-
knowledgebaseChunksIds: context.knowledgeUsed.chunksIds,
|
|
64
|
-
};
|
|
65
|
-
}
|
|
66
|
-
return toolExecution;
|
|
67
|
-
}
|
|
68
|
-
getSafeToolArguments(rawToolArguments) {
|
|
69
|
-
try {
|
|
70
|
-
return JSON.parse(rawToolArguments);
|
|
71
|
-
}
|
|
72
|
-
catch (_error) {
|
|
73
|
-
return {};
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
6
|
}
|
|
77
7
|
exports.SpecialistRunner = SpecialistRunner;
|
|
78
8
|
//# sourceMappingURL=specialist-runner.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"specialist-runner.js","sourceRoot":"","sources":["../../../src/runners/specialist-runner.ts"],"names":[],"mappings":";;;AACA
|
|
1
|
+
{"version":3,"file":"specialist-runner.js","sourceRoot":"","sources":["../../../src/runners/specialist-runner.ts"],"names":[],"mappings":";;;AACA,+CAA0C;AAE1C,MAAa,gBAGX,SAAQ,wBAAgC;CAAG;AAH7C,4CAG6C"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@botonic/plugin-ai-agents",
|
|
3
|
-
"version": "0.49.0-alpha.
|
|
3
|
+
"version": "0.49.0-alpha.3",
|
|
4
4
|
"main": "./lib/cjs/index.js",
|
|
5
5
|
"module": "./lib/esm/index.js",
|
|
6
6
|
"description": "Use AI Agents to generate your contents",
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
"format": "biome format --write src/ tests/"
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"@botonic/core": "^0.49.0-alpha.
|
|
17
|
+
"@botonic/core": "^0.49.0-alpha.3",
|
|
18
18
|
"@openai/agents": "^0.10.1",
|
|
19
19
|
"axios": "^1.15.2",
|
|
20
20
|
"openai": "^6.36.0",
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import type { CampaignV2, ContactInfo, ResolvedPlugins } from '@botonic/core'
|
|
2
2
|
import { Agent, type AgentOutputType, type ModelSettings } from '@openai/agents'
|
|
3
3
|
import type { z } from 'zod'
|
|
4
|
-
import { OPENAI_PROVIDER } from '../constants'
|
|
5
4
|
import type { DebugLogger } from '../debug-logger'
|
|
6
5
|
import type { GuardrailTrackingContext } from '../guardrails/input'
|
|
7
6
|
import type { LLMConfig } from '../llm-config'
|
|
@@ -74,7 +73,7 @@ export class SpecialistAgent<
|
|
|
74
73
|
const inputGuardrails = await specialistAgent.getInputGuardrails()
|
|
75
74
|
|
|
76
75
|
specialistAgent.logger.logModelSettings({
|
|
77
|
-
provider:
|
|
76
|
+
provider: specialistAgent.llmConfig.getProviderName(),
|
|
78
77
|
model,
|
|
79
78
|
reasoning: modelSettings.reasoning as { effort: string } | undefined,
|
|
80
79
|
text: modelSettings.text as { verbosity: string } | undefined,
|
package/src/constants.ts
CHANGED
|
@@ -1,13 +1,7 @@
|
|
|
1
1
|
export const HUBTYPE_API_URL =
|
|
2
2
|
process.env.HUBTYPE_API_URL || 'https://api.hubtype.com'
|
|
3
3
|
|
|
4
|
-
// OpenAI
|
|
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
|
+
// Azure OpenAI Configuration (used as local-dev fallback; production values come from BotSettings/BotSecrets)
|
|
11
5
|
export const AZURE_OPENAI_API_KEY = process.env.AZURE_OPENAI_API_KEY // pragma: allowlist secret
|
|
12
6
|
export const AZURE_OPENAI_API_BASE = process.env.AZURE_OPENAI_API_BASE
|
|
13
7
|
export const AZURE_OPENAI_API_VERSION =
|
|
@@ -19,3 +13,14 @@ export const MAX_MEMORY_LENGTH = 25
|
|
|
19
13
|
|
|
20
14
|
export const DEFAULT_TIMEOUT_16_SECONDS = 16000
|
|
21
15
|
export const DEFAULT_MAX_RETRIES = 2
|
|
16
|
+
|
|
17
|
+
export const LLM_PROVIDERS = {
|
|
18
|
+
LITELLM: 'litellm',
|
|
19
|
+
AZURE: 'azure',
|
|
20
|
+
} as const
|
|
21
|
+
|
|
22
|
+
export const LITELLM_TAG_KEYS = {
|
|
23
|
+
BOT_ID: 'bot_id',
|
|
24
|
+
ORG_ID: 'org_id',
|
|
25
|
+
SEPARATOR: ',',
|
|
26
|
+
} as const
|
package/src/debug-logger.ts
CHANGED
|
@@ -4,7 +4,6 @@ import {
|
|
|
4
4
|
type ToolExecution,
|
|
5
5
|
} from '@botonic/core'
|
|
6
6
|
import type { ModelSettings } from '@openai/agents'
|
|
7
|
-
import { OPENAI_PROVIDER } from './constants'
|
|
8
7
|
import type { AgenticInputMessage, MemoryOptions, RunResult } from './types'
|
|
9
8
|
|
|
10
9
|
const PREFIX = '[BotonicPluginAiAgents]'
|
|
@@ -44,7 +43,6 @@ export interface DebugLogger {
|
|
|
44
43
|
class EnabledDebugLogger implements DebugLogger {
|
|
45
44
|
logInitialConfig(config: DebugLoggerConfig): void {
|
|
46
45
|
console.log(`${PREFIX} === Plugin Initialization ===`)
|
|
47
|
-
console.log(`${PREFIX} Provider: ${OPENAI_PROVIDER}`)
|
|
48
46
|
console.log(
|
|
49
47
|
`${PREFIX} Message History API Version: ${config.messageHistoryApiVersion}`
|
|
50
48
|
)
|
|
@@ -157,13 +155,21 @@ class EnabledDebugLogger implements DebugLogger {
|
|
|
157
155
|
}
|
|
158
156
|
|
|
159
157
|
class DisabledDebugLogger implements DebugLogger {
|
|
158
|
+
// biome-ignore lint/suspicious/noEmptyBlockStatements: intentional no-op implementation
|
|
160
159
|
logInitialConfig(): void {}
|
|
160
|
+
// biome-ignore lint/suspicious/noEmptyBlockStatements: intentional no-op implementation
|
|
161
161
|
logAgentDebugInfo(): void {}
|
|
162
|
+
// biome-ignore lint/suspicious/noEmptyBlockStatements: intentional no-op implementation
|
|
162
163
|
logModelSettings(): void {}
|
|
164
|
+
// biome-ignore lint/suspicious/noEmptyBlockStatements: intentional no-op implementation
|
|
163
165
|
logRunnerStart(_model: string, _modelSettings: ModelSettings): void {}
|
|
166
|
+
// biome-ignore lint/suspicious/noEmptyBlockStatements: intentional no-op implementation
|
|
164
167
|
logRunResult(): void {}
|
|
168
|
+
// biome-ignore lint/suspicious/noEmptyBlockStatements: intentional no-op implementation
|
|
165
169
|
logGuardrailTriggered(): void {}
|
|
170
|
+
// biome-ignore lint/suspicious/noEmptyBlockStatements: intentional no-op implementation
|
|
166
171
|
logRunnerError(): void {}
|
|
172
|
+
// biome-ignore lint/suspicious/noEmptyBlockStatements: intentional no-op implementation
|
|
167
173
|
logToolExecution(): void {}
|
|
168
174
|
}
|
|
169
175
|
|
package/src/guardrails/input.ts
CHANGED
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
} from '@openai/agents'
|
|
8
8
|
import { z } from 'zod'
|
|
9
9
|
import { isProd } from '../constants'
|
|
10
|
-
import {
|
|
10
|
+
import type { LLMConfig } from '../llm-config'
|
|
11
11
|
import { HubtypeApiClient } from '../services/hubtype-api-client'
|
|
12
12
|
import { TrackFeature, TrackProductName } from '../services/types'
|
|
13
13
|
import type { GuardrailRule, ResultRawResponse } from '../types'
|
|
@@ -123,7 +123,6 @@ async function sendGuardrailLlmRunTracking(
|
|
|
123
123
|
const durationPerCall = Math.round(totalDuration / rawResponses.length)
|
|
124
124
|
const temperature =
|
|
125
125
|
(llmConfig.modelSettings.temperature as number | undefined) ?? 0
|
|
126
|
-
const apiVersion = getApiVersion()
|
|
127
126
|
|
|
128
127
|
const llmRuns = rawResponses.map(response => ({
|
|
129
128
|
inference_id: trackingContext.inferenceId,
|
|
@@ -134,7 +133,7 @@ async function sendGuardrailLlmRunTracking(
|
|
|
134
133
|
(response.providerData?.model as string | undefined) ??
|
|
135
134
|
llmConfig.modelName,
|
|
136
135
|
feature: TrackFeature.AI_AGENT_GUARDRAIL,
|
|
137
|
-
api_version:
|
|
136
|
+
api_version: llmConfig.getApiVersion(),
|
|
138
137
|
num_prompt_tokens: response.usage.inputTokens,
|
|
139
138
|
num_completion_tokens: response.usage.outputTokens,
|
|
140
139
|
duration_in_milliseconds: durationPerCall,
|
package/src/index.ts
CHANGED
|
@@ -20,7 +20,7 @@ import {
|
|
|
20
20
|
} from './constants'
|
|
21
21
|
import { createDebugLogger, type DebugLogger } from './debug-logger'
|
|
22
22
|
import { LLMConfig } from './llm-config'
|
|
23
|
-
import { RouterRunner,
|
|
23
|
+
import { RouterRunner, SpecialistRunner } from './runners'
|
|
24
24
|
import { HubtypeApiClient } from './services/hubtype-api-client'
|
|
25
25
|
import type {
|
|
26
26
|
AgenticInputMessage,
|
|
@@ -90,7 +90,7 @@ export default class BotonicPluginAiAgents<
|
|
|
90
90
|
|
|
91
91
|
try {
|
|
92
92
|
if (aiAgentArgs.type === AiAgentType.Specialist) {
|
|
93
|
-
return await this.
|
|
93
|
+
return await this.executeSpecialistAIAgent(
|
|
94
94
|
botContext,
|
|
95
95
|
aiAgentArgs,
|
|
96
96
|
authToken,
|
|
@@ -126,7 +126,7 @@ export default class BotonicPluginAiAgents<
|
|
|
126
126
|
}
|
|
127
127
|
}
|
|
128
128
|
|
|
129
|
-
private async
|
|
129
|
+
private async executeSpecialistAIAgent(
|
|
130
130
|
botContext: BotContext<TPlugins, TExtraData>,
|
|
131
131
|
aiAgentArgs: AiAgentSpecialistArgs,
|
|
132
132
|
authToken: string,
|
|
@@ -136,11 +136,12 @@ export default class BotonicPluginAiAgents<
|
|
|
136
136
|
this.maxRetries,
|
|
137
137
|
this.timeout,
|
|
138
138
|
aiAgentArgs.model,
|
|
139
|
-
aiAgentArgs.verbosity
|
|
139
|
+
aiAgentArgs.verbosity,
|
|
140
|
+
botContext
|
|
140
141
|
)
|
|
141
142
|
|
|
142
143
|
// Get LLM config, tools and agent
|
|
143
|
-
const { tools, agent } = await this.
|
|
144
|
+
const { tools, agent } = await this.getSpecialistAgentAndTools(
|
|
144
145
|
botContext,
|
|
145
146
|
aiAgentArgs,
|
|
146
147
|
aiAgentArgs.outputMessagesSchemas || [],
|
|
@@ -176,7 +177,7 @@ export default class BotonicPluginAiAgents<
|
|
|
176
177
|
)
|
|
177
178
|
|
|
178
179
|
// Run agent
|
|
179
|
-
const runner = new
|
|
180
|
+
const runner = new SpecialistRunner<TPlugins, TExtraData>(
|
|
180
181
|
agent,
|
|
181
182
|
llmConfig,
|
|
182
183
|
inferenceId,
|
|
@@ -197,12 +198,13 @@ export default class BotonicPluginAiAgents<
|
|
|
197
198
|
this.maxRetries,
|
|
198
199
|
this.timeout,
|
|
199
200
|
aiAgentArgs.model,
|
|
200
|
-
aiAgentArgs.verbosity
|
|
201
|
+
aiAgentArgs.verbosity,
|
|
202
|
+
botContext
|
|
201
203
|
)
|
|
202
204
|
|
|
203
205
|
const specialistsAgents = await Promise.all(
|
|
204
206
|
specialists.map(async specialistData => {
|
|
205
|
-
const { agent } = await this.
|
|
207
|
+
const { agent } = await this.getSpecialistAgentAndTools(
|
|
206
208
|
botContext,
|
|
207
209
|
specialistData,
|
|
208
210
|
aiAgentArgs.outputMessagesSchemas || [],
|
|
@@ -263,7 +265,7 @@ export default class BotonicPluginAiAgents<
|
|
|
263
265
|
return await runner.run(messages, context)
|
|
264
266
|
}
|
|
265
267
|
|
|
266
|
-
private async
|
|
268
|
+
private async getSpecialistAgentAndTools(
|
|
267
269
|
botContext: BotContext,
|
|
268
270
|
aiAgentArgs: AiAgentArgs,
|
|
269
271
|
outputMessagesSchemas: ZodObject<any>[],
|
|
@@ -277,7 +279,8 @@ export default class BotonicPluginAiAgents<
|
|
|
277
279
|
// Build agent
|
|
278
280
|
const sourceIds =
|
|
279
281
|
aiAgentArgs.type === AiAgentType.Specialist ? aiAgentArgs.sourceIds : []
|
|
280
|
-
|
|
282
|
+
|
|
283
|
+
const specialist = await SpecialistAgent.create<TPlugins, TExtraData>({
|
|
281
284
|
name: aiAgentArgs.name,
|
|
282
285
|
instructions: aiAgentArgs.instructions,
|
|
283
286
|
tools: tools,
|
|
@@ -295,9 +298,9 @@ export default class BotonicPluginAiAgents<
|
|
|
295
298
|
inferenceId,
|
|
296
299
|
},
|
|
297
300
|
})
|
|
298
|
-
const
|
|
301
|
+
const specialistAgent = specialist.getAgent()
|
|
299
302
|
|
|
300
|
-
return { agent:
|
|
303
|
+
return { agent: specialistAgent, tools }
|
|
301
304
|
}
|
|
302
305
|
|
|
303
306
|
private async getMessages(
|