No description
Find a file
2025-08-07 20:38:50 +03:00
alembic add drugs db index 2025-08-07 20:38:50 +03:00
scripts add drug dosages parsing, add postgres db 2025-08-07 01:04:44 +03:00
src add drugs db index 2025-08-07 20:38:50 +03:00
.gitignore add drug parser; add iha estimation rules 2025-07-31 22:08:02 +03:00
.python-version initial commit 2025-07-25 14:01:16 +03:00
alembic.ini add drug dosages parsing, add postgres db 2025-08-07 01:04:44 +03:00
compose.yaml add drug dosages parsing, add postgres db 2025-08-07 01:04:44 +03:00
Dockerfile initial commit 2025-07-25 14:01:16 +03:00
pyproject.toml add drugs db index 2025-08-07 20:38:50 +03:00
README.md refactor estimation service to use structured agent 2025-07-28 17:07:48 +03:00
uv.lock add drugs db index 2025-08-07 20:38:50 +03:00

Lolly AI

A FastAPI-based insurance AI assistant that integrates with talestorm-ai for chat capabilities and provides insurance estimation services.

Features

  • Insurance Chat: AI-powered chat interface for insurance-related questions
  • Insurance Estimation: AI-powered estimation using TALESTORM API for comprehensive underwriting and pricing
  • Integration: Seamless integration with talestorm-ai API
  • Modern API: Built with FastAPI for high performance and automatic documentation

Quick Start with Docker Compose

The easiest way to run lolly-ai is using Docker Compose, which will set up both lolly-ai and its dependency talestorm-ai.

Prerequisites

  • Docker and Docker Compose installed
  • talestorm-ai repository cloned in the same parent directory as lolly-ai

Setup

  1. Clone both repositories:
git clone <talestorm-ai-repo-url> ../talestorm-ai
git clone <lolly-ai-repo-url> lolly-ai
cd lolly-ai
  1. Create a .env file with your configuration:
# Database Configuration (for talestorm-ai)
POSTGRES_USER=postgres
POSTGRES_PASSWORD=password
POSTGRES_DB=talestorm
PUBLIC_POSTGRES_PORT=5432

# talestorm-ai Configuration
PUBLIC_TALESTORM_PORT=8000
ADMIN_API_KEY=changeme-admin-key
OPENAI_API_KEY=your-openai-api-key-here

# lolly-ai Configuration
PUBLIC_LOLLY_PORT=7310
TALESTORM_API_KEY=your-talestorm-api-key-here
TALESTORM_AGENT_ID=your-talestorm-chat-agent-id-here
TALESTORM_ESTIMATION_AGENT_ID=your-talestorm-estimation-agent-id-here
INSURANCE_API_BASE_URL=https://apilolly.cyberpug.ru

# Server Configuration
HOST=0.0.0.0
PORT=7310
DEBUG=false

# CORS Configuration
CORS_ORIGINS=*

# Logging
LOG_LEVEL=INFO
  1. Start the services:
docker compose up -d
  1. Access the services:

Development with Docker Compose

For development, you can mount the source code:

docker compose up -d

The source code is automatically mounted, so changes will be reflected immediately.

Stopping the services

docker compose down

To remove volumes as well:

docker compose down -v

Agent Configuration

The system uses two different TALESTORM agents for different purposes:

  • TALESTORM_AGENT_ID: Used for general insurance chat functionality
  • TALESTORM_ESTIMATION_AGENT_ID: Used specifically for insurance estimation with structured output schema

This separation allows for specialized agents optimized for their respective tasks.

Estimation Service

The estimation service has been refactored to use the TALESTORM API instead of local underwriting logic. This provides:

  • AI-Powered Analysis: Uses advanced AI models for risk assessment and pricing
  • Comprehensive Evaluation: Analyzes all health factors, medications, and conditions
  • Structured Output: Returns detailed tier assignments and pricing for each applicant
  • Flexible Response: Handles both accepted and rejected applications with detailed reasoning

Estimation Request Format

The service accepts insurance application data and returns structured estimation results:

