Well it’s quite complicated, I’m used langchain and it doesn’t support it natively so I’ve tried my best
I’ll share an example of memory history (it’s in italian)
MESSAGES: {
"history": [
{
"id": [
"HumanMessage"
],
"kwargs": {
"content": "Buonasera, vorrei prenotare un tavolo per stasera alle 21 fuori.",
"additional_kwargs": {}
}
},
{
"id": [
"AIMessage"
],
"kwargs": {
"content": "",
"additional_kwargs": {
"function_call": {
"name": "selezione_azione",
"arguments": "{\n \"selezione\": \"prenotazione\"\n}"
}
}
}
},
{
"id": [
"FunctionMessage"
],
"kwargs": {
"content": "{azione:\"prenotazione\"}",
"name": "selezione_azione",
"additional_kwargs": {
"name": "selezione_azione"
}
}
},
{
"id": [
"HumanMessage"
], "kwargs": {
"content": "",
"additional_kwargs": {}
}
},
{
"id": [
"AIMessage"
],
"kwargs": {
"content": "",
"additional_kwargs": {
"function_call": {
"name": "prenotazione",
"arguments": "{\n \"data\": {\n \"giorno\": \"oggi\",\n \"orario\": \"21:00\"\n },\n \"extra\": {\n \"zona\": \"fuori\"\n }\n}"
}
}
}
}
]
}
After this i remove the last Function Message and the last empty Human Message leaving AIMessage only.
Now the AI should be able to detect that an answer is possible to be given, but it replay the function another time
MESSAGES: {
"history": [
{
"id": [
"HumanMessage"
],
"kwargs": {
"content": "Buonasera, vorrei prenotare un tavolo per stasera alle 21 fuori.",
"additional_kwargs": {}
}
},
{
"id": [
"AIMessage"
],
"kwargs": {
"content": "",
"additional_kwargs": {
"function_call": {
"name": "selezione_azione",
"arguments": "{\n \"selezione\": \"prenotazione\"\n}"
}
}
}
},
{
"id": [
"AIMessage"
],
"kwargs": {
"content": "",
"additional_kwargs": {
"function_call": {
"name": "prenotazione",
"arguments": "{\n \"data\": {\n \"giorno\": \"oggi\",\n \"orario\": \"21:00\"\n },\n \"extra\": {\n \"zona\": \"fuori\"\n }\n}"
}
}
}
}, {
"id": [
"FunctionMessage"
],
"kwargs": {
"content": "{tavolo_disponibile:true}",
"name": "prenotazione",
"additional_kwargs": {
"name": "prenotazione"
}
}
},
{
"id": [
"HumanMessage"
],
"kwargs": {
"content": "",
"additional_kwargs": {}
}
},
{
"id": [
"AIMessage"
],
"kwargs": {
"content": "",
"additional_kwargs": {
"function_call": {
"name": "prenotazione",
"arguments": "{\n \"data\": {\n \"giorno\": \"oggi\",\n \"orario\": \"21:00\"\n },\n \"extra\": {\n \"zona\": \"fuori\"\n }\n}"
}
}
}
}
]
}
And it goes over in the same loop. If instead of asking “Stasera alle 21 fuori” I just ask “Stasera alle 21” it works as it should