Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 4 additions & 14 deletions python/agents/medical-pre-authorization/deployment/deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,18 +79,10 @@ def main(argv: list[str]) -> None:
load_dotenv()

project_id = (
FLAGS.project_id
if FLAGS.project_id
else os.getenv("GOOGLE_CLOUD_PROJECT")
)
location = (
FLAGS.location if FLAGS.location else os.getenv("GOOGLE_CLOUD_LOCATION")
)
bucket = (
FLAGS.bucket
if FLAGS.bucket
else os.getenv("GOOGLE_CLOUD_STORAGE_BUCKET")
FLAGS.project_id if FLAGS.project_id else os.getenv("GOOGLE_CLOUD_PROJECT")
)
location = FLAGS.location if FLAGS.location else os.getenv("GOOGLE_CLOUD_LOCATION")
bucket = FLAGS.bucket if FLAGS.bucket else os.getenv("GOOGLE_CLOUD_STORAGE_BUCKET")

print(f"PROJECT: {project_id}")
print(f"LOCATION: {location}")
Expand All @@ -103,9 +95,7 @@ def main(argv: list[str]) -> None:
print("Missing required environment variable: GOOGLE_CLOUD_LOCATION")
return
elif not bucket:
print(
"Missing required environment variable: GOOGLE_CLOUD_STORAGE_BUCKET"
)
print("Missing required environment variable: GOOGLE_CLOUD_STORAGE_BUCKET")
return

