@botonic/plugin-ai-agents 0.48.1 → 0.49.0-alpha.1

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.
Files changed (160) hide show
  1. package/lib/cjs/agents/base-agent.d.ts +28 -0
  2. package/lib/cjs/agents/base-agent.js +39 -0
  3. package/lib/cjs/agents/base-agent.js.map +1 -0
  4. package/lib/cjs/agents/index.d.ts +2 -0
  5. package/lib/cjs/agents/index.js +8 -0
  6. package/lib/cjs/agents/index.js.map +1 -0
  7. package/lib/cjs/agents/router-agent.d.ts +25 -0
  8. package/lib/cjs/agents/router-agent.js +33 -0
  9. package/lib/cjs/agents/router-agent.js.map +1 -0
  10. package/lib/cjs/agents/specialist-agent.d.ts +35 -0
  11. package/lib/cjs/{agent-builder.js → agents/specialist-agent.js} +48 -49
  12. package/lib/cjs/agents/specialist-agent.js.map +1 -0
  13. package/lib/cjs/bot-config-tools.js +3 -4
  14. package/lib/cjs/bot-config-tools.js.map +1 -1
  15. package/lib/cjs/debug-logger.d.ts +1 -1
  16. package/lib/cjs/debug-logger.js +4 -1
  17. package/lib/cjs/debug-logger.js.map +1 -1
  18. package/lib/cjs/guardrails/input.d.ts +1 -1
  19. package/lib/cjs/guardrails/input.js +20 -9
  20. package/lib/cjs/guardrails/input.js.map +1 -1
  21. package/lib/cjs/index.d.ts +4 -1
  22. package/lib/cjs/index.js +112 -51
  23. package/lib/cjs/index.js.map +1 -1
  24. package/lib/cjs/llm-config.d.ts +2 -1
  25. package/lib/cjs/llm-config.js +3 -0
  26. package/lib/cjs/llm-config.js.map +1 -1
  27. package/lib/cjs/runners/base-runner.d.ts +26 -0
  28. package/lib/cjs/runners/base-runner.js +114 -0
  29. package/lib/cjs/runners/base-runner.js.map +1 -0
  30. package/lib/cjs/runners/index.d.ts +2 -0
  31. package/lib/cjs/runners/index.js +8 -0
  32. package/lib/cjs/runners/index.js.map +1 -0
  33. package/lib/cjs/runners/router-runner.d.ts +6 -0
  34. package/lib/cjs/runners/router-runner.js +29 -0
  35. package/lib/cjs/runners/router-runner.js.map +1 -0
  36. package/lib/cjs/runners/specialist-runner.d.ts +10 -0
  37. package/lib/cjs/runners/specialist-runner.js +78 -0
  38. package/lib/cjs/runners/specialist-runner.js.map +1 -0
  39. package/lib/cjs/structured-output/bot-executor.d.ts +6 -42
  40. package/lib/cjs/structured-output/bot-executor.js +9 -9
  41. package/lib/cjs/structured-output/bot-executor.js.map +1 -1
  42. package/lib/cjs/structured-output/carousel.d.ts +6 -78
  43. package/lib/cjs/structured-output/carousel.js +2 -1
  44. package/lib/cjs/structured-output/carousel.js.map +1 -1
  45. package/lib/cjs/structured-output/exit.d.ts +4 -8
  46. package/lib/cjs/structured-output/exit.js +4 -4
  47. package/lib/cjs/structured-output/exit.js.map +1 -1
  48. package/lib/cjs/structured-output/index.d.ts +48 -553
  49. package/lib/cjs/structured-output/index.js +15 -0
  50. package/lib/cjs/structured-output/index.js.map +1 -1
  51. package/lib/cjs/structured-output/text-with-buttons.d.ts +10 -49
  52. package/lib/cjs/structured-output/text-with-buttons.js +10 -10
  53. package/lib/cjs/structured-output/text-with-buttons.js.map +1 -1
  54. package/lib/cjs/structured-output/text.d.ts +4 -18
  55. package/lib/cjs/structured-output/text.js +2 -1
  56. package/lib/cjs/structured-output/text.js.map +1 -1
  57. package/lib/cjs/tools/index.d.ts +1 -1
  58. package/lib/cjs/tools/index.js +3 -2
  59. package/lib/cjs/tools/index.js.map +1 -1
  60. package/lib/cjs/tools/retrieve-knowledge.d.ts +3 -6
  61. package/lib/cjs/tools/retrieve-knowledge.js +7 -5
  62. package/lib/cjs/tools/retrieve-knowledge.js.map +1 -1
  63. package/lib/cjs/types.d.ts +2 -3
  64. package/lib/esm/agents/base-agent.d.ts +28 -0
  65. package/lib/esm/agents/base-agent.js +39 -0
  66. package/lib/esm/agents/base-agent.js.map +1 -0
  67. package/lib/esm/agents/index.d.ts +2 -0
  68. package/lib/esm/agents/index.js +8 -0
  69. package/lib/esm/agents/index.js.map +1 -0
  70. package/lib/esm/agents/router-agent.d.ts +25 -0
  71. package/lib/esm/agents/router-agent.js +33 -0
  72. package/lib/esm/agents/router-agent.js.map +1 -0
  73. package/lib/esm/agents/specialist-agent.d.ts +35 -0
  74. package/lib/esm/{agent-builder.js → agents/specialist-agent.js} +48 -49
  75. package/lib/esm/agents/specialist-agent.js.map +1 -0
  76. package/lib/esm/bot-config-tools.js +3 -4
  77. package/lib/esm/bot-config-tools.js.map +1 -1
  78. package/lib/esm/debug-logger.d.ts +1 -1
  79. package/lib/esm/debug-logger.js +4 -1
  80. package/lib/esm/debug-logger.js.map +1 -1
  81. package/lib/esm/guardrails/input.d.ts +1 -1
  82. package/lib/esm/guardrails/input.js +20 -9
  83. package/lib/esm/guardrails/input.js.map +1 -1
  84. package/lib/esm/index.d.ts +4 -1
  85. package/lib/esm/index.js +112 -51
  86. package/lib/esm/index.js.map +1 -1
  87. package/lib/esm/llm-config.d.ts +2 -1
  88. package/lib/esm/llm-config.js +3 -0
  89. package/lib/esm/llm-config.js.map +1 -1
  90. package/lib/esm/runners/base-runner.d.ts +26 -0
  91. package/lib/esm/runners/base-runner.js +114 -0
  92. package/lib/esm/runners/base-runner.js.map +1 -0
  93. package/lib/esm/runners/index.d.ts +2 -0
  94. package/lib/esm/runners/index.js +8 -0
  95. package/lib/esm/runners/index.js.map +1 -0
  96. package/lib/esm/runners/router-runner.d.ts +6 -0
  97. package/lib/esm/runners/router-runner.js +29 -0
  98. package/lib/esm/runners/router-runner.js.map +1 -0
  99. package/lib/esm/runners/specialist-runner.d.ts +10 -0
  100. package/lib/esm/runners/specialist-runner.js +78 -0
  101. package/lib/esm/runners/specialist-runner.js.map +1 -0
  102. package/lib/esm/structured-output/bot-executor.d.ts +6 -42
  103. package/lib/esm/structured-output/bot-executor.js +9 -9
  104. package/lib/esm/structured-output/bot-executor.js.map +1 -1
  105. package/lib/esm/structured-output/carousel.d.ts +6 -78
  106. package/lib/esm/structured-output/carousel.js +2 -1
  107. package/lib/esm/structured-output/carousel.js.map +1 -1
  108. package/lib/esm/structured-output/exit.d.ts +4 -8
  109. package/lib/esm/structured-output/exit.js +4 -4
  110. package/lib/esm/structured-output/exit.js.map +1 -1
  111. package/lib/esm/structured-output/index.d.ts +48 -553
  112. package/lib/esm/structured-output/index.js +15 -0
  113. package/lib/esm/structured-output/index.js.map +1 -1
  114. package/lib/esm/structured-output/text-with-buttons.d.ts +10 -49
  115. package/lib/esm/structured-output/text-with-buttons.js +10 -10
  116. package/lib/esm/structured-output/text-with-buttons.js.map +1 -1
  117. package/lib/esm/structured-output/text.d.ts +4 -18
  118. package/lib/esm/structured-output/text.js +2 -1
  119. package/lib/esm/structured-output/text.js.map +1 -1
  120. package/lib/esm/tools/index.d.ts +1 -1
  121. package/lib/esm/tools/index.js +3 -2
  122. package/lib/esm/tools/index.js.map +1 -1
  123. package/lib/esm/tools/retrieve-knowledge.d.ts +3 -6
  124. package/lib/esm/tools/retrieve-knowledge.js +7 -5
  125. package/lib/esm/tools/retrieve-knowledge.js.map +1 -1
  126. package/lib/esm/types.d.ts +2 -3
  127. package/package.json +5 -6
  128. package/src/agents/base-agent.ts +75 -0
  129. package/src/agents/index.ts +2 -0
  130. package/src/agents/router-agent.ts +71 -0
  131. package/src/{agent-builder.ts → agents/specialist-agent.ts} +77 -77
  132. package/src/bot-config-tools.ts +3 -4
  133. package/src/debug-logger.ts +10 -4
  134. package/src/guardrails/input.ts +26 -9
  135. package/src/index.ts +216 -82
  136. package/src/llm-config.ts +5 -0
  137. package/src/runners/base-runner.ts +190 -0
  138. package/src/runners/index.ts +2 -0
  139. package/src/runners/router-runner.ts +41 -0
  140. package/src/runners/specialist-runner.ts +112 -0
  141. package/src/structured-output/bot-executor.ts +3 -3
  142. package/src/structured-output/carousel.ts +2 -2
  143. package/src/structured-output/exit.ts +3 -3
  144. package/src/structured-output/index.ts +15 -0
  145. package/src/structured-output/text-with-buttons.ts +3 -3
  146. package/src/structured-output/text.ts +2 -2
  147. package/src/tools/index.ts +4 -1
  148. package/src/tools/retrieve-knowledge.ts +32 -29
  149. package/src/types.ts +2 -3
  150. package/lib/cjs/agent-builder.d.ts +0 -37
  151. package/lib/cjs/agent-builder.js.map +0 -1
  152. package/lib/cjs/runner.d.ts +0 -18
  153. package/lib/cjs/runner.js +0 -180
  154. package/lib/cjs/runner.js.map +0 -1
  155. package/lib/esm/agent-builder.d.ts +0 -37
  156. package/lib/esm/agent-builder.js.map +0 -1
  157. package/lib/esm/runner.d.ts +0 -18
  158. package/lib/esm/runner.js +0 -180
  159. package/lib/esm/runner.js.map +0 -1
  160. package/src/runner.ts +0 -283
