Medical Function-Calling LLM (Fine-tuned DeepSeek-R1-Distill-Qwen-1.5B)

This model is a fine-tuned version of deepseek-ai/DeepSeek-R1-Distill-Qwen-1.5B, specialized for medical domain function-calling tasks.
It is trained on Salesforce/xlam-function-calling-60k to reliably produce structured JSON outputs for healthcare applications such as appointment booking, medical record retrieval, patient communication, and medical triage support.


Model Details

  • Developed by: Alton Lavin D’Souza
  • Funded by: Self-funded
  • Model type: Instruction-tuned causal language model with function-calling capabilities
  • Language(s): English
  • License: MIT
  • Finetuned from model: deepseek-ai/DeepSeek-R1-Distill-Qwen-1.5B

Model Sources


Uses

Direct Use

  • Conversational AI assistants in healthcare
  • Automated structured response generation in JSON
  • Integration with electronic health record (EHR) systems
  • Medical workflow automation (e.g., booking appointments, retrieving patient data)

Downstream Use

  • Fine-tuning for specific healthcare specialties
  • Integration into clinical decision support systems
  • Agent-based medical AI systems with tool use

Out-of-Scope Use

  • Direct diagnosis without human oversight
  • Emergency medical response without clinician involvement
  • General-purpose non-medical applications (may work but not optimized)

Bias, Risks, and Limitations

This model may:

  • Hallucinate medical facts if prompted outside its training scope
  • Produce incomplete JSON structures if instructions are ambiguous
  • Require strict validation before integration into real-world healthcare systems

⚠️ Important: This model is not a substitute for a licensed medical professional.


Tool Calling Example:

import json
import os
import pickle
import time
from datetime import datetime, timedelta ,time as time_1
from threading import Thread
from typing import TypedDict, Dict, List, Any
from urllib.request import Request

import pytz
import torch
from duckduckgo_search import DDGS
from google_auth_oauthlib.flow import InstalledAppFlow
from googleapiclient.discovery import build
from langchain_community.tools import TavilySearchResults
from langgraph.constants import START, END
from langgraph.graph import StateGraph
from regex import regex, search
from smolagents import DuckDuckGoSearchTool
from sympy.physics.units.definitions.dimension_definitions import information
from transformers import AutoModelForCausalLM, AutoTokenizer, TextIteratorStreamer
from dotenv import load_dotenv
from tzlocal import get_localzone

load_dotenv()

torch.manual_seed(11)
model_name = "aldsouza/health-agent"
pattern = r'''
    \{                      # Opening brace of the function block
    \s*"name"\s*:\s*"([^"]+)"\s*,      # Capture the function name
    \s*"arguments"\s*:\s*(\{            # Capture the arguments JSON object starting brace
    (?:[^{}]++ | (?2))*?                # Recursive matching for balanced braces (PCRE syntax)
    \})                                # Closing brace of arguments
    \s*\}                             # Closing brace of the function block
    '''

tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForCausalLM.from_pretrained(model_name, torch_dtype=torch.float16).to("cuda")
# model_1 = AutoModelForCausalLM.from_pretrained("deepseek-ai/DeepSeek-R1-Distill-Qwen-1.5B",torch_dtype=torch.float16).to("cuda")

