Agent based healthcare chatbot

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?

1 Like

Hello,

Did you try something yet? I would recommend starting with this documentation about the OpenAI Assitant https://platform.openai.com/docs/assistants/overview

Depending on the amount of information you have, you could do two things:

  1. If it’s a lot of information (more than 128,000) you could use the Assistants API and give it all the info as a PDF file and ask your questions

  2. If the information can be inside the 128,000, just add it as part of the prompt using the completions API.

In both cases I suggest you use tool calling so the answer has a well designed structure.

2 Likes

The assistant works. We have built that part. We want to have a way of conversing with the Chatbot and using the assistant to do the lookup part.

What is tool calling? Any information on that.

Good! What is your next step? You need to add the chatbot to your website and you want to make it accessible?

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.

What is tool calling? Any information on that.

Used to be called function calling:

https://platform.openai.com/docs/assistants/tools/function-calling

It can be a bit confusing the first time you read that because can give you the impression that you actually need to code something.

You don’t. What you do is define a JSON schema for the response status.

e.g. you have your healthcare data in a PDF and the JSON schema basically says that the LLM will always return this structure:

  • Name of the patient (string)
  • Age (number)
  • Cholestrol LDL level (number)
  • Cholestrol LDL level status (enum [“optimal”, “near optimal”, “borderline high”, “high”, “very high”])

and so on.

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.

2 Likes

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.

1 Like

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?

1 Like

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.

3 Likes

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.

2 Likes

Yes. In any case if the solution requires a connection to something like SQL server, function calling is still a very useful (almost required) tool

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