File size: 4,247 Bytes
645a051
 
 
 
 
 
 
 
 
 
cd7c282
 
fd1472e
f295ef3
 
 
 
645a051
 
fd1472e
cd7c282
fd1472e
915b009
fd1472e
645a051
 
 
 
fd1472e
915b009
645a051
 
 
 
915b009
fd1472e
645a051
 
 
fd1472e
f295ef3
645a051
 
6b5e05b
645a051
 
 
fd1472e
cd7c282
fd1472e
915b009
fd1472e
645a051
 
 
 
fd1472e
915b009
645a051
 
 
 
915b009
645a051
 
 
 
f295ef3
645a051
6b5e05b
645a051
 
 
fd1472e
cd7c282
fd1472e
915b009
fd1472e
645a051
 
 
 
fd1472e
915b009
645a051
 
 
 
915b009
fd1472e
645a051
 
 
fd1472e
f295ef3
645a051
6b5e05b
645a051
 
 
fd1472e
cd7c282
fd1472e
915b009
fd1472e
645a051
 
 
 
fd1472e
915b009
645a051
 
 
 
915b009
645a051
 
 
 
f295ef3
645a051
 
6b5e05b
645a051
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
"""Magentic-compatible agents using ChatAgent pattern."""

from agent_framework import ChatAgent

from src.agents.tools import (
    get_bibliography,
    search_clinical_trials,
    search_preprints,
    search_pubmed,
)
from src.clients.base import BaseChatClient
from src.clients.factory import get_chat_client
from src.config.domain import ResearchDomain, get_domain_config
from src.prompts.hypothesis import get_system_prompt as get_hypothesis_prompt
from src.prompts.judge import get_system_prompt as get_judge_prompt
from src.prompts.report import get_system_prompt as get_report_prompt
from src.prompts.search import get_system_prompt as get_search_prompt


def create_search_agent(
    chat_client: BaseChatClient | None = None,
    domain: ResearchDomain | str | None = None,
    api_key: str | None = None,
) -> ChatAgent:
    """Create a search agent with internal LLM and search tools.

    Args:
        chat_client: Optional custom chat client. If None, uses default.
        domain: Research domain for customization.
        api_key: Optional BYOK key (auto-detects provider from prefix).

    Returns:
        ChatAgent configured for biomedical search
    """
    client = chat_client or get_chat_client(api_key=api_key)
    config = get_domain_config(domain)

    return ChatAgent(
        name="SearchAgent",
        description=config.search_agent_description,
        instructions=get_search_prompt(domain),
        chat_client=client,
        tools=[search_pubmed, search_clinical_trials, search_preprints],
        temperature=1.0,  # Explicitly set for reasoning model compatibility (o1/o3)
    )


def create_judge_agent(
    chat_client: BaseChatClient | None = None,
    domain: ResearchDomain | str | None = None,
    api_key: str | None = None,
) -> ChatAgent:
    """Create a judge agent that evaluates evidence quality.

    Args:
        chat_client: Optional custom chat client. If None, uses default.
        domain: Research domain for customization.
        api_key: Optional BYOK key (auto-detects provider from prefix).

    Returns:
        ChatAgent configured for evidence assessment
    """
    client = chat_client or get_chat_client(api_key=api_key)

    return ChatAgent(
        name="JudgeAgent",
        description="Evaluates evidence quality and determines if sufficient for synthesis",
        instructions=get_judge_prompt(domain),
        chat_client=client,
        temperature=1.0,  # Explicitly set for reasoning model compatibility
    )


def create_hypothesis_agent(
    chat_client: BaseChatClient | None = None,
    domain: ResearchDomain | str | None = None,
    api_key: str | None = None,
) -> ChatAgent:
    """Create a hypothesis generation agent.

    Args:
        chat_client: Optional custom chat client. If None, uses default.
        domain: Research domain for customization.
        api_key: Optional BYOK key (auto-detects provider from prefix).

    Returns:
        ChatAgent configured for hypothesis generation
    """
    client = chat_client or get_chat_client(api_key=api_key)
    config = get_domain_config(domain)

    return ChatAgent(
        name="HypothesisAgent",
        description=config.hypothesis_agent_description,
        instructions=get_hypothesis_prompt(domain),
        chat_client=client,
        temperature=1.0,  # Explicitly set for reasoning model compatibility
    )


def create_report_agent(
    chat_client: BaseChatClient | None = None,
    domain: ResearchDomain | str | None = None,
    api_key: str | None = None,
) -> ChatAgent:
    """Create a report synthesis agent.

    Args:
        chat_client: Optional custom chat client. If None, uses default.
        domain: Research domain for customization.
        api_key: Optional BYOK key (auto-detects provider from prefix).

    Returns:
        ChatAgent configured for report generation
    """
    client = chat_client or get_chat_client(api_key=api_key)

    return ChatAgent(
        name="ReportAgent",
        description="Synthesizes research findings into structured reports",
        instructions=get_report_prompt(domain),
        chat_client=client,
        tools=[get_bibliography],
        temperature=1.0,  # Explicitly set for reasoning model compatibility
    )