medical_tools = [
    {
        "name": "symptom_checker",
        "description": "Analyze symptoms and provide possible conditions.",
        "parameters": {
            "symptoms": {
                "description": "List of symptoms reported by the patient.",
                "type": "list[str]",
                "default": ["headache", "fever"]
            }
        }
    },
    {
        "name": "medication_lookup",
        "description": "Look up details about a medication by its name.",
        "parameters": {
            "medication_name": {
                "description": "Name of the medication to look up.",
                "type": "str",
                "default": "Aspirin"
            }
        }
    },
    {
        "name": "book_appointment",
        "description": "Schedule a medical appointment with a doctor.",
        "parameters": {
            "patient_name": {
                "description": "Name of the patient.",
                "type": "str",
                "default": "John Doe"
            },
            "doctor_specialty": {
                "description": "Specialty of the doctor to book.",
                "type": "str",
                "default": "general practitioner"
            },
            "date": {
                "description": "Preferred date of appointment (YYYY-MM-DD).",
                "type": "str",
                "default": "2025-08-20"
            }
        }
    },
    {
        "name": "get_lab_results",
        "description": "Retrieve lab test results for a patient by test ID.",
        "parameters": {
            "patient_id": {
                "description": "Unique patient identifier.",
                "type": "str",
                "default": "123456"
            },
            "test_id": {
                "description": "Lab test identifier.",
                "type": "str",
                "default": "cbc"
            }
        }
    },
    {
        "name": "request_missing_info",
        "description": "Ask the user for missing or incomplete information needed to fulfill their request.",
        "parameters": {
            "missing_fields": {
                "description": "List of missing required fields to be clarified by the user.",
                "type": "list[str]",
                "default": []
            },
            "context": {
                "description": "Optional context or explanation to help the user provide the missing information.",
                "type": "str",
                "default": ""
            }
        }
    },
    {
        "name": "medical_device_info",
        "description": "Retrieve detailed information about a medical device by its name or model number.",
        "parameters": {
            "device_name": {
                "description": "The name or model number of the medical device to look up.",
                "type": "str",
                "default": "Blood Pressure Monitor"
            }
        }
    }, {
        "name": "record_blood_pressure",
        "description": "Record a patient's blood pressure reading with systolic, diastolic, and pulse rate values.",
        "parameters": {
            "patient_id": {
                "description": "Unique identifier of the patient.",
                "type": "str",
                "default": "123456"
            },
            "systolic": {
                "description": "Systolic blood pressure value (mmHg).",
                "type": "int",
                "default": 120
            },
            "diastolic": {
                "description": "Diastolic blood pressure value (mmHg).",
                "type": "int",
                "default": 80
            },
            "pulse_rate": {
                "description": "Pulse rate in beats per minute.",
                "type": "int",
                "default": 70
            },
            "measurement_time": {
                "description": "Timestamp of the measurement (YYYY-MM-DD HH:MM).",
                "type": "str",
                "default": "2025-08-12 09:00"
            }
        }
    }, {
        "name": "start_blood_pressure_test",
        "description": "Initiate a blood pressure measurement test for a patient using a connected device.",
        "parameters": {
            "patient_id": {
                "description": "Unique identifier of the patient.",
                "type": "str",
                "default": "123456"
            },
            "device_id": {
                "description": "Identifier or model of the blood pressure measuring device.",
                "type": "str",
                "default": "BP-Device-001"
            }
        }
    }
]
# Compose the system prompt embedding the tools JSON
system_prompt = f"""
You are an intelligent AI assistant that uses available tools (functions) to help users achieve their medical-related goals. Your job is to understand the user's intent, identify missing information if needed, and then select and call the most appropriate function(s) to solve the task.

# Rules:
- ALWAYS use the tools provided to answer the user's request, unless explicitly told not to.
- Ask clarifying questions ONLY if the user's request is ambiguous or lacks required input parameters.
- If multiple tools are needed, use them in sequence.
- DO NOT make up data or assume values — request any missing input clearly.

# Output Format:
- Respond using a JSON list of function calls in the following format:
  [
    {{
      "name": "function_name",
      "arguments": {{
        "param1": "value1",
        "param2": "value2"
      }}
  ]
- Only include the functions needed to complete the task.
- If no function is needed or the input is unclear, ask a clarifying question instead of guessing.
- Do NOT respond with explanations or natural language outside the JSON block unless explicitly instructed.

Following are the tools provided to you:
{json.dumps(medical_tools, indent=2)}
"""
SCOPES = ['https://www.googleapis.com/auth/calendar']

def symptom_checker(kwargs):
    print(f"Checking diseases for following symptoms on the web:")
    symptoms = kwargs.get("symptoms",[])
    print(symptoms)
    for i, arg in enumerate(symptoms):
        print(f"{i}. {arg}")
    results = TavilySearchResults()
    information = ""
    for result in results.invoke(f"What causes {''.join(symptoms)}"):
        information = information + result["content"] + "\n"
    return {
        "status":200,
        "message":information
    }

