@botonic/plugin-ai-agents 0.48.0 → 0.49.0-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cjs/agents/base-agent.d.ts +28 -0
- package/lib/cjs/agents/base-agent.js +39 -0
- package/lib/cjs/agents/base-agent.js.map +1 -0
- package/lib/cjs/agents/index.d.ts +2 -0
- package/lib/cjs/agents/index.js +8 -0
- package/lib/cjs/agents/index.js.map +1 -0
- package/lib/cjs/agents/router-agent.d.ts +25 -0
- package/lib/cjs/agents/router-agent.js +33 -0
- package/lib/cjs/agents/router-agent.js.map +1 -0
- package/lib/cjs/agents/worker-agent.d.ts +35 -0
- package/lib/cjs/{agent-builder.js → agents/worker-agent.js} +48 -49
- package/lib/cjs/agents/worker-agent.js.map +1 -0
- package/lib/cjs/bot-config-tools.js +3 -4
- package/lib/cjs/bot-config-tools.js.map +1 -1
- package/lib/cjs/debug-logger.d.ts +1 -1
- package/lib/cjs/debug-logger.js +4 -1
- package/lib/cjs/debug-logger.js.map +1 -1
- package/lib/cjs/guardrails/input.d.ts +1 -1
- package/lib/cjs/guardrails/input.js +25 -9
- package/lib/cjs/guardrails/input.js.map +1 -1
- package/lib/cjs/index.d.ts +4 -1
- package/lib/cjs/index.js +112 -51
- package/lib/cjs/index.js.map +1 -1
- package/lib/cjs/llm-config.d.ts +2 -1
- package/lib/cjs/llm-config.js +3 -0
- package/lib/cjs/llm-config.js.map +1 -1
- package/lib/cjs/runners/base-runner.d.ts +26 -0
- package/lib/cjs/runners/base-runner.js +114 -0
- package/lib/cjs/runners/base-runner.js.map +1 -0
- package/lib/cjs/runners/index.d.ts +2 -0
- package/lib/cjs/runners/index.js +8 -0
- package/lib/cjs/runners/index.js.map +1 -0
- package/lib/cjs/runners/router-runner.d.ts +6 -0
- package/lib/cjs/runners/router-runner.js +29 -0
- package/lib/cjs/runners/router-runner.js.map +1 -0
- package/lib/cjs/runners/worker-runner.d.ts +10 -0
- package/lib/cjs/runners/worker-runner.js +78 -0
- package/lib/cjs/runners/worker-runner.js.map +1 -0
- package/lib/cjs/structured-output/bot-executor.d.ts +6 -42
- package/lib/cjs/structured-output/bot-executor.js +9 -9
- package/lib/cjs/structured-output/bot-executor.js.map +1 -1
- package/lib/cjs/structured-output/carousel.d.ts +6 -78
- package/lib/cjs/structured-output/carousel.js +2 -1
- package/lib/cjs/structured-output/carousel.js.map +1 -1
- package/lib/cjs/structured-output/exit.d.ts +4 -8
- package/lib/cjs/structured-output/exit.js +4 -4
- package/lib/cjs/structured-output/exit.js.map +1 -1
- package/lib/cjs/structured-output/index.d.ts +48 -553
- package/lib/cjs/structured-output/index.js +15 -0
- package/lib/cjs/structured-output/index.js.map +1 -1
- package/lib/cjs/structured-output/text-with-buttons.d.ts +10 -49
- package/lib/cjs/structured-output/text-with-buttons.js +10 -10
- package/lib/cjs/structured-output/text-with-buttons.js.map +1 -1
- package/lib/cjs/structured-output/text.d.ts +4 -18
- package/lib/cjs/structured-output/text.js +2 -1
- package/lib/cjs/structured-output/text.js.map +1 -1
- package/lib/cjs/tools/index.d.ts +1 -1
- package/lib/cjs/tools/index.js +3 -2
- package/lib/cjs/tools/index.js.map +1 -1
- package/lib/cjs/tools/retrieve-knowledge.d.ts +3 -6
- package/lib/cjs/tools/retrieve-knowledge.js +7 -5
- package/lib/cjs/tools/retrieve-knowledge.js.map +1 -1
- package/lib/cjs/types.d.ts +2 -3
- package/lib/esm/agents/base-agent.d.ts +28 -0
- package/lib/esm/agents/base-agent.js +39 -0
- package/lib/esm/agents/base-agent.js.map +1 -0
- package/lib/esm/agents/index.d.ts +2 -0
- package/lib/esm/agents/index.js +8 -0
- package/lib/esm/agents/index.js.map +1 -0
- package/lib/esm/agents/router-agent.d.ts +25 -0
- package/lib/esm/agents/router-agent.js +33 -0
- package/lib/esm/agents/router-agent.js.map +1 -0
- package/lib/esm/agents/worker-agent.d.ts +35 -0
- package/lib/esm/{agent-builder.js → agents/worker-agent.js} +48 -49
- package/lib/esm/agents/worker-agent.js.map +1 -0
- package/lib/esm/bot-config-tools.js +3 -4
- package/lib/esm/bot-config-tools.js.map +1 -1
- package/lib/esm/debug-logger.d.ts +1 -1
- package/lib/esm/debug-logger.js +4 -1
- package/lib/esm/debug-logger.js.map +1 -1
- package/lib/esm/guardrails/input.d.ts +1 -1
- package/lib/esm/guardrails/input.js +25 -9
- package/lib/esm/guardrails/input.js.map +1 -1
- package/lib/esm/index.d.ts +4 -1
- package/lib/esm/index.js +112 -51
- package/lib/esm/index.js.map +1 -1
- package/lib/esm/llm-config.d.ts +2 -1
- package/lib/esm/llm-config.js +3 -0
- package/lib/esm/llm-config.js.map +1 -1
- package/lib/esm/runners/base-runner.d.ts +26 -0
- package/lib/esm/runners/base-runner.js +114 -0
- package/lib/esm/runners/base-runner.js.map +1 -0
- package/lib/esm/runners/index.d.ts +2 -0
- package/lib/esm/runners/index.js +8 -0
- package/lib/esm/runners/index.js.map +1 -0
- package/lib/esm/runners/router-runner.d.ts +6 -0
- package/lib/esm/runners/router-runner.js +29 -0
- package/lib/esm/runners/router-runner.js.map +1 -0
- package/lib/esm/runners/worker-runner.d.ts +10 -0
- package/lib/esm/runners/worker-runner.js +78 -0
- package/lib/esm/runners/worker-runner.js.map +1 -0
- package/lib/esm/structured-output/bot-executor.d.ts +6 -42
- package/lib/esm/structured-output/bot-executor.js +9 -9
- package/lib/esm/structured-output/bot-executor.js.map +1 -1
- package/lib/esm/structured-output/carousel.d.ts +6 -78
- package/lib/esm/structured-output/carousel.js +2 -1
- package/lib/esm/structured-output/carousel.js.map +1 -1
- package/lib/esm/structured-output/exit.d.ts +4 -8
- package/lib/esm/structured-output/exit.js +4 -4
- package/lib/esm/structured-output/exit.js.map +1 -1
- package/lib/esm/structured-output/index.d.ts +48 -553
- package/lib/esm/structured-output/index.js +15 -0
- package/lib/esm/structured-output/index.js.map +1 -1
- package/lib/esm/structured-output/text-with-buttons.d.ts +10 -49
- package/lib/esm/structured-output/text-with-buttons.js +10 -10
- package/lib/esm/structured-output/text-with-buttons.js.map +1 -1
- package/lib/esm/structured-output/text.d.ts +4 -18
- package/lib/esm/structured-output/text.js +2 -1
- package/lib/esm/structured-output/text.js.map +1 -1
- package/lib/esm/tools/index.d.ts +1 -1
- package/lib/esm/tools/index.js +3 -2
- package/lib/esm/tools/index.js.map +1 -1
- package/lib/esm/tools/retrieve-knowledge.d.ts +3 -6
- package/lib/esm/tools/retrieve-knowledge.js +7 -5
- package/lib/esm/tools/retrieve-knowledge.js.map +1 -1
- package/lib/esm/types.d.ts +2 -3
- package/package.json +6 -7
- package/src/agents/base-agent.ts +75 -0
- package/src/agents/index.ts +2 -0
- package/src/agents/router-agent.ts +71 -0
- package/src/{agent-builder.ts → agents/worker-agent.ts} +75 -77
- package/src/bot-config-tools.ts +3 -4
- package/src/debug-logger.ts +10 -4
- package/src/guardrails/input.ts +35 -9
- package/src/index.ts +216 -82
- package/src/llm-config.ts +5 -0
- package/src/runners/base-runner.ts +190 -0
- package/src/runners/index.ts +2 -0
- package/src/runners/router-runner.ts +41 -0
- package/src/runners/worker-runner.ts +112 -0
- package/src/structured-output/bot-executor.ts +3 -3
- package/src/structured-output/carousel.ts +2 -2
- package/src/structured-output/exit.ts +3 -3
- package/src/structured-output/index.ts +15 -0
- package/src/structured-output/text-with-buttons.ts +3 -3
- package/src/structured-output/text.ts +2 -2
- package/src/tools/index.ts +4 -1
- package/src/tools/retrieve-knowledge.ts +32 -29
- package/src/types.ts +2 -3
- package/lib/cjs/agent-builder.d.ts +0 -37
- package/lib/cjs/agent-builder.js.map +0 -1
- package/lib/cjs/runner.d.ts +0 -18
- package/lib/cjs/runner.js +0 -180
- package/lib/cjs/runner.js.map +0 -1
- package/lib/esm/agent-builder.d.ts +0 -37
- package/lib/esm/agent-builder.js.map +0 -1
- package/lib/esm/runner.d.ts +0 -18
- package/lib/esm/runner.js +0 -180
- package/lib/esm/runner.js.map +0 -1
- package/src/runner.ts +0 -283
|
@@ -1,56 +1,17 @@
|
|
|
1
|
-
import type
|
|
2
|
-
import z from 'zod';
|
|
1
|
+
import { OutputMessageType, type TextWithButtonsMessage } from '@botonic/core';
|
|
2
|
+
import { z } from 'zod';
|
|
3
3
|
export type { TextWithButtonsMessage };
|
|
4
4
|
export declare const TextWithButtonsSchema: z.ZodObject<{
|
|
5
|
-
type: z.
|
|
5
|
+
type: z.ZodLiteral<OutputMessageType.TextWithButtons>;
|
|
6
6
|
content: z.ZodObject<{
|
|
7
7
|
text: z.ZodString;
|
|
8
8
|
buttons: z.ZodArray<z.ZodObject<{
|
|
9
9
|
text: z.ZodString;
|
|
10
10
|
url: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
11
|
-
target: z.ZodOptional<z.ZodNullable<z.ZodDefault<z.ZodEnum<
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
url?: string | null | undefined;
|
|
19
|
-
target?: "_blank" | "_self" | null | undefined;
|
|
20
|
-
}>, "many">;
|
|
21
|
-
}, "strip", z.ZodTypeAny, {
|
|
22
|
-
text: string;
|
|
23
|
-
buttons: {
|
|
24
|
-
text: string;
|
|
25
|
-
url?: string | null | undefined;
|
|
26
|
-
target?: "_blank" | "_self" | null | undefined;
|
|
27
|
-
}[];
|
|
28
|
-
}, {
|
|
29
|
-
text: string;
|
|
30
|
-
buttons: {
|
|
31
|
-
text: string;
|
|
32
|
-
url?: string | null | undefined;
|
|
33
|
-
target?: "_blank" | "_self" | null | undefined;
|
|
34
|
-
}[];
|
|
35
|
-
}>;
|
|
36
|
-
}, "strip", z.ZodTypeAny, {
|
|
37
|
-
type: "textWithButtons";
|
|
38
|
-
content: {
|
|
39
|
-
text: string;
|
|
40
|
-
buttons: {
|
|
41
|
-
text: string;
|
|
42
|
-
url?: string | null | undefined;
|
|
43
|
-
target?: "_blank" | "_self" | null | undefined;
|
|
44
|
-
}[];
|
|
45
|
-
};
|
|
46
|
-
}, {
|
|
47
|
-
type: "textWithButtons";
|
|
48
|
-
content: {
|
|
49
|
-
text: string;
|
|
50
|
-
buttons: {
|
|
51
|
-
text: string;
|
|
52
|
-
url?: string | null | undefined;
|
|
53
|
-
target?: "_blank" | "_self" | null | undefined;
|
|
54
|
-
}[];
|
|
55
|
-
};
|
|
56
|
-
}>;
|
|
11
|
+
target: z.ZodOptional<z.ZodNullable<z.ZodDefault<z.ZodEnum<{
|
|
12
|
+
_blank: "_blank";
|
|
13
|
+
_self: "_self";
|
|
14
|
+
}>>>>;
|
|
15
|
+
}, z.core.$strip>>;
|
|
16
|
+
}, z.core.$strip>;
|
|
17
|
+
}, z.core.$strip>;
|
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.TextWithButtonsSchema = void 0;
|
|
4
|
-
const
|
|
5
|
-
const zod_1 =
|
|
6
|
-
exports.TextWithButtonsSchema = zod_1.
|
|
4
|
+
const core_1 = require("@botonic/core");
|
|
5
|
+
const zod_1 = require("zod");
|
|
6
|
+
exports.TextWithButtonsSchema = zod_1.z
|
|
7
7
|
.object({
|
|
8
|
-
type: zod_1.
|
|
9
|
-
content: zod_1.
|
|
10
|
-
text: zod_1.
|
|
11
|
-
buttons: zod_1.
|
|
12
|
-
text: zod_1.
|
|
13
|
-
url: zod_1.
|
|
14
|
-
target: zod_1.
|
|
8
|
+
type: zod_1.z.literal(core_1.OutputMessageType.TextWithButtons),
|
|
9
|
+
content: zod_1.z.object({
|
|
10
|
+
text: zod_1.z.string(),
|
|
11
|
+
buttons: zod_1.z.array(zod_1.z.object({
|
|
12
|
+
text: zod_1.z.string(),
|
|
13
|
+
url: zod_1.z.string().nullable().optional(),
|
|
14
|
+
target: zod_1.z
|
|
15
15
|
.enum(['_blank', '_self'])
|
|
16
16
|
.default('_blank')
|
|
17
17
|
.nullable()
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"text-with-buttons.js","sourceRoot":"","sources":["../../../src/structured-output/text-with-buttons.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"text-with-buttons.js","sourceRoot":"","sources":["../../../src/structured-output/text-with-buttons.ts"],"names":[],"mappings":";;;AAAA,wCAA8E;AAC9E,6BAAuB;AAIV,QAAA,qBAAqB,GAAG,OAAC;KACnC,MAAM,CAAC;IACN,IAAI,EAAE,OAAC,CAAC,OAAO,CAAC,wBAAiB,CAAC,eAAe,CAAC;IAClD,OAAO,EAAE,OAAC,CAAC,MAAM,CAAC;QAChB,IAAI,EAAE,OAAC,CAAC,MAAM,EAAE;QAChB,OAAO,EAAE,OAAC,CAAC,KAAK,CACd,OAAC,CAAC,MAAM,CAAC;YACP,IAAI,EAAE,OAAC,CAAC,MAAM,EAAE;YAChB,GAAG,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE,CAAC,QAAQ,EAAE;YACrC,MAAM,EAAE,OAAC;iBACN,IAAI,CAAC,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;iBACzB,OAAO,CAAC,QAAQ,CAAC;iBACjB,QAAQ,EAAE;iBACV,QAAQ,EAAE;iBACV,QAAQ,CACP,0FAA0F,CAC3F;SACJ,CAAC,CACH;KACF,CAAC;CACH,CAAC;KACD,QAAQ,CACP,oEAAoE,CACrE,CAAA"}
|
|
@@ -1,23 +1,9 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { OutputMessageType, type TextMessage } from '@botonic/core';
|
|
2
2
|
import { z } from 'zod';
|
|
3
3
|
export type { TextMessage };
|
|
4
4
|
export declare const TextSchema: z.ZodObject<{
|
|
5
|
-
type: z.
|
|
5
|
+
type: z.ZodLiteral<OutputMessageType.Text>;
|
|
6
6
|
content: z.ZodObject<{
|
|
7
7
|
text: z.ZodString;
|
|
8
|
-
},
|
|
9
|
-
|
|
10
|
-
}, {
|
|
11
|
-
text: string;
|
|
12
|
-
}>;
|
|
13
|
-
}, "strip", z.ZodTypeAny, {
|
|
14
|
-
type: "text";
|
|
15
|
-
content: {
|
|
16
|
-
text: string;
|
|
17
|
-
};
|
|
18
|
-
}, {
|
|
19
|
-
type: "text";
|
|
20
|
-
content: {
|
|
21
|
-
text: string;
|
|
22
|
-
};
|
|
23
|
-
}>;
|
|
8
|
+
}, z.core.$strip>;
|
|
9
|
+
}, z.core.$strip>;
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.TextSchema = void 0;
|
|
4
|
+
const core_1 = require("@botonic/core");
|
|
4
5
|
const zod_1 = require("zod");
|
|
5
6
|
exports.TextSchema = zod_1.z
|
|
6
7
|
.object({
|
|
7
|
-
type: zod_1.z.
|
|
8
|
+
type: zod_1.z.literal(core_1.OutputMessageType.Text),
|
|
8
9
|
content: zod_1.z.object({
|
|
9
10
|
text: zod_1.z.string(),
|
|
10
11
|
}),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"text.js","sourceRoot":"","sources":["../../../src/structured-output/text.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"text.js","sourceRoot":"","sources":["../../../src/structured-output/text.ts"],"names":[],"mappings":";;;AAAA,wCAAmE;AACnE,6BAAuB;AAIV,QAAA,UAAU,GAAG,OAAC;KACxB,MAAM,CAAC;IACN,IAAI,EAAE,OAAC,CAAC,OAAO,CAAC,wBAAiB,CAAC,IAAI,CAAC;IACvC,OAAO,EAAE,OAAC,CAAC,MAAM,CAAC;QAChB,IAAI,EAAE,OAAC,CAAC,MAAM,EAAE;KACjB,CAAC;CACH,CAAC;KACD,QAAQ,CAAC,gBAAgB,CAAC,CAAA"}
|
package/lib/cjs/tools/index.d.ts
CHANGED
package/lib/cjs/tools/index.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.mandatoryTools = exports.
|
|
3
|
+
exports.mandatoryTools = exports.RETRIEVE_KNOWLEDGE_TOOL_NAME = exports.createRetrieveKnowledge = void 0;
|
|
4
4
|
var retrieve_knowledge_1 = require("./retrieve-knowledge");
|
|
5
|
-
Object.defineProperty(exports, "
|
|
5
|
+
Object.defineProperty(exports, "createRetrieveKnowledge", { enumerable: true, get: function () { return retrieve_knowledge_1.createRetrieveKnowledge; } });
|
|
6
|
+
Object.defineProperty(exports, "RETRIEVE_KNOWLEDGE_TOOL_NAME", { enumerable: true, get: function () { return retrieve_knowledge_1.RETRIEVE_KNOWLEDGE_TOOL_NAME; } });
|
|
6
7
|
exports.mandatoryTools = [];
|
|
7
8
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/tools/index.ts"],"names":[],"mappings":";;;AAEA,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/tools/index.ts"],"names":[],"mappings":";;;AAEA,2DAG6B;AAF3B,6HAAA,uBAAuB,OAAA;AACvB,kIAAA,4BAA4B,OAAA;AAGjB,QAAA,cAAc,GAAW,EAAE,CAAA"}
|
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
import type { Context } from '../types';
|
|
3
|
-
export declare const
|
|
3
|
+
export declare const RETRIEVE_KNOWLEDGE_TOOL_NAME = "retrieve_knowledge";
|
|
4
|
+
export declare const createRetrieveKnowledge: (sourceIds: string[]) => import("@openai/agents").FunctionTool<Context<import("@botonic/core").ResolvedPlugins, any>, z.ZodObject<{
|
|
4
5
|
query: z.ZodString;
|
|
5
|
-
},
|
|
6
|
-
query: string;
|
|
7
|
-
}, {
|
|
8
|
-
query: string;
|
|
9
|
-
}>, string>;
|
|
6
|
+
}, z.core.$strip>, string>;
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.createRetrieveKnowledge = exports.RETRIEVE_KNOWLEDGE_TOOL_NAME = void 0;
|
|
4
4
|
const agents_1 = require("@openai/agents");
|
|
5
5
|
const zod_1 = require("zod");
|
|
6
6
|
const hubtype_api_client_1 = require("../services/hubtype-api-client");
|
|
7
|
-
exports.
|
|
8
|
-
|
|
7
|
+
exports.RETRIEVE_KNOWLEDGE_TOOL_NAME = 'retrieve_knowledge';
|
|
8
|
+
const createRetrieveKnowledge = (sourceIds) => (0, agents_1.tool)({
|
|
9
|
+
name: exports.RETRIEVE_KNOWLEDGE_TOOL_NAME,
|
|
9
10
|
description: 'Consult the knowledge base for information before answering. Use this tool to make sure the information you provide is faithful.',
|
|
10
11
|
parameters: zod_1.z.object({
|
|
11
12
|
query: zod_1.z.string().describe('The query to search the knowledge base for'),
|
|
@@ -16,17 +17,18 @@ exports.retrieveKnowledge = (0, agents_1.tool)({
|
|
|
16
17
|
if (!context) {
|
|
17
18
|
throw new Error('Context is required');
|
|
18
19
|
}
|
|
19
|
-
const sourceIds = context.sourceIds;
|
|
20
20
|
const client = new hubtype_api_client_1.HubtypeApiClient(context.authToken);
|
|
21
21
|
const chunks = await client.retrieveSimilarChunks(query, sourceIds);
|
|
22
|
+
const chunksIds = chunks.map(chunk => chunk.id);
|
|
22
23
|
const chunkTexts = chunks.map(chunk => chunk.text);
|
|
23
24
|
context.knowledgeUsed = {
|
|
24
25
|
query,
|
|
25
26
|
sourceIds,
|
|
26
|
-
chunksIds
|
|
27
|
+
chunksIds,
|
|
27
28
|
chunkTexts,
|
|
28
29
|
};
|
|
29
30
|
return chunkTexts;
|
|
30
31
|
},
|
|
31
32
|
});
|
|
33
|
+
exports.createRetrieveKnowledge = createRetrieveKnowledge;
|
|
32
34
|
//# sourceMappingURL=retrieve-knowledge.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"retrieve-knowledge.js","sourceRoot":"","sources":["../../../src/tools/retrieve-knowledge.ts"],"names":[],"mappings":";;;AAAA,2CAAsD;AACtD,6BAAuB;AAEvB,uEAAiE;AAGpD,QAAA,
|
|
1
|
+
{"version":3,"file":"retrieve-knowledge.js","sourceRoot":"","sources":["../../../src/tools/retrieve-knowledge.ts"],"names":[],"mappings":";;;AAAA,2CAAsD;AACtD,6BAAuB;AAEvB,uEAAiE;AAGpD,QAAA,4BAA4B,GAAG,oBAAoB,CAAA;AAEzD,MAAM,uBAAuB,GAAG,CAAC,SAAmB,EAAE,EAAE,CAC7D,IAAA,aAAI,EAAC;IACH,IAAI,EAAE,oCAA4B;IAClC,WAAW,EACT,kIAAkI;IACpI,UAAU,EAAE,OAAC,CAAC,MAAM,CAAC;QACnB,KAAK,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,4CAA4C,CAAC;KACzE,CAAC;IACF,OAAO,EAAE,KAAK,EACZ,KAAwB,EACxB,UAAgC,EACb,EAAE;QACrB,MAAM,OAAO,GAAG,UAAU,EAAE,OAAO,CAAA;QACnC,MAAM,KAAK,GAAG,KAAK,CAAC,KAAK,CAAA;QACzB,IAAI,CAAC,OAAO,EAAE,CAAC;YACb,MAAM,IAAI,KAAK,CAAC,qBAAqB,CAAC,CAAA;QACxC,CAAC;QACD,MAAM,MAAM,GAAG,IAAI,qCAAgB,CAAC,OAAO,CAAC,SAAS,CAAC,CAAA;QACtD,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,qBAAqB,CAAC,KAAK,EAAE,SAAS,CAAC,CAAA;QACnE,MAAM,SAAS,GAAG,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC,KAAK,CAAC,EAAE,CAAC,CAAA;QAC/C,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;YACT,UAAU;SACX,CAAA;QAED,OAAO,UAAU,CAAA;IACnB,CAAC;CACF,CAAC,CAAA;AA/BS,QAAA,uBAAuB,2BA+BhC"}
|
package/lib/cjs/types.d.ts
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import { AgenticOutputMessage, AiAgentArgs, type BotContext, GuardrailRule, InferenceResponse, type ResolvedPlugins, RunResult } from '@botonic/core';
|
|
2
2
|
import type { Agent, AgentInputItem, AgentOutputType, RunContext as OpenAIRunContext, Tool as OpenAITool } from '@openai/agents';
|
|
3
|
-
import type {
|
|
3
|
+
import type { ZodType } from 'zod';
|
|
4
4
|
import type { OutputSchema } from './structured-output';
|
|
5
5
|
export interface Context<TPlugins extends ResolvedPlugins = ResolvedPlugins, TExtraData = any> {
|
|
6
6
|
authToken: string;
|
|
7
|
-
sourceIds: string[];
|
|
8
7
|
knowledgeUsed: {
|
|
9
8
|
query: string;
|
|
10
9
|
sourceIds: string[];
|
|
@@ -17,7 +16,7 @@ export type RunContext<TPlugins extends ResolvedPlugins = ResolvedPlugins, TExtr
|
|
|
17
16
|
export interface CustomTool<TPlugins extends ResolvedPlugins = ResolvedPlugins, TExtraData = any> {
|
|
18
17
|
name: string;
|
|
19
18
|
description: string;
|
|
20
|
-
schema:
|
|
19
|
+
schema: ZodType;
|
|
21
20
|
func: (input?: any, runContext?: RunContext<TPlugins, TExtraData>) => Promise<any>;
|
|
22
21
|
}
|
|
23
22
|
export interface Chunk {
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { AgentOutputType, InputGuardrail, Model, ModelSettings } from '@openai/agents';
|
|
2
|
+
import type { z } from 'zod';
|
|
3
|
+
import type { GuardrailTrackingContext } from '../guardrails/input';
|
|
4
|
+
import type { LLMConfig } from '../llm-config';
|
|
5
|
+
import { type OutputSchema } from '../structured-output';
|
|
6
|
+
import type { GuardrailRule } from '../types';
|
|
7
|
+
export interface BaseAgentOptions {
|
|
8
|
+
name: string;
|
|
9
|
+
instructions: string;
|
|
10
|
+
llmConfig: LLMConfig;
|
|
11
|
+
inputGuardrailRules: GuardrailRule[];
|
|
12
|
+
outputMessagesSchemas?: z.ZodObject[];
|
|
13
|
+
guardrailTrackingContext: GuardrailTrackingContext;
|
|
14
|
+
}
|
|
15
|
+
export declare abstract class BaseAgent {
|
|
16
|
+
protected name: string;
|
|
17
|
+
protected instructions: string;
|
|
18
|
+
protected llmConfig: LLMConfig;
|
|
19
|
+
private inputGuardrailRules;
|
|
20
|
+
private outputMessagesSchemas;
|
|
21
|
+
private guardrailTrackingContext;
|
|
22
|
+
constructor(options: BaseAgentOptions);
|
|
23
|
+
protected getAgentModelSettings(): ModelSettings;
|
|
24
|
+
protected getInputGuardrails(): Promise<InputGuardrail[]>;
|
|
25
|
+
protected getOutputType(): AgentOutputType<typeof OutputSchema>;
|
|
26
|
+
protected addOutputInstructions(instructions: string): string;
|
|
27
|
+
protected getModel(): Promise<string | Model>;
|
|
28
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BaseAgent = void 0;
|
|
4
|
+
const guardrails_1 = require("../guardrails");
|
|
5
|
+
const structured_output_1 = require("../structured-output");
|
|
6
|
+
class BaseAgent {
|
|
7
|
+
constructor(options) {
|
|
8
|
+
this.name = options.name;
|
|
9
|
+
this.instructions = options.instructions;
|
|
10
|
+
this.llmConfig = options.llmConfig;
|
|
11
|
+
this.inputGuardrailRules = options.inputGuardrailRules;
|
|
12
|
+
this.outputMessagesSchemas = options.outputMessagesSchemas || [];
|
|
13
|
+
this.guardrailTrackingContext = options.guardrailTrackingContext;
|
|
14
|
+
}
|
|
15
|
+
getAgentModelSettings() {
|
|
16
|
+
const modelSettings = { ...this.llmConfig.modelSettings };
|
|
17
|
+
if (this.llmConfig.modelSettings.reasoning) {
|
|
18
|
+
modelSettings.reasoning = { ...this.llmConfig.modelSettings.reasoning };
|
|
19
|
+
}
|
|
20
|
+
if (this.llmConfig.modelSettings.text) {
|
|
21
|
+
modelSettings.text = { ...this.llmConfig.modelSettings.text };
|
|
22
|
+
}
|
|
23
|
+
return modelSettings;
|
|
24
|
+
}
|
|
25
|
+
async getInputGuardrails() {
|
|
26
|
+
return await (0, guardrails_1.createInputGuardrails)(this.inputGuardrailRules, this.llmConfig, this.guardrailTrackingContext);
|
|
27
|
+
}
|
|
28
|
+
getOutputType() {
|
|
29
|
+
return (0, structured_output_1.getOutputSchema)(this.outputMessagesSchemas);
|
|
30
|
+
}
|
|
31
|
+
addOutputInstructions(instructions) {
|
|
32
|
+
return `${instructions}\n\n${(0, structured_output_1.getOutputInstructions)()}`;
|
|
33
|
+
}
|
|
34
|
+
async getModel() {
|
|
35
|
+
return await this.llmConfig.getModel();
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
exports.BaseAgent = BaseAgent;
|
|
39
|
+
//# sourceMappingURL=base-agent.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base-agent.js","sourceRoot":"","sources":["../../../src/agents/base-agent.ts"],"names":[],"mappings":";;;AAQA,8CAAqD;AAGrD,4DAI6B;AAY7B,MAAsB,SAAS;IAQ7B,YAAY,OAAyB;QACnC,IAAI,CAAC,IAAI,GAAG,OAAO,CAAC,IAAI,CAAA;QACxB,IAAI,CAAC,YAAY,GAAG,OAAO,CAAC,YAAY,CAAA;QACxC,IAAI,CAAC,SAAS,GAAG,OAAO,CAAC,SAAS,CAAA;QAClC,IAAI,CAAC,mBAAmB,GAAG,OAAO,CAAC,mBAAmB,CAAA;QACtD,IAAI,CAAC,qBAAqB,GAAG,OAAO,CAAC,qBAAqB,IAAI,EAAE,CAAA;QAChE,IAAI,CAAC,wBAAwB,GAAG,OAAO,CAAC,wBAAwB,CAAA;IAClE,CAAC;IAES,qBAAqB;QAC7B,MAAM,aAAa,GAAkB,EAAE,GAAG,IAAI,CAAC,SAAS,CAAC,aAAa,EAAE,CAAA;QACxE,IAAI,IAAI,CAAC,SAAS,CAAC,aAAa,CAAC,SAAS,EAAE,CAAC;YAC3C,aAAa,CAAC,SAAS,GAAG,EAAE,GAAG,IAAI,CAAC,SAAS,CAAC,aAAa,CAAC,SAAS,EAAE,CAAA;QACzE,CAAC;QACD,IAAI,IAAI,CAAC,SAAS,CAAC,aAAa,CAAC,IAAI,EAAE,CAAC;YACtC,aAAa,CAAC,IAAI,GAAG,EAAE,GAAG,IAAI,CAAC,SAAS,CAAC,aAAa,CAAC,IAAI,EAAE,CAAA;QAC/D,CAAC;QACD,OAAO,aAAa,CAAA;IACtB,CAAC;IAES,KAAK,CAAC,kBAAkB;QAChC,OAAO,MAAM,IAAA,kCAAqB,EAChC,IAAI,CAAC,mBAAmB,EACxB,IAAI,CAAC,SAAS,EACd,IAAI,CAAC,wBAAwB,CAC9B,CAAA;IACH,CAAC;IAES,aAAa;QACrB,OAAO,IAAA,mCAAe,EAAC,IAAI,CAAC,qBAAqB,CAAC,CAAA;IACpD,CAAC;IAES,qBAAqB,CAAC,YAAoB;QAClD,OAAO,GAAG,YAAY,OAAO,IAAA,yCAAqB,GAAE,EAAE,CAAA;IACxD,CAAC;IAES,KAAK,CAAC,QAAQ;QACtB,OAAO,MAAM,IAAI,CAAC,SAAS,CAAC,QAAQ,EAAE,CAAA;IACxC,CAAC;CACF;AA/CD,8BA+CC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.WorkerAgent = exports.RouterAgent = void 0;
|
|
4
|
+
var router_agent_1 = require("./router-agent");
|
|
5
|
+
Object.defineProperty(exports, "RouterAgent", { enumerable: true, get: function () { return router_agent_1.RouterAgent; } });
|
|
6
|
+
var worker_agent_1 = require("./worker-agent");
|
|
7
|
+
Object.defineProperty(exports, "WorkerAgent", { enumerable: true, get: function () { return worker_agent_1.WorkerAgent; } });
|
|
8
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/agents/index.ts"],"names":[],"mappings":";;;AAAA,+CAA4C;AAAnC,2GAAA,WAAW,OAAA;AACpB,+CAA4C;AAAnC,2GAAA,WAAW,OAAA"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { ResolvedPlugins } from '@botonic/core';
|
|
2
|
+
import { type AgentOutputType, type Handoff } from '@openai/agents';
|
|
3
|
+
import type { z } from 'zod';
|
|
4
|
+
import type { GuardrailTrackingContext } from '../guardrails/input';
|
|
5
|
+
import type { LLMConfig } from '../llm-config';
|
|
6
|
+
import type { OutputSchema } from '../structured-output';
|
|
7
|
+
import type { AIAgent, Context, GuardrailRule } from '../types';
|
|
8
|
+
import { BaseAgent } from './base-agent';
|
|
9
|
+
interface RouterAgentOptions<TPlugins extends ResolvedPlugins = ResolvedPlugins, TExtraData = unknown> {
|
|
10
|
+
name: string;
|
|
11
|
+
instructions: string;
|
|
12
|
+
llmConfig: LLMConfig;
|
|
13
|
+
handoffs: Handoff<Context<TPlugins, TExtraData>, AgentOutputType<typeof OutputSchema>>[];
|
|
14
|
+
inputGuardrailRules: GuardrailRule[];
|
|
15
|
+
outputMessagesSchemas?: z.ZodObject[];
|
|
16
|
+
guardrailTrackingContext: GuardrailTrackingContext;
|
|
17
|
+
}
|
|
18
|
+
export declare class RouterAgent<TPlugins extends ResolvedPlugins = ResolvedPlugins, TExtraData = unknown> extends BaseAgent {
|
|
19
|
+
private handoffs;
|
|
20
|
+
private agent;
|
|
21
|
+
private constructor();
|
|
22
|
+
static create<TPlugins extends ResolvedPlugins = ResolvedPlugins, TExtraData = unknown>(options: RouterAgentOptions<TPlugins, TExtraData>): Promise<RouterAgent<TPlugins, TExtraData>>;
|
|
23
|
+
getAgent(): AIAgent<TPlugins, TExtraData>;
|
|
24
|
+
}
|
|
25
|
+
export {};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RouterAgent = void 0;
|
|
4
|
+
const agents_1 = require("@openai/agents");
|
|
5
|
+
const extensions_1 = require("@openai/agents-core/extensions");
|
|
6
|
+
const base_agent_1 = require("./base-agent");
|
|
7
|
+
class RouterAgent extends base_agent_1.BaseAgent {
|
|
8
|
+
constructor(options) {
|
|
9
|
+
super(options);
|
|
10
|
+
this.handoffs = options.handoffs;
|
|
11
|
+
}
|
|
12
|
+
static async create(options) {
|
|
13
|
+
const routerAgent = new RouterAgent(options);
|
|
14
|
+
const inputGuardrails = await routerAgent.getInputGuardrails();
|
|
15
|
+
// Agent.create is typed as Agent<UnknownContext>; we run with Context<TPlugins, TExtraData>.
|
|
16
|
+
const agent = agents_1.Agent.create({
|
|
17
|
+
name: routerAgent.name,
|
|
18
|
+
model: await routerAgent.getModel(),
|
|
19
|
+
modelSettings: routerAgent.getAgentModelSettings(),
|
|
20
|
+
instructions: routerAgent.addOutputInstructions(`${extensions_1.RECOMMENDED_PROMPT_PREFIX}${routerAgent.instructions}`),
|
|
21
|
+
handoffs: routerAgent.handoffs,
|
|
22
|
+
outputType: routerAgent.getOutputType(),
|
|
23
|
+
inputGuardrails,
|
|
24
|
+
});
|
|
25
|
+
routerAgent.agent = agent;
|
|
26
|
+
return routerAgent;
|
|
27
|
+
}
|
|
28
|
+
getAgent() {
|
|
29
|
+
return this.agent;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
exports.RouterAgent = RouterAgent;
|
|
33
|
+
//# sourceMappingURL=router-agent.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"router-agent.js","sourceRoot":"","sources":["../../../src/agents/router-agent.ts"],"names":[],"mappings":";;;AACA,2CAA0E;AAC1E,+DAA0E;AAM1E,6CAAwC;AAkBxC,MAAa,WAGX,SAAQ,sBAAS;IAOjB,YAAoB,OAAiD;QACnE,KAAK,CAAC,OAAO,CAAC,CAAA;QACd,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAA;IAClC,CAAC;IAED,MAAM,CAAC,KAAK,CAAC,MAAM,CAIjB,OAAiD;QAEjD,MAAM,WAAW,GAAG,IAAI,WAAW,CAAuB,OAAO,CAAC,CAAA;QAClE,MAAM,eAAe,GAAG,MAAM,WAAW,CAAC,kBAAkB,EAAE,CAAA;QAE9D,6FAA6F;QAC7F,MAAM,KAAK,GAAG,cAAK,CAAC,MAAM,CAAC;YACzB,IAAI,EAAE,WAAW,CAAC,IAAI;YACtB,KAAK,EAAE,MAAM,WAAW,CAAC,QAAQ,EAAE;YACnC,aAAa,EAAE,WAAW,CAAC,qBAAqB,EAAE;YAClD,YAAY,EAAE,WAAW,CAAC,qBAAqB,CAC7C,GAAG,sCAAyB,GAAG,WAAW,CAAC,YAAY,EAAE,CAC1D;YACD,QAAQ,EAAE,WAAW,CAAC,QAAQ;YAC9B,UAAU,EAAE,WAAW,CAAC,aAAa,EAAE;YACvC,eAAe;SAChB,CAAkC,CAAA;QAEnC,WAAW,CAAC,KAAK,GAAG,KAAK,CAAA;QACzB,OAAO,WAAW,CAAA;IACpB,CAAC;IAED,QAAQ;QACN,OAAO,IAAI,CAAC,KAAK,CAAA;IACnB,CAAC;CACF;AA5CD,kCA4CC"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { CampaignV2, ContactInfo, ResolvedPlugins } from '@botonic/core';
|
|
2
|
+
import type { z } from 'zod';
|
|
3
|
+
import type { DebugLogger } from '../debug-logger';
|
|
4
|
+
import type { GuardrailTrackingContext } from '../guardrails/input';
|
|
5
|
+
import type { LLMConfig } from '../llm-config';
|
|
6
|
+
import type { AIAgent, GuardrailRule, Tool } from '../types';
|
|
7
|
+
import { BaseAgent } from './base-agent';
|
|
8
|
+
interface WorkerAgentOptions<TPlugins extends ResolvedPlugins = ResolvedPlugins, TExtraData = unknown> {
|
|
9
|
+
name: string;
|
|
10
|
+
instructions: string;
|
|
11
|
+
tools: Tool<TPlugins, TExtraData>[];
|
|
12
|
+
campaignsContext?: CampaignV2[];
|
|
13
|
+
contactInfo: ContactInfo[];
|
|
14
|
+
inputGuardrailRules: GuardrailRule[];
|
|
15
|
+
sourceIds: string[];
|
|
16
|
+
outputMessagesSchemas?: z.ZodObject[];
|
|
17
|
+
llmConfig: LLMConfig;
|
|
18
|
+
logger: DebugLogger;
|
|
19
|
+
guardrailTrackingContext: GuardrailTrackingContext;
|
|
20
|
+
}
|
|
21
|
+
export declare class WorkerAgent<TPlugins extends ResolvedPlugins = ResolvedPlugins, TExtraData = unknown> extends BaseAgent {
|
|
22
|
+
private tools;
|
|
23
|
+
private logger;
|
|
24
|
+
private agent;
|
|
25
|
+
private constructor();
|
|
26
|
+
static create<TPlugins extends ResolvedPlugins = ResolvedPlugins, TExtraData = unknown>(options: WorkerAgentOptions<TPlugins, TExtraData>): Promise<WorkerAgent<TPlugins, TExtraData>>;
|
|
27
|
+
getAgent(): AIAgent<TPlugins, TExtraData>;
|
|
28
|
+
private getWorkerModelSettings;
|
|
29
|
+
private addExtraInstructions;
|
|
30
|
+
private getContactInfoInstructions;
|
|
31
|
+
private getMetadataInstructions;
|
|
32
|
+
private getCampaignInstructions;
|
|
33
|
+
private addHubtypeTools;
|
|
34
|
+
}
|
|
35
|
+
export {};
|
|
@@ -1,55 +1,68 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.WorkerAgent = void 0;
|
|
4
4
|
const agents_1 = require("@openai/agents");
|
|
5
|
-
const constants_1 = require("
|
|
6
|
-
const
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
class AIAgentBuilder {
|
|
5
|
+
const constants_1 = require("../constants");
|
|
6
|
+
const tools_1 = require("../tools");
|
|
7
|
+
const base_agent_1 = require("./base-agent");
|
|
8
|
+
class WorkerAgent extends base_agent_1.BaseAgent {
|
|
10
9
|
constructor(options) {
|
|
11
|
-
|
|
10
|
+
super({
|
|
11
|
+
name: options.name,
|
|
12
|
+
instructions: options.instructions,
|
|
13
|
+
llmConfig: options.llmConfig,
|
|
14
|
+
inputGuardrailRules: options.inputGuardrailRules,
|
|
15
|
+
outputMessagesSchemas: options.outputMessagesSchemas,
|
|
16
|
+
guardrailTrackingContext: options.guardrailTrackingContext,
|
|
17
|
+
});
|
|
12
18
|
this.instructions = this.addExtraInstructions(options.instructions, options.contactInfo, options.campaignsContext);
|
|
13
19
|
this.tools = this.addHubtypeTools(options.tools, options.sourceIds);
|
|
14
|
-
this.externalOutputMessagesSchemas = options.outputMessagesSchemas || [];
|
|
15
|
-
this.inputGuardrails = [];
|
|
16
|
-
this.llmConfig = options.llmConfig;
|
|
17
20
|
this.logger = options.logger;
|
|
18
|
-
if (options.inputGuardrailRules.length > 0) {
|
|
19
|
-
const inputGuardrail = (0, guardrails_1.createInputGuardrail)(options.inputGuardrailRules, options.llmConfig, options.guardrailTrackingContext);
|
|
20
|
-
this.inputGuardrails.push(inputGuardrail);
|
|
21
|
-
}
|
|
22
21
|
}
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
const
|
|
27
|
-
const hasRetrieveKnowledge =
|
|
28
|
-
|
|
22
|
+
static async create(options) {
|
|
23
|
+
const workerAgent = new WorkerAgent(options);
|
|
24
|
+
const model = workerAgent.llmConfig.modelName;
|
|
25
|
+
const resolvedModel = await workerAgent.getModel();
|
|
26
|
+
const hasRetrieveKnowledge = workerAgent.tools.some(tool => tool.name === tools_1.RETRIEVE_KNOWLEDGE_TOOL_NAME);
|
|
27
|
+
const modelSettings = workerAgent.getWorkerModelSettings(hasRetrieveKnowledge);
|
|
28
|
+
const inputGuardrails = await workerAgent.getInputGuardrails();
|
|
29
|
+
workerAgent.logger.logModelSettings({
|
|
29
30
|
provider: constants_1.OPENAI_PROVIDER,
|
|
30
31
|
model,
|
|
31
|
-
reasoning:
|
|
32
|
-
text:
|
|
33
|
-
toolChoice:
|
|
32
|
+
reasoning: modelSettings.reasoning,
|
|
33
|
+
text: modelSettings.text,
|
|
34
|
+
toolChoice: modelSettings.toolChoice,
|
|
34
35
|
hasRetrieveKnowledge,
|
|
35
36
|
});
|
|
36
|
-
|
|
37
|
-
name:
|
|
38
|
-
model,
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
37
|
+
const agent = new agents_1.Agent({
|
|
38
|
+
name: workerAgent.name,
|
|
39
|
+
model: resolvedModel,
|
|
40
|
+
modelSettings,
|
|
41
|
+
instructions: workerAgent.instructions,
|
|
42
|
+
tools: workerAgent.tools,
|
|
43
|
+
outputType: workerAgent.getOutputType(),
|
|
44
|
+
inputGuardrails,
|
|
43
45
|
outputGuardrails: [],
|
|
44
46
|
});
|
|
47
|
+
workerAgent.agent = agent;
|
|
48
|
+
return workerAgent;
|
|
49
|
+
}
|
|
50
|
+
getAgent() {
|
|
51
|
+
return this.agent;
|
|
52
|
+
}
|
|
53
|
+
getWorkerModelSettings(hasRetrieveKnowledge) {
|
|
54
|
+
const modelSettings = this.getAgentModelSettings();
|
|
55
|
+
if (hasRetrieveKnowledge) {
|
|
56
|
+
modelSettings.toolChoice = tools_1.RETRIEVE_KNOWLEDGE_TOOL_NAME;
|
|
57
|
+
}
|
|
58
|
+
return modelSettings;
|
|
45
59
|
}
|
|
46
60
|
addExtraInstructions(initialInstructions, contactInfo, campaignsContext) {
|
|
47
61
|
const instructions = `<instructions>\n${initialInstructions.trim()}\n</instructions>`;
|
|
48
62
|
const metadataInstructions = this.getMetadataInstructions();
|
|
49
63
|
const contactInfoInstructions = this.getContactInfoInstructions(contactInfo);
|
|
50
64
|
const campaignInstructions = this.getCampaignInstructions(campaignsContext);
|
|
51
|
-
|
|
52
|
-
return `${instructions}\n\n${metadataInstructions}\n\n${contactInfoInstructions}\n\n${campaignInstructions}\n\n${outputInstructions}`;
|
|
65
|
+
return this.addOutputInstructions(`${instructions}\n\n${metadataInstructions}\n\n${contactInfoInstructions}\n\n${campaignInstructions}`);
|
|
53
66
|
}
|
|
54
67
|
getContactInfoInstructions(contactInfo) {
|
|
55
68
|
const structuredContactInfo = contactInfo
|
|
@@ -80,27 +93,13 @@ class AIAgentBuilder {
|
|
|
80
93
|
.map((campaign, index) => `<campaign_context_${index + 1}>\n${campaign.agent_context}\n</campaign_context_${index + 1}>`)
|
|
81
94
|
.join('\n');
|
|
82
95
|
}
|
|
83
|
-
getOutputInstructions() {
|
|
84
|
-
const example = {
|
|
85
|
-
messages: [
|
|
86
|
-
{
|
|
87
|
-
type: 'text',
|
|
88
|
-
content: {
|
|
89
|
-
text: 'Hello, how can I help you today?',
|
|
90
|
-
},
|
|
91
|
-
},
|
|
92
|
-
],
|
|
93
|
-
};
|
|
94
|
-
const output = `Return a JSON that follows the output schema provided. Never return multiple output schemas concatenated by a line break.\n<example>\n${JSON.stringify(example)}\n</example>`;
|
|
95
|
-
return `<output>\n${output}\n</output>`;
|
|
96
|
-
}
|
|
97
96
|
addHubtypeTools(tools, sourceIds) {
|
|
98
97
|
const hubtypeTools = [...tools_1.mandatoryTools];
|
|
99
98
|
if (sourceIds.length > 0) {
|
|
100
|
-
hubtypeTools.push(tools_1.
|
|
99
|
+
hubtypeTools.push((0, tools_1.createRetrieveKnowledge)(sourceIds));
|
|
101
100
|
}
|
|
102
101
|
return [...hubtypeTools, ...tools];
|
|
103
102
|
}
|
|
104
103
|
}
|
|
105
|
-
exports.
|
|
106
|
-
//# sourceMappingURL=agent
|
|
104
|
+
exports.WorkerAgent = WorkerAgent;
|
|
105
|
+
//# sourceMappingURL=worker-agent.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"worker-agent.js","sourceRoot":"","sources":["../../../src/agents/worker-agent.ts"],"names":[],"mappings":";;;AACA,2CAAgF;AAEhF,4CAA8C;AAK9C,oCAIiB;AAEjB,6CAAwC;AAmBxC,MAAa,WAGX,SAAQ,sBAAS;IAKjB,YAAoB,OAAiD;QACnE,KAAK,CAAC;YACJ,IAAI,EAAE,OAAO,CAA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YAAY,EAAE,GAAG,KAAK,CAAC,CAAA;IACpC,CAAC;CACF;AAnJD,kCAmJC"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getToolsForBotConfig = getToolsForBotConfig;
|
|
4
|
-
const
|
|
4
|
+
const zod_1 = require("zod");
|
|
5
5
|
/**
|
|
6
6
|
* Maps custom AI agent tools to the format expected by bot config (e.g. for flow-builder).
|
|
7
7
|
* Converts each tool's Zod schema to JSON Schema so it can be serialized in the config.
|
|
@@ -10,9 +10,8 @@ function getToolsForBotConfig(customTools) {
|
|
|
10
10
|
return customTools.map(tool => ({
|
|
11
11
|
name: tool.name,
|
|
12
12
|
description: tool.description,
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
$refStrategy: 'none',
|
|
13
|
+
schema: zod_1.z.toJSONSchema(tool.schema, {
|
|
14
|
+
target: 'draft-07',
|
|
16
15
|
}),
|
|
17
16
|
}));
|
|
18
17
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bot-config-tools.js","sourceRoot":"","sources":["../../src/bot-config-tools.ts"],"names":[],"mappings":";;AASA,
|
|
1
|
+
{"version":3,"file":"bot-config-tools.js","sourceRoot":"","sources":["../../src/bot-config-tools.ts"],"names":[],"mappings":";;AASA,oDAUC;AAlBD,6BAAuB;AAIvB;;;GAGG;AACH,SAAgB,oBAAoB,CAClC,WAAyB;IAEzB,OAAO,WAAW,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QAC9B,IAAI,EAAE,IAAI,CAAC,IAAI;QACf,WAAW,EAAE,IAAI,CAAC,WAAW;QAC7B,MAAM,EAAE,OAAC,CAAC,YAAY,CAAC,IAAI,CAAC,MAAM,EAAE;YAClC,MAAM,EAAE,UAAU;SACnB,CAA6B;KAC/B,CAAC,CAAC,CAAA;AACL,CAAC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type AiAgentArgs, type ToolExecution } from '@botonic/core';
|
|
2
2
|
import type { ModelSettings } from '@openai/agents';
|
|
3
3
|
import type { AgenticInputMessage, MemoryOptions, RunResult } from './types';
|
|
4
4
|
export interface DebugLoggerConfig {
|