• bitcoinBitcoin(BTC)$84,585.001.26%
  • ethereumEthereum(ETH)$2,720.382.74%
  • tetherTether(USDT)$1.000.01%
  • binancecoinBNB(BNB)$779.541.17%
  • rippleXRP(XRP)$1.629.69%
  • usd-coinUSDC(USDC)$1.000.01%
  • solanaSolana(SOL)$120.496.07%
  • tronTRON(TRX)$0.337437-0.63%
  • zcashZcash(ZEC)$1,593.407.17%
  • Figure HelocFigure Heloc(FIGR_HELOC)$1.03-0.76%
  • HyperliquidHyperliquid(HYPE)$93.482.25%
  • dogecoinDogecoin(DOGE)$0.0983896.01%
  • moneroMonero(XMR)$569.724.60%
  • chainlinkChainlink(LINK)$14.1915.60%
  • whitebitWhiteBIT Coin(WBT)$84.521.14%
  • USDSUSDS(USDS)$1.000.00%
  • cardanoCardano(ADA)$0.2561828.30%
  • RainRain(RAIN)$0.011926-0.56%
  • leo-tokenLEO Token(LEO)$8.82-1.00%
  • stellarStellar(XLM)$0.22565212.70%
  • bitcoin-cashBitcoin Cash(BCH)$337.060.50%
  • nearNEAR Protocol(NEAR)$5.0515.44%
  • uniswapUniswap(UNI)$9.879.24%
  • litecoinLitecoin(LTC)$70.577.07%
  • CantonCanton(CC)$0.12394514.40%
  • Ethena USDeEthena USDe(USDE)$1.000.00%
  • avalanche-2Avalanche(AVAX)$10.685.42%
  • suiSui(SUI)$1.1519.90%
  • daiDai(DAI)$1.000.02%
  • USD1USD1(USD1)$1.000.01%
  • hedera-hashgraphHedera(HBAR)$0.0963046.72%
  • the-open-networkGram (prev. Toncoin)(GRAM)$1.432.05%
  • BittensorBittensor(TAO)$310.099.29%
  • shiba-inuShiba Inu(SHIB)$0.0000066.03%
  • crypto-com-chainCronos(CRO)$0.0659018.19%
  • Global DollarGlobal Dollar(USDG)$1.000.01%
  • BitwayBitway(BTW)$1.1411.42%
  • MemeCoreMemeCore(M)$1.19-2.03%
  • paypal-usdPayPal USD(PYUSD)$1.000.01%
  • tether-goldTether Gold(XAUT)$4,297.260.70%
  • OndoOndo(ONDO)$0.5416.40%
  • okbOKB(OKB)$120.992.48%
  • EthenaEthena(ENA)$0.24218917.36%
  • Circle USYCCircle USYC(USYC)$1.140.01%
  • Ripple USDRipple USD(RLUSD)$1.000.01%
  • aaveAave(AAVE)$149.138.40%
  • BlackRock USD Institutional Digital Liquidity FundBlackRock USD Institutional Digital Liquidity Fund(BUIDL)$1.000.00%
  • Ondo US Dollar YieldOndo US Dollar Yield(USDY)$1.14-0.11%
  • mantleMantle(MNT)$0.680.60%
  • polkadotPolkadot(DOT)$1.196.82%
TradePoint.io
  • Main
  • AI & Technology
  • Stock Charts
  • Market & News
  • Business
  • Finance Tips
  • Trade Tube
  • Blog
  • Shop
No Result
View All Result
TradePoint.io
No Result
View All Result

A Coding Guide to Design a Complete Agentic Workflow in Gemini for Automated Medical Evidence Gathering and Prior Authorization Submission

December 20, 2025
in AI & Technology
Reading Time: 6 mins read
A A
A Coding Guide to Design a Complete Agentic Workflow in Gemini for Automated Medical Evidence Gathering and Prior Authorization Submission
ShareShareShareShareShare

In this tutorial, we devise how to orchestrate a fully functional, tool-using medical prior-authorization agent powered by Gemini. We walk through each component step by step, from securely configuring the model to building realistic external tools and finally constructing an intelligent agent loop that reasons, acts, and responds entirely through structured JSON. As we progress, we see how the system thinks, retrieves evidence, and interacts with simulated medical systems to complete a complex workflow. Check out the FULL CODES here.

!pip install -q -U google-generative-ai


import google.generativeai as genai
from google.colab import userdata
import os
import getpass
import json
import time


try:
   GOOGLE_API_KEY = userdata.get('GOOGLE_API_KEY')
except:
   print("Please enter your Google API Key:")
   GOOGLE_API_KEY = getpass.getpass("API Key: ")


genai.configure(api_key=GOOGLE_API_KEY)


print("\n🔍 Scanning for available models...")
available_models = [m.name for m in genai.list_models()]
target_model = ""


if 'models/gemini-1.5-flash' in available_models:
   target_model="gemini-1.5-flash"