def medication_lookup(kwargs):
    medication_name = kwargs.get("medication_name")
    print(f"Looking up the web for information on {medication_name}....")
    results = TavilySearchResults()
    information = ""
    for result in results.invoke(f"What is {medication_name}?"):
        information = information + result["content"] + "\n"
    return {
            "status": 200,
            "message": information
        }


def create_google_calendar_meeting(
        summary: str,
        start_datetime: str,
        end_datetime: str,
        attendees_emails: list,
        timezone: str = 'America/Chicago'
):
    """
    Creates a Google Calendar event.

    Args:
        summary (str): Event title.
        start_datetime (str): Start datetime in ISO format, e.g., "2025-08-18T10:00:00-06:00".
        end_datetime (str): End datetime in ISO format.
        attendees_emails (list): List of attendee emails.
        timezone (str): Timezone string, default 'America/Chicago'.
    """

    creds = None
    # Load saved credentials if available
    if os.path.exists('token.pickle'):
        with open('token.pickle', 'rb') as token:
            creds = pickle.load(token)

    # Authenticate if necessary
    if not creds or not creds.valid:
        if creds and creds.expired and creds.refresh_token:
            creds.refresh(Request())
        else:
            flow = InstalledAppFlow.from_client_secrets_file('credentials.json', SCOPES)
            creds = flow.run_local_server(port=0)
        with open('token.pickle', 'wb') as token:
            pickle.dump(creds, token)

    service = build('calendar', 'v3', credentials=creds)

    event = {
        'summary': summary,
        'location': 'Virtual / Google Meet',
        'description': f'{summary} meeting.',
        'start': {'dateTime': start_datetime, 'timeZone': timezone},
        'end': {'dateTime': end_datetime, 'timeZone': timezone},
        'attendees': [{'email': email} for email in attendees_emails],
        'reminders': {'useDefault': True},
    }

    created_event = service.events().insert(
        calendarId='primary', body=event, sendUpdates='all'
    ).execute()

    print(f"Event created: {created_event.get('htmlLink')}")
    return created_event
def book_appointment(kwargs):
    patient_name = kwargs.get("patient_name")
    doctor_specialty = kwargs.get("doctor_specialty")
    date_str = kwargs.get("date")
    parsed_date = datetime.strptime(date_str, "%Y-%m-%d").date()

    # Default time 9:00 AM Mountain Time
    mountain_tz = pytz.timezone("America/Denver")
    dt_mt = datetime.combine(parsed_date, time_1(9, 0))
    dt_mt = mountain_tz.localize(dt_mt)

    # Autodetect local timezone
    local_tz = get_localzone()
    dt_local = dt_mt.astimezone(local_tz)
    dt_local_end = dt_local + timedelta(hours=1)
    result = create_google_calendar_meeting(
        f"Meeting for {patient_name}",
        dt_local.isoformat(),
        dt_local_end.isoformat(),
        ["[email protected]", "[email protected]"]
    )
    return {
        "status":200,
        "message": f"Event Created:{result}"
    }


function_execution_map = {
    "symptom_checker": symptom_checker,
    "medication_lookup": medication_lookup,
    "book_appointment": book_appointment
}


# Example prompt using the medical tools
# messages = [
#     {
#         "content": system_prompt,
#         "role": "system"
#     },
#     {
#         "content": (
#             "I have a headache and mild fever. What could be the possible conditions? "
#             "Also, lookup medication details for 'Ibuprofen'. "
#             "Please book an appointment for patient 'Alice Smith' with a neurologist on 2025-09-01."
#         ),
#         "role": "user"
#     }
# ]

# streamer = TextStreamer(tokenizer, skip_prompt=True)
# streamer = TextIteratorStreamer(tokenizer, skip_prompt=True)
# inputs = tokenizer.apply_chat_template(
#     messages,
#     add_generation_prompt=True,
#     tokenize=True,
#     return_dict=True,
#     return_tensors="pt",
# ).to(model.device)
# inputs = tokenizer.apply_chat_template(
#     messages,
#     add_generation_prompt=True,
#     tokenize=True,
#     return_dict=True,
#     return_tensors="pt",
# ).to(mo)

