think of a use case, a healthcare chatbot which is also agent based. We have written the agent and it responds with a query MRN. The agent uses the gpt-4o model, to perform the task given in the instructions.
What we want to do is, suppose there is a chatbot that specifically starts with an MRN input and save it in memory, and then lookup using the MRN to find the information requested by user. The conversation could go like “Hi, How are you”?
BOT - “I am doing fine. Please provide me with the MRN to be used”
and then the user could ask, “what is the value of last Cholestrol LDL levels?”, and it finds an answer by going through the agent and perform an instruction set. Is all this doable? If yes, then how?
Basically, we want convert the agent into an interaction based chatbot, we don’t know how?
For now what we want is instead of providing the MRN as a search query, we are thinking of giving a conversational edge to it, by converting it into a chatbot. So it converses around the data on which the assistant is hooked up. For eg. it greets the user, like chatgpt does, does not answer outside the scope which is the data fetched by using the MRN.
You are basically giving the LLM the structure of the output and the machine tries to make the best decision to fill out the fields you have defined with the rules or restrictions you want.
My approach for this is to always do it on WhatsApp. At least in my context (LATAM), WhatsApp is the main communication tool for persons and businesses so it’s the natural thing.
Thank you for the information. I’m not sure if I fully understand your approach. My understanding of function calling is that if I use a function, I actually need to write it, execute it (when required) and then submit the result to the thread. Is there another way?
The suggestion from @geekykidstuff focuses on a product design where the model receives all necessary data for answering the question directly through the prompt.
In contrast, you’re referring to a solution where the model calls a function, passing an anonymized user ID to a service like an SQL server, which then returns the requested data for the model to process and present to the user.
I find the second option to be far more reliable, especially when handling sensitive and critical data.
From a product design perspective, it’s essential to ensure the data presented to the human in the loop is accurate. I strongly recommend investing the additional time to go through the function calling and assistants API examples in the cookbook.https://cookbook.openai.com/
Alternatively, if at all possible, you can also supply the assistant with the required data and run extensive evaluations to ensure optimal results.
I think I got it. We have to switch context by requesting User Inputs. Something like below conversation thread
U - Hi
B - Hi, How are you? Please provide me with the MRN to be used.
U - 1234567
B - Please tell me what would you like to know? 1. Labs, 2. Meds, 3. Radiology 4. General
and so on the conversation continues. Now these conversations can go to the chat completions api for a more human sounding conversation.
When the user supplies the MRN, it goes through assistants api to gather all data that it has found in the database, and then the chatbot takes over.
My understanding of function calling is that if I use a function, I actually need to write it, execute it (when required) and then submit the result to the thread. Is there another way?
You don’t write the function you send as in “coding” the function. You define the JSON schema of the function (check my previous answer) and that’s what you send to the API.
The API will return the data following the structure you defined and the idea is that structure is compatible with functions you have in your backend for instance.
So imagine you have a function written in Python that expects a date and a total amount and computes some projected value.
You send to GPT a whole text that contains a lot of data but you only care about the amount and date mentioned in the text. So your JSON schema (your tool calling) has a structure that has total_amount and date.
So each time you send a text to GPT, the API will extract those two parameters from your text and, since you already have structured data, now you can use them directly in you Python function that receives those values as argument to compute something