File size: 1,338 Bytes
4b8585c
e46883d
dc97d01
 
 
4b8585c
 
 
 
 
 
 
 
 
 
dc97d01
 
 
 
 
 
 
 
4b8585c
 
 
 
 
 
dc97d01
 
 
4b8585c
 
 
 
dc97d01
4b8585c
 
 
97aee42
4b8585c
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
"""Parlant server and agent initialization."""

import os

from parlant.core.loggers import LogLevel
from parlant.sdk import Agent, NLPServices, Server

AGENT_NAME = "Patient Trial Copilot"
AGENT_DESCRIPTION = (
    "AI copilot helping NSCLC patients find matching clinical trials. "
    "Extracts patient profiles from medical documents, searches ClinicalTrials.gov, "
    "evaluates eligibility criterion-by-criterion, and identifies actionable gaps "
    "where additional data could unlock new trial options."
)

_LOG_LEVEL_MAP = {
    "trace": LogLevel.TRACE,
    "debug": LogLevel.DEBUG,
    "info": LogLevel.INFO,
    "warning": LogLevel.WARNING,
    "error": LogLevel.ERROR,
}


async def create_server_and_agent(
    host: str = "0.0.0.0",
    port: int = 8800,
) -> tuple[Server, Agent]:
    """Create and start Parlant server with the TrialPath agent."""
    log_level_str = os.environ.get("PARLANT_LOG_LEVEL", "info").lower()
    log_level = _LOG_LEVEL_MAP.get(log_level_str, LogLevel.INFO)

    server = Server(
        nlp_service=NLPServices.gemini,
        host=host,
        port=port,
        log_level=log_level,
    )
    await server.__aenter__()

    agent = await server.create_agent(
        name=AGENT_NAME,
        description=AGENT_DESCRIPTION,
        max_engine_iterations=10,
    )

    return server, agent