# generation_kwargs = dict(inputs,streamer=streamer,
#         max_new_tokens=4096,
#         temperature=0.7,)
# thread = Thread(target=model.generate, kwargs=generation_kwargs,daemon=True)
# thread.start()
# for new_text in streamer:
#     print(new_text, end="")
# with torch.no_grad():
#     outputs = model.generate(
#         **inputs,streamer=streamer,
#         max_new_tokens=4096,
#         temperature=0.7,
#     )

class State(TypedDict):
    messages: List[Dict[str, Any]]
    plan: List[Dict[str, Any]]
    task: str


graph_builder = StateGraph(State)

PLANNING_AGENT = "PLANNING_AGENT"


def planning(state: State):
    print("Coming up with Plan")
    messages = state.get("messages", [])
    inputs = tokenizer.apply_chat_template(
        messages,
        add_generation_prompt=True,
        tokenize=True,
        return_dict=True,
        return_tensors="pt",
    ).to(model.device)
    streamer = TextIteratorStreamer(tokenizer, skip_prompt=True)
    generation_kwargs = dict(inputs, streamer=streamer,
                             max_new_tokens=4096,
                             temperature=0.7, )
    thread = Thread(target=model.generate, kwargs=generation_kwargs, daemon=True)
    thread.start()
    generated_text = ""
    for new_text in streamer:
        print(new_text, end="")
        generated_text = generated_text + new_text
    generated_text = generated_text.replace("<|end▁of▁sentence|>","").replace("</think>","")

    matches = regex.findall(pattern, generated_text, regex.VERBOSE)
    plan = state.get("plan", [])

    for i, (func_name, args_json) in enumerate(matches, 1):
        plan_entry = dict()
        plan_entry["function_name"] = func_name
        plan_entry["arguments"] = json.loads(args_json)
        plan.append(plan_entry)

    messages.append({"role": "assistant", "content": generated_text})

    return {"messages":messages, "plan": plan}


ROUTER = "ROUTER"


def router(state: State):
    plan = state.get("plan", [])
    if len(plan) > 0:
        return "execute_plan"
    return "respond"


def execute_plan(state: State):
    print("Executing")
    plan = state.get("plan", [])
    for plan_entry in plan:
        plan_entry["status"] = dict()
        print(f"Executing {plan_entry['function_name']} with details {plan_entry['arguments']}")
        print("Approve Execution?(y/n)")
        response = input()
        response = response.strip().lower()

        if response == "y":
            print("Approved.")
            if plan_entry["function_name"] in function_execution_map.keys():
                function = function_execution_map[plan_entry["function_name"]]
                result = function(plan_entry["arguments"])
                plan_entry["status"] = result
            else:
                print(f"Capability not implemented for {plan_entry['function_name']}")
            print("Done with task.")
            print("Proceeding with next.")

        elif response == "n":
            print("Not approved.")
        else:
            print("Invalid input, please enter 'y' or 'n'.")


    return {"plan": plan}


def respond(state: State):
    print(state.get("messages")[-1]["content"])
    return {"plan": state.get("plan")}


def summarize(state: State):
    plan = state.get("plan")
    messages = state.get("messages")
    summary_prompt = []
    summary_prompt.append({
        "role": "user","content": f"Summarize the results obtained from the following tool executions:\n {json.dumps(plan,indent=2)}"
    })
    inputs = tokenizer.apply_chat_template(
        summary_prompt,
        add_generation_prompt=True,
        tokenize=True,
        return_dict=True,
        return_tensors="pt",
    ).to(model.device)
    streamer = TextIteratorStreamer(tokenizer, skip_prompt=True)
    generation_kwargs = dict(inputs, streamer=streamer,
                             max_new_tokens=4096,
                             temperature=0.7, )
    thread = Thread(target=model.generate, kwargs=generation_kwargs, daemon=True)
    thread.start()
    generated_text = ""
    for new_text in streamer:
        print(new_text, end="")
        generated_text = generated_text + new_text

    messages.append({"role": "assistant", "content": generated_text})

    return {"messages":messages}


EXECUTE_PLAN = "EXECUTE_PLAN"
RESPOND = "RESPOND"
SUMMARIZE = "SUMMARIZE"
graph_builder.add_node(PLANNING_AGENT, planning)
graph_builder.add_node(EXECUTE_PLAN, execute_plan)
graph_builder.add_node(RESPOND, respond)
graph_builder.add_node(SUMMARIZE, summarize)