elif 'models/gemini-1.5-flash-001' in available_models:
   target_model="gemini-1.5-flash-001"
elif 'models/gemini-pro' in available_models:
   target_model="gemini-pro"
else:
   for m in available_models:
       if 'generateContent' in genai.get_model(m).supported_generation_methods:
           target_model = m
           break


if not target_model:
   raise ValueError("❌ No text generation models found for this API key.")


print(f"✅ Selected Model: {target_model}")
model = genai.GenerativeModel(target_model)

We set up our environment and automatically detect the best available Gemini model. We configure the API key securely and let the system choose the most capable model without hardcoding anything. This ensures that we start the tutorial with a clean, flexible, and reliable foundation. Check out the FULL CODES here.

YOU MAY ALSO LIKE

Google Adds Creepy Avatars To Gemini 3.8 Live’s Agents

Fastino Releases GLiNER2.5-Decide: A 340M Open-Weight Decision Model That Runs on CPU

class MedicalTools:
   def __init__(self):
       self.ehr_docs = [
           "Patient: John Doe | DOB: 1980-05-12",
           "Visit 2023-01-10: Diagnosed with Type 2 Diabetes. Prescribed Metformin.",
           "Visit 2023-04-15: Patient reports severe GI distress with Metformin. Discontinued.",
           "Visit 2023-04-20: BMI recorded at 32.5. A1C is 8.4%.",
           "Visit 2023-05-01: Doctor recommends starting Ozempic (Semaglutide)."
       ]


   def search_ehr(self, query):
       print(f"   🔎 [Tool] Searching EHR for: '{query}'...")
       results = [doc for doc in self.ehr_docs if any(q.lower() in doc.lower() for q in query.split())]
       if not results:
           return "No records found."
       return "\n".join(results)


   def submit_prior_auth(self, drug_name, justification):
       print(f"   📤 [Tool] Submitting claim for {drug_name}...")
       justification_lower = justification.lower()
       if "metformin" in justification_lower and ("discontinued" in justification_lower or "intolerance" in justification_lower):
           if "bmi" in justification_lower and "32" in justification_lower:
               return "SUCCESS: Authorization Approved. Auth ID: #998877"
       return "DENIED: Policy requires proof of (1) Metformin failure and (2) BMI > 30."

We define the medical tools that our agent can use during the workflow. We simulate an EHR search and a prior-authorization submission system so the agent has real actions to perform. By doing this, we ground the agent’s reasoning in tool-enabled interactions rather than plain text generation. Check out the FULL CODES here.

class AgenticSystem:
   def __init__(self, model, tools):
       self.model = model
       self.tools = tools
       self.history = []
       self.max_steps = 6
      
       self.system_prompt = """
       You are an expert Medical Prior Authorization Agent.
       Your goal is to get approval for a medical procedure/drug.
      
       You have access to these tools:
       1. search_ehr(query)
       2. submit_prior_auth(drug_name, justification)


       RULES:
       1. ALWAYS think before you act.
       2. You MUST output your response in STRICT JSON format:
          {
            "thought": "Your reasoning here",
            "action": "tool_name_or_finish",
            "action_input": "argument_string_or_dict"
          }
       3. Do not guess patient data. Use 'search_ehr'.
       4. If you have the evidence, use 'submit_prior_auth'.
       5. If the task is done, use action "finish".
       """

We initialize the agent and provide its full system prompt. We define the rules, the JSON response format, and the expectation that the agent must think before acting. This gives us a controlled, deterministic structure for building a safe and traceable agent loop. Check out the FULL CODES here.

 def execute_tool(self, action_name, action_input):
       if action_name == "search_ehr":
           return self.tools.search_ehr(action_input)
       elif action_name == "submit_prior_auth":
           if isinstance(action_input, str):
               return "Error: submit_prior_auth requires a dictionary."
           return self.tools.submit_prior_auth(**action_input)
       else:
           return "Error: Unknown tool."


   def run(self, objective):
       print(f"🤖 AGENT STARTING. Objective: {objective}\n" + "-"*50)
       self.history.append(f"User: {objective}")


       for i in range(self.max_steps):
           print(f"\n🔄 STEP {i+1}")
           prompt = self.system_prompt + "\n\nHistory:\n" + "\n".join(self.history) + "\n\nNext JSON:"
          
           try:
               response = self.model.generate_content(prompt)
               text_response = response.text.strip().replace("```json", "").replace("```", "")
               agent_decision = json.loads(text_response)
           except Exception as e:
               print(f"   ⚠️ Error parsing AI response. Retrying... ({e})")
               continue


           print(f"   🧠 THOUGHT: {agent_decision['thought']}")
           print(f"   👉 ACTION: {agent_decision['action']}")


           if agent_decision['action'] == "finish":
               print(f"\n✅ TASK COMPLETED: {agent_decision['action_input']}")
               break
          
           tool_result = self.execute_tool(agent_decision['action'], agent_decision['action_input'])
           print(f"   👁️ OBSERVATION: {tool_result}")


           self.history.append(f"Assistant: {text_response}")
           self.history.append(f"System: {tool_result}")
          
           if "SUCCESS" in str(tool_result):
               print("\n🎉 SUCCESS! The Agent successfully navigated the insurance portal.")
               break