@@ -0,0 +1,41 @@
1
+ import type { ResolvedPlugins } from '@botonic/core'
2
+ import { Handoff } from '@openai/agents'
3
+ import type { Agent } from '@openai/agents-core'
4
+
5
+ import type { Context, RunResult } from '../types'
6
+ import { BaseRunner, type RunnerResult } from './base-runner'
7
+
8
+ export class RouterRunner<
9
+ TPlugins extends ResolvedPlugins = ResolvedPlugins,
10
+ TExtraData = unknown,
11
+ > extends BaseRunner<TPlugins, TExtraData> {
12
+ protected override buildRunResult(
13
+ result: RunnerResult,
14
+ context: Context<TPlugins, TExtraData>,
15
+ memoryLength: number
16
+ ): RunResult {
17
+ const base = super.buildRunResult(result, context, memoryLength)
18
+
19
+ const availableSpecialists = (this.agent.handoffs ?? []).map(
20
+ (entry: Agent<any, any> | Handoff<any, any>) => {
21
+ const isHandoff = entry instanceof Handoff
22
+ const agent = isHandoff ? entry.agent : (entry as Agent<any, any>)
23
+ const description = isHandoff
24
+ ? entry.toolDescription
25
+ : agent.handoffDescription
26
+ return { name: agent.name, description }
27
+ }
28
+ )
29
+
30
+ const startingAgentName = this.agent.name ?? ''
31
+ const lastAgentName = result.lastAgent?.name ?? ''
32
+
33
+ return {
34
+ ...base,
35
+ startingAgentName,
36
+ lastAgentName,
37
+ availableSpecialists,
38
+ isTransferredToSpecialist: startingAgentName !== lastAgentName,
39
+ }
40
+ }
41
+ }
@@ -0,0 +1,112 @@
1
+ import type { ResolvedPlugins, ToolExecution } from '@botonic/core'
2
+ import { RunToolCallItem, RunToolCallOutputItem } from '@openai/agents'
3
+ import { RETRIEVE_KNOWLEDGE_TOOL_NAME } from '../tools'
4
+ import type { Context } from '../types'
5
+ import { BaseRunner, type RunnerResult } from './base-runner'
6
+
7
+ export class SpecialistRunner<
8
+ TPlugins extends ResolvedPlugins = ResolvedPlugins,
9
+ TExtraData = unknown,
10
+ > extends BaseRunner<TPlugins, TExtraData> {
11
+ protected getToolsExecuted(
12
+ result: RunnerResult,
13
+ context: Context<TPlugins, TExtraData>
14
+ ): ToolExecution[] {
15
+ const toolResultsByCallId = this.getToolResultsByCallId(result.newItems)
16
+
17
+ return (
18
+ result.newItems
19
+ ?.filter(item => item instanceof RunToolCallItem)
20
+ .map((item: RunToolCallItem) =>
21
+ this.getToolExecutionInfo(
22
+ item as RunToolCallItem,
23
+ context,
24
+ toolResultsByCallId
25
+ )
26
+ )
27
+ .filter(
28
+ (toolExecution: ToolExecution) => toolExecution.toolName !== ''
29
+ ) || []
30
+ )
31
+ }
32
+
33
+ private getToolResultsByCallId(
34
+ newItems: unknown[] = []
35
+ ): Map<string, string> {
36
+ const map = new Map<string, string>()
37
+ for (const item of newItems) {
38
+ if (!(item instanceof RunToolCallOutputItem)) {
39
+ continue
40
+ }
41
+ const rawItem = item.rawItem as {
42
+ callId?: string
43
+ output?: string | { type?: string; text?: string }
44
+ }
45
+ const callId = rawItem?.callId
46
+ const output = rawItem?.output
47
+ if (callId == null || output == null) {
48
+ continue
49
+ }
50
+ const text = this.extractToolResult(output)
51
+ if (text != null) {
52
+ map.set(callId, text)
53
+ }
54
+ }
55
+ return map
56
+ }
57
+
58
+ private extractToolResult(
59
+ output: string | { type?: string; text?: string }
60
+ ): string | undefined {
61
+ if (typeof output === 'string') {
62
+ return output
63
+ }
64
+ return output?.type === 'text' && typeof output?.text === 'string'
65
+ ? output.text
66
+ : undefined
67
+ }
68
+
69
+ private getToolExecutionInfo(
70
+ item: RunToolCallItem,
71
+ context: Context<TPlugins, TExtraData>,
72
+ toolResultsByCallId: Map<string, string>
73
+ ): ToolExecution {
74
+ if (item.rawItem.type !== 'function_call') {
75
+ return {
76
+ toolName: '',
77
+ toolArguments: {},
78
+ }
79
+ }
80
+ const toolName = item.rawItem.name
81
+ const toolArguments = this.getSafeToolArguments(item.rawItem.arguments)
82
+ const toolResults = item.rawItem.callId
83
+ ? toolResultsByCallId.get(item.rawItem.callId)
84
+ : undefined
85
+
86
+ const toolExecution: ToolExecution = {
87
+ toolName,
88
+ toolArguments,
89
+ toolResults,
90
+ }
91
+
92
+ if (toolName === RETRIEVE_KNOWLEDGE_TOOL_NAME) {
93
+ return {
94
+ ...toolExecution,
95
+ knowledgebaseSourcesIds: context.knowledgeUsed.sourceIds,
96
+ knowledgebaseChunksIds: context.knowledgeUsed.chunksIds,
97
+ }
98
+ }
99
+
100
+ return toolExecution
101
+ }
102
+
103
+ private getSafeToolArguments(
104
+ rawToolArguments: string
105
+ ): Record<string, unknown> {
106
+ try {
107
+ return JSON.parse(rawToolArguments)
108
+ } catch (_error) {
109
+ return {}
110
+ }
111
+ }
112
+ }
@@ -1,11 +1,11 @@
1
- import type { BotExecutorMessage } from '@botonic/core'
2
- import z from 'zod'
1
+ import { type BotExecutorMessage, OutputMessageType } from '@botonic/core'
2
+ import { z } from 'zod'
3
3
 
