@botonic/plugin-ai-agents 0.44.0-alpha.2 → 0.44.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/agent-builder.d.ts +3 -0
- package/lib/cjs/agent-builder.js +11 -8
- package/lib/cjs/agent-builder.js.map +1 -1
- package/lib/cjs/debug-logger.d.ts +31 -0
- package/lib/cjs/debug-logger.js +99 -0
- package/lib/cjs/debug-logger.js.map +1 -0
- package/lib/cjs/index.d.ts +1 -0
- package/lib/cjs/index.js +12 -1
- package/lib/cjs/index.js.map +1 -1
- package/lib/cjs/runner.d.ts +3 -1
- package/lib/cjs/runner.js +12 -3
- package/lib/cjs/runner.js.map +1 -1
- package/lib/cjs/types.d.ts +2 -0
- package/lib/esm/agent-builder.d.ts +3 -0
- package/lib/esm/agent-builder.js +11 -8
- package/lib/esm/agent-builder.js.map +1 -1
- package/lib/esm/debug-logger.d.ts +31 -0
- package/lib/esm/debug-logger.js +99 -0
- package/lib/esm/debug-logger.js.map +1 -0
- package/lib/esm/index.d.ts +1 -0
- package/lib/esm/index.js +12 -1
- package/lib/esm/index.js.map +1 -1
- package/lib/esm/runner.d.ts +3 -1
- package/lib/esm/runner.js +12 -3
- package/lib/esm/runner.js.map +1 -1
- package/lib/esm/types.d.ts +2 -0
- package/package.json +2 -2
- package/src/agent-builder.ts +19 -9
- package/src/debug-logger.ts +170 -0
- package/src/index.ts +19 -1
- package/src/runner.ts +22 -3
- package/src/types.ts +2 -0
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { CampaignV2, ContactInfo, ResolvedPlugins } from '@botonic/core';
|
|
2
|
+
import { DebugLogger } from './debug-logger';
|
|
2
3
|
import { AIAgent, GuardrailRule, Tool } from './types';
|
|
3
4
|
interface AIAgentBuilderOptions<TPlugins extends ResolvedPlugins = ResolvedPlugins, TExtraData = any> {
|
|
4
5
|
name: string;
|
|
@@ -8,12 +9,14 @@ interface AIAgentBuilderOptions<TPlugins extends ResolvedPlugins = ResolvedPlugi
|
|
|
8
9
|
contactInfo: ContactInfo[];
|
|
9
10
|
inputGuardrailRules: GuardrailRule[];
|
|
10
11
|
sourceIds: string[];
|
|
12
|
+
logger: DebugLogger;
|
|
11
13
|
}
|
|
12
14
|
export declare class AIAgentBuilder<TPlugins extends ResolvedPlugins = ResolvedPlugins, TExtraData = any> {
|
|
13
15
|
private name;
|
|
14
16
|
private instructions;
|
|
15
17
|
private tools;
|
|
16
18
|
private inputGuardrails;
|
|
19
|
+
private logger;
|
|
17
20
|
constructor(options: AIAgentBuilderOptions<TPlugins, TExtraData>);
|
|
18
21
|
build(): AIAgent<TPlugins, TExtraData>;
|
|
19
22
|
private addExtraInstructions;
|
package/lib/cjs/agent-builder.js
CHANGED
|
@@ -12,6 +12,7 @@ class AIAgentBuilder {
|
|
|
12
12
|
this.instructions = this.addExtraInstructions(options.instructions, options.contactInfo, options.campaignsContext);
|
|
13
13
|
this.tools = this.addHubtypeTools(options.tools, options.sourceIds);
|
|
14
14
|
this.inputGuardrails = [];
|
|
15
|
+
this.logger = options.logger;
|
|
15
16
|
if (options.inputGuardrailRules.length > 0) {
|
|
16
17
|
const inputGuardrail = (0, guardrails_1.createInputGuardrail)(options.inputGuardrailRules);
|
|
17
18
|
this.inputGuardrails.push(inputGuardrail);
|
|
@@ -23,19 +24,21 @@ class AIAgentBuilder {
|
|
|
23
24
|
modelSettings.reasoning = { effort: 'none' };
|
|
24
25
|
modelSettings.text = { verbosity: 'medium' };
|
|
25
26
|
}
|
|
26
|
-
|
|
27
|
+
const hasRetrieveKnowledge = this.tools.includes(tools_1.retrieveKnowledge);
|
|
28
|
+
if (hasRetrieveKnowledge && constants_1.OPENAI_PROVIDER === 'azure') {
|
|
27
29
|
modelSettings.toolChoice = tools_1.retrieveKnowledge.name;
|
|
28
30
|
}
|
|
29
31
|
// When using standard OpenAI API, we need to specify the model
|
|
30
32
|
// Azure OpenAI uses deployment name instead
|
|
31
33
|
const model = constants_1.OPENAI_PROVIDER === 'openai' ? constants_1.OPENAI_MODEL : undefined;
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
34
|
+
this.logger.logModelSettings({
|
|
35
|
+
provider: constants_1.OPENAI_PROVIDER,
|
|
36
|
+
model,
|
|
37
|
+
reasoning: modelSettings.reasoning,
|
|
38
|
+
text: modelSettings.text,
|
|
39
|
+
toolChoice: modelSettings.toolChoice,
|
|
40
|
+
hasRetrieveKnowledge,
|
|
41
|
+
});
|
|
39
42
|
return new agents_1.Agent({
|
|
40
43
|
name: this.name,
|
|
41
44
|
model,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agent-builder.js","sourceRoot":"","sources":["../../src/agent-builder.ts"],"names":[],"mappings":";;;AACA,2CAKuB;AAEvB,2CAA2D;
|
|
1
|
+
{"version":3,"file":"agent-builder.js","sourceRoot":"","sources":["../../src/agent-builder.ts"],"names":[],"mappings":";;;AACA,2CAKuB;AAEvB,2CAA2D;AAE3D,6CAAmD;AACnD,2DAAkD;AAClD,mCAA2D;AAiB3D,MAAa,cAAc;IAUzB,YAAY,OAAoD;QAC9D,IAAI,CAAC,IAAI,GAAG,OAAO,CAAC,IAAI,CAAA;QACxB,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC,oBAAoB,CAC3C,OAAO,CAAC,YAAY,EACpB,OAAO,CAAC,WAAW,EACnB,OAAO,CAAC,gBAAgB,CACzB,CAAA;QACD,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,eAAe,CAAC,OAAO,CAAC,KAAK,EAAE,OAAO,CAAC,SAAS,CAAC,CAAA;QACnE,IAAI,CAAC,eAAe,GAAG,EAAE,CAAA;QACzB,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC,MAAM,CAAA;QAC5B,IAAI,OAAO,CAAC,mBAAmB,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YAC3C,MAAM,cA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CAAC,EAAE,CAAC,QAAQ,CAAC,aAAa,CACnC,CAAA;QACD,IAAI,oBAAoB,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YACtC,OAAO,EAAE,CAAA;QACX,CAAC;QACD,OAAO,oBAAoB;aACxB,GAAG,CACF,CAAC,QAAQ,EAAE,KAAK,EAAE,EAAE,CAClB,qBAAqB,KAAK,GAAG,CAAC,MAAM,QAAQ,CAAC,aAAa,wBAAwB,KAAK,GAAG,CAAC,GAAG,CACjG;aACA,IAAI,CAAC,IAAI,CAAC,CAAA;IACf,CAAC;IAEO,qBAAqB;QAC3B,MAAM,OAAO,GAAG;YACd,QAAQ,EAAE;gBACR;oBACE,IAAI,EAAE,MAAM;oBACZ,OAAO,EAAE;wBACP,IAAI,EAAE,kCAAkC;qBACzC;iBACF;aACF;SACF,CAAA;QACD,MAAM,MAAM,GAAG,yIAAyI,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,cAAc,CAAA;QAC7L,OAAO,aAAa,MAAM,aAAa,CAAA;IACzC,CAAC;IAEO,eAAe,CACrB,KAAmC,EACnC,SAAmB;QAEnB,MAAM,YAAY,GAAW,CAAC,GAAG,sBAAc,CAAC,CAAA;QAChD,IAAI,SAAS,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YACzB,YAAY,CAAC,IAAI,CAAC,yBAAiB,CAAC,CAAA;QACtC,CAAC;QACD,OAAO,CAAC,GAAG,YAAY,EAAE,GAAG,KAAK,CAAC,CAAA;IACpC,CAAC;CACF;AAlJD,wCAkJC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { AiAgentArgs } from '@botonic/core';
|
|
2
|
+
import { AgenticInputMessage, MemoryOptions, RunResult } from './types';
|
|
3
|
+
export interface DebugLoggerConfig {
|
|
4
|
+
messageHistoryApiVersion: string;
|
|
5
|
+
maxRetries: number;
|
|
6
|
+
timeout: number;
|
|
7
|
+
customToolNames: string[];
|
|
8
|
+
memory: MemoryOptions;
|
|
9
|
+
}
|
|
10
|
+
export interface ModelSettingsInfo {
|
|
11
|
+
provider: string;
|
|
12
|
+
model: string | undefined;
|
|
13
|
+
reasoning?: {
|
|
14
|
+
effort: string;
|
|
15
|
+
};
|
|
16
|
+
text?: {
|
|
17
|
+
verbosity: string;
|
|
18
|
+
};
|
|
19
|
+
toolChoice?: string;
|
|
20
|
+
hasRetrieveKnowledge: boolean;
|
|
21
|
+
}
|
|
22
|
+
export interface DebugLogger {
|
|
23
|
+
logInitialConfig(config: DebugLoggerConfig): void;
|
|
24
|
+
logAgentDebugInfo(aiAgentArgs: AiAgentArgs, toolNames: string[], messages: AgenticInputMessage[]): void;
|
|
25
|
+
logModelSettings(settings: ModelSettingsInfo): void;
|
|
26
|
+
logRunnerStart(): void;
|
|
27
|
+
logRunResult(runResult: RunResult, startTime: number): void;
|
|
28
|
+
logGuardrailTriggered(): void;
|
|
29
|
+
logRunnerError(startTime: number, error: unknown): void;
|
|
30
|
+
}
|
|
31
|
+
export declare function createDebugLogger(enableDebug: boolean): DebugLogger;
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createDebugLogger = createDebugLogger;
|
|
4
|
+
const constants_1 = require("./constants");
|
|
5
|
+
const PREFIX = '[BotonicPluginAiAgents]';
|
|
6
|
+
class EnabledDebugLogger {
|
|
7
|
+
getModelInfo() {
|
|
8
|
+
const model = constants_1.OPENAI_PROVIDER === 'azure'
|
|
9
|
+
? constants_1.AZURE_OPENAI_API_DEPLOYMENT_NAME
|
|
10
|
+
: constants_1.OPENAI_MODEL;
|
|
11
|
+
const apiBase = constants_1.OPENAI_PROVIDER === 'azure' && constants_1.AZURE_OPENAI_API_BASE
|
|
12
|
+
? constants_1.AZURE_OPENAI_API_BASE
|
|
13
|
+
: 'OpenAI API';
|
|
14
|
+
return { model, apiBase };
|
|
15
|
+
}
|
|
16
|
+
logInitialConfig(config) {
|
|
17
|
+
const { model, apiBase } = this.getModelInfo();
|
|
18
|
+
console.log(`${PREFIX} === Plugin Initialization ===`);
|
|
19
|
+
console.log(`${PREFIX} Provider: ${constants_1.OPENAI_PROVIDER}`);
|
|
20
|
+
console.log(`${PREFIX} Model/Deployment: ${model}`);
|
|
21
|
+
console.log(`${PREFIX} API Base: ${apiBase}`);
|
|
22
|
+
console.log(`${PREFIX} Message History API Version: ${config.messageHistoryApiVersion}`);
|
|
23
|
+
console.log(`${PREFIX} Max Retries: ${config.maxRetries}`);
|
|
24
|
+
console.log(`${PREFIX} Timeout: ${config.timeout}ms`);
|
|
25
|
+
console.log(`${PREFIX} Custom Tools Registered: ${config.customToolNames.join(', ') || 'none'}`);
|
|
26
|
+
console.log(`${PREFIX} Memory Options:`, {
|
|
27
|
+
maxMessages: config.memory.maxMessages ?? constants_1.MAX_MEMORY_LENGTH,
|
|
28
|
+
includeToolCalls: config.memory.includeToolCalls ?? true,
|
|
29
|
+
maxFullToolResults: config.memory.maxFullToolResults ?? 1,
|
|
30
|
+
debugMode: config.memory.debugMode ?? false,
|
|
31
|
+
});
|
|
32
|
+
console.log(`${PREFIX} === End Plugin Initialization ===`);
|
|
33
|
+
}
|
|
34
|
+
logAgentDebugInfo(aiAgentArgs, toolNames, messages) {
|
|
35
|
+
console.log(`${PREFIX} === AI Agent Debug Info ===`);
|
|
36
|
+
console.log(`${PREFIX} Agent Name: ${aiAgentArgs.name}`);
|
|
37
|
+
console.log(`${PREFIX} Active Tools: ${JSON.stringify(toolNames)}`);
|
|
38
|
+
console.log(`${PREFIX} Source IDs: ${JSON.stringify(aiAgentArgs.sourceIds || [])}`);
|
|
39
|
+
console.log(`${PREFIX} Message History Count: ${messages.length}`);
|
|
40
|
+
console.log(`${PREFIX} Input Guardrail Rules: ${aiAgentArgs.inputGuardrailRules?.length || 0}`);
|
|
41
|
+
console.log(`${PREFIX} Instructions:`);
|
|
42
|
+
console.log(aiAgentArgs.instructions);
|
|
43
|
+
console.log(`${PREFIX} === End Debug Info ===`);
|
|
44
|
+
}
|
|
45
|
+
logModelSettings(settings) {
|
|
46
|
+
console.log(`${PREFIX} === Agent Model Settings ===`);
|
|
47
|
+
console.log(`${PREFIX} Has Retrieve Knowledge Tool: ${settings.hasRetrieveKnowledge}`);
|
|
48
|
+
if (settings.reasoning) {
|
|
49
|
+
console.log(`${PREFIX} Reasoning Effort: ${settings.reasoning.effort}`);
|
|
50
|
+
}
|
|
51
|
+
if (settings.text) {
|
|
52
|
+
console.log(`${PREFIX} Text Verbosity: ${settings.text.verbosity}`);
|
|
53
|
+
}
|
|
54
|
+
if (settings.toolChoice) {
|
|
55
|
+
console.log(`${PREFIX} Tool Choice: ${settings.toolChoice}`);
|
|
56
|
+
}
|
|
57
|
+
console.log(`${PREFIX} === End Model Settings ===`);
|
|
58
|
+
}
|
|
59
|
+
logRunnerStart() {
|
|
60
|
+
console.log(`${PREFIX} === Runner Execution Start ===`);
|
|
61
|
+
}
|
|
62
|
+
logRunResult(runResult, startTime) {
|
|
63
|
+
const elapsedMs = Date.now() - startTime;
|
|
64
|
+
console.log(`${PREFIX} === Runner Execution Complete ===`);
|
|
65
|
+
console.log(`${PREFIX} Execution Time: ${elapsedMs}ms`);
|
|
66
|
+
console.log(`${PREFIX} Output Messages Count: ${runResult.messages.length}`);
|
|
67
|
+
console.log(`${PREFIX} Exit: ${runResult.exit}`);
|
|
68
|
+
console.log(`${PREFIX} Error: ${runResult.error}`);
|
|
69
|
+
console.log(`${PREFIX} Tools Executed: ${JSON.stringify(runResult.toolsExecuted.map(t => t.toolName))}`);
|
|
70
|
+
if (runResult.inputGuardrailsTriggered.length > 0) {
|
|
71
|
+
console.log(`${PREFIX} Input Guardrails Triggered: ${runResult.inputGuardrailsTriggered.length}`);
|
|
72
|
+
}
|
|
73
|
+
if (runResult.outputGuardrailsTriggered.length > 0) {
|
|
74
|
+
console.log(`${PREFIX} Output Guardrails Triggered: ${runResult.outputGuardrailsTriggered.length}`);
|
|
75
|
+
}
|
|
76
|
+
console.log(`${PREFIX} === End Runner Execution ===`);
|
|
77
|
+
}
|
|
78
|
+
logGuardrailTriggered() {
|
|
79
|
+
console.log(`${PREFIX} Input guardrail triggered`);
|
|
80
|
+
}
|
|
81
|
+
logRunnerError(startTime, error) {
|
|
82
|
+
const elapsedMs = Date.now() - startTime;
|
|
83
|
+
console.log(`${PREFIX} Runner execution failed after ${elapsedMs}ms`);
|
|
84
|
+
console.log(`${PREFIX} Error:`, error);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
class DisabledDebugLogger {
|
|
88
|
+
logInitialConfig() { }
|
|
89
|
+
logAgentDebugInfo() { }
|
|
90
|
+
logModelSettings() { }
|
|
91
|
+
logRunnerStart() { }
|
|
92
|
+
logRunResult() { }
|
|
93
|
+
logGuardrailTriggered() { }
|
|
94
|
+
logRunnerError() { }
|
|
95
|
+
}
|
|
96
|
+
function createDebugLogger(enableDebug) {
|
|
97
|
+
return enableDebug ? new EnabledDebugLogger() : new DisabledDebugLogger();
|
|
98
|
+
}
|
|
99
|
+
//# sourceMappingURL=debug-logger.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"debug-logger.js","sourceRoot":"","sources":["../../src/debug-logger.ts"],"names":[],"mappings":";;AAuKA,8CAEC;AAvKD,2CAMoB;AAGpB,MAAM,MAAM,GAAG,yBAAyB,CAAA;AAiCxC,MAAM,kBAAkB;IACd,YAAY;QAClB,MAAM,KAAK,GACT,2BAAe,KAAK,OAAO;YACzB,CAAC,CAAC,4CAAgC;YAClC,CAAC,CAAC,wBAAY,CAAA;QAClB,MAAM,OAAO,GACX,2BAAe,KAAK,OAAO,IAAI,iCAAqB;YAClD,CAAC,CAAC,iCAAqB;YACvB,CAAC,CAAC,YAAY,CAAA;QAClB,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,CAAA;IAC3B,CAAC;IAED,gBAAgB,CAAC,MAAyB;QACxC,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,GAAG,IAAI,CA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M,iCAAiC,SAAS,CAAC,yBAAyB,CAAC,MAAM,EAAE,CACvF,CAAA;QACH,CAAC;QACD,OAAO,CAAC,GAAG,CAAC,GAAG,MAAM,+BAA+B,CAAC,CAAA;IACvD,CAAC;IAED,qBAAqB;QACnB,OAAO,CAAC,GAAG,CAAC,GAAG,MAAM,4BAA4B,CAAC,CAAA;IACpD,CAAC;IAED,cAAc,CAAC,SAAiB,EAAE,KAAc;QAC9C,MAAM,SAAS,GAAG,IAAI,CAAC,GAAG,EAAE,GAAG,SAAS,CAAA;QACxC,OAAO,CAAC,GAAG,CAAC,GAAG,MAAM,kCAAkC,SAAS,IAAI,CAAC,CAAA;QACrE,OAAO,CAAC,GAAG,CAAC,GAAG,MAAM,SAAS,EAAE,KAAK,CAAC,CAAA;IACxC,CAAC;CACF;AAED,MAAM,mBAAmB;IACvB,gBAAgB,KAAU,CAAC;IAC3B,iBAAiB,KAAU,CAAC;IAC5B,gBAAgB,KAAU,CAAC;IAC3B,cAAc,KAAU,CAAC;IACzB,YAAY,KAAU,CAAC;IACvB,qBAAqB,KAAU,CAAC;IAChC,cAAc,KAAU,CAAC;CAC1B;AAED,SAAgB,iBAAiB,CAAC,WAAoB;IACpD,OAAO,WAAW,CAAC,CAAC,CAAC,IAAI,kBAAkB,EAAE,CAAC,CAAC,CAAC,IAAI,mBAAmB,EAAE,CAAA;AAC3E,CAAC"}
|
package/lib/cjs/index.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ export default class BotonicPluginAiAgents<TPlugins extends ResolvedPlugins = Re
|
|
|
4
4
|
private readonly authToken?;
|
|
5
5
|
private readonly messageHistoryApiVersion;
|
|
6
6
|
private readonly memory;
|
|
7
|
+
private readonly logger;
|
|
7
8
|
toolDefinitions: CustomTool<TPlugins, TExtraData>[];
|
|
8
9
|
constructor(options?: PluginAiAgentOptions<TPlugins, TExtraData>);
|
|
9
10
|
pre(): void;
|
package/lib/cjs/index.js
CHANGED
|
@@ -4,6 +4,7 @@ const tslib_1 = require("tslib");
|
|
|
4
4
|
const agents_1 = require("@openai/agents");
|
|
5
5
|
const agent_builder_1 = require("./agent-builder");
|
|
6
6
|
const constants_1 = require("./constants");
|
|
7
|
+
const debug_logger_1 = require("./debug-logger");
|
|
7
8
|
const hubtype_api_client_1 = require("./hubtype-api-client");
|
|
8
9
|
const openai_1 = require("./openai");
|
|
9
10
|
const runner_1 = require("./runner");
|
|
@@ -19,6 +20,14 @@ class BotonicPluginAiAgents {
|
|
|
19
20
|
this.toolDefinitions = options?.customTools || [];
|
|
20
21
|
this.messageHistoryApiVersion = options?.messageHistoryApiVersion ?? 'v2';
|
|
21
22
|
this.memory = options?.memory ?? {};
|
|
23
|
+
this.logger = (0, debug_logger_1.createDebugLogger)(options?.enableDebug ?? false);
|
|
24
|
+
this.logger.logInitialConfig({
|
|
25
|
+
messageHistoryApiVersion: this.messageHistoryApiVersion,
|
|
26
|
+
maxRetries: options?.maxRetries ?? 2,
|
|
27
|
+
timeout: options?.timeout ?? 16000,
|
|
28
|
+
customToolNames: this.toolDefinitions.map(t => t.name),
|
|
29
|
+
memory: this.memory,
|
|
30
|
+
});
|
|
22
31
|
}
|
|
23
32
|
pre() {
|
|
24
33
|
return;
|
|
@@ -38,6 +47,7 @@ class BotonicPluginAiAgents {
|
|
|
38
47
|
inputGuardrailRules: aiAgentArgs.inputGuardrailRules || [],
|
|
39
48
|
sourceIds: aiAgentArgs.sourceIds || [],
|
|
40
49
|
campaignsContext: request.input.context?.campaigns_v2,
|
|
50
|
+
logger: this.logger,
|
|
41
51
|
}).build();
|
|
42
52
|
const messages = await this.getMessages(request, authToken, constants_1.MAX_MEMORY_LENGTH);
|
|
43
53
|
const context = {
|
|
@@ -51,7 +61,8 @@ class BotonicPluginAiAgents {
|
|
|
51
61
|
},
|
|
52
62
|
request,
|
|
53
63
|
};
|
|
54
|
-
|
|
64
|
+
this.logger.logAgentDebugInfo(aiAgentArgs, tools.map(t => t.name), messages);
|
|
65
|
+
const runner = new runner_1.AIAgentRunner(agent, this.logger);
|
|
55
66
|
return await runner.run(messages, context);
|
|
56
67
|
}
|
|
57
68
|
catch (error) {
|
package/lib/cjs/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;AACA,2CAAqC;AAErC,mDAAgD;AAChD,2CAAuD;AACvD,6DAAuD;AACvD,qCAAsC;AACtC,qCAAwC;AAYxC,MAAqB,qBAAqB;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;AACA,2CAAqC;AAErC,mDAAgD;AAChD,2CAAuD;AACvD,iDAA+D;AAC/D,6DAAuD;AACvD,qCAAsC;AACtC,qCAAwC;AAYxC,MAAqB,qBAAqB;IAUxC,YAAY,OAAoD;QAFzD,oBAAe,GAAuC,EAAE,CAAA;QAG7D,IAAA,oBAAW,EAAC,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,OAAO,CAAC,CAAA;QAElD,IAAI,OAAO,EAAE,wBAAwB,KAAK,IAAI,IAAI,OAAO,EAAE,MAAM,EAAE,CAAC;YAClE,MAAM,IAAI,KAAK,CACb,2DAA2D;gBACzD,+DAA+D,CAClE,CAAA;QACH,CAAC;QAED,IAAI,CAAC,SAAS,GAAG,OAAO,EAAE,SAAS,CAAA;QACnC,IAAI,CAAC,eAAe,GAAG,OAAO,EAAE,WAAW,IAAI,EAAE,CAAA;QACjD,IAAI,CAAC,wBAAwB,GAAG,OAAO,EAAE,wBAAwB,IAAI,IAAI,CAAA;QACzE,IAAI,CAAC,MAAM,GAAG,OAAO,EAAE,MAAM,IAAI,EAAE,CAAA;QACnC,IAAI,CAAC,MAAM,GAAG,IAAA,gCAAiB,EAAC,OAAO,EAAE,WAAW,IAAI,KAAK,CAAC,CAAA;QAE9D,IAAI,CAAC,MAAM,CAAC,gBAAgB,CAAC;YAC3B,wBAAwB,EAAE,IAAI,CAAC,wBAAwB;YACv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AC3C,OAAO,MAAM,aAAa,CAAC,WAAW,CAAC,OAAO,EAAE,YAAY,CAAC,CAAA;QAC/D,CAAC;QAED,gBAAgB;QAChB,MAAM,MAAM,GAAG,MAAM,aAAa,CAAC,aAAa,CAAC,OAAO,EAAE;YACxD,WAAW,EAAE,IAAI,CAAC,MAAM,CAAC,WAAW,IAAI,YAAY;YACpD,gBAAgB,EAAE,IAAI,CAAC,MAAM,CAAC,gBAAgB,IAAI,IAAI;YACtD,kBAAkB,EAAE,IAAI,CAAC,MAAM,CAAC,kBAAkB,IAAI,CAAC;YACvD,SAAS,EAAE,IAAI,CAAC,MAAM,CAAC,SAAS,IAAI,KAAK;SAC1C,CAAC,CAAA;QACF,OAAO,MAAM,CAAC,QAAQ,CAAA;IACxB,CAAC;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,EAA0C;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;AA5ID,wCA4IC;AAED,kDAAuB"}
|
package/lib/cjs/runner.d.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { ResolvedPlugins } from '@botonic/core';
|
|
2
|
+
import { DebugLogger } from './debug-logger';
|
|
2
3
|
import { AgenticInputMessage, AIAgent, Context, RunResult } from './types';
|
|
3
4
|
export declare class AIAgentRunner<TPlugins extends ResolvedPlugins = ResolvedPlugins, TExtraData = any> {
|
|
4
5
|
private agent;
|
|
5
|
-
|
|
6
|
+
private logger;
|
|
7
|
+
constructor(agent: AIAgent<TPlugins, TExtraData>, logger: DebugLogger);
|
|
6
8
|
run(messages: AgenticInputMessage[], context: Context<TPlugins, TExtraData>): Promise<RunResult>;
|
|
7
9
|
private getToolsExecuted;
|
|
8
10
|
private getToolExecutionInfo;
|
package/lib/cjs/runner.js
CHANGED
|
@@ -4,10 +4,13 @@ exports.AIAgentRunner = void 0;
|
|
|
4
4
|
const agents_1 = require("@openai/agents");
|
|
5
5
|
const tools_1 = require("./tools");
|
|
6
6
|
class AIAgentRunner {
|
|
7
|
-
constructor(agent) {
|
|
7
|
+
constructor(agent, logger) {
|
|
8
8
|
this.agent = agent;
|
|
9
|
+
this.logger = logger;
|
|
9
10
|
}
|
|
10
11
|
async run(messages, context) {
|
|
12
|
+
const startTime = Date.now();
|
|
13
|
+
this.logger.logRunnerStart();
|
|
11
14
|
try {
|
|
12
15
|
const runner = new agents_1.Runner({
|
|
13
16
|
modelSettings: { temperature: 0 },
|
|
@@ -21,7 +24,7 @@ class AIAgentRunner {
|
|
|
21
24
|
const hasExit = outputMessages.length === 0 ||
|
|
22
25
|
outputMessages.some(message => message.type === 'exit');
|
|
23
26
|
const toolsExecuted = this.getToolsExecuted(result, context);
|
|
24
|
-
|
|
27
|
+
const runResult = {
|
|
25
28
|
messages: hasExit
|
|
26
29
|
? []
|
|
27
30
|
: outputMessages.filter(message => message.type !== 'exit'),
|
|
@@ -32,10 +35,12 @@ class AIAgentRunner {
|
|
|
32
35
|
inputGuardrailsTriggered: [],
|
|
33
36
|
outputGuardrailsTriggered: [],
|
|
34
37
|
};
|
|
38
|
+
this.logger.logRunResult(runResult, startTime);
|
|
39
|
+
return runResult;
|
|
35
40
|
}
|
|
36
41
|
catch (error) {
|
|
37
42
|
if (error instanceof agents_1.InputGuardrailTripwireTriggered) {
|
|
38
|
-
|
|
43
|
+
const runResult = {
|
|
39
44
|
messages: [],
|
|
40
45
|
memoryLength: 0,
|
|
41
46
|
toolsExecuted: [],
|
|
@@ -44,7 +49,11 @@ class AIAgentRunner {
|
|
|
44
49
|
inputGuardrailsTriggered: error.result.output.outputInfo,
|
|
45
50
|
outputGuardrailsTriggered: [],
|
|
46
51
|
};
|
|
52
|
+
this.logger.logGuardrailTriggered();
|
|
53
|
+
this.logger.logRunResult(runResult, startTime);
|
|
54
|
+
return runResult;
|
|
47
55
|
}
|
|
56
|
+
this.logger.logRunnerError(startTime, error);
|
|
48
57
|
throw error;
|
|
49
58
|
}
|
|
50
59
|
}
|
package/lib/cjs/runner.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runner.js","sourceRoot":"","sources":["../../src/runner.ts"],"names":[],"mappings":";;;AACA,2CAIuB;
|
|
1
|
+
{"version":3,"file":"runner.js","sourceRoot":"","sources":["../../src/runner.ts"],"names":[],"mappings":";;;AACA,2CAIuB;AAGvB,mCAA2C;AAkB3C,MAAa,aAAa;IAOxB,YAAY,KAAoC,EAAE,MAAmB;QACnE,IAAI,CAAC,KAAK,GAAG,KAAK,CAAA;QAClB,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,EAAE,CAAA;QAE5B,IAAI,CAAC;YACH,MAAM,MAAM,GAAG,IAAI,eAAM,CAAC;gBACxB,aAAa,EAAE,EAAE,WAAW,EAAE,CAAC,EAAE;aAClC,CAAC,CAAA;YACF,2FAA2F;YAC3F,qFAAqF;YACrF,MAAM,MAAM,GAAG,CAAC,MAAM,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,EAAE,QAAQ,EAAE;gBACrD,OAAO;aACR,CAAC,CAAwB,CAAA;YAE1B,MAAM,cAAc,GAAG,MAAM,CAAC,WAAW,EAAE,QAA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AAC;YACf,OAAO,EAAE,CAAA;QACX,CAAC;IACH,CAAC;CACF;AAhID,sCAgIC"}
|
package/lib/cjs/types.d.ts
CHANGED
|
@@ -42,6 +42,8 @@ export interface PluginAiAgentOptions<TPlugins extends ResolvedPlugins = Resolve
|
|
|
42
42
|
messageHistoryApiVersion?: MessageHistoryApiVersion;
|
|
43
43
|
/** Options for V2 message history API. Only used when messageHistoryApiVersion is 'v2'. */
|
|
44
44
|
memory?: MemoryOptions;
|
|
45
|
+
/** Enable debug logging for AI agent configuration and execution details. */
|
|
46
|
+
enableDebug?: boolean;
|
|
45
47
|
}
|
|
46
48
|
export type AgenticInputMessage = AgentInputItem;
|
|
47
49
|
export { AgenticOutputMessage, AiAgentArgs, GuardrailRule, InferenceResponse, RunResult, };
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { CampaignV2, ContactInfo, ResolvedPlugins } from '@botonic/core';
|
|
2
|
+
import { DebugLogger } from './debug-logger';
|
|
2
3
|
import { AIAgent, GuardrailRule, Tool } from './types';
|
|
3
4
|
interface AIAgentBuilderOptions<TPlugins extends ResolvedPlugins = ResolvedPlugins, TExtraData = any> {
|
|
4
5
|
name: string;
|
|
@@ -8,12 +9,14 @@ interface AIAgentBuilderOptions<TPlugins extends ResolvedPlugins = ResolvedPlugi
|
|
|
8
9
|
contactInfo: ContactInfo[];
|
|
9
10
|
inputGuardrailRules: GuardrailRule[];
|
|
10
11
|
sourceIds: string[];
|
|
12
|
+
logger: DebugLogger;
|
|
11
13
|
}
|
|
12
14
|
export declare class AIAgentBuilder<TPlugins extends ResolvedPlugins = ResolvedPlugins, TExtraData = any> {
|
|
13
15
|
private name;
|
|
14
16
|
private instructions;
|
|
15
17
|
private tools;
|
|
16
18
|
private inputGuardrails;
|
|
19
|
+
private logger;
|
|
17
20
|
constructor(options: AIAgentBuilderOptions<TPlugins, TExtraData>);
|
|
18
21
|
build(): AIAgent<TPlugins, TExtraData>;
|
|
19
22
|
private addExtraInstructions;
|
package/lib/esm/agent-builder.js
CHANGED
|
@@ -12,6 +12,7 @@ class AIAgentBuilder {
|
|
|
12
12
|
this.instructions = this.addExtraInstructions(options.instructions, options.contactInfo, options.campaignsContext);
|
|
13
13
|
this.tools = this.addHubtypeTools(options.tools, options.sourceIds);
|
|
14
14
|
this.inputGuardrails = [];
|
|
15
|
+
this.logger = options.logger;
|
|
15
16
|
if (options.inputGuardrailRules.length > 0) {
|
|
16
17
|
const inputGuardrail = (0, guardrails_1.createInputGuardrail)(options.inputGuardrailRules);
|
|
17
18
|
this.inputGuardrails.push(inputGuardrail);
|
|
@@ -23,19 +24,21 @@ class AIAgentBuilder {
|
|
|
23
24
|
modelSettings.reasoning = { effort: 'none' };
|
|
24
25
|
modelSettings.text = { verbosity: 'medium' };
|
|
25
26
|
}
|
|
26
|
-
|
|
27
|
+
const hasRetrieveKnowledge = this.tools.includes(tools_1.retrieveKnowledge);
|
|
28
|
+
if (hasRetrieveKnowledge && constants_1.OPENAI_PROVIDER === 'azure') {
|
|
27
29
|
modelSettings.toolChoice = tools_1.retrieveKnowledge.name;
|
|
28
30
|
}
|
|
29
31
|
// When using standard OpenAI API, we need to specify the model
|
|
30
32
|
// Azure OpenAI uses deployment name instead
|
|
31
33
|
const model = constants_1.OPENAI_PROVIDER === 'openai' ? constants_1.OPENAI_MODEL : undefined;
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
34
|
+
this.logger.logModelSettings({
|
|
35
|
+
provider: constants_1.OPENAI_PROVIDER,
|
|
36
|
+
model,
|
|
37
|
+
reasoning: modelSettings.reasoning,
|
|
38
|
+
text: modelSettings.text,
|
|
39
|
+
toolChoice: modelSettings.toolChoice,
|
|
40
|
+
hasRetrieveKnowledge,
|
|
41
|
+
});
|
|
39
42
|
return new agents_1.Agent({
|
|
40
43
|
name: this.name,
|
|
41
44
|
model,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agent-builder.js","sourceRoot":"","sources":["../../src/agent-builder.ts"],"names":[],"mappings":";;;AACA,2CAKuB;AAEvB,2CAA2D;
|
|
1
|
+
{"version":3,"file":"agent-builder.js","sourceRoot":"","sources":["../../src/agent-builder.ts"],"names":[],"mappings":";;;AACA,2CAKuB;AAEvB,2CAA2D;AAE3D,6CAAmD;AACnD,2DAAkD;AAClD,mCAA2D;AAiB3D,MAAa,cAAc;IAUzB,YAAY,OAAoD;QAC9D,IAAI,CAAC,IAAI,GAAG,OAAO,CAAC,IAAI,CAAA;QACxB,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC,oBAAoB,CAC3C,OAAO,CAAC,YAAY,EACpB,OAAO,CAAC,WAAW,EACnB,OAAO,CAAC,gBAAgB,CACzB,CAAA;QACD,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,eAAe,CAAC,OAAO,CAAC,KAAK,EAAE,OAAO,CAAC,SAAS,CAAC,CAAA;QACnE,IAAI,CAAC,eAAe,GAAG,EAAE,CAAA;QACzB,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC,MAAM,CAAA;QAC5B,IAAI,OAAO,CAAC,mBAAmB,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YAC3C,MAAM,cAAc,GAAG,IAAA,iCAAoB,EAAC,OAAO,CAAC,mBAAmB,CAAC,CAAA;YACxE,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,cAAc,CAAC,CAAA;QAC3C,CAAC;IACH,CAAC;IAED,KAAK;QACH,MAAM,aAAa,GAAkB,EAAmB,CAAA;QACxD,IAAI,2BAAe,KAAK,QAAQ,EAAE,CAAC;YACjC,aAAa,CAAC,SAAS,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,CAAA;YAC5C,aAAa,CAAC,IAAI,GAAG,EAAE,SAAS,EAAE,QAAQ,EAAE,CAAA;QAC9C,CAAC;QAED,MAAM,oBAAoB,GAAG,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,yBAAiB,CAAC,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ACP,IAAI,EAAE,kCAAkC;qBACzC;iBACF;aACF;SACF,CAAA;QACD,MAAM,MAAM,GAAG,yIAAyI,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,cAAc,CAAA;QAC7L,OAAO,aAAa,MAAM,aAAa,CAAA;IACzC,CAAC;IAEO,eAAe,CACrB,KAAmC,EACnC,SAAmB;QAEnB,MAAM,YAAY,GAAW,CAAC,GAAG,sBAAc,CAAC,CAAA;QAChD,IAAI,SAAS,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YACzB,YAAY,CAAC,IAAI,CAAC,yBAAiB,CAAC,CAAA;QACtC,CAAC;QACD,OAAO,CAAC,GAAG,YAAY,EAAE,GAAG,KAAK,CAAC,CAAA;IACpC,CAAC;CACF;AAlJD,wCAkJC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { AiAgentArgs } from '@botonic/core';
|
|
2
|
+
import { AgenticInputMessage, MemoryOptions, RunResult } from './types';
|
|
3
|
+
export interface DebugLoggerConfig {
|
|
4
|
+
messageHistoryApiVersion: string;
|
|
5
|
+
maxRetries: number;
|
|
6
|
+
timeout: number;
|
|
7
|
+
customToolNames: string[];
|
|
8
|
+
memory: MemoryOptions;
|
|
9
|
+
}
|
|
10
|
+
export interface ModelSettingsInfo {
|
|
11
|
+
provider: string;
|
|
12
|
+
model: string | undefined;
|
|
13
|
+
reasoning?: {
|
|
14
|
+
effort: string;
|
|
15
|
+
};
|
|
16
|
+
text?: {
|
|
17
|
+
verbosity: string;
|
|
18
|
+
};
|
|
19
|
+
toolChoice?: string;
|
|
20
|
+
hasRetrieveKnowledge: boolean;
|
|
21
|
+
}
|
|
22
|
+
export interface DebugLogger {
|
|
23
|
+
logInitialConfig(config: DebugLoggerConfig): void;
|
|
24
|
+
logAgentDebugInfo(aiAgentArgs: AiAgentArgs, toolNames: string[], messages: AgenticInputMessage[]): void;
|
|
25
|
+
logModelSettings(settings: ModelSettingsInfo): void;
|
|
26
|
+
logRunnerStart(): void;
|
|
27
|
+
logRunResult(runResult: RunResult, startTime: number): void;
|
|
28
|
+
logGuardrailTriggered(): void;
|
|
29
|
+
logRunnerError(startTime: number, error: unknown): void;
|
|
30
|
+
}
|
|
31
|
+
export declare function createDebugLogger(enableDebug: boolean): DebugLogger;
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createDebugLogger = createDebugLogger;
|
|
4
|
+
const constants_1 = require("./constants");
|
|
5
|
+
const PREFIX = '[BotonicPluginAiAgents]';
|
|
6
|
+
class EnabledDebugLogger {
|
|
7
|
+
getModelInfo() {
|
|
8
|
+
const model = constants_1.OPENAI_PROVIDER === 'azure'
|
|
9
|
+
? constants_1.AZURE_OPENAI_API_DEPLOYMENT_NAME
|
|
10
|
+
: constants_1.OPENAI_MODEL;
|
|
11
|
+
const apiBase = constants_1.OPENAI_PROVIDER === 'azure' && constants_1.AZURE_OPENAI_API_BASE
|
|
12
|
+
? constants_1.AZURE_OPENAI_API_BASE
|
|
13
|
+
: 'OpenAI API';
|
|
14
|
+
return { model, apiBase };
|
|
15
|
+
}
|
|
16
|
+
logInitialConfig(config) {
|
|
17
|
+
const { model, apiBase } = this.getModelInfo();
|
|
18
|
+
console.log(`${PREFIX} === Plugin Initialization ===`);
|
|
19
|
+
console.log(`${PREFIX} Provider: ${constants_1.OPENAI_PROVIDER}`);
|
|
20
|
+
console.log(`${PREFIX} Model/Deployment: ${model}`);
|
|
21
|
+
console.log(`${PREFIX} API Base: ${apiBase}`);
|
|
22
|
+
console.log(`${PREFIX} Message History API Version: ${config.messageHistoryApiVersion}`);
|
|
23
|
+
console.log(`${PREFIX} Max Retries: ${config.maxRetries}`);
|
|
24
|
+
console.log(`${PREFIX} Timeout: ${config.timeout}ms`);
|
|
25
|
+
console.log(`${PREFIX} Custom Tools Registered: ${config.customToolNames.join(', ') || 'none'}`);
|
|
26
|
+
console.log(`${PREFIX} Memory Options:`, {
|
|
27
|
+
maxMessages: config.memory.maxMessages ?? constants_1.MAX_MEMORY_LENGTH,
|
|
28
|
+
includeToolCalls: config.memory.includeToolCalls ?? true,
|
|
29
|
+
maxFullToolResults: config.memory.maxFullToolResults ?? 1,
|
|
30
|
+
debugMode: config.memory.debugMode ?? false,
|
|
31
|
+
});
|
|
32
|
+
console.log(`${PREFIX} === End Plugin Initialization ===`);
|
|
33
|
+
}
|
|
34
|
+
logAgentDebugInfo(aiAgentArgs, toolNames, messages) {
|
|
35
|
+
console.log(`${PREFIX} === AI Agent Debug Info ===`);
|
|
36
|
+
console.log(`${PREFIX} Agent Name: ${aiAgentArgs.name}`);
|
|
37
|
+
console.log(`${PREFIX} Active Tools: ${JSON.stringify(toolNames)}`);
|
|
38
|
+
console.log(`${PREFIX} Source IDs: ${JSON.stringify(aiAgentArgs.sourceIds || [])}`);
|
|
39
|
+
console.log(`${PREFIX} Message History Count: ${messages.length}`);
|
|
40
|
+
console.log(`${PREFIX} Input Guardrail Rules: ${aiAgentArgs.inputGuardrailRules?.length || 0}`);
|
|
41
|
+
console.log(`${PREFIX} Instructions:`);
|
|
42
|
+
console.log(aiAgentArgs.instructions);
|
|
43
|
+
console.log(`${PREFIX} === End Debug Info ===`);
|
|
44
|
+
}
|
|
45
|
+
logModelSettings(settings) {
|
|
46
|
+
console.log(`${PREFIX} === Agent Model Settings ===`);
|
|
47
|
+
console.log(`${PREFIX} Has Retrieve Knowledge Tool: ${settings.hasRetrieveKnowledge}`);
|
|
48
|
+
if (settings.reasoning) {
|
|
49
|
+
console.log(`${PREFIX} Reasoning Effort: ${settings.reasoning.effort}`);
|
|
50
|
+
}
|
|
51
|
+
if (settings.text) {
|
|
52
|
+
console.log(`${PREFIX} Text Verbosity: ${settings.text.verbosity}`);
|
|
53
|
+
}
|
|
54
|
+
if (settings.toolChoice) {
|
|
55
|
+
console.log(`${PREFIX} Tool Choice: ${settings.toolChoice}`);
|
|
56
|
+
}
|
|
57
|
+
console.log(`${PREFIX} === End Model Settings ===`);
|
|
58
|
+
}
|
|
59
|
+
logRunnerStart() {
|
|
60
|
+
console.log(`${PREFIX} === Runner Execution Start ===`);
|
|
61
|
+
}
|
|
62
|
+
logRunResult(runResult, startTime) {
|
|
63
|
+
const elapsedMs = Date.now() - startTime;
|
|
64
|
+
console.log(`${PREFIX} === Runner Execution Complete ===`);
|
|
65
|
+
console.log(`${PREFIX} Execution Time: ${elapsedMs}ms`);
|
|
66
|
+
console.log(`${PREFIX} Output Messages Count: ${runResult.messages.length}`);
|
|
67
|
+
console.log(`${PREFIX} Exit: ${runResult.exit}`);
|
|
68
|
+
console.log(`${PREFIX} Error: ${runResult.error}`);
|
|
69
|
+
console.log(`${PREFIX} Tools Executed: ${JSON.stringify(runResult.toolsExecuted.map(t => t.toolName))}`);
|
|
70
|
+
if (runResult.inputGuardrailsTriggered.length > 0) {
|
|
71
|
+
console.log(`${PREFIX} Input Guardrails Triggered: ${runResult.inputGuardrailsTriggered.length}`);
|
|
72
|
+
}
|
|
73
|
+
if (runResult.outputGuardrailsTriggered.length > 0) {
|
|
74
|
+
console.log(`${PREFIX} Output Guardrails Triggered: ${runResult.outputGuardrailsTriggered.length}`);
|
|
75
|
+
}
|
|
76
|
+
console.log(`${PREFIX} === End Runner Execution ===`);
|
|
77
|
+
}
|
|
78
|
+
logGuardrailTriggered() {
|
|
79
|
+
console.log(`${PREFIX} Input guardrail triggered`);
|
|
80
|
+
}
|
|
81
|
+
logRunnerError(startTime, error) {
|
|
82
|
+
const elapsedMs = Date.now() - startTime;
|
|
83
|
+
console.log(`${PREFIX} Runner execution failed after ${elapsedMs}ms`);
|
|
84
|
+
console.log(`${PREFIX} Error:`, error);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
class DisabledDebugLogger {
|
|
88
|
+
logInitialConfig() { }
|
|
89
|
+
logAgentDebugInfo() { }
|
|
90
|
+
logModelSettings() { }
|
|
91
|
+
logRunnerStart() { }
|
|
92
|
+
logRunResult() { }
|
|
93
|
+
logGuardrailTriggered() { }
|
|
94
|
+
logRunnerError() { }
|
|
95
|
+
}
|
|
96
|
+
function createDebugLogger(enableDebug) {
|
|
97
|
+
return enableDebug ? new EnabledDebugLogger() : new DisabledDebugLogger();
|
|
98
|
+
}
|
|
99
|
+
//# sourceMappingURL=debug-logger.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"debug-logger.js","sourceRoot":"","sources":["../../src/debug-logger.ts"],"names":[],"mappings":";;AAuKA,8CAEC;AAvKD,2CAMoB;AAGpB,MAAM,MAAM,GAAG,yBAAyB,CAAA;AAiCxC,MAAM,kBAAkB;IACd,YAAY;QAClB,MAAM,KAAK,GACT,2BAAe,KAAK,OAAO;YACzB,CAAC,CAAC,4CAAgC;YAClC,CAAC,CAAC,wBAAY,CAAA;QAClB,MAAM,OAAO,GACX,2BAAe,KAAK,OAAO,IAAI,iCAAqB;YAClD,CAAC,CAAC,iCAAqB;YACvB,CAAC,CAAC,YAAY,CAAA;QAClB,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,CAAA;IAC3B,CAAC;IAED,gBAAgB,CAAC,MAAyB;QACxC,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC,YAAY,EAAE,CAAA;QAE9C,OAAO,CAAC,GAAG,CAAC,GAAG,MAAM,gCAAgC,CAAC,CAAA;QACtD,OAAO,CAAC,GAAG,CAAC,GAAG,MAAM,cAAc,2BAAe,EAAE,CAAC,CAAA;QACrD,OAAO,CAAC,GAAG,CAAC,GAAG,MAAM,sBAAsB,KAAK,EAAE,CAAC,CAAA;QACnD,OAAO,CAAC,GAAG,CAAC,GAAG,MAAM,cAAc,OAAO,EAAE,CAAC,CAAA;QAC7C,OAAO,CAAC,GAAG,CACT,GAAG,MAAM,iCAAiC,MAAM,CAAC,wBAAwB,EAAE,CAC5E,CAAA;QACD,OAAO,CAAC,GAAG,CAAC,GAAG,MAAM,iBAAiB,MAAM,CAAC,UAAU,E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,KAAK,CAAC,CAAA;IACxC,CAAC;CACF;AAED,MAAM,mBAAmB;IACvB,gBAAgB,KAAU,CAAC;IAC3B,iBAAiB,KAAU,CAAC;IAC5B,gBAAgB,KAAU,CAAC;IAC3B,cAAc,KAAU,CAAC;IACzB,YAAY,KAAU,CAAC;IACvB,qBAAqB,KAAU,CAAC;IAChC,cAAc,KAAU,CAAC;CAC1B;AAED,SAAgB,iBAAiB,CAAC,WAAoB;IACpD,OAAO,WAAW,CAAC,CAAC,CAAC,IAAI,kBAAkB,EAAE,CAAC,CAAC,CAAC,IAAI,mBAAmB,EAAE,CAAA;AAC3E,CAAC"}
|
package/lib/esm/index.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ export default class BotonicPluginAiAgents<TPlugins extends ResolvedPlugins = Re
|
|
|
4
4
|
private readonly authToken?;
|
|
5
5
|
private readonly messageHistoryApiVersion;
|
|
6
6
|
private readonly memory;
|
|
7
|
+
private readonly logger;
|
|
7
8
|
toolDefinitions: CustomTool<TPlugins, TExtraData>[];
|
|
8
9
|
constructor(options?: PluginAiAgentOptions<TPlugins, TExtraData>);
|
|
9
10
|
pre(): void;
|
package/lib/esm/index.js
CHANGED
|
@@ -4,6 +4,7 @@ const tslib_1 = require("tslib");
|
|
|
4
4
|
const agents_1 = require("@openai/agents");
|
|
5
5
|
const agent_builder_1 = require("./agent-builder");
|
|
6
6
|
const constants_1 = require("./constants");
|
|
7
|
+
const debug_logger_1 = require("./debug-logger");
|
|
7
8
|
const hubtype_api_client_1 = require("./hubtype-api-client");
|
|
8
9
|
const openai_1 = require("./openai");
|
|
9
10
|
const runner_1 = require("./runner");
|
|
@@ -19,6 +20,14 @@ class BotonicPluginAiAgents {
|
|
|
19
20
|
this.toolDefinitions = options?.customTools || [];
|
|
20
21
|
this.messageHistoryApiVersion = options?.messageHistoryApiVersion ?? 'v2';
|
|
21
22
|
this.memory = options?.memory ?? {};
|
|
23
|
+
this.logger = (0, debug_logger_1.createDebugLogger)(options?.enableDebug ?? false);
|
|
24
|
+
this.logger.logInitialConfig({
|
|
25
|
+
messageHistoryApiVersion: this.messageHistoryApiVersion,
|
|
26
|
+
maxRetries: options?.maxRetries ?? 2,
|
|
27
|
+
timeout: options?.timeout ?? 16000,
|
|
28
|
+
customToolNames: this.toolDefinitions.map(t => t.name),
|
|
29
|
+
memory: this.memory,
|
|
30
|
+
});
|
|
22
31
|
}
|
|
23
32
|
pre() {
|
|
24
33
|
return;
|
|
@@ -38,6 +47,7 @@ class BotonicPluginAiAgents {
|
|
|
38
47
|
inputGuardrailRules: aiAgentArgs.inputGuardrailRules || [],
|
|
39
48
|
sourceIds: aiAgentArgs.sourceIds || [],
|
|
40
49
|
campaignsContext: request.input.context?.campaigns_v2,
|
|
50
|
+
logger: this.logger,
|
|
41
51
|
}).build();
|
|
42
52
|
const messages = await this.getMessages(request, authToken, constants_1.MAX_MEMORY_LENGTH);
|
|
43
53
|
const context = {
|
|
@@ -51,7 +61,8 @@ class BotonicPluginAiAgents {
|
|
|
51
61
|
},
|
|
52
62
|
request,
|
|
53
63
|
};
|
|
54
|
-
|
|
64
|
+
this.logger.logAgentDebugInfo(aiAgentArgs, tools.map(t => t.name), messages);
|
|
65
|
+
const runner = new runner_1.AIAgentRunner(agent, this.logger);
|
|
55
66
|
return await runner.run(messages, context);
|
|
56
67
|
}
|
|
57
68
|
catch (error) {
|
package/lib/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;AACA,2CAAqC;AAErC,mDAAgD;AAChD,2CAAuD;AACvD,6DAAuD;AACvD,qCAAsC;AACtC,qCAAwC;AAYxC,MAAqB,qBAAqB;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;AACA,2CAAqC;AAErC,mDAAgD;AAChD,2CAAuD;AACvD,iDAA+D;AAC/D,6DAAuD;AACvD,qCAAsC;AACtC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A;IACxB,CAAC;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,EAA0C;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;AA5ID,wCA4IC;AAED,kDAAuB"}
|
package/lib/esm/runner.d.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { ResolvedPlugins } from '@botonic/core';
|
|
2
|
+
import { DebugLogger } from './debug-logger';
|
|
2
3
|
import { AgenticInputMessage, AIAgent, Context, RunResult } from './types';
|
|
3
4
|
export declare class AIAgentRunner<TPlugins extends ResolvedPlugins = ResolvedPlugins, TExtraData = any> {
|
|
4
5
|
private agent;
|
|
5
|
-
|
|
6
|
+
private logger;
|
|
7
|
+
constructor(agent: AIAgent<TPlugins, TExtraData>, logger: DebugLogger);
|
|
6
8
|
run(messages: AgenticInputMessage[], context: Context<TPlugins, TExtraData>): Promise<RunResult>;
|
|
7
9
|
private getToolsExecuted;
|
|
8
10
|
private getToolExecutionInfo;
|
package/lib/esm/runner.js
CHANGED
|
@@ -4,10 +4,13 @@ exports.AIAgentRunner = void 0;
|
|
|
4
4
|
const agents_1 = require("@openai/agents");
|
|
5
5
|
const tools_1 = require("./tools");
|
|
6
6
|
class AIAgentRunner {
|
|
7
|
-
constructor(agent) {
|
|
7
|
+
constructor(agent, logger) {
|
|
8
8
|
this.agent = agent;
|
|
9
|
+
this.logger = logger;
|
|
9
10
|
}
|
|
10
11
|
async run(messages, context) {
|
|
12
|
+
const startTime = Date.now();
|
|
13
|
+
this.logger.logRunnerStart();
|
|
11
14
|
try {
|
|
12
15
|
const runner = new agents_1.Runner({
|
|
13
16
|
modelSettings: { temperature: 0 },
|
|
@@ -21,7 +24,7 @@ class AIAgentRunner {
|
|
|
21
24
|
const hasExit = outputMessages.length === 0 ||
|
|
22
25
|
outputMessages.some(message => message.type === 'exit');
|
|
23
26
|
const toolsExecuted = this.getToolsExecuted(result, context);
|
|
24
|
-
|
|
27
|
+
const runResult = {
|
|
25
28
|
messages: hasExit
|
|
26
29
|
? []
|
|
27
30
|
: outputMessages.filter(message => message.type !== 'exit'),
|
|
@@ -32,10 +35,12 @@ class AIAgentRunner {
|
|
|
32
35
|
inputGuardrailsTriggered: [],
|
|
33
36
|
outputGuardrailsTriggered: [],
|
|
34
37
|
};
|
|
38
|
+
this.logger.logRunResult(runResult, startTime);
|
|
39
|
+
return runResult;
|
|
35
40
|
}
|
|
36
41
|
catch (error) {
|
|
37
42
|
if (error instanceof agents_1.InputGuardrailTripwireTriggered) {
|
|
38
|
-
|
|
43
|
+
const runResult = {
|
|
39
44
|
messages: [],
|
|
40
45
|
memoryLength: 0,
|
|
41
46
|
toolsExecuted: [],
|
|
@@ -44,7 +49,11 @@ class AIAgentRunner {
|
|
|
44
49
|
inputGuardrailsTriggered: error.result.output.outputInfo,
|
|
45
50
|
outputGuardrailsTriggered: [],
|
|
46
51
|
};
|
|
52
|
+
this.logger.logGuardrailTriggered();
|
|
53
|
+
this.logger.logRunResult(runResult, startTime);
|
|
54
|
+
return runResult;
|
|
47
55
|
}
|
|
56
|
+
this.logger.logRunnerError(startTime, error);
|
|
48
57
|
throw error;
|
|
49
58
|
}
|
|
50
59
|
}
|
package/lib/esm/runner.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runner.js","sourceRoot":"","sources":["../../src/runner.ts"],"names":[],"mappings":";;;AACA,2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,oBAAoB,CAC1B,IAAqB,EACrB,OAAsC;QAEtC,IAAI,IAAI,CAAC,OAAO,CAAC,IAAI,KAAK,eAAe,EAAE,CAAC;YAC1C,OAAO;gBACL,QAAQ,EAAE,EAAE;gBACZ,aAAa,EAAE,EAAE;aAClB,CAAA;QACH,CAAC;QACD,MAAM,QAAQ,GAAG,IAAI,CAAC,OAAO,CAAC,IAAI,CAAA;QAClC,MAAM,aAAa,GAAG,IAAI,CAAC,oBAAoB,CAAC,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,CAAA;QAEvE,IAAI,QAAQ,KAAK,yBAAiB,CAAC,IAAI,EAAE,CAAC;YACxC,OAAO;gBACL,QAAQ;gBACR,aAAa;gBACb,uBAAuB,EAAE,OAAO,CAAC,aAAa,CAAC,SAAS;gBACxD,sBAAsB,EAAE,OAAO,CAAC,aAAa,CAAC,SAAS;aACxD,CAAA;QACH,CAAC;QAED,OAAO;YACL,QAAQ;YACR,aAAa;SACd,CAAA;IACH,CAAC;IAEO,oBAAoB,CAAC,gBAAwB;QACnD,IAAI,CAAC;YACH,OAAO,IAAI,CAAC,KAAK,CAAC,gBAAgB,CAAC,CAAA;QACrC,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO,EAAE,CAAA;QACX,CAAC;IACH,CAAC;CACF;AAhID,sCAgIC"}
|
package/lib/esm/types.d.ts
CHANGED
|
@@ -42,6 +42,8 @@ export interface PluginAiAgentOptions<TPlugins extends ResolvedPlugins = Resolve
|
|
|
42
42
|
messageHistoryApiVersion?: MessageHistoryApiVersion;
|
|
43
43
|
/** Options for V2 message history API. Only used when messageHistoryApiVersion is 'v2'. */
|
|
44
44
|
memory?: MemoryOptions;
|
|
45
|
+
/** Enable debug logging for AI agent configuration and execution details. */
|
|
46
|
+
enableDebug?: boolean;
|
|
45
47
|
}
|
|
46
48
|
export type AgenticInputMessage = AgentInputItem;
|
|
47
49
|
export { AgenticOutputMessage, AiAgentArgs, GuardrailRule, InferenceResponse, RunResult, };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@botonic/plugin-ai-agents",
|
|
3
|
-
"version": "0.44.0-alpha.
|
|
3
|
+
"version": "0.44.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",
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
"lint_core": "../../node_modules/.bin/eslint_d --cache --quiet 'src/**/*.ts*'"
|
|
14
14
|
},
|
|
15
15
|
"dependencies": {
|
|
16
|
-
"@botonic/core": "^0.44.0-alpha.
|
|
16
|
+
"@botonic/core": "^0.44.0-alpha.3",
|
|
17
17
|
"@openai/agents": "^0.3.9",
|
|
18
18
|
"axios": "^1.13.2",
|
|
19
19
|
"openai": "^6.0.0",
|
package/src/agent-builder.ts
CHANGED
|
@@ -7,6 +7,7 @@ import {
|
|
|
7
7
|
} from '@openai/agents'
|
|
8
8
|
|
|
9
9
|
import { OPENAI_MODEL, OPENAI_PROVIDER } from './constants'
|
|
10
|
+
import { DebugLogger } from './debug-logger'
|
|
10
11
|
import { createInputGuardrail } from './guardrails'
|
|
11
12
|
import { OutputSchema } from './structured-output'
|
|
12
13
|
import { mandatoryTools, retrieveKnowledge } from './tools'
|
|
@@ -23,6 +24,7 @@ interface AIAgentBuilderOptions<
|
|
|
23
24
|
contactInfo: ContactInfo[]
|
|
24
25
|
inputGuardrailRules: GuardrailRule[]
|
|
25
26
|
sourceIds: string[]
|
|
27
|
+
logger: DebugLogger
|
|
26
28
|
}
|
|
27
29
|
|
|
28
30
|
export class AIAgentBuilder<
|
|
@@ -33,6 +35,7 @@ export class AIAgentBuilder<
|
|
|
33
35
|
private instructions: string
|
|
34
36
|
private tools: Tool<TPlugins, TExtraData>[]
|
|
35
37
|
private inputGuardrails: InputGuardrail[]
|
|
38
|
+
private logger: DebugLogger
|
|
36
39
|
|
|
37
40
|
constructor(options: AIAgentBuilderOptions<TPlugins, TExtraData>) {
|
|
38
41
|
this.name = options.name
|
|
@@ -43,6 +46,7 @@ export class AIAgentBuilder<
|
|
|
43
46
|
)
|
|
44
47
|
this.tools = this.addHubtypeTools(options.tools, options.sourceIds)
|
|
45
48
|
this.inputGuardrails = []
|
|
49
|
+
this.logger = options.logger
|
|
46
50
|
if (options.inputGuardrailRules.length > 0) {
|
|
47
51
|
const inputGuardrail = createInputGuardrail(options.inputGuardrailRules)
|
|
48
52
|
this.inputGuardrails.push(inputGuardrail)
|
|
@@ -56,7 +60,8 @@ export class AIAgentBuilder<
|
|
|
56
60
|
modelSettings.text = { verbosity: 'medium' }
|
|
57
61
|
}
|
|
58
62
|
|
|
59
|
-
|
|
63
|
+
const hasRetrieveKnowledge = this.tools.includes(retrieveKnowledge)
|
|
64
|
+
if (hasRetrieveKnowledge && OPENAI_PROVIDER === 'azure') {
|
|
60
65
|
modelSettings.toolChoice = retrieveKnowledge.name
|
|
61
66
|
}
|
|
62
67
|
|
|
@@ -64,14 +69,19 @@ export class AIAgentBuilder<
|
|
|
64
69
|
// Azure OpenAI uses deployment name instead
|
|
65
70
|
const model = OPENAI_PROVIDER === 'openai' ? OPENAI_MODEL : undefined
|
|
66
71
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
72
|
+
this.logger.logModelSettings({
|
|
73
|
+
provider: OPENAI_PROVIDER,
|
|
74
|
+
model,
|
|
75
|
+
reasoning: modelSettings.reasoning as { effort: string } | undefined,
|
|
76
|
+
text: modelSettings.text as { verbosity: string } | undefined,
|
|
77
|
+
toolChoice: modelSettings.toolChoice as string | undefined,
|
|
78
|
+
hasRetrieveKnowledge,
|
|
79
|
+
})
|
|
80
|
+
|
|
81
|
+
return new Agent<
|
|
82
|
+
Context<TPlugins, TExtraData>,
|
|
83
|
+
AgentOutputType<typeof OutputSchema>
|
|
84
|
+
>({
|
|
75
85
|
name: this.name,
|
|
76
86
|
model,
|
|
77
87
|
instructions: this.instructions,
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
import { AiAgentArgs } from '@botonic/core'
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
AZURE_OPENAI_API_BASE,
|
|
5
|
+
AZURE_OPENAI_API_DEPLOYMENT_NAME,
|
|
6
|
+
MAX_MEMORY_LENGTH,
|
|
7
|
+
OPENAI_MODEL,
|
|
8
|
+
OPENAI_PROVIDER,
|
|
9
|
+
} from './constants'
|
|
10
|
+
import { AgenticInputMessage, MemoryOptions, RunResult } from './types'
|
|
11
|
+
|
|
12
|
+
const PREFIX = '[BotonicPluginAiAgents]'
|
|
13
|
+
|
|
14
|
+
export interface DebugLoggerConfig {
|
|
15
|
+
messageHistoryApiVersion: string
|
|
16
|
+
maxRetries: number
|
|
17
|
+
timeout: number
|
|
18
|
+
customToolNames: string[]
|
|
19
|
+
memory: MemoryOptions
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export interface ModelSettingsInfo {
|
|
23
|
+
provider: string
|
|
24
|
+
model: string | undefined
|
|
25
|
+
reasoning?: { effort: string }
|
|
26
|
+
text?: { verbosity: string }
|
|
27
|
+
toolChoice?: string
|
|
28
|
+
hasRetrieveKnowledge: boolean
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export interface DebugLogger {
|
|
32
|
+
logInitialConfig(config: DebugLoggerConfig): void
|
|
33
|
+
logAgentDebugInfo(
|
|
34
|
+
aiAgentArgs: AiAgentArgs,
|
|
35
|
+
toolNames: string[],
|
|
36
|
+
messages: AgenticInputMessage[]
|
|
37
|
+
): void
|
|
38
|
+
logModelSettings(settings: ModelSettingsInfo): void
|
|
39
|
+
logRunnerStart(): void
|
|
40
|
+
logRunResult(runResult: RunResult, startTime: number): void
|
|
41
|
+
logGuardrailTriggered(): void
|
|
42
|
+
logRunnerError(startTime: number, error: unknown): void
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
class EnabledDebugLogger implements DebugLogger {
|
|
46
|
+
private getModelInfo(): { model: string; apiBase: string } {
|
|
47
|
+
const model =
|
|
48
|
+
OPENAI_PROVIDER === 'azure'
|
|
49
|
+
? AZURE_OPENAI_API_DEPLOYMENT_NAME
|
|
50
|
+
: OPENAI_MODEL
|
|
51
|
+
const apiBase =
|
|
52
|
+
OPENAI_PROVIDER === 'azure' && AZURE_OPENAI_API_BASE
|
|
53
|
+
? AZURE_OPENAI_API_BASE
|
|
54
|
+
: 'OpenAI API'
|
|
55
|
+
return { model, apiBase }
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
logInitialConfig(config: DebugLoggerConfig): void {
|
|
59
|
+
const { model, apiBase } = this.getModelInfo()
|
|
60
|
+
|
|
61
|
+
console.log(`${PREFIX} === Plugin Initialization ===`)
|
|
62
|
+
console.log(`${PREFIX} Provider: ${OPENAI_PROVIDER}`)
|
|
63
|
+
console.log(`${PREFIX} Model/Deployment: ${model}`)
|
|
64
|
+
console.log(`${PREFIX} API Base: ${apiBase}`)
|
|
65
|
+
console.log(
|
|
66
|
+
`${PREFIX} Message History API Version: ${config.messageHistoryApiVersion}`
|
|
67
|
+
)
|
|
68
|
+
console.log(`${PREFIX} Max Retries: ${config.maxRetries}`)
|
|
69
|
+
console.log(`${PREFIX} Timeout: ${config.timeout}ms`)
|
|
70
|
+
console.log(
|
|
71
|
+
`${PREFIX} Custom Tools Registered: ${config.customToolNames.join(', ') || 'none'}`
|
|
72
|
+
)
|
|
73
|
+
console.log(`${PREFIX} Memory Options:`, {
|
|
74
|
+
maxMessages: config.memory.maxMessages ?? MAX_MEMORY_LENGTH,
|
|
75
|
+
includeToolCalls: config.memory.includeToolCalls ?? true,
|
|
76
|
+
maxFullToolResults: config.memory.maxFullToolResults ?? 1,
|
|
77
|
+
debugMode: config.memory.debugMode ?? false,
|
|
78
|
+
})
|
|
79
|
+
console.log(`${PREFIX} === End Plugin Initialization ===`)
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
logAgentDebugInfo(
|
|
83
|
+
aiAgentArgs: AiAgentArgs,
|
|
84
|
+
toolNames: string[],
|
|
85
|
+
messages: AgenticInputMessage[]
|
|
86
|
+
): void {
|
|
87
|
+
console.log(`${PREFIX} === AI Agent Debug Info ===`)
|
|
88
|
+
console.log(`${PREFIX} Agent Name: ${aiAgentArgs.name}`)
|
|
89
|
+
console.log(`${PREFIX} Active Tools: ${JSON.stringify(toolNames)}`)
|
|
90
|
+
console.log(
|
|
91
|
+
`${PREFIX} Source IDs: ${JSON.stringify(aiAgentArgs.sourceIds || [])}`
|
|
92
|
+
)
|
|
93
|
+
console.log(`${PREFIX} Message History Count: ${messages.length}`)
|
|
94
|
+
console.log(
|
|
95
|
+
`${PREFIX} Input Guardrail Rules: ${aiAgentArgs.inputGuardrailRules?.length || 0}`
|
|
96
|
+
)
|
|
97
|
+
console.log(`${PREFIX} Instructions:`)
|
|
98
|
+
console.log(aiAgentArgs.instructions)
|
|
99
|
+
console.log(`${PREFIX} === End Debug Info ===`)
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
logModelSettings(settings: ModelSettingsInfo): void {
|
|
103
|
+
console.log(`${PREFIX} === Agent Model Settings ===`)
|
|
104
|
+
console.log(
|
|
105
|
+
`${PREFIX} Has Retrieve Knowledge Tool: ${settings.hasRetrieveKnowledge}`
|
|
106
|
+
)
|
|
107
|
+
if (settings.reasoning) {
|
|
108
|
+
console.log(`${PREFIX} Reasoning Effort: ${settings.reasoning.effort}`)
|
|
109
|
+
}
|
|
110
|
+
if (settings.text) {
|
|
111
|
+
console.log(`${PREFIX} Text Verbosity: ${settings.text.verbosity}`)
|
|
112
|
+
}
|
|
113
|
+
if (settings.toolChoice) {
|
|
114
|
+
console.log(`${PREFIX} Tool Choice: ${settings.toolChoice}`)
|
|
115
|
+
}
|
|
116
|
+
console.log(`${PREFIX} === End Model Settings ===`)
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
logRunnerStart(): void {
|
|
120
|
+
console.log(`${PREFIX} === Runner Execution Start ===`)
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
logRunResult(runResult: RunResult, startTime: number): void {
|
|
124
|
+
const elapsedMs = Date.now() - startTime
|
|
125
|
+
|
|
126
|
+
console.log(`${PREFIX} === Runner Execution Complete ===`)
|
|
127
|
+
console.log(`${PREFIX} Execution Time: ${elapsedMs}ms`)
|
|
128
|
+
console.log(`${PREFIX} Output Messages Count: ${runResult.messages.length}`)
|
|
129
|
+
console.log(`${PREFIX} Exit: ${runResult.exit}`)
|
|
130
|
+
console.log(`${PREFIX} Error: ${runResult.error}`)
|
|
131
|
+
console.log(
|
|
132
|
+
`${PREFIX} Tools Executed: ${JSON.stringify(runResult.toolsExecuted.map(t => t.toolName))}`
|
|
133
|
+
)
|
|
134
|
+
if (runResult.inputGuardrailsTriggered.length > 0) {
|
|
135
|
+
console.log(
|
|
136
|
+
`${PREFIX} Input Guardrails Triggered: ${runResult.inputGuardrailsTriggered.length}`
|
|
137
|
+
)
|
|
138
|
+
}
|
|
139
|
+
if (runResult.outputGuardrailsTriggered.length > 0) {
|
|
140
|
+
console.log(
|
|
141
|
+
`${PREFIX} Output Guardrails Triggered: ${runResult.outputGuardrailsTriggered.length}`
|
|
142
|
+
)
|
|
143
|
+
}
|
|
144
|
+
console.log(`${PREFIX} === End Runner Execution ===`)
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
logGuardrailTriggered(): void {
|
|
148
|
+
console.log(`${PREFIX} Input guardrail triggered`)
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
logRunnerError(startTime: number, error: unknown): void {
|
|
152
|
+
const elapsedMs = Date.now() - startTime
|
|
153
|
+
console.log(`${PREFIX} Runner execution failed after ${elapsedMs}ms`)
|
|
154
|
+
console.log(`${PREFIX} Error:`, error)
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
class DisabledDebugLogger implements DebugLogger {
|
|
159
|
+
logInitialConfig(): void {}
|
|
160
|
+
logAgentDebugInfo(): void {}
|
|
161
|
+
logModelSettings(): void {}
|
|
162
|
+
logRunnerStart(): void {}
|
|
163
|
+
logRunResult(): void {}
|
|
164
|
+
logGuardrailTriggered(): void {}
|
|
165
|
+
logRunnerError(): void {}
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
export function createDebugLogger(enableDebug: boolean): DebugLogger {
|
|
169
|
+
return enableDebug ? new EnabledDebugLogger() : new DisabledDebugLogger()
|
|
170
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { tool } from '@openai/agents'
|
|
|
3
3
|
|
|
4
4
|
import { AIAgentBuilder } from './agent-builder'
|
|
5
5
|
import { isProd, MAX_MEMORY_LENGTH } from './constants'
|
|
6
|
+
import { createDebugLogger, DebugLogger } from './debug-logger'
|
|
6
7
|
import { HubtypeApiClient } from './hubtype-api-client'
|
|
7
8
|
import { setUpOpenAI } from './openai'
|
|
8
9
|
import { AIAgentRunner } from './runner'
|
|
@@ -24,6 +25,7 @@ export default class BotonicPluginAiAgents<
|
|
|
24
25
|
private readonly authToken?: string
|
|
25
26
|
private readonly messageHistoryApiVersion: MessageHistoryApiVersion
|
|
26
27
|
private readonly memory: MemoryOptions
|
|
28
|
+
private readonly logger: DebugLogger
|
|
27
29
|
public toolDefinitions: CustomTool<TPlugins, TExtraData>[] = []
|
|
28
30
|
|
|
29
31
|
constructor(options?: PluginAiAgentOptions<TPlugins, TExtraData>) {
|
|
@@ -40,6 +42,15 @@ export default class BotonicPluginAiAgents<
|
|
|
40
42
|
this.toolDefinitions = options?.customTools || []
|
|
41
43
|
this.messageHistoryApiVersion = options?.messageHistoryApiVersion ?? 'v2'
|
|
42
44
|
this.memory = options?.memory ?? {}
|
|
45
|
+
this.logger = createDebugLogger(options?.enableDebug ?? false)
|
|
46
|
+
|
|
47
|
+
this.logger.logInitialConfig({
|
|
48
|
+
messageHistoryApiVersion: this.messageHistoryApiVersion,
|
|
49
|
+
maxRetries: options?.maxRetries ?? 2,
|
|
50
|
+
timeout: options?.timeout ?? 16000,
|
|
51
|
+
customToolNames: this.toolDefinitions.map(t => t.name),
|
|
52
|
+
memory: this.memory,
|
|
53
|
+
})
|
|
43
54
|
}
|
|
44
55
|
|
|
45
56
|
pre(): void {
|
|
@@ -67,6 +78,7 @@ export default class BotonicPluginAiAgents<
|
|
|
67
78
|
inputGuardrailRules: aiAgentArgs.inputGuardrailRules || [],
|
|
68
79
|
sourceIds: aiAgentArgs.sourceIds || [],
|
|
69
80
|
campaignsContext: request.input.context?.campaigns_v2,
|
|
81
|
+
logger: this.logger,
|
|
70
82
|
}).build()
|
|
71
83
|
|
|
72
84
|
const messages = await this.getMessages(
|
|
@@ -86,7 +98,13 @@ export default class BotonicPluginAiAgents<
|
|
|
86
98
|
request,
|
|
87
99
|
}
|
|
88
100
|
|
|
89
|
-
|
|
101
|
+
this.logger.logAgentDebugInfo(
|
|
102
|
+
aiAgentArgs,
|
|
103
|
+
tools.map(t => t.name),
|
|
104
|
+
messages
|
|
105
|
+
)
|
|
106
|
+
|
|
107
|
+
const runner = new AIAgentRunner<TPlugins, TExtraData>(agent, this.logger)
|
|
90
108
|
return await runner.run(messages, context)
|
|
91
109
|
} catch (error) {
|
|
92
110
|
console.error('error plugin returns undefined', error)
|
package/src/runner.ts
CHANGED
|
@@ -5,6 +5,7 @@ import {
|
|
|
5
5
|
RunToolCallItem,
|
|
6
6
|
} from '@openai/agents'
|
|
7
7
|
|
|
8
|
+
import { DebugLogger } from './debug-logger'
|
|
8
9
|
import { retrieveKnowledge } from './tools'
|
|
9
10
|
import {
|
|
10
11
|
AgenticInputMessage,
|
|
@@ -28,15 +29,21 @@ export class AIAgentRunner<
|
|
|
28
29
|
TExtraData = any,
|
|
29
30
|
> {
|
|
30
31
|
private agent: AIAgent<TPlugins, TExtraData>
|
|
32
|
+
private logger: DebugLogger
|
|
31
33
|
|
|
32
|
-
constructor(agent: AIAgent<TPlugins, TExtraData
|
|
34
|
+
constructor(agent: AIAgent<TPlugins, TExtraData>, logger: DebugLogger) {
|
|
33
35
|
this.agent = agent
|
|
36
|
+
this.logger = logger
|
|
34
37
|
}
|
|
35
38
|
|
|
36
39
|
async run(
|
|
37
40
|
messages: AgenticInputMessage[],
|
|
38
41
|
context: Context<TPlugins, TExtraData>
|
|
39
42
|
): Promise<RunResult> {
|
|
43
|
+
const startTime = Date.now()
|
|
44
|
+
|
|
45
|
+
this.logger.logRunnerStart()
|
|
46
|
+
|
|
40
47
|
try {
|
|
41
48
|
const runner = new Runner({
|
|
42
49
|
modelSettings: { temperature: 0 },
|
|
@@ -53,7 +60,7 @@ export class AIAgentRunner<
|
|
|
53
60
|
outputMessages.some(message => message.type === 'exit')
|
|
54
61
|
const toolsExecuted = this.getToolsExecuted(result, context)
|
|
55
62
|
|
|
56
|
-
|
|
63
|
+
const runResult: RunResult = {
|
|
57
64
|
messages: hasExit
|
|
58
65
|
? []
|
|
59
66
|
: (outputMessages.filter(
|
|
@@ -66,9 +73,13 @@ export class AIAgentRunner<
|
|
|
66
73
|
inputGuardrailsTriggered: [],
|
|
67
74
|
outputGuardrailsTriggered: [],
|
|
68
75
|
}
|
|
76
|
+
|
|
77
|
+
this.logger.logRunResult(runResult, startTime)
|
|
78
|
+
|
|
79
|
+
return runResult
|
|
69
80
|
} catch (error) {
|
|
70
81
|
if (error instanceof InputGuardrailTripwireTriggered) {
|
|
71
|
-
|
|
82
|
+
const runResult: RunResult = {
|
|
72
83
|
messages: [],
|
|
73
84
|
memoryLength: 0,
|
|
74
85
|
toolsExecuted: [],
|
|
@@ -77,7 +88,15 @@ export class AIAgentRunner<
|
|
|
77
88
|
inputGuardrailsTriggered: error.result.output.outputInfo,
|
|
78
89
|
outputGuardrailsTriggered: [],
|
|
79
90
|
}
|
|
91
|
+
|
|
92
|
+
this.logger.logGuardrailTriggered()
|
|
93
|
+
this.logger.logRunResult(runResult, startTime)
|
|
94
|
+
|
|
95
|
+
return runResult
|
|
80
96
|
}
|
|
97
|
+
|
|
98
|
+
this.logger.logRunnerError(startTime, error)
|
|
99
|
+
|
|
81
100
|
throw error
|
|
82
101
|
}
|
|
83
102
|
}
|
package/src/types.ts
CHANGED
|
@@ -87,6 +87,8 @@ export interface PluginAiAgentOptions<
|
|
|
87
87
|
messageHistoryApiVersion?: MessageHistoryApiVersion
|
|
88
88
|
/** Options for V2 message history API. Only used when messageHistoryApiVersion is 'v2'. */
|
|
89
89
|
memory?: MemoryOptions
|
|
90
|
+
/** Enable debug logging for AI agent configuration and execution details. */
|
|
91
|
+
enableDebug?: boolean
|
|
90
92
|
}
|
|
91
93
|
|
|
92
94
|
export type AgenticInputMessage = AgentInputItem
|