File size: 7,001 Bytes
645a051 cd7c282 fd1472e 645a051 fd1472e cd7c282 fd1472e 915b009 fd1472e 645a051 fd1472e 915b009 645a051 915b009 fd1472e 645a051 fd1472e 645a051 fd1472e 645a051 6b5e05b 645a051 fd1472e cd7c282 fd1472e 915b009 fd1472e 645a051 fd1472e 915b009 645a051 915b009 fd1472e 645a051 fd1472e 645a051 3cb2e43 645a051 6b5e05b 645a051 fd1472e cd7c282 fd1472e 915b009 fd1472e 645a051 fd1472e 915b009 645a051 915b009 fd1472e 645a051 fd1472e 645a051 fa696e8 645a051 6b5e05b 645a051 fd1472e cd7c282 fd1472e 915b009 fd1472e 645a051 fd1472e 915b009 645a051 915b009 fd1472e 645a051 fd1472e 645a051 fd1472e 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 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 |
"""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
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=f"""You are a biomedical search specialist. When asked to find evidence:
1. Analyze the request to determine what to search for
2. Extract key search terms (drug names, disease names, mechanisms)
3. Use the appropriate search tools:
- search_pubmed for peer-reviewed papers
- search_clinical_trials for clinical studies
- search_preprints for cutting-edge findings
4. Summarize what you found and highlight key evidence
Be thorough - search multiple databases when appropriate.
Focus on finding: mechanisms of action, clinical evidence, and specific findings
related to {config.name}.""",
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)
config = get_domain_config(domain)
return ChatAgent(
name="JudgeAgent",
description="Evaluates evidence quality and determines if sufficient for synthesis",
instructions=f"""{config.judge_system_prompt}
When asked to evaluate:
1. Review all evidence presented in the conversation
2. Score on two dimensions (0-10 each):
- Mechanism Score: How well is the biological mechanism explained?
- Clinical Score: How strong is the clinical/preclinical evidence?
3. Determine if evidence is SUFFICIENT for a final report:
- Sufficient: Clear mechanism + supporting clinical data
- Insufficient: Gaps in mechanism OR weak clinical evidence
4. If insufficient, suggest specific search queries to fill gaps
## CRITICAL OUTPUT FORMAT
To ensure the workflow terminates when appropriate, you MUST follow these rules:
IF evidence is SUFFICIENT (confidence >= 70%):
Start your response with a line like:
"β
SUFFICIENT EVIDENCE (confidence: 72%). STOP SEARCHING. Delegate to ReportAgent NOW."
Use your actual numeric confidence instead of 72.
Then explain why.
IF evidence is INSUFFICIENT:
Start with "β INSUFFICIENT: <Reason>."
Then provide scores and next queries.
Be rigorous but fair. Look for:
- Molecular targets and pathways
- Animal model studies
- Human clinical trials
- Safety data
- Drug-drug interactions""",
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=f"""{config.hypothesis_system_prompt}
Based on evidence:
1. Identify the key molecular targets involved
2. Map the biological pathways affected
3. Generate testable hypotheses in this format:
DRUG -> TARGET -> PATHWAY -> THERAPEUTIC EFFECT
Example:
Testosterone -> Androgen receptor -> Dopamine modulation -> Enhanced libido
4. Explain the rationale for each hypothesis
5. Suggest what additional evidence would support or refute it
Focus on mechanistic plausibility and existing evidence.""",
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)
config = get_domain_config(domain)
return ChatAgent(
name="ReportAgent",
description="Synthesizes research findings into structured reports",
instructions=f"""{config.report_system_prompt}
When asked to synthesize:
Generate a structured report with these sections:
## Executive Summary
Brief overview of findings and recommendation
## Methodology
Databases searched, queries used, evidence reviewed
## Key Findings
### Mechanism of Action
- Molecular targets
- Biological pathways
- Proposed mechanism
### Clinical Evidence
- Preclinical studies
- Clinical trials
- Safety profile
## Candidates
List specific candidates with potential
## Limitations
Gaps in evidence, conflicting data, caveats
## Conclusion
Final recommendation with confidence level
## References
Use the 'get_bibliography' tool to fetch the complete list of citations.
Format them as a numbered list.
Be comprehensive but concise. Cite evidence for all claims.""",
chat_client=client,
tools=[get_bibliography],
temperature=1.0, # Explicitly set for reasoning model compatibility
)
|