{
  "status": "accepted",
  "details": {
    "dtq": false,
    "reason": "All applicants have manageable conditions...",
    "tier": 3,
    "total_price": 815.75
  },
  "results": [
    {
      "name": "Sarah Johnson",
      "applicant_type": "primary",
      "age": 39,
      "bmi": 23.38,
      "tier": 3,
      "rx_spend": 40.0,
      "message": "Type 2 diabetes well-controlled..."
    }
  ]
}

API Endpoints

All API endpoints are versioned under /api/v1/:

/api/v1/sessions (POST)

Create a new chat session.

Query Parameters:

  • agent_id (optional): Specific agent ID to use for the session

Response:

{
  "session_id": "session-uuid"
}

/api/v1/sessions (GET)

List all available sessions.

Response:

{
  "sessions": [
    {
      "id": "session-uuid",
      "organization_id": "org-uuid",
      "agent_id": "agent-uuid",
      "created_at": "2024-01-01T00:00:00Z"
    }
  ]
}

/api/v1/sessions/{session_id} (GET)

Get details of a specific session.

Response:

{
  "id": "session-uuid",
  "organization_id": "org-uuid",
  "agent_id": "agent-uuid",
  "created_at": "2024-01-01T00:00:00Z"
}

/api/v1/agents (GET)

List available AI agents.

Response:

{
  "agents": [
    {
      "id": "agent-uuid",
      "name": "Insurance Assistant",
      "model_name": "gpt-3.5-turbo",
      "model_provider": "openai",
      "enable_rag_search": true,
      "instructions": "You are an insurance expert..."
    }
  ]
}

/api/v1/insurance_chat (POST)

Handles insurance-related chat requests.

Request Body:

{
  "message": "What does my health insurance cover?",
  "session_id": "optional-session-id"
}

Response:

{
  "session_id": "session-uuid",
  "answer": "Your health insurance covers...",
  "sources": [
    {
      "plan_name": "Cigna 1000 Classic",
      "chunk_number": 0,
      "content_chunk": "This plan covers preventive care, doctor visits, and prescription drugs..."
    }
  ],
  "history": [
    {
      "role": "user",
      "message": "What does my health insurance cover?"
    },
    {
      "role": "assistant", 
      "message": "Your health insurance covers..."
    }
  ]
}

/api/v1/estimation (POST)

Handles insurance estimation and underwriting requests.

Request Body:

{
  "uid": "string",
  "applicants": [
    {
      "applicant": 1,
      "firstName": "string",
      "lastName": "string",
      "midName": "string",
      "phone": "string",
      "gender": "male",
      "dob": "2025-07-25",
      "nicotine": true,
      "weight": 0,
      "heightFt": 0,
      "heightIn": 0
    }
  ],
  "plans": [
    {
      "id": 0,
      "coverage": 1,
      "tier": "string"
    }
  ],
  "phq": {
    "treatment": true,
    "invalid": true,
    "pregnancy": true,
    "effectiveDate": "2025-07-25",
    "disclaimer": true,
    "signature": "string",
    "medications": [
      {
        "applicant": 0,
        "name": "string",
        "rxcui": "string",
        "dosage": "string",
        "frequency": "string",
        "description": "string"
      }
    ],
    "issues": [
      {
        "key": "string",
        "details": [
          {
            "key": "string",
            "description": "string"
          }
        ]
      }
    ],
    "conditions": [
      {
        "key": "string",
        "description": "string"
      }
    ]
  },
  "income": 0,
  "address": {
    "address1": "string",
    "address2": "string",
    "city": "string",
    "state": "string",
    "zipcode": "string"
  }
}

Response:

{
  "status": "accepted",
  "details": {
    "dtq": true,
    "reason": "string",
    "tier": 0,
    "total_price": 0
  },
  "results": [
    {
      "name": "string",
      "applicant_type": "Primary",
      "age": 0,
      "bmi": 0,
      "tier": 0,
      "rx_spend": 0,
      "message": "string"
    }
  ]
}