I am creating an AI that does customer service. And it needs to update a database column when the user answers all the qualification questions.
That is, there is a function:
name: “answered_questions_db”
description: “Use this function to update the database, after the lead answers all the questions”
And then I created a Python function called “answered_questions_db”, which takes the lead’s ID as a parameter and updates the database.
In the AI’s system prompt, there’s a part:
"after the lead answers all the above questions, update the database by calling the function ‘answered_questions_db’
The problem is that the AI is not calling the function and in the conversation with the lead returns as an answer “I updated the database…”.
What is the ideal prompt to force the AI to execute a function at a certain stage of the service?
Note: The problem is not in the code, because in the AI’s prompt instructions there are other instructions like this, where I tell the AI to call the function to update the database or perform some action, and it is working normally. For example, after asking the lead’s name, the AI creates a new row in the database with the lead’s name and phone number.
Remove any talk about functions from the system prompt.
Place all usage guidelines into the function description and description of parameters.
Then just make sure those descriptions include clear language an AI can conditionally evaluate without ambiguity. What the function does for the user and what it returns that will improve answering or to report on the success should be made clear.
1 Like
AI is not capable of literally calling the function, but instead responding with an accurate function object with correct arguments present. The actual call must be done independently in code, once functional call is detected in a run.
The ability to identify the function needs and readying its arguments is what AI achieves for you here. Not the literal call.
If you’re expecting APIs to literally call functions present in your code base, then you’re mistaken. It can only give you the valid function call object, with all relevant parameters pre-filled.
Try :
Identify when functional call is required as part of run ?
Trigger the function with arguments already present.
Include response in thread, continue AI response workflow.
Hope this helps ! Lear more here
Dude, thank you so much, it worked perfectly on the first try!
When I create a function that serves to create a response for the Lead, it worked without any difficulty, as the AI easily understands that it needs that function to respond.
However, the functions I am creating are actions parallel to the service, which do not need to be “fulfilled” in order to respond to the lead, like this case of updating a database, according to the lead’s response.
sorry for my english, Im using GPT to translate 