Skip to content

Commit 3f1152c

Browse files
committed
test: add a test that check behavior for exit_agent tool
1 parent 1e416bf commit 3f1152c

File tree

3 files changed

+28
-14
lines changed

3 files changed

+28
-14
lines changed

packages/botonic-plugin-flow-builder/src/types.ts

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
1-
import {
2-
BotContext,
3-
PluginPreRequest,
4-
ResolvedPlugins,
5-
Session,
6-
} from '@botonic/core'
1+
import { BotContext, PluginPreRequest, ResolvedPlugins } from '@botonic/core'
72

83
import { HtFlowBuilderData } from './content-fields/hubtype-fields'
94

@@ -92,19 +87,18 @@ export interface AiAgentResponse {
9287
message: AgentMessage
9388
}
9489

95-
interface AssistantMessage {
90+
export type AgentMessage = AssistantMessage | ToolMessage
91+
export interface AssistantMessage {
9692
role: 'assistant'
9793
content: string
9894
}
9995

100-
interface ToolMessage {
96+
export interface ToolMessage {
10197
role: 'tool'
10298
tool_name: string
10399
tool_params?: Record<string, unknown>
104100
}
105101

106-
export type AgentMessage = AssistantMessage | ToolMessage
107-
108102
export interface SmartIntentResponse {
109103
data: {
110104
smart_intent_title: string

packages/botonic-plugin-flow-builder/tests/__mocks__/ai-agent.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
interface MockAiAgentOptions {
2-
message: { role: string; content: string }
3-
}
1+
import { AiAgentResponse } from '../../src/types'
42

5-
export function mockAiAgentResponse({ message }: MockAiAgentOptions) {
3+
export function mockAiAgentResponse({ message }: AiAgentResponse) {
64
return jest.fn(() => {
75
return Promise.resolve({ message })
86
})

packages/botonic-plugin-flow-builder/tests/ai-agent.test.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,4 +59,26 @@ describe('Check the contents returned by the plugin when it use an ai agent', ()
5959
'I can provide you with information about current temperatures, forecasts, and the probability of rain for your location. Just let me know where you are or where you’re interested in, and I’ll give you the details!'
6060
)
6161
})
62+
63+
test('When agent response is of role tool and name exit_agent, the plugin should respond with the tool response of fallback flow', async () => {
64+
const { contents } = await createFlowBuilderPluginAndGetContents({
65+
flowBuilderOptions: {
66+
flow: aiAgentTestFlow,
67+
getAiAgentResponse: mockAiAgentResponse({
68+
message: {
69+
role: 'tool',
70+
tool_name: 'exit_agent',
71+
},
72+
}),
73+
},
74+
requestArgs: {
75+
input: {
76+
data: 'Who has won the league this year?',
77+
type: INPUT.TEXT,
78+
},
79+
},
80+
})
81+
82+
expect((contents[0] as FlowText).text).toEqual('Fallback')
83+
})
6284
})

0 commit comments

Comments
 (0)