
chat with fhir
Agent AI experiment to integrate generative ai and a FHIR server
Repository Info
About This Server
Agent AI experiment to integrate generative ai and a FHIR server
Model Context Protocol (MCP) - This server can be integrated with AI applications to provide additional context and capabilities, enabling enhanced AI interactions and functionality.
Documentation
chat-with-fhir
Overview (English)
This repository contains three examples built as an experiment of AI agents designed to interact with FHIR (Fast Healthcare Interoperability Resources) data. All examples are intended to be run with Ollama.
Setup (English)
Before running any of the examples, ensure you have the following prerequisites:
-
Clone the repository:
git clone [this_repository_url] cd chat-with-fhir -
Install Python dependencies:(Better to use a virtual environment .venv and activate it)
pip install -r requirements.txt -
Install Ollama: Download and install Ollama from the official website: https://ollama.com/ Ensure Ollama is running in the background.
Examples
1. Simple Agent with Local Tool
This example demonstrates a basic ADK agent with a tool defined within the same file. The tool interacts with the public HAPI FHIR server to retrieve the total number of patients.
How to run:
-
After cloning the repository and installing dependencies, place the agent file (e.g.,
agent.py) directly into thechat-with-fhirfolder within the project -
Run the agent from the root folder:
adk web
Here you can see an example
!Ejemplo
And also you can debug the tool defined into the code
!Ejemplo
2. Agent with Simple Gradio Interface
This example shows how to deploy the simple agent with a basic graphical user interface using Gradio. It performs the same task as the first example (retrieving the patient count from the HAPI FHIR server). It's easy to deploy within a server and with different UI.
How to run:
- Ensure you have installed the
gradiodependency, is into the requirements.txt. - Run the Gradio application directly using Python:
This will typically open a web interface in your browser, or click on the url.python ./chat-with-fhir/gradio_app_example.py
Insert into the user_input your question.. !Ejemplo Wait for the response !Ejemplo Then it works.. !Ejemplo
3. Agent Connecting to an MCP Tool Server
This example demonstrates how to connect an ADK agent to a Model Context Protocol (MCP) tool server. The MCP server can provide various tools, in this case, likely for interacting with FHIR data in a more complex and reusable way. This aproach ensures agent independence development from tool development.
Prerequisites:
- Download the MCP Tool Server: You need to download and set up the specific MCP tool server you intend to use from this repo .
- Install Node.js: Ensure you have Node.js installed on your system to run the MCP server if it's a Node.js application.
How to run the agent:
- Follow the general setup steps (clone repo, install Python dependencies, ensure Ollama is running).
- Run the agent python:
The agent will attempt to connect to the MCP server specified in your code and use its provided tools and displays the output into the terminal.python ./chat-with-fhir/agent_mcp_tools.py
.env File Configuration (English)
The .env file in this repository is used to configure environment variables for the examples. Here's an explanation of the variables:
# Override default ENV variables for Ollama
OPENAI_BASE_URL=http://localhost:11434/v1
# The base URL for the Ollama API. This is typically http://localhost:11434/v1 if Ollama is running locally with default settings.
OPENAI_API_KEY=unused
# While the variable name suggests an OpenAI API key, with Ollama, this is often unused or can be set to a placeholder like 'unused'. Ollama doesn't require API keys for locally running models.
CHAT_MODEL=stewyphoenix19/phi3-mini_v1
# The name or ID of the language model to be used by the agent. This refers to a model available in your Ollama setup. This model is a lightweight tool ready model used for simple tests.
MCP_SERVER_PATH=D:\Desarrollo\IA\chat_with_fhir_mcp\mcp-fhir\build
# The absolute path to the entry point of th MCP tool server downloaded. In this case, it points to a directory called build inside the cloned project, so ensure your server is configured to run from this location or adjust the path to the specific server script.
You can see an example below !Ejemplo
And how the agent gets some fhir data from the server !Ejemplo
Some troubles we found with adk and windows
https://github.com/google/adk-python/issues/49
Chat-with-fhir
Resumen
Este repositorio contiene tres ejemplos de agentes de IA diseñados para interactuar con datos FHIR (Fast Healthcare Interoperability Resources). Todos los ejemplos están pensados para ejecutarse con Ollama.
Configuración
Antes de ejecutar cualquiera de los ejemplos, asegúrate de tener los siguientes requisitos previos:
- Clonar el repositorio:
Bash
git clone [url_de_este_repositorio]
cd chat-with-fhir
- Instalar las dependencias de Python: (Preferible usar un entorno virtual usando venv)
Bash
pip install -r requirements.txt
- Instalar Ollama: Descarga e instala Ollama desde el sitio web oficial. Asegúrate de que Ollama se esté ejecutando en segundo plano.
Ejemplos
- Agente Simple con Herramienta Local
Este ejemplo demuestra un agente ADK básico con una herramienta definida en el mismo archivo. La herramienta interactúa con el servidor público FHIR de HAPI FHIR para recuperar el número total de pacientes.
Cómo ejecutar:
Después de clonar el repositorio e instalar las dependencias, coloca el archivo del agente (por ejemplo, agent.py) directamente en la carpeta chat-with-fhir del proyecto clonado. Ejecuta el agente usando la CLI de ADK: Bash
adk web
- Agente con Interfaz Gráfica Simple en Gradio
Este ejemplo muestra cómo desplegar el agente simple con una interfaz gráfica de usuario básica utilizando Gradio. Realiza la misma tarea que el primer ejemplo (recuperar el recuento de pacientes del servidor HAPI FHIR), pero muestra de una manera simple cómo se puede desplegar usando un servidor y gradio.
Cómo ejecutarlo:
- Asegúrate de haber instalado la dependencia gradio (pip install gradio).
- Ejecuta la aplicación Gradio directamente usando Python: Bash
python gradio_app_example.py
Esto abrirá una interfaz web en tu navegador, si no, pulsa control y haz click sobre la url de la consola.
- Agente Conectándose a un Servidor de Herramientas MCP
Este ejemplo demuestra cómo conectar un agente ADK a un servidor de herramientas Model Context Protocol (MCP). El servidor MCP puede proporcionar varias herramientas, en este caso, para interactuar con datos FHIR de una manera más compleja. MCP es bueno para independizar el desarrollo de los agnetes del desarrollo de las herramientas y recursos a los que estos tendrán acceso.
Requisitos previos:
- Descargar el Servidor de Herramientas MCP: Necesitas descargar y configurar el servidor de herramientas MCP específico desde este repo.
- Instalar Node.js: Asegúrate de tener Node.js instalado en tu sistema para ejecutar el servidor MCP si es una aplicación de Node.js.
- Ejecutar el Servidor de Herramientas MCP: Inicia el servidor de herramientas MCP según su documentación.
Cómo ejecutar el agente:
- Sigue los pasos generales de configuración (clonar el repositorio, instalar las dependencias de Python, asegurarte de que Ollama se esté ejecutando).
- Ejecuta el agente usando python Bash
python ./chat-with-fhir/agent_mcp_tools.py
El agente intentará conectarse al servidor MCP especificado en tu código y utilizar las herramientas proporcionadas para acceder al servidor FHIR y responder las preguntas (query en el código) diréctamente en la consola.
Configuración del Archivo .env (Español) El archivo .env en este repositorio se utiliza para configurar variables de entorno para los ejemplos. Aquí tienes una explicación de las variables:
Fragmento de código
# Override default ENV variables for Ollama
OPENAI_BASE_URL=http://localhost:11434/v1
# La URL base para la API de Ollama. Normalmente es http://localhost:11434/v1 si Ollama se está ejecutando localmente con la configuración predeterminada.
OPENAI_API_KEY=unused
# Aunque el nombre de la variable sugiere una clave de API de OpenAI, con Ollama, a menudo no se usa o se puede establecer en un marcador de posición como 'unused'. Ollama no requiere claves de API para los modelos que se ejecutan localmente.
CHAT_MODEL=stewyphoenix19/phi3-mini_v1
# El nombre o ID del modelo de lenguaje que utilizará el agente. Esto se refiere a un modelo disponible en tu configuración de Ollama.
MCP_SERVER_PATH=D:\Desarrollo\IA\chat_with_fhir_mcp\mcp-fhir\build
# La ruta absoluta al punto de entrada de tu servidor de herramientas MCP. En este
Quick Start
Clone the repository
git clone https://github.com/llucbrell/chat-with-fhirInstall dependencies
cd chat-with-fhir
npm installFollow the documentation
Check the repository's README.md file for specific installation and usage instructions.
Repository Details
Recommended MCP Servers
Discord MCP
Enable AI assistants to seamlessly interact with Discord servers, channels, and messages.
Knit MCP
Connect AI agents to 200+ SaaS applications and automate workflows.
Apify MCP Server
Deploy and interact with Apify actors for web scraping and data extraction.
BrowserStack MCP
BrowserStack MCP Server for automated testing across multiple browsers.
Zapier MCP
A Zapier server that provides automation capabilities for various apps.