graph_builder.add_edge(START, PLANNING_AGENT)
graph_builder.add_conditional_edges(PLANNING_AGENT, router, {
    "execute_plan": EXECUTE_PLAN, "respond": RESPOND
})
graph_builder.add_edge(EXECUTE_PLAN, SUMMARIZE)
graph_builder.add_edge(SUMMARIZE, RESPOND)
graph_builder.add_edge(RESPOND, END)
compiled_graph = graph_builder.compile()
png_bytes = compiled_graph.get_graph().draw_mermaid_png()

# Save to file
with open("graph.png", "wb") as f:
    f.write(png_bytes)

print("Graph saved as graph.png")

messages = [
    {
        "content": system_prompt,
        "role": "system"
    },
    {
        "content": (
            "I have a headache and mild fever. What could be the possible conditions? "
            "Also, lookup medication details for 'Ibuprofen'. "
            "Please book an appointment for patient 'Alice Smith' with a neurologist on 2025-08-18."
        ),
        "role": "user"
    }
]
different_user_prompt = [
    {
        "content": system_prompt,
        "role": "system"
    },
    {
        "content": (
            "My mother has chest pain and shortness of breath. "
            "Can you analyze her symptoms? "
            "Also, please look up information about 'Nitroglycerin' medication. "
            "Finally, get lab results for patient ID '987654' for the test 'lipid_panel'."
        ),
        "role": "user"
    }
]
compiled_graph.invoke({"messages": messages})
# compiled_graph.invoke({"messages": different_user_prompt})

Requirements

accelerate==1.9.0
aiohappyeyeballs==2.6.1
aiohttp==3.12.15
aiosignal==1.4.0
annotated-types==0.7.0
anyio==4.10.0
attrs==25.3.0
auto_gptq==0.7.1
autolab-core==1.1.1
beautifulsoup4==4.13.4
bitsandbytes==0.46.1
cachetools==5.5.2
certifi==2025.7.14
charset-normalizer==3.4.2
click==8.2.1
colorama==0.4.6
colorlog==6.9.0
contourpy==1.3.3
cycler==0.12.1
dataclasses-json==0.6.7
datasets==4.0.0
dateparser==1.2.2
ddgs==9.5.4
dill==0.3.8
dotenv==0.9.9
duckduckgo_search==8.1.1
duckling==1.8.0
filelock==3.13.1
fonttools==4.59.0
freetype-py==2.5.1
frozenlist==1.7.0
fsspec==2024.6.1
gekko==1.3.0
google-api-core==2.25.1
google-api-python-client==2.179.0
google-auth==2.40.3
google-auth-httplib2==0.2.0
google-auth-oauthlib==1.2.2
googleapis-common-protos==1.70.0
greenlet==3.2.4
h11==0.16.0
hf-xet==1.1.7
httpcore==1.0.9
httplib2==0.22.0
httpx==0.28.1
httpx-sse==0.4.1
huggingface-hub==0.34.3
idna==3.10
imageio==2.37.0
Jinja2==3.1.4
joblib==1.5.1
jpype1==1.6.0
jsonpatch==1.33
jsonpointer==3.0.0
jsonschema==4.25.0
jsonschema-specifications==2025.4.1
kiwisolver==1.4.8
langchain==0.3.27
langchain-community==0.3.27
langchain-core==0.3.74
langchain-huggingface==0.3.1
langchain-text-splitters==0.3.9
langgraph==0.6.5
langgraph-checkpoint==2.1.1
langgraph-prebuilt==0.6.4
langgraph-sdk==0.2.0
langsmith==0.4.14
lazy_loader==0.4
lxml==6.0.0
manifold3d==3.2.1
mapbox_earcut==1.0.3
markdown-it-py==3.0.0
markdownify==1.1.0
MarkupSafe==2.1.5
marshmallow==3.26.1
matplotlib==3.10.5
mdurl==0.1.2
mpmath==1.3.0
multidict==6.6.3
multiprocess==0.70.16
mypy_extensions==1.1.0
networkx==3.3
numpy==2.1.2
oauthlib==3.3.1
opencv-python==4.12.0.88
optimum==1.27.0
orjson==3.11.2
ormsgpack==1.10.0
packaging==25.0
pandas==2.3.1
peft==0.17.0
pillow==11.0.0
primp==0.15.0
propcache==0.3.2
proto-plus==1.26.1
protobuf==6.32.0
psutil==7.0.0
pyarrow==21.0.0
pyasn1==0.6.1
pyasn1_modules==0.4.2
pycollada==0.9.2
pydantic==2.11.7
pydantic-settings==2.10.1
pydantic_core==2.33.2
pyglet==2.1.8
Pygments==2.19.2
PyOpenGL==3.1.0
pyparsing==3.2.3
pyreadline==2.1
pyrender==0.1.45
python-dateutil==2.9.0.post0
python-dotenv==1.1.1
pytz==2025.2
PyYAML==6.0.2
referencing==0.36.2
regex==2025.7.34
requests==2.32.4
requests-oauthlib==2.0.0
requests-toolbelt==1.0.0
rich==14.1.0
rouge==1.0.1
rpds-py==0.27.0
rsa==4.9.1
rtree==1.4.1
ruamel.yaml==0.18.14
ruamel.yaml.clib==0.2.12
safetensors==0.5.3
scikit-image==0.25.2
scikit-learn==1.7.1
scipy==1.16.1
sentencepiece==0.2.1
setproctitle==1.3.6
shapely==2.1.1
six==1.17.0
smolagents==1.20.0
sniffio==1.3.1
soupsieve==2.7
SQLAlchemy==2.0.43
svg.path==7.0
sympy==1.13.3
tenacity==9.1.2
threadpoolctl==3.6.0
tifffile==2025.6.11
tokenizers==0.21.4
torch==2.7.1+cu126
torchaudio==2.7.1+cu126
torchvision==0.22.1+cu126
tqdm==4.67.1
transformers==4.54.1
trimesh==4.7.4
trl==0.20.0
typing-inspect==0.9.0
typing-inspection==0.4.1
typing_extensions==4.14.1
tzdata==2025.2
tzlocal==5.3.1
uritemplate==4.2.0
urllib3==2.5.0
vhacdx==0.0.8.post2
visualization==1.0.0
xxhash==3.5.0
yarl==1.20.1
zstandard==0.24.0

