Skip to content

Commit f05075d

Browse files
committed
feat: add human-agent-handoff and avaliable-flights tools
1 parent 0713754 commit f05075d

File tree

1 file changed

+64
-9
lines changed

1 file changed

+64
-9
lines changed

packages/botonic-plugin-flow-builder/src/content-fields/flow-ai-agent.tsx

+64-9
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { HandOffBuilder } from '@botonic/core'
12
import { ActionRequest, Text } from '@botonic/react'
23
import axios, { AxiosResponse } from 'axios'
34

@@ -110,6 +111,35 @@ const actionResults = (parameters: any) => {
110111
status: 'on time',
111112
...parameters,
112113
},
114+
'human-agent-handoff': {
115+
queueId: 'b5062566-b5f6-4e68-be44-d95697dbac11',
116+
...parameters,
117+
},
118+
'available-flights': {
119+
flights: [
120+
{
121+
number: 'XDC1234',
122+
departureTime: new Date().toISOString(),
123+
arrivalTime: new Date(
124+
new Date().getTime() + 2 * 60 * 60 * 1000
125+
).toISOString(),
126+
departureLocation: parameters.departure_location,
127+
arrivalLocation: 'Madrid',
128+
status: 'on time',
129+
},
130+
{
131+
number: 'XDC1235',
132+
departureTime: new Date().toISOString(),
133+
arrivalTime: new Date(
134+
new Date().getTime() + 3 * 60 * 60 * 1000
135+
).toISOString(),
136+
departureLocation: parameters.departureLocation,
137+
arrivalLocation: 'London',
138+
status: 'delayed',
139+
},
140+
],
141+
...parameters,
142+
},
113143
}
114144
}
115145

@@ -148,13 +178,32 @@ class AiAgentAPI {
148178
// TODO: Resolve how to executed the actions in the bot
149179
// const result = action.name(action.parameters)
150180
const result = actionResults(action.parameters)[action.name]
181+
if (action.name === 'human-agent-handoff') {
182+
await this.handoff(request, result.queueId)
183+
newActionCallsOutputs.push({
184+
name: action.name,
185+
args: action.parameters,
186+
call_id: action.call_id,
187+
output: 'Case created',
188+
})
189+
} else if (action.name === 'exit') {
190+
console.log('EXIT!!!!!!!!')
191+
request.session.aiAgent!.active = false
192+
newActionCallsOutputs.push({
193+
name: action.name,
194+
args: action.parameters,
195+
call_id: action.call_id,
196+
output: 'ya no hablas con ai agent',
197+
})
198+
} else {
199+
newActionCallsOutputs.push({
200+
name: action.name,
201+
args: action.parameters,
202+
call_id: action.call_id,
203+
output: JSON.stringify(result),
204+
})
205+
}
151206
console.log('Response with actions:', response)
152-
newActionCallsOutputs.push({
153-
name: action.name,
154-
args: action.parameters,
155-
call_id: action.call_id,
156-
output: JSON.stringify(result),
157-
})
158207
}
159208

160209
return await this.runLoop(
@@ -214,8 +263,8 @@ class AiAgentAPI {
214263
toolMessages.push(toolMessage)
215264
toolCalls.push({
216265
id: action_call_output.call_id,
217-
name: 'action',
218-
args: {},
266+
name: action_call_output.name, //'action',
267+
args: action_call_output.args, //{},
219268
})
220269
}
221270
messages.push({ role: 'ai', tool_calls: toolCalls })
@@ -239,12 +288,18 @@ class AiAgentAPI {
239288

240289
if (response.data.actions) {
241290
console.log('Actions from api agent ai', response.data.actions)
242-
request.session.aiAgent!.active = false
291+
// request.session.aiAgent!.active = false
243292
return { actions: response.data.actions }
244293
}
245294
} catch (e) {
246295
console.error(e)
247296
}
248297
return { answer: 'API call failed' }
249298
}
299+
300+
async handoff(request: ActionRequest, queueId: string): Promise<void> {
301+
const handoffBuilder = new HandOffBuilder(request.session)
302+
handoffBuilder.withQueue(queueId)
303+
handoffBuilder.handOff()
304+
}
250305
}

0 commit comments

Comments
 (0)