Hayley.AAI
by hyly.AI
Live
⚠ This version contains breaking changes. See Changelog β†’
⌘K
Overview✦Hayley Features
Microservices
SMS AdapterChat AdapterMail AdapterVoice Adapter
Node RetrievalRAG RetrievalFixed Response
Agent OrchestratorHayley EngineTranslate to Human
SPF GeneratorOMC-KgProperty KG
Resources
All ServicesChangelog
APIs
APIsBenchmarksTesting Properties
Tools
Knowledge GraphLogs & AccessHelp & Tools
Microservices β€Ί Utility β€Ί SPF Service

SPF Service

v1.0UtilityPublished
Updated 5d ago
v1.0 β€” Published
Service Request Lifecycle

SPF


Overview

The Hayley Chat Adapter Microservice is an orchestration layer that processes conversational AI queries for property management platforms. It acts as the central hub between the Hayley AI Engine (ML/NLP) and all downstream services.

Core responsibilities:

  • Route and validate chat queries from property management platforms
  • Forward requests to Hayley Engine for intent classification and response generation
  • Format responses based on retrieval type (node,Β rag,Β fixed,Β adapter,Β spf)
  • Persist messages via GraphQL for conversation history
  • Extract contact information (name, phone, email) for agent escalation
  • Support multi-language responses (English / Spanish)
  • Track distributed traces and latency metrics via Langfuse + OpenTelemetry

  • Architecture

    High-Level Flow

    kotlin
    1 2 3 4 5 6 7
    Client
      └─► FastAPI Server (Port 6000)
            └─► Hayley Chat Adapter
                  β”œβ”€β–Ί Hayley Engine (ML/NLP)
                  β”œβ”€β–Ί Translate to Human (Spanish)
                  β”œβ”€β–Ί Agent Handoff Service
                  └─► GraphQL API (Message Persistence)

    Tech Stack

    LayerTechnologyVersion
    Web FrameworkFastAPIβ‰₯ 0.111.0
    ASGI ServerUvicorn0.30.1
    ValidationPydanticlatest
    HTTP Clientrequests, aiohttplatest
    NLPspaCy + en_core_web_mdβ‰₯ 3.7.0
    Phone Parsingphonenumbersβ‰₯ 8.13.0
    Cachingfastapi-cache2 (InMemory)latest
    Token Countingtiktoken (cl100k_base)latest
    Logginglogurulatest
    LLM ObservabilityLangfuseβ‰₯ 3.11.2
    Distributed TracingOpenTelemetryβ‰₯ 1.28.0
    ConfigPyYAMLlatest

    Directory Structure

    markdown
    1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
    hayley-chat-adapter-microservice/
    β”œβ”€β”€ app.py                        ← FastAPI entrypoint, endpoints, Langfuse init
    β”œβ”€β”€ config.yaml                   ← Environment-specific service URLs
    β”œβ”€β”€ requirements.txt              ← Python dependencies
    β”œβ”€β”€ Dockerfile                    ← Docker build (exposes port 6000)
    β”œβ”€β”€ .env                          ← Secrets and environment variables
    β”‚
    β”œβ”€β”€ bean/
    β”‚   └── chat_adapter_response.py ← Pydantic response model
    β”‚
    β”œβ”€β”€ utils/
    β”‚   β”œβ”€β”€ chat_adapter.py          ← Core orchestration logic
    β”‚   β”œβ”€β”€ utils.py                 ← GraphQL, caching, contact extraction
    β”‚   β”œβ”€β”€ arguments.py             ← Constants and defaults
    β”‚   └── constants.py             ← System-wide constants
    β”‚
    └── deployments/
        β”œβ”€β”€ qa/Jenkinsfile
        β”œβ”€β”€ stg/Jenkinsfile
        └── prod/Jenkinsfile

    Request Processing Flow

    plain text
    1 2 3 4 5 6 7 8 9 10 11 12 13
    1.  POST /chat_adapter received
    2.  Pydantic validates request          β†’ 400 on failure
    3.  Trim history to last 4 messages
    4.  Call Hayley Engine
    5.  Format response by retrieval_type:
          "node" + "neighborhood_summary"  β†’ verbose response
          "node"                           β†’ format_node_response_to_markdown()
          "rag|fixed|adapter|spf"          β†’ concise response
    6.  Extract contact info (if sub_intent matches)
    7.  createHayleyMessage [question] via GraphQL
    8.  Fire async agent handoff (non-blocking)
    9.  createHayleyMessage [answer] via GraphQL
    10. Return assembled response with trace_id

    API Contract

    POST /chat_adapter

    Request

    graphql
    1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
    {
      "propertyId": "1234567890123456789",
      "message": "Show me available 2-bedroom apartments",
      "orgId": "9876543210987654321",
      "org_name": "Example Org Name",
      "session_id": "aaaabbbbccccddddeeeeffffgggghhhh",
      "conversation_id": "1111111111111111111",
      "graphql_api_key": "Rjp3U6OfhyuxMVSYHCJErDlFeZamWs5QwIX4dKik",
      "tourScheduleEnabled": true,
      "history": [
        { "role": "user", "content": "Hello" },
        { "role": "assistant", "content": "Hi! How can I help?" }
      ],
      "entry_id": "optional-entry-id",
      "booking_id": "optional-booking-id",
      "reschedule_information": {},
      "schedule_information": {},
      "spanish_support_enabled": false,
      "spanish_toggle": false,
      "is_first_entry": false
    }

    Field Validation Rules

    Response

    graphql
    1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
    {
      "response": "Here are available 2-bedroom units at...",
      "intent": "property_search",
      "sub_intent": "unit_availability",
      "message_id": "1709542253522009420",
      "retrieval_type": "node",
      "orchestrator_level1_details": {},
      "orchestrator_level2_details": {},
      "keyword_cache": { "bedrooms": 2 },
      "not_available": [],
      "context": null,
      "follow_up": "Would you like to schedule a tour?",
      "latency": {
        "hayley_engine_latency": 1234,
        "chat_adapter_latency": 2456,
        "extract_and_update_contact_latency": 45,
        "create_message_latency": 312
      },
      "language": "en",
      "agent_handoff": null,
      "memory": null,
      "trace_id": "4bf92f3577b34da6a3ce929d0e0e4736"
    }

    Error Responses

    graphql
    1 2 3 4 5 6 7 8
    // 400 β€” Validation error
    { "detail": { "message": "Invalid propertyId format", "trace_id": "4bf92f35..." } }
    
    // 500 β€” Internal error
    { "detail": { "message": "Unexpected error", "trace_id": "4bf92f35..." } }
    
    // 503 β€” Downstream unavailable
    { "detail": "Service temporarily unavailable" }

    Environment URLs

    Downstream Services by Environment

  • QA: /qa
  • STG: /stg
  • Prod: /main
  • Dependencies

    Internal Microservices

    ServicePurpose
    Hayley EngineML/NLP β€” intent classification and response generation
    Translate to HumanSpanish translation whenΒ spanish_toggle=true
    Agent HandoffHuman escalation β€” async fire-and-forget viaΒ hyly_agent_handoffΒ package
    GraphQL APIMessage persistence β€”Β createHayleyMessage,Β updateHayleyConversation

    External Property Management APIs

    EndpointPurpose
    /api/v1/unitsRetrieve property unit data
    /api/v1/floor_plans/Fetch floor plan information
    /api/v1/apartments/all_type_available_time_slotsGet available tour time slots
    /api/v1/hayley/google_queryExtract neighborhood keywords
    /api/v1/properties/api_tokenFetch GraphQL API token

    Python Packages

    On this page
    SPFOverviewArchitectureHigh-Level FlowTech StackDirectory StructureRequest Processing FlowAPI ContractPOST /chat_adapterEnvironment URLsDependenciesInternal MicroservicesExternal Property Management APIsPython Packages
    Copy Page