How to Get Started

from transformers import AutoModelForCausalLM, AutoTokenizer
import torch

import json

torch.manual_seed(42)
model_name = "aldsouza/health-agent"

tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForCausalLM.from_pretrained(model_name, torch_dtype=torch.float16).to("cuda")

medical_tools = [
        {
            "name": "symptom_checker",
            "description": "Analyze symptoms and provide possible conditions.",
            "parameters": {
                "symptoms": {
                    "description": "List of symptoms reported by the patient.",
                    "type": "list[str]",
                    "default": ["headache", "fever"]
                }
            }
        },
        {
            "name": "medication_lookup",
            "description": "Look up details about a medication by its name.",
            "parameters": {
                "medication_name": {
                    "description": "Name of the medication to look up.",
                    "type": "str",
                    "default": "Aspirin"
                }
            }
        },
        {
            "name": "book_appointment",
            "description": "Schedule a medical appointment with a doctor.",
            "parameters": {
                "patient_name": {
                    "description": "Name of the patient.",
                    "type": "str",
                    "default": "John Doe"
                },
                "doctor_specialty": {
                    "description": "Specialty of the doctor to book.",
                    "type": "str",
                    "default": "general practitioner"
                },
                "date": {
                    "description": "Preferred date of appointment (YYYY-MM-DD).",
                    "type": "str",
                    "default": "2025-08-20"
                }
            }
        },
        {
            "name": "get_lab_results",
            "description": "Retrieve lab test results for a patient by test ID.",
            "parameters": {
                "patient_id": {
                    "description": "Unique patient identifier.",
                    "type": "str",
                    "default": "123456"
                },
                "test_id": {
                    "description": "Lab test identifier.",
                    "type": "str",
                    "default": "cbc"
                }
            }
        },
        {
            "name": "request_missing_info",
            "description": "Ask the user for missing or incomplete information needed to fulfill their request.",
            "parameters": {
                "missing_fields": {
                    "description": "List of missing required fields to be clarified by the user.",
                    "type": "list[str]",
                    "default": []
                },
                "context": {
                    "description": "Optional context or explanation to help the user provide the missing information.",
                    "type": "str",
                    "default": ""
                }
            }
        },
        {
            "name": "medical_device_info",
            "description": "Retrieve detailed information about a medical device by its name or model number.",
            "parameters": {
                "device_name": {
                    "description": "The name or model number of the medical device to look up.",
                    "type": "str",
                    "default": "Blood Pressure Monitor"
                }
            }
        }, {
            "name": "record_blood_pressure",
            "description": "Record a patient's blood pressure reading with systolic, diastolic, and pulse rate values.",
            "parameters": {
                "patient_id": {
                    "description": "Unique identifier of the patient.",
                    "type": "str",
                    "default": "123456"
                },
                "systolic": {
                    "description": "Systolic blood pressure value (mmHg).",
                    "type": "int",
                    "default": 120
                },
                "diastolic": {
                    "description": "Diastolic blood pressure value (mmHg).",
                    "type": "int",
                    "default": 80
                },
                "pulse_rate": {
                    "description": "Pulse rate in beats per minute.",
                    "type": "int",
                    "default": 70
                },
                "measurement_time": {
                    "description": "Timestamp of the measurement (YYYY-MM-DD HH:MM).",
                    "type": "str",
                    "default": "2025-08-12 09:00"
                }
            }
        }, {
            "name": "start_blood_pressure_test",
            "description": "Initiate a blood pressure measurement test for a patient using a connected device.",
            "parameters": {
                "patient_id": {
                    "description": "Unique identifier of the patient.",
                    "type": "str",
                    "default": "123456"
                },
                "device_id": {
                    "description": "Identifier or model of the blood pressure measuring device.",
                    "type": "str",
                    "default": "BP-Device-001"
                }
            }
        }
    ]
    # Compose the system prompt embedding the tools JSON
    system_prompt = f"""
You are an intelligent AI assistant that uses available tools (functions) to help users achieve their medical-related goals. Your job is to understand the user's intent, identify missing information if needed, and then select and call the most appropriate function(s) to solve the task.

# Rules:
- ALWAYS use the tools provided to answer the user's request, unless explicitly told not to.
- Ask clarifying questions ONLY if the user's request is ambiguous or lacks required input parameters.
- If multiple tools are needed, use them in sequence.
- DO NOT make up data or assume values — request any missing input clearly.

# Output Format:
- Respond using a JSON list of function calls in the following format:
  [
    {{
      "name": "function_name",
      "arguments": {{
        "param1": "value1",
        "param2": "value2"
      }}
  ]
- Only include the functions needed to complete the task.
- If no function is needed or the input is unclear, ask a clarifying question instead of guessing.
- Do NOT respond with explanations or natural language outside the JSON block unless explicitly instructed.

Following are the tools provided to you:
{json.dumps(medical_tools, indent=2)}
"""

    # Example prompt using the medical tools
messages = [
        {
            "content": system_prompt,
            "role": "system"
        },
        {
            "content": (
                "I have a headache and mild fever. What could be the possible conditions? "
                "Also, lookup medication details for 'Ibuprofen'. "
                "Please book an appointment for patient 'Alice Smith' with a neurologist on 2025-09-01."
            ),
            "role": "user"
        }
    ]

inputs = tokenizer.apply_chat_template(
        messages,
        add_generation_prompt=True,
        tokenize=True,
        return_dict=True,
        return_tensors="pt",
    ).to(model.device)

    with torch.no_grad():
        outputs = model.generate(
            **inputs,
            max_new_tokens=4096,
            temperature=0.7,
        )

    response = tokenizer.decode(outputs[0])

print(tokenizer.decode(outputs[0], skip_special_tokens=True))
Downloads last month
321
Safetensors
Model size
1.14B params
Tensor type
F32
·
F16
·
U8
·
Inference Providers NEW
This model isn't deployed by any Inference Provider. 🙋 Ask for provider support

Model tree for aldsouza/health-agent

Quantized
(222)
this model

Dataset used to train aldsouza/health-agent