Automating Chat

I’ve recently started more deeply pondering how to utilize the LLMs and automation more deeply in my workflow. I have attempted a couple of scripts and felt slightly stymied. When David Sparks released his Robot Assistant Field Guide this week, my interest was again piqued. I want to feed DEVONthink a chat query and have it look in a particular group to establish its “knowledge base”. As an example, if I have a patient ask me a question via text or email, I want DEVONthink to utilize the history of this patient that I have in a group to help me come up with answers. I am able to do all of it up until the point of “get chat response for message” as I get a response about only being able to access the metadata for the group if I send it a reference to the group or I get a too many records error if I send it a reference to the children of said group.

DEVONthink handles all of this properly if I select the group in a think window and type my prompt into the chat window manually. Is there a way to get the same functionality via an AppleScript call?

Rick

What is this, specifically?

Also, you’ve said nothing about the AI provider and model you’re using.

DT4 is great for generic literature searches.

With regard to specific patient queries, have you considered OpenEvidence given that (1) It is HIPAA compliant; and (2) It is purpose-built for such queries and extremely helpful/accurate with its responses and literature citations?; and (3) It is free for licensed medical providers or healthcare related students

Currently the group contains all the emails and text messages I’ve exchanged with that particular patient (named as patient full name), but could easily contain text documents with current problem list, current medications, etc.

I did not realize that specific AI provider mattered. I would hope that changing between them once I discover which is “best” at the moment would be possible. I am dabbling in both ChatGPT and Claude Cowork. Within DT, I have ChatGPT selected with GPT 5.2 as default.

Rick

I do have and utilize OpenEvidence. This is a different sort of workflow though. I want empathetic, yet scientifically accurate information in concise language. This is not particularly challenging evidence I am going for, but more a tone with how to get it across… (I tend to be a little too scientific when denying a desired/requested prescription to my patients).

HIPAA compliance is the specific reason I want to keep the data within DEVONthink.

Rick

MORE specifically, here is the prompt that ChatGPT has helped me come up with (first iteration):slight_smile:

**Task:** Draft a medically appropriate, empathetic **text-message reply** (max **900 characters**, 1-2 short paragraphs + bullets OK) to the patient message below.

**Context:** Before drafting, **search this DEVONthink group** for the patient’s **prior texts from the last 24 months** and extract: (a) the **exact meds** previously prescribed or recommended, (b) any **documented allergies**, (c) any prior **antibiotic courses and outcomes**, and (d) any pattern of **repeated antibiotic requests**.

**Output requirements:**

- Include **2-4 targeted follow-up questions** only if pertinent to the problem at hand (focus on red flag symptoms, duration/worsening).

- Give **1-3 specific, safe OTC/self-care suggestions** that don’t duplicate ingredients.

- If pertinent to the complaint, add if antibiotics are/aren’t indicated, state that **briefly** and suggest **next step**(same-day visit vs. watchful waiting).

- Avoid long explanations; keep it **SMS length**.

- After the draft text, add a short **Used context:** … line listing the key meds/history of similar complaints you pulled from prior messages. References are for me and not to be included in the text response to the patient.

**Patient’s latest message:**

OK but you need to use local LLM in that case.

Or you need to establish a HIPAA BAA with Anthropic - they used to do that readyil but it’s hard to do nowadays unless you are an Enterprise customer.

Or you could get a BastionGPT account with a HIPAA BAA and use the DT4 OpenAI cinoatubke endpoint:

@jrickmd so you really want to send patients’ emails and data to openai?

2 Likes

Hmmm. What I understood was that if it was in DT, it used that data locally no matter the agent. I will have to go back and re-read the specifics. :grimacing:

Ok, now that we’ve established my ignorance and future privacy and HIPAA violations (thank you both and likely what @BLUEFROG was also getting at :grimacing: ), I have moved to Ollama and can get a deidentified review of history through the chat window.

Is there a way to interact in an automated fashion with DEVONthink to gather this from Ollama without manually selecting the patient group and typing into the chat window?

Rick

As long as you have API access to the AI provider, you can dynamically change the provider/model.

Note: Claude Cowork is an entirely separate thing and inaccessible in DEVONthink.

I have moved to Ollama and can get a deidentified review of history through the chat window.

Local AI is very hardware-limited. See the Getting Started > AI Explained section of the built-in Help and manual. That being said, again, what model are you attempting to use. Practically, a 20B parameter model is the bare minimum for “professional” work but that also realistically requires a Mac with 32GB RAM or more.

Is there a way to interact in an automated fashion with DEVONthink to gather this from Ollama?

Ollama is not the LLM. It’s the interface for the LLM. So if you’re referring to using Ollama’s chat interface, no DEVONthink isn’t going to talk to or share information with it. DEVONthink can talk to Ollama, directing its prompts to a loaded model.

without manually selecting the patient group and typing into the chat window

What is the issue with selecting the patient group?
And such intentionality is strongly recommended as DEVONthink does what it can to isolate your data. AI doesn’t get free-for-all access to your databases.

First, I appreciate the thoughtfulness of your reply and also appreciate DEVONthink’s privacy oriented thought processes.

What I’ve landed on right now with Claude’s help is using the Ollama integration for very simple summarization and de-identifying of data on my local computer. With that now protected data, I would do more of the intensive work with Claude. What I need from DT to automate that process is to be able to call an AppleScript with my chat prompt and a reference to the group, and have it do what it does now when I type in the chat prompt when the group is selected.

Automations such as this are my joy and I do as much as I can to keep that joy. To ME this cries out to be automated rather than selecting a group (which I do automate) and then typing my prompt into the chat. I would be more than happy with the AS restricting to a single group as a means of protecting the user’s database which would replicate what I’m doing by typing into chat and then copying out the result.

I think an example with screenshots would be a big help to understand your goals and workflow.