4
4
  export type { BotExecutorMessage }
5
5
 
6
6
  export const BotExecutorSchema = z
7
7
  .object({
8
- type: z.enum(['botExecutor']),
8
+ type: z.literal(OutputMessageType.BotExecutor),
9
9
  content: z.object({
10
10
  text: z.string(),
11
11
  buttons: z.array(
@@ -1,11 +1,11 @@
1
- import type { CarouselMessage } from '@botonic/core'
1
+ import { type CarouselMessage, OutputMessageType } from '@botonic/core'
2
2
  import { z } from 'zod'
3
3
 
4
4
  export type { CarouselMessage }
5
5
 
6
6
  export const CarouselSchema = z
7
7
  .object({
8
- type: z.enum(['carousel']),
8
+ type: z.literal(OutputMessageType.Carousel),
9
9
  content: z.object({
10
10
  text: z.string().nullable().optional(),
11
11
  elements: z.array(
@@ -1,11 +1,11 @@
1
- import type { ExitMessage } from '@botonic/core'
2
- import z from 'zod'
1
+ import { type ExitMessage, OutputMessageType } from '@botonic/core'
2
+ import { z } from 'zod'
3
3
 
4
4
  export type { ExitMessage }
5
5
 
6
6
  export const ExitSchema = z
7
7
  .object({
8
- type: z.enum(['exit']),
8
+ type: z.literal(OutputMessageType.Exit),
9
9
  })
10
10
  .describe(
11
11
  'An exit message. This message should only be used to exit the agent due to out of context or the user asking to exit the conversation'
@@ -32,3 +32,18 @@ export function getOutputSchema(
32
32
  ),
33
33
  })
34
34
  }
35
+
36
+ export function getOutputInstructions(): string {
37
+ const example = {
38
+ messages: [
39
+ {
40
+ type: 'text',
41
+ content: {
42
+ text: 'Hello, how can I help you today?',
43
+ },
44
+ },
45
+ ],
46
+ }
47
+ 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>`
48
+ return `<output>\n${output}\n</output>`
49
+ }
@@ -1,11 +1,11 @@
1
- import type { TextWithButtonsMessage } from '@botonic/core'
2
- import z from 'zod'
1
+ import { OutputMessageType, type TextWithButtonsMessage } from '@botonic/core'
2
+ import { z } from 'zod'
3
3
 
4
4
  export type { TextWithButtonsMessage }
5
5
 
6
6
  export const TextWithButtonsSchema = z
7
7
  .object({
8
- type: z.enum(['textWithButtons']),
8
+ type: z.literal(OutputMessageType.TextWithButtons),
9
9
  content: z.object({
10
10
  text: z.string(),
11
11
  buttons: z.array(
@@ -1,11 +1,11 @@
1
- import type { TextMessage } from '@botonic/core'
1
+ import { OutputMessageType, type TextMessage } from '@botonic/core'
2
2
  import { z } from 'zod'
3
3
 
4
4
  export type { TextMessage }
5
5
 
6
6
  export const TextSchema = z
7
7
  .object({
8
- type: z.enum(['text']),
8
+ type: z.literal(OutputMessageType.Text),
9
9
  content: z.object({
10
10
  text: z.string(),
11
11
  }),
@@ -1,5 +1,8 @@
1
1
  import type { Tool } from '../types'
2
2
 
3
- export { retrieveKnowledge } from './retrieve-knowledge'
3
+ export {
4
+ createRetrieveKnowledge,
5
+ RETRIEVE_KNOWLEDGE_TOOL_NAME,
6
+ } from './retrieve-knowledge'
4
7
 
5
8
  export const mandatoryTools: Tool[] = []
@@ -4,34 +4,37 @@ import { z } from 'zod'
4
4
  import { HubtypeApiClient } from '../services/hubtype-api-client'
5
5
  import type { Context } from '../types'
6
6
 
7
- export const retrieveKnowledge = tool({
8
- name: 'retrieve_knowledge',
9
- description:
10
- 'Consult the knowledge base for information before answering. Use this tool to make sure the information you provide is faithful.',
11
- parameters: z.object({
12
- query: z.string().describe('The query to search the knowledge base for'),
13
- }),
14
- execute: async (
15
- input: { query: string },
16
- runContext?: RunContext<Context>
17
- ): Promise<string[]> => {
18
- const context = runContext?.context
19
- const query = input.query
20
- if (!context) {
21
- throw new Error('Context is required')
22
- }
23
- const sourceIds = context.sourceIds
24
- const client = new HubtypeApiClient(context.authToken)
25
- const chunks = await client.retrieveSimilarChunks(query, sourceIds)
26
- const chunkTexts = chunks.map(chunk => chunk.text)
7
+ export const RETRIEVE_KNOWLEDGE_TOOL_NAME = 'retrieve_knowledge'
27
8
 
28
- context.knowledgeUsed = {
29
- query,
30
- sourceIds,
31
- chunksIds: chunks.map(chunk => chunk.id),
32
- chunkTexts,
33
- }
9
+ export const createRetrieveKnowledge = (sourceIds: string[]) =>
10
+ tool({
11
+ name: RETRIEVE_KNOWLEDGE_TOOL_NAME,
12
+ description:
13
+ 'Consult the knowledge base for information before answering. Use this tool to make sure the information you provide is faithful.',
14
+ parameters: z.object({
15
+ query: z.string().describe('The query to search the knowledge base for'),
16
+ }),
17
+ execute: async (
18
+ input: { query: string },
19
+ runContext?: RunContext<Context>
20
+ ): Promise<string[]> => {
21
+ const context = runContext?.context
22
+ const query = input.query
23
+ if (!context) {
24
+ throw new Error('Context is required')
25
+ }
26
+ const client = new HubtypeApiClient(context.authToken)
27
+ const chunks = await client.retrieveSimilarChunks(query, sourceIds)
28
+ const chunksIds = chunks.map(chunk => chunk.id)
29
+ const chunkTexts = chunks.map(chunk => chunk.text)
34
30
 
35
- return chunkTexts
36
- },
37
- })
31
+ context.knowledgeUsed = {
32
+ query,
33
+ sourceIds,
34
+ chunksIds,
35
+ chunkTexts,
36
+ }
37
+
38
+ return chunkTexts
39
+ },
40
+ })
package/src/types.ts CHANGED
@@ -14,7 +14,7 @@ import type {
14
14
  RunContext as OpenAIRunContext,
15
15
  Tool as OpenAITool,
16
16
  } from '@openai/agents'
17
- import type { ZodSchema } from 'zod'
17
+ import type { ZodType } from 'zod'
18
18
 
19
19
  import type { OutputSchema } from './structured-output'
20
20
 
@@ -23,7 +23,6 @@ export interface Context<
23
23
  TExtraData = any,
24
24
  > {
25
25
  authToken: string
26
- sourceIds: string[]
27
26
  knowledgeUsed: {
28
27
  query: string
29
28
  sourceIds: string[]
@@ -44,7 +43,7 @@ export interface CustomTool<
44
43
  > {
45
44
  name: string
46
45
  description: string
47
- schema: ZodSchema
46
+ schema: ZodType
48
47
  func: (
49
48
  input?: any,
50
49
  runContext?: RunContext<TPlugins, TExtraData>
@@ -1,37 +0,0 @@
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
- interface AIAgentBuilderOptions<TPlugins extends ResolvedPlugins = ResolvedPlugins, TExtraData = any> {
8
- name: string;
9
- instructions: string;
10
- tools: Tool<TPlugins, TExtraData>[];
11
- campaignsContext?: CampaignV2[];
12
- contactInfo: ContactInfo[];
13
- inputGuardrailRules: GuardrailRule[];
14
- sourceIds: string[];
15
- outputMessagesSchemas?: z.ZodObject<any>[];
16
- llmConfig: LLMConfig;
17
- logger: DebugLogger;
18
- guardrailTrackingContext: GuardrailTrackingContext;
19
- }
20
- export declare class AIAgentBuilder<TPlugins extends ResolvedPlugins = ResolvedPlugins, TExtraData = any> {
21
- private name;
22
- private instructions;
23
- private tools;
24
- private externalOutputMessagesSchemas;
25
- private inputGuardrails;
26
- llmConfig: LLMConfig;
27
- private logger;
28
- constructor(options: AIAgentBuilderOptions<TPlugins, TExtraData>);
29
- build(): AIAgent<TPlugins, TExtraData>;
30
- private addExtraInstructions;
31
- private getContactInfoInstructions;
32
- private getMetadataInstructions;
33
- private getCampaignInstructions;
34
- private getOutputInstructions;
35
- private addHubtypeTools;
36
- }
37
- export {};
@@ -1 +0,0 @@
1
- {"version":3,"file":"agent-builder.js","sourceRoot":"","sources":["../../src/agent-builder.ts"],"names":[],"mappings":";;;AACA,2CAIuB;AAGvB,2CAA6C;AAE7C,6CAAmD;AAGnD,2DAAwE;AACxE,mCAA2D;AAoB3D,MAAa,cAAc;IAYzB,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,6BAA6B,GAAG,OAAO,CAAC,qBAAqB,IAAI,EAAE,CAAA;QACxE,IAAI,CAAC,eAAe,GAAG,EAAE,CAAA;QACzB,IAAI,CAAC,SAAS,GAAG,OAAO,CAAC,SAAS,CAAA;QAClC,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,EAC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AAwB,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;AApJD,wCAoJC"}
@@ -1,18 +0,0 @@
1
- import type { ResolvedPlugins } from '@botonic/core';
2
- import type { DebugLogger } from './debug-logger';
3
- import { type LLMConfig } from './llm-config';
4
- import type { AgenticInputMessage, AIAgent, Context, RunResult } from './types';
5
- export declare class AIAgentRunner<TPlugins extends ResolvedPlugins = ResolvedPlugins, TExtraData = any> {
6
- private agent;
7
- private llmConfig;
8
- private inferenceId;
9
- private logger;
10
- constructor(agent: AIAgent<TPlugins, TExtraData>, openAiClient: LLMConfig, inferenceId: string, logger: DebugLogger);
11
- run(messages: AgenticInputMessage[], context: Context<TPlugins, TExtraData>): Promise<RunResult>;
12
- private sendLlmRunTracking;
13
- private getToolsExecuted;
14
- private getToolResultsByCallId;
15
- private extractToolResult;
16
- private getToolExecutionInfo;
17
- private getSafeToolArguments;
18
- }
package/lib/cjs/runner.js DELETED
@@ -1,180 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.AIAgentRunner = void 0;
4
- const agents_1 = require("@openai/agents");
5
- const constants_1 = require("./constants");
6
- const llm_config_1 = require("./llm-config");
7
- const hubtype_api_client_1 = require("./services/hubtype-api-client");
8
- const types_1 = require("./services/types");
9
- const tools_1 = require("./tools");
10
- class AIAgentRunner {
11
- constructor(agent, openAiClient, inferenceId, logger) {
12
- this.agent = agent;
13
- this.llmConfig = openAiClient;
14
- this.inferenceId = inferenceId;
15
- this.logger = logger;
16
- }
17
- async run(messages, context) {
18
- const startTime = Date.now();
19
- this.logger.logRunnerStart(this.llmConfig.modelName, this.llmConfig.modelSettings);
20
- try {
21
- const modelProvider = this.llmConfig.modelProvider;
22
- const modelSettings = this.llmConfig.modelSettings;
23
- const hasRetrieveKnowledge = this.agent.tools.includes(tools_1.retrieveKnowledge);
24
- if (hasRetrieveKnowledge && constants_1.OPENAI_PROVIDER === 'azure') {
25
- modelSettings.toolChoice = tools_1.retrieveKnowledge.name;
26
- }
27
- const runner = new agents_1.Runner({
28
- modelSettings,
29
- modelProvider,
30
- tracingDisabled: true,
31
- });
32
- // Type assertion to bypass strict type checking - the actual return type from runner.run()
33
- // doesn't perfectly match our interface, but the properties we access are compatible
34
- const result = (await runner.run(this.agent, messages, {
35
- context,
36
- }));
37
- const endTime = Date.now();
38
- await this.sendLlmRunTracking(result, context, startTime, endTime);
39
- const outputMessages = result.finalOutput?.messages || [];
40
- const hasExit = outputMessages.length === 0 ||
41
- outputMessages.some(message => message.type === 'exit');
42
- const toolsExecuted = this.getToolsExecuted(result, context);
43
- const runResult = {
44
- messages: hasExit
45
- ? []
46
- : outputMessages.filter(message => message.type !== 'exit'),
47
- toolsExecuted,
48
- exit: hasExit,
49
- memoryLength: messages.length,
50
- error: false,
51
- inputGuardrailsTriggered: [],
52
- outputGuardrailsTriggered: [],
53
- };
54
- this.logger.logRunResult(runResult, startTime);
55
- return runResult;
56
- }
57
- catch (error) {
58
- if (error instanceof agents_1.InputGuardrailTripwireTriggered) {
59
- const runResult = {
60
- messages: [],
61
- memoryLength: 0,
62
- toolsExecuted: [],
63
- exit: true,
64
- error: false,
65
- inputGuardrailsTriggered: error.result.output.outputInfo,
66
- outputGuardrailsTriggered: [],
67
- };
68
- this.logger.logGuardrailTriggered();
69
- this.logger.logRunResult(runResult, startTime);
70
- return runResult;
71
- }
72
- this.logger.logRunnerError(startTime, error);
73
- throw error;
74
- }
75
- }
76
- async sendLlmRunTracking(result, context, startTime, endTime) {
77
- if (!constants_1.isProd) {
78
- return;
79
- }
80
- const rawResponses = result.rawResponses ?? [];
81
- if (rawResponses.length === 0) {
82
- return;
83
- }
84
- const botId = context.request.session.bot.id;
85
- const isTest = context.request.session.is_test_integration;
86
- const totalDuration = endTime - startTime;
87
- const durationPerCall = Math.round(totalDuration / rawResponses.length);
88
- const temperature = this.llmConfig.modelSettings.temperature ?? 0;
89
- const apiVersion = (0, llm_config_1.getApiVersion)();
90
- const llmRuns = rawResponses.map(response => ({
91
- inference_id: this.inferenceId,
92
- is_test: isTest,
93
- product_name: types_1.TrackProductName.AI_AGENT,
94
- deployment_name: this.llmConfig.modelName,
95
- model_name: response.providerData?.['model'] ??
96
- this.llmConfig.modelName,
97
- feature: types_1.TrackFeature.AI_AGENT_RUN,
98
- api_version: apiVersion,
99
- num_prompt_tokens: response.usage.inputTokens,
100
- num_completion_tokens: response.usage.outputTokens,
101
- duration_in_milliseconds: durationPerCall,
102
- temperature,
103
- error: null,
104
- }));
105
- const client = new hubtype_api_client_1.HubtypeApiClient(context.authToken);
106
- await client.trackLlmRuns(botId, {
107
- llm_runs: llmRuns,
108
- });
109
- }
110
- getToolsExecuted(result, context) {
111
- const toolResultsByCallId = this.getToolResultsByCallId(result.newItems);
112
- return (result.newItems
113
- ?.filter(item => item instanceof agents_1.RunToolCallItem)
114
- .map((item) => this.getToolExecutionInfo(item, context, toolResultsByCallId))
115
- .filter((toolExecution) => toolExecution.toolName !== '') || []);
116
- }
117
- getToolResultsByCallId(newItems) {
118
- const map = new Map();
119
- for (const item of newItems || []) {
120
- if (!(item instanceof agents_1.RunToolCallOutputItem)) {
121
- continue;
122
- }
123
- const rawItem = item.rawItem;
124
- const callId = rawItem?.callId;
125
- const output = rawItem?.output;
126
- if (callId == null || output == null) {
127
- continue;
128
- }
129
- const text = this.extractToolResult(output);
130
- if (text != null) {
131
- map.set(callId, text);
132
- }
133
- }
134
- return map;
135
- }
136
- extractToolResult(output) {
137
- if (typeof output === 'string') {
138
- return output;
139
- }
140
- return output?.type === 'text' && typeof output?.text === 'string'
141
- ? output.text
142
- : undefined;
143
- }
144
- getToolExecutionInfo(item, context, toolResultsByCallId) {
145
- if (item.rawItem.type !== 'function_call') {
146
- return {
147
- toolName: '',
148
- toolArguments: {},
149
- };
150
- }
151
- const toolName = item.rawItem.name;
152
- const toolArguments = this.getSafeToolArguments(item.rawItem.arguments);
153
- const toolResults = item.rawItem.callId
154
- ? toolResultsByCallId.get(item.rawItem.callId)
155
- : undefined;
156
- const toolExecution = {
157
- toolName,
158
- toolArguments,
159
- toolResults,
160
- };
161
- if (toolName === tools_1.retrieveKnowledge.name) {
162
- return {
163
- ...toolExecution,
164
- knowledgebaseSourcesIds: context.knowledgeUsed.sourceIds,
165
- knowledgebaseChunksIds: context.knowledgeUsed.chunksIds,
166
- };
167
- }
168
- return toolExecution;
169
- }
170
- getSafeToolArguments(rawToolArguments) {
171
- try {
172
- return JSON.parse(rawToolArguments);
173
- }
174
- catch (_error) {
175
- return {};
176
- }
177
- }
178
- }
179
- exports.AIAgentRunner = AIAgentRunner;
180
- //# sourceMappingURL=runner.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"runner.js","sourceRoot":"","sources":["../../src/runner.ts"],"names":[],"mappings":";;;AAKA,2CAKuB;AACvB,2CAAqD;AAErD,6CAA4D;AAC5D,sEAAgE;AAChE,4CAAiE;AACjE,mCAA2C;AAsB3C,MAAa,aAAa;IASxB,YACE,KAAoC,EACpC,YAAuB,EACvB,WA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AO;gBACL,GAAG,aAAa;gBAChB,uBAAuB,EAAE,OAAO,CAAC,aAAa,CAAC,SAAS;gBACxD,sBAAsB,EAAE,OAAO,CAAC,aAAa,CAAC,SAAS;aACxD,CAAA;QACH,CAAC;QAED,OAAO,aAAa,CAAA;IACtB,CAAC;IAEO,oBAAoB,CAAC,gBAAwB;QACnD,IAAI,CAAC;YACH,OAAO,IAAI,CAAC,KAAK,CAAC,gBAAgB,CAAC,CAAA;QACrC,CAAC;QAAC,OAAO,MAAM,EAAE,CAAC;YAChB,OAAO,EAAE,CAAA;QACX,CAAC;IACH,CAAC;CACF;AApPD,sCAoPC"}
@@ -1,37 +0,0 @@
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
- interface AIAgentBuilderOptions<TPlugins extends ResolvedPlugins = ResolvedPlugins, TExtraData = any> {
8
- name: string;
9
- instructions: string;
10
- tools: Tool<TPlugins, TExtraData>[];
11
- campaignsContext?: CampaignV2[];
12
- contactInfo: ContactInfo[];
13
- inputGuardrailRules: GuardrailRule[];
14
- sourceIds: string[];
15
- outputMessagesSchemas?: z.ZodObject<any>[];
16
- llmConfig: LLMConfig;
17
- logger: DebugLogger;
18
- guardrailTrackingContext: GuardrailTrackingContext;
19
- }
20
- export declare class AIAgentBuilder<TPlugins extends ResolvedPlugins = ResolvedPlugins, TExtraData = any> {
21
- private name;
22
- private instructions;
23
- private tools;
24
- private externalOutputMessagesSchemas;
25
- private inputGuardrails;
26
- llmConfig: LLMConfig;
27
- private logger;
28
- constructor(options: AIAgentBuilderOptions<TPlugins, TExtraData>);
29
- build(): AIAgent<TPlugins, TExtraData>;
30
- private addExtraInstructions;
31
- private getContactInfoInstructions;
32
- private getMetadataInstructions;
33
- private getCampaignInstructions;
34
- private getOutputInstructions;
35
- private addHubtypeTools;
36
- }
37
- export {};
@@ -1 +0,0 @@
1
- {"version":3,"file":"agent-builder.js","sourceRoot":"","sources":["../../src/agent-builder.ts"],"names":[],"mappings":";;;AACA,2CAIuB;AAGvB,2CAA6C;AAE7C,6CAAmD;AAGnD,2DAAwE;AACxE,mCAA2D;AAoB3D,MAAa,cAAc;IAYzB,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,6BAA6B,GAAG,OAAO,CAAC,qBAAqB,IAAI,EAAE,CAAA;QACxE,IAAI,CAAC,eAAe,GAAG,EAAE,CAAA;QACzB,IAAI,CAAC,SAAS,GAAG,OAAO,CAAC,SAAS,CAAA;QAClC,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,EACzC,OAAO,CAAC,mBAAmB,EAC3B,OAAO,CAAC,SAAS,EACjB,OAAO,CAAC,wBAAwB,CACjC,CAAA;YACD,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,cAAc,CAAC,CAAA;QAC3C,CAAC;IACH,CAAC;IAED,KAAK;QACH,+DAA+D;QAC/D,4CAA4C;QAE5C,MAAM,KAAK,GAAG,IAAI,CAAC,SAAS,CAAC,SAAS,CAAA;QACtC,MAAM,oBAAoB,GAAG,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,yBAAiB,CAAC,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