Skip to content

Commit 1e416bf

Browse files
committed
feat: when agent responds with a exit_tool plugin follow with knowledge base or fallback
1 parent 7159fe4 commit 1e416bf

File tree

3 files changed

+45
-4
lines changed

3 files changed

+45
-4
lines changed

packages/botonic-plugin-ai-agents/src/types.ts

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export interface AiAgentRequestDataTest {
1919
instructions: string
2020
}
2121

22-
export type MessageRole = 'user' | 'assistant'
22+
export type MessageRole = 'user' | 'assistant' | 'tool'
2323

2424
export interface AiAgentRequestData {
2525
message: string
@@ -29,5 +29,23 @@ export interface AiAgentRequestData {
2929
}
3030

3131
export interface AiAgentResponse {
32-
message: { role: string; content: string }
32+
message: AgentMessage
3333
}
34+
35+
export interface AssistantMessage {
36+
role: 'assistant'
37+
content: string
38+
}
39+
40+
export interface UserMessage {
41+
role: 'user'
42+
content: string
43+
}
44+
45+
export interface ToolMessage {
46+
role: 'tool'
47+
tool_name: string
48+
tool_params?: Record<string, unknown>
49+
}
50+
51+
export type AgentMessage = AssistantMessage | ToolMessage

packages/botonic-plugin-flow-builder/src/action/ai-agent.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,18 @@ function updateContentsWithAiAgentResponse(
4242
contents: FlowContent[],
4343
aiAgentResponse: AiAgentResponse
4444
): FlowContent[] {
45+
if (
46+
aiAgentResponse.message.role === 'tool' &&
47+
aiAgentResponse.message.tool_name === 'exit_agent'
48+
) {
49+
return []
50+
}
51+
4552
return contents.map(content => {
46-
if (content instanceof FlowAiAgent) {
53+
if (
54+
content instanceof FlowAiAgent &&
55+
aiAgentResponse.message.role === 'assistant'
56+
) {
4757
content.text = aiAgentResponse.message.content
4858
}
4959

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

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,22 @@ export interface KnowledgeBaseResponse {
8989
}
9090

9191
export interface AiAgentResponse {
92-
message: { role: string; content: string }
92+
message: AgentMessage
9393
}
9494

95+
interface AssistantMessage {
96+
role: 'assistant'
97+
content: string
98+
}
99+
100+
interface ToolMessage {
101+
role: 'tool'
102+
tool_name: string
103+
tool_params?: Record<string, unknown>
104+
}
105+
106+
export type AgentMessage = AssistantMessage | ToolMessage
107+
95108
export interface SmartIntentResponse {
96109
data: {
97110
smart_intent_title: string

0 commit comments

Comments
 (0)