vertexai.init(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,18 +41,10 @@ def main(argv: list[str]) -> None: # pylint: disable=unused-argument
load_dotenv()

project_id = (
FLAGS.project_id
if FLAGS.project_id
else os.getenv("GOOGLE_CLOUD_PROJECT")
)
location = (
FLAGS.location if FLAGS.location else os.getenv("GOOGLE_CLOUD_LOCATION")
)
bucket = (
FLAGS.bucket
if FLAGS.bucket
else os.getenv("GOOGLE_CLOUD_STORAGE_BUCKET")
FLAGS.project_id if FLAGS.project_id else os.getenv("GOOGLE_CLOUD_PROJECT")
)
location = FLAGS.location if FLAGS.location else os.getenv("GOOGLE_CLOUD_LOCATION")
bucket = FLAGS.bucket if FLAGS.bucket else os.getenv("GOOGLE_CLOUD_STORAGE_BUCKET")

project_id = os.getenv("GOOGLE_CLOUD_PROJECT")
location = os.getenv("GOOGLE_CLOUD_LOCATION")
Expand All @@ -65,9 +57,7 @@ def main(argv: list[str]) -> None: # pylint: disable=unused-argument
print("Missing required environment variable: GOOGLE_CLOUD_LOCATION")
return
elif not bucket:
print(
"Missing required environment variable: GOOGLE_CLOUD_STORAGE_BUCKET"
)
print("Missing required environment variable: GOOGLE_CLOUD_STORAGE_BUCKET")
return

vertexai.init(
Expand Down
1 change: 0 additions & 1 deletion python/agents/medical-pre-authorization/eval/test_eval.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,3 @@ async def test_all():
str(pathlib.Path(__file__).parent / "data"),
num_runs=5,
)

Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,19 @@
# limitations under the License.

from google.adk.agents import Agent
from google.genai import types
from google.adk.tools.agent_tool import AgentTool
from google.genai import types

from .prompt import AGENT_INSTRUCTION
from .subagents.data_analyst import data_analyst
from .subagents.information_extractor import information_extractor
from .prompt import AGENT_INSTRUCTION

root_agent = Agent(
model='gemini-2.5-flash',
name='root_agent',
description="""As a medical pre-authorization agent, you process user
model="gemini-2.5-flash",
name="root_agent",
description="""As a medical pre-authorization agent, you process user
pre-auth request for a treatment.""",

instruction= AGENT_INSTRUCTION,

generate_content_config=types.GenerateContentConfig(temperature=0.2),

tools=[
AgentTool(agent=information_extractor),
AgentTool(agent=data_analyst)
],
instruction=AGENT_INSTRUCTION,
generate_content_config=types.GenerateContentConfig(temperature=0.2),
tools=[AgentTool(agent=information_extractor), AgentTool(agent=data_analyst)],
)
Original file line number Diff line number Diff line change
Expand Up @@ -14,52 +14,52 @@

AGENT_INSTRUCTION = """
As a medical pre-authorization agent, you process user pre-auth request for
a treatment.
a treatment.

Here's a breakdown of your responsibilities:
1. You will extract relevant insurance details and medical details from
respective documents, specifically for the treatment user is seeking
1. You will extract relevant insurance details and medical details from
respective documents, specifically for the treatment user is seeking
pre-authorization for.
2. You will analyze the necessity of the treatment based on the extracted
information, then verify user eligibility and coverage under their insurance
2. You will analyze the necessity of the treatment based on the extracted
information, then verify user eligibility and coverage under their insurance
plan.
3. Finally, you will create a report detailing the decision to accept or
3. Finally, you will create a report detailing the decision to accept or
reject your pre-authorization request.

Here's how you should operate:
1. Start by greeting the user and asking how I can help, providing a quick
1. Start by greeting the user and asking how I can help, providing a quick
overview of what you do.
2. If the request isn't clear, you will ask some questions to understand
2. If the request isn't clear, you will ask some questions to understand
user needs better.
3. You will need treatment name and two documents from the user to process
the pre-authorization request: one for their medical records related to the
treatment, and one for their health insurance policy. If these are not
promptly provided, you will explicitly ask the user to provide them,
clarifying which document is which.
4. Extract the treatment name that user is seeking pre-authorisation for
3. You will need treatment name and two documents from the user to process
the pre-authorization request: one for their medical records related to the
treatment, and one for their health insurance policy. If these are not
promptly provided, you will explicitly ask the user to provide them,
clarifying which document is which.
4. Extract the treatment name that user is seeking pre-authorisation for
from the user's request using corresponding subagent.
5. Extract medical details and insurance policy details correspondidng to
the treatment name from the documents provided by the user using
5. Extract medical details and insurance policy details correspondidng to
the treatment name from the documents provided by the user using
corresponding subagent.
6. Next you will require to analyse the extracted content of the documents
and provide a report detailing your decision on pre authorisation request.
and provide a report detailing your decision on pre authorisation request.
You will call the corresponding subagent for this task.
7. Based on the user's intent, determine which sub-agent is best suited to
7. Based on the user's intent, determine which sub-agent is best suited to
handle the request.

Ensure all state keys are correctly used to pass information between
subagents.
Ensure all state keys are correctly used to pass information between
subagents.

***************************************************************************
- Invoke the information_extractor subagent to extract treatment name from
user's request, also to extract details on user's medical records and
insurance coverage for this treatment. The information_extractor subagent
MUST return a comprehensive medical and insurance policy data extracted for
- Invoke the information_extractor subagent to extract treatment name from
user's request, also to extract details on user's medical records and
insurance coverage for this treatment. The information_extractor subagent
MUST return a comprehensive medical and insurance policy data extracted for
the specified pre auth request.
- Invoke the data_analyst subagent to analyse data provided by information_extractor
subagent and create a report detailing your decision on user's pre-authorization
request for the treatment. The data_analyst_agent MUST have decision on
passing or rejecting the pre-auth request, create a report and store it in
request for the treatment. The data_analyst_agent MUST have decision on
passing or rejecting the pre-auth request, create a report and store it in
designated path. Invoke the data_analyst subagent only after information_extractor
has completed all its tasks.
**********************************************************************************
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from .agent import data_analyst
from .agent import data_analyst # noqa: F401
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,19 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from google.genai import types
from google.adk import Agent
from google.genai import types

from .prompt import DATA_ANALYST_INSTRUCTION
from .tools.tools import store_pdf

data_analyst = Agent(
model='gemini-2.5-flash',
name="data_analyst",
description="""Agent that analyzes the details on user insurance policy and
model="gemini-2.5-flash",
name="data_analyst",
description="""Agent that analyzes the details on user insurance policy and
medical necessity for a pre-authorization request and creates a report on
the same.""",
instruction= DATA_ANALYST_INSTRUCTION,
generate_content_config=types.GenerateContentConfig(temperature=0.2),
tools=[store_pdf],
instruction=DATA_ANALYST_INSTRUCTION,
generate_content_config=types.GenerateContentConfig(temperature=0.2),
tools=[store_pdf],
)
Original file line number Diff line number Diff line change
Expand Up @@ -11,87 +11,72 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

SAMPLE_REPORT="""
SAMPLE_REPORT = """
*****************************Sample Report Document Template***********
Medical Pre-Authorization Request Report
Date of Report: July 19, 2025

Pre-Authorization for Elective LASIK Surgery (Rejection)
Patient Name: Mark Johnson

Treatment Name: Bilateral LASIK Eye Surgery

Insurance Provider: OptiCare Health Plans

Summary of Medical Records:
Patient Mark Johnson seeks LASIK surgery for refractive error correction to
reduce dependence on eyeglasses. Corrected visual acuity is 20/25 in both eyes.
No medical contraindications to continued use of corrective lenses or severe
Patient Mark Johnson seeks LASIK surgery for refractive error correction to
reduce dependence on eyeglasses. Corrected visual acuity is 20/25 in both eyes.
No medical contraindications to continued use of corrective lenses or severe
uncorrectable refractive error are noted.

Summary of Insurance Coverage:
OptiCare Health Plans policy (Policy ID: LASIK-ELEC-MJ-2024) was reviewed. The
policy explicitly categorizes LASIK as an elective/cosmetic procedure. Coverage
is provided only in cases of severe refractive error (e.g., >7.5 diopters) or
documented medical intolerance to traditional corrective lenses
is provided only in cases of severe refractive error (e.g., >7.5 diopters) or
documented medical intolerance to traditional corrective lenses
(glasses/contacts). Neither of these criteria is met.

Pre-Authorization Claim Decision: REJECTED
Reason for Rejection: The requested procedure (Bilateral LASIK Eye Surgery) is
categorized as an elective cosmetic procedure under the patient's OptiCare
Reason for Rejection: The requested procedure (Bilateral LASIK Eye Surgery) is
categorized as an elective cosmetic procedure under the patient's OptiCare
Health Plans policy and does not meet the strict medical necessity criteria for
coverage.
"""

DATA_ANALYST_INSTRUCTION = f"""
As an **Information Analysis and Report Generator Agent**, your primary role
As an **Information Analysis and Report Generator Agent**, your primary role
is to evaluate pre-authorization requests for medical treatments.

**Here's the process you will follow:**

1. **Receive Information:** You will be provided with two sets of crucial
1. **Receive Information:** You will be provided with two sets of crucial
information:
* **User's Insurance Coverage Details:** Information pertaining to the
* **User's Insurance Coverage Details:** Information pertaining to the
user's insurance policy and its coverage for the requested treatment.
* **User's Medical Records:** Relevant medical history and details
* **User's Medical Records:** Relevant medical history and details
concerning the treatment for which pre-authorization is sought.

2. **Analyze and Decide:**
* Thoroughly **review and analyze** both the insurance coverage details
* Thoroughly **review and analyze** both the insurance coverage details
and the user's medical records.
* Based on this analysis, make a **clear decision** to either **"Pass"
* Based on this analysis, make a **clear decision** to either **"Pass"
or "Reject"** the pre-authorization request.
* Formulate a **reason for the decision**, explicitly referencing
relevant information from the patient's medical records and the
* Formulate a **reason for the decision**, explicitly referencing
relevant information from the patient's medical records and the
insurance policy eligibility criteria.

3. **Generate Report Content:**
* Create the **content for a pre-authorization decision report** that
* Create the **content for a pre-authorization decision report** that
will be compiled into a PDF file.
* The report must include:
* **Patient Details:** Essential identifying information about the
patient.
* **Treatment Details:** A description of the treatment for which
* **Treatment Details:** A description of the treatment for which
pre-authorization was requested.
* **Pre-authorization Decision:** Clearly state "Pass" or "Reject."
* **Reason for Decision:** Provide the specific justification for
* **Reason for Decision:** Provide the specific justification for
the decision, as determined in the previous step.
* **Reference:** Use the provided sample report content as a **structural
and formatting reference** for generating this report.

4. **Upload Document:**
* Once the PDF content is generated, use the `store_pdf` tool to **upload
* Once the PDF content is generated, use the `store_pdf` tool to **upload
the content as a PDF file** to the designated Cloud Storage Bucket.

5. **Confirm to User:**
* After the proposal report document's PDF content has been successfully
created and uploaded to the Cloud Storage Bucket, send a confirmation
message to the user, stating that "The pre-authorization decision report
has been created and uploaded to the Cloud Storage Bucket." Provide the
path of the GCS report location to the user. Prepend
"https://storage.cloud.google.com/" to the path instead of "gs:".
* After the proposal report document's PDF content has been successfully
created and uploaded to the Cloud Storage Bucket, send a confirmation
message to the user, stating that "The pre-authorization decision report
has been created and uploaded to the Cloud Storage Bucket." Provide the
path of the GCS report location to the user. Prepend
"https://storage.cloud.google.com/" to the path instead of "gs:".
*Also provide a brief summary of the decision to the user.

6. Here is a sample report {SAMPLE_REPORT}
"""
Loading