We implement the core agent loop where reasoning, tool execution, and observations happen step by step. We watch the agent decide its next action, execute tools, update history, and evaluate success conditions. This is where the agent truly comes alive and performs iterative reasoning. Check out the FULL CODES here.

tools_instance = MedicalTools()
agent = AgenticSystem(model, tools_instance)
agent.run("Please get prior authorization for Ozempic for patient John Doe.")

We instantiate the tools and agent, then run the entire system end-to-end with a real objective. We see the full workflow unfold as the agent navigates through medical history, validates evidence, and attempts prior authorization. This final snippet demonstrates the complete pipeline working seamlessly.

In conclusion, we reflect on how this compact yet powerful framework enables us to design real-world agentic behaviors that go beyond simple text responses. We watch our agent plan, consult tools, gather evidence, and ultimately complete a structured insurance authorization task, entirely through autonomous reasoning. It provides confidence that we can now expand the system with additional tools, stronger policies, domain-specific logic, or even multi-agent collaboration.


Check out the FULL CODES here. Feel free to check out our GitHub Page for Tutorials, Codes and Notebooks. Also, feel free to follow us on Twitter and don’t forget to join our 100k+ ML SubReddit and Subscribe to our Newsletter.


Asif Razzaq is the CEO of Marktechpost Media Inc.. As a visionary entrepreneur and engineer, Asif is committed to harnessing the potential of Artificial Intelligence for social good. His most recent endeavor is the launch of an Artificial Intelligence Media Platform, Marktechpost, which stands out for its in-depth coverage of machine learning and deep learning news that is both technically sound and easily understandable by a wide audience. The platform boasts of over 2 million monthly views, illustrating its popularity among audiences.

Credit: Source link

ShareTweetSendSharePin

Related Posts

Google Adds Creepy Avatars To Gemini 3.8 Live’s Agents
AI & Technology

Google Adds Creepy Avatars To Gemini 3.8 Live’s Agents

September 25, 2026
Fastino Releases GLiNER2.5-Decide: A 340M Open-Weight Decision Model That Runs on CPU
AI & Technology

Fastino Releases GLiNER2.5-Decide: A 340M Open-Weight Decision Model That Runs on CPU

September 25, 2026
Black Forest Labs Releases FLUX 3 Action: A 7B Open-Weights World Action Model That Tops RoboLab-120
AI & Technology

Black Forest Labs Releases FLUX 3 Action: A 7B Open-Weights World Action Model That Tops RoboLab-120

September 25, 2026
Warzone Is Adding A Button To Hide All The Goofy Skins
AI & Technology

Warzone Is Adding A Button To Hide All The Goofy Skins

September 24, 2026
Next Post
D.C. pipe bomb suspect confessed to planting explosives in FBI interview

D.C. pipe bomb suspect confessed to planting explosives in FBI interview

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Search

No Result
View All Result
Embracer Group AB (publ) (EBCRY) Shareholder/Analyst Call Transcript

Embracer Group AB (publ) (EBCRY) Shareholder/Analyst Call Transcript

September 24, 2026
Former Amb. to China warns U.S. must be ‘very, very careful’ about Iran sanctions targeting Beijing

Former Amb. to China warns U.S. must be ‘very, very careful’ about Iran sanctions targeting Beijing

September 24, 2026
Jury deliberates in Lindsay Clancy murder trial

Jury deliberates in Lindsay Clancy murder trial

September 22, 2026

About

Learn more

Our Services

Legal

Privacy Policy

Terms of Use

Bloggers

Learn more

Article Links

Contact

Advertise

Ask us anything

©2020- TradePoint.io - All rights reserved!

Tradepoint.io, being just a publishing and technology platform, is not a registered broker-dealer or investment adviser. So we do not provide investment advice. Rather, brokerage services are provided to clients of Tradepoint.io by independent SEC-registered broker-dealers and members of FINRA/SIPC. Every form of investing carries some risk and past performance is not a guarantee of future results. “Tradepoint.io“, “Instant Investing” and “My Trading Tools” are registered trademarks of Apperbuild, LLC.

This website is operated by Apperbuild, LLC. We have no link to any brokerage firm and we do not provide investment advice. Every information and resource we provide is solely for the education of our readers. © 2020 Apperbuild, LLC. All rights reserved.

No Result
View All Result
  • Main
  • AI & Technology
  • Stock Charts
  • Market & News
  • Business
  • Finance Tips
  • Trade Tube
  • Blog
  • Shop

© 2023 - TradePoint.io - All Rights Reserved!