|
| 1 | +"""Truth HITL service entrypoint.""" |
| 2 | + |
| 3 | +import os |
| 4 | + |
| 5 | +from holiday_peak_lib.agents import FoundryAgentConfig |
| 6 | +from holiday_peak_lib.agents.memory import ColdMemory, HotMemory, WarmMemory |
| 7 | +from holiday_peak_lib.app_factory import build_service_app |
| 8 | +from holiday_peak_lib.config import MemorySettings |
| 9 | +from holiday_peak_lib.utils import EventHubSubscription, create_eventhub_lifespan |
| 10 | +from truth_hitl.adapters import build_hitl_adapters |
| 11 | +from truth_hitl.agents import TruthHITLAgent, register_mcp_tools |
| 12 | +from truth_hitl.event_handlers import build_event_handlers |
| 13 | +from truth_hitl.routes import build_review_router |
| 14 | + |
| 15 | +SERVICE_NAME = "truth-hitl" |
| 16 | +memory_settings = MemorySettings() |
| 17 | +endpoint = os.getenv("PROJECT_ENDPOINT") or os.getenv("FOUNDRY_ENDPOINT") |
| 18 | +project_name = os.getenv("PROJECT_NAME") or os.getenv("FOUNDRY_PROJECT_NAME") |
| 19 | +stream = (os.getenv("FOUNDRY_STREAM") or "").lower() in {"1", "true", "yes"} |
| 20 | +slm_agent_id = os.getenv("FOUNDRY_AGENT_ID_FAST") |
| 21 | +llm_agent_id = os.getenv("FOUNDRY_AGENT_ID_RICH") |
| 22 | +slm_deployment = os.getenv("MODEL_DEPLOYMENT_NAME_FAST") |
| 23 | +llm_deployment = os.getenv("MODEL_DEPLOYMENT_NAME_RICH") |
| 24 | + |
| 25 | +slm_config = ( |
| 26 | + FoundryAgentConfig( |
| 27 | + endpoint=endpoint, |
| 28 | + agent_id=slm_agent_id, |
| 29 | + deployment_name=slm_deployment, |
| 30 | + project_name=project_name, |
| 31 | + stream=stream, |
| 32 | + ) |
| 33 | + if endpoint and slm_agent_id |
| 34 | + else None |
| 35 | +) |
| 36 | + |
| 37 | +llm_config = ( |
| 38 | + FoundryAgentConfig( |
| 39 | + endpoint=endpoint, |
| 40 | + agent_id=llm_agent_id, |
| 41 | + deployment_name=llm_deployment, |
| 42 | + project_name=project_name, |
| 43 | + stream=stream, |
| 44 | + ) |
| 45 | + if endpoint and llm_agent_id |
| 46 | + else None |
| 47 | +) |
| 48 | + |
| 49 | +app = build_service_app( |
| 50 | + SERVICE_NAME, |
| 51 | + agent_class=TruthHITLAgent, |
| 52 | + hot_memory=(HotMemory(memory_settings.redis_url) if memory_settings.redis_url else None), |
| 53 | + warm_memory=( |
| 54 | + WarmMemory( |
| 55 | + memory_settings.cosmos_account_uri, |
| 56 | + memory_settings.cosmos_database, |
| 57 | + memory_settings.cosmos_container, |
| 58 | + ) |
| 59 | + if memory_settings.cosmos_account_uri |
| 60 | + else None |
| 61 | + ), |
| 62 | + cold_memory=( |
| 63 | + ColdMemory( |
| 64 | + memory_settings.blob_account_url, |
| 65 | + memory_settings.blob_container, |
| 66 | + ) |
| 67 | + if memory_settings.blob_account_url |
| 68 | + else None |
| 69 | + ), |
| 70 | + slm_config=slm_config, |
| 71 | + llm_config=llm_config, |
| 72 | + mcp_setup=register_mcp_tools, |
| 73 | + lifespan=create_eventhub_lifespan( |
| 74 | + service_name=SERVICE_NAME, |
| 75 | + subscriptions=[ |
| 76 | + EventHubSubscription("hitl-jobs", "hitl-service"), |
| 77 | + ], |
| 78 | + handlers=build_event_handlers(), |
| 79 | + ), |
| 80 | +) |
| 81 | + |
| 82 | +# Mount the review REST routes |
| 83 | +_adapters = build_hitl_adapters() |
| 84 | +app.include_router(build_review_router(_adapters)) |
0 commit comments