How I Built Smarter AI Tools for Pharma: From Generative AI to Agentic AI
- Rifx.Online
- Generative AI , Autonomous Systems , Health
- 19 Jan, 2025
When I first started developing AI tools for the pharmaceutical industry, my idea was simple: to tackle real, everyday challenges. I’ve spent years watching compliance teams drowning in paperwork, medical writers struggling to communicate complex information to patients, and countless people lost in the maze of their healthcare journeys. Generative AI seemed like the answer — and in many ways, it was. But as we’ve seen these tools deployed, I began to see their limitations. They are powerful, yes, but passive — always waiting for the next command, the next prompt.
That realization led me to explore Agentic AI — a concept where tools don’t just respond but act, adapt, and anticipate.
In this article, I’ll share how my tools reflect these principles, their current capabilities, and where I see them going in the future.
Dynamic Retrieval for Smarter Compliance Analysis
Regulatory compliance is one of the most time-consuming processes in the pharmaceutical industry. Reviewing promotional claims against evolving codes of practice requires attention to detail, legal knowledge, and hours of manual work. My compliance tool simplifies this process by using Retrieval-Augmented Generation (RAG), which combines real-time data retrieval with the analytical power of Generative AI.
At the heart of this system is the ability to dynamically fetch regulatory data from a Firestore database. This ensures that the tool always works with the latest rules and guidelines, whether analyzing claims under the ABPI code or other frameworks.
Here’s how the function retrieves relevant code excerpts for analysis:
async function getCodeExcerpts(codes) {
const codeExcerpts = {};
for (const code of codes) {
const doc = await db.collection("claims").doc(code).get();
if (doc.exists) {
codeExcerpts[code] = doc.data();
} else {
console.error(`Code ${code} not found in Firestore`);
throw new Error(`Code ${code} not found in Firestore`);
}
}
return codeExcerpts;
}
How It Works
1. Selecting Codes: Users choose the regulatory codes they want to apply to their content (e.g., ABPI, EFPIA or PhRMA).
2. Fetching Relevant Data: The tool queries Firestore to retrieve the exact sections of the chosen codes relevant to the claim being analyzed.
3. Grounding AI Outputs: These code excerpts are fed into the AI, ensuring its suggestions and analyses are grounded in verified, domain-specific rules.
By integrating real-time retrieval, the tool eliminates the risk of outdated analysis and ensures its outputs are always aligned with current regulations. This not only saves users time but also reduces compliance risks by grounding AI decisions in trusted, up-to-date data.
While the current version of the tool uses RAG to ground its outputs in reliable data, it remains largely reactive, waiting for users to input claims or select codes for analysis.
Transforming it into a fully agentic system would allow the tool to take initiative and act autonomously.
By taking initiative, adapting to changes, and collaborating seamlessly with users, the tool could significantly reduce the workload for compliance teams while improving the accuracy and timeliness of regulatory reviews.
But compliance is just one piece of the puzzle. Tailoring medical communication is another critical challenge AI can help solve.
Personalizing Medical Text for All
Communicating medical information effectively requires tailoring it to different audiences — patients, caregivers, and healthcare professionals all need information presented in a way that suits their understanding and needs. To address this challenge, I developed a tool that uses audience-specific prompts combined with Generative AI to optimize medical text dynamically.
Here’s an example of how the backend processes text for different audiences:
async function optimiseText(text, audiencePrompt, tonePrompt, apiKey) {
try {
const response = await callOpenAI(apiKey, [
{
role: "system",
content: `${audiencePrompt} ${tonePrompt}`
},
{
role: "user",
content: text
}
]);
return response;
} catch (error) {
console.error("Error in optimiseText:", error);
throw error;
}
}
How It Works
1. Audience Prompts: Each audience has a specific prompt. For example:
• For a child: “Explain this as if talking to a 7-year-old. Use simple words, short sentences, and fun analogies.”
• For a pharmacist: “Focus on medication-related details, drug interactions, and patient counseling tips.”
2. Tone Prompts: The tool also adjusts tone based on user preferences, such as making the message more confident, friendly, or scientific.
3. Generative AI Processing: The tool sends the text, audience prompt, and tone prompt to OpenAI’s API, which returns a tailored response.
By adapting medical text to both the audience and tone, the tool bridges communication gaps and ensures that complex medical information is clear, accessible, and actionable.
Currently, the tool relies on prompts to adjust content. To make it more agentic, I’m working on incorporating real-time feedback loops. For example, if a user consistently prefers simpler explanations, the tool could automatically adapt its outputs over time.
Empowering Patients with Doctor-Ready Questions
Understanding medical notes is only half the battle for patients — asking the right questions during doctor appointments can make all the difference. Patiently AI is an iOS app that generates relevant, tailored questions based on the user’s medical notes. This feature ensures patients feel more confident and prepared when discussing their health with their doctor.
Here’s how the backend generates these questions:
func generateQuestions(fromText text: String, completion: @escaping (Result<[String], Error>) -> Void) {
guard let url = URL(string: "https://us-central1-medicaltextoptimiser.cloudfunctions.net/translate") else {
completion(.failure(NSError(domain: "Invalid URL", code: 0, userInfo: nil)))
return
}
var request = URLRequest(url: url)
request.httpMethod = "POST"
request.addValue("application/json", forHTTPHeaderField: "Content-Type")
let payload: [String: Any] = [
"type": "generateQuestions",
"text": text
]
do {
request.httpBody = try JSONSerialization.data(withJSONObject: payload, options: [])
} catch {
completion(.failure(error))
return
}
URLSession.shared.dataTask(with: request) { data, response, error in
if let error = error {
completion(.failure(error))
return
}
guard let data = data, let httpResponse = response as? HTTPURLResponse, httpResponse.statusCode == 200 else {
completion(.failure(NSError(domain: "Invalid Response", code: 0, userInfo: nil)))
return
}
do {
if let json = try JSONSerialization.jsonObject(with: data, options: []) as? [String: Any],
let questions = json["questions"] as? [String] {
completion(.success(questions))
} else {
completion(.failure(NSError(domain: "Invalid JSON", code: 0, userInfo: nil)))
}
} catch {
completion(.failure(error))
}
}.resume()
}
How It Works
1. User Input: The user provides their medical notes as input.
2. Tailored Generation: The backend processes the notes and generates a list of relevant questions.
3. Actionable Output: The questions are tailored to help patients seek clarity on diagnoses, treatment options, and next steps.
Example Output
For the input: “The patient was diagnosed with hypertension and prescribed amlodipine,” the app might generate:
• What is the purpose of amlodipine, and how does it work?
• Are there any side effects I should watch out for?
• How long should I take this medication, and are there alternatives?
Right now, the app requires the user to input a medical note before taking action. A truly agentic version would monitor patient data over time, offering reminders, alerts, and tailored advice without needing explicit input.
What I Learned Along the Way
Building AI tools for healthcare has been an eye-opening journey. It’s shown me just how much technology can do to reshape pharma and healthcare. Take compliance workflows, for example — AI doesn’t just save time; it helps teams better understand the rules. By highlighting key points and making complex guidelines easier to follow, these tools can turn a frustrating process into a smoother, more confident one.
The development of patient communication tools has taught us something equally valuable. While we started with the goal of simplifying medical language, we’ve come to understand that effective communication isn’t just about vocabulary. It’s about context, timing, and personal preferences. This insight is shaping how we think about AI’s role in healthcare communication — not just as a translator, but as a tool that could adapt to individual learning styles and comprehension levels.
Perhaps most importantly, this work has highlighted that AI’s greatest potential isn’t in automation — it’s in augmentation. The goal isn’t to replace healthcare professionals but to give them tools that could handle routine tasks, freeing up their time to focus on what matters most: complex cases and patient relationships.
Moving Toward Fully Agentic Tools
As we look ahead, the evolution of AI tools points to a future where AI becomes an active participant in healthcare, not just a passive tool. Imagine walking into a doctor’s office where your medical AI companion has already:
· Analyzed your recent symptoms and lab results
· Prepared relevant questions based on your health history
· Identified potential medication interactions
· Suggested lifestyle adjustments based on your personal patterns
But technology alone isn’t the answer. The future we’re building toward is one where AI and human expertise work in harmony, each enhancing the other’s capabilities. Our next generation of tools will focus on this delicate balance, creating systems that can take initiative while respecting the irreplaceable role of human judgment and empathy.
I invite you to join this conversation about the future of healthcare AI. Whether you’re a healthcare provider, a technologist, or a patient, your perspective matters. The tools we’re building today will shape the healthcare experiences of tomorrow, and the best solutions will come from diverse voices and viewpoints.
The healthcare tools we’re building today will shape the patient experiences of tomorrow. I’d love to hear your thoughts — whether you’re a provider, technologist, or patient, let’s collaborate to create a future where AI not only saves time but genuinely improves lives.
About Me
I’m Nick Lamb, PhD, a pharma innovator and creator of AI tools like Patiently AI and MedCheckr. I specialize in bridging gaps between AI and healthcare to make processes smarter and more human-centered.
More Stories
https://readmedium.com/from-generative-ai-to-agentic-ai-pharmas-next-revolution-1cbf1721252c
Connect with Me
• LinkedIn: linkedin.com/in/medcopywriter
• Website: pharmatools.ai