Builds PaperTrail from the base skeleton into a full evidence-verification platform for the "Built with Claude: Life Sciences" hackathon (Builder Track). New named-user features (Build Beyond the Bench): - Lab Notebook Companion — rough bench notes -> structured, searchable, grounded experiment records (lib/labNotebook, /console/lab-notebook, migration 0059) - Clinical Trial Matcher — de-identified patient notes -> ranked eligible ClinicalTrials.gov trials with per-criterion inclusion/exclusion reasoning (lib/trialMatcher, /console/trial-matcher, migrations 0060) Platform: - Deterministic verification moat (biostats recompute, exact-span grounding) - 11 biomedical evidence engines (FAERS, GWAS, Open Targets, ChEMBL, ClinVar, PharmGKB, PubTator, DDI, repurposing, biomarker, unified verifier) - Evidence Intelligence (KG, dossier, provenance/export, RWE) + enterprise governance (RBAC, /api/v1 gateway, metering, audit chain, retention) - 17 OSS projects assimilated into native TypeScript on our stack (backend/engines retained + credited in NOTICE) - Multi-format upload (PDF/DOCX/XLSX/CSV/MD/TXT), logo, marketing site - Next.js 16 upgrade, benchmark harness (honest smoke-test caveat) Licensing: Apache-2.0 (LICENSE + NOTICE).
78 lines
2.9 KiB
Python
78 lines
2.9 KiB
Python
from .utils.file_formats import \
|
|
write_md_to_pdf, \
|
|
write_md_to_word, \
|
|
write_text_to_md
|
|
|
|
from .utils.views import print_agent_output
|
|
|
|
|
|
class PublisherAgent:
|
|
def __init__(self, output_dir: str, websocket=None, stream_output=None, headers=None):
|
|
self.websocket = websocket
|
|
self.stream_output = stream_output
|
|
self.output_dir = output_dir.strip()
|
|
self.headers = headers or {}
|
|
|
|
async def publish_research_report(self, research_state: dict, publish_formats: dict):
|
|
layout = self.generate_layout(research_state)
|
|
await self.write_report_by_formats(layout, publish_formats)
|
|
|
|
return layout
|
|
|
|
def generate_layout(self, research_state: dict):
|
|
sections = []
|
|
for subheader in research_state.get("research_data", []):
|
|
if isinstance(subheader, dict):
|
|
# Handle dictionary case
|
|
for key, value in subheader.items():
|
|
sections.append(f"{value}")
|
|
else:
|
|
# Handle string case
|
|
sections.append(f"{subheader}")
|
|
|
|
sections_text = '\n\n'.join(sections)
|
|
references = '\n'.join(f"{reference}" for reference in research_state.get("sources", []))
|
|
headers = research_state.get("headers", {})
|
|
|
|
diagrams_text = ""
|
|
diagrams = research_state.get("diagrams", [])
|
|
if diagrams:
|
|
diagrams_text = "\n## Visualizations\n" + "\n\n".join(diagrams) + "\n"
|
|
|
|
layout = f"""# {headers.get('title')}
|
|
#### {headers.get("date")}: {research_state.get('date')}
|
|
|
|
## {headers.get("introduction")}
|
|
{research_state.get('introduction')}
|
|
|
|
## {headers.get("table_of_contents")}
|
|
{research_state.get('table_of_contents')}
|
|
|
|
{sections_text}
|
|
|
|
## {headers.get("conclusion")}
|
|
{research_state.get('conclusion')}
|
|
{diagrams_text}
|
|
## {headers.get("references")}
|
|
{references}
|
|
"""
|
|
return layout
|
|
|
|
async def write_report_by_formats(self, layout:str, publish_formats: dict):
|
|
if publish_formats.get("pdf"):
|
|
await write_md_to_pdf(layout, self.output_dir)
|
|
if publish_formats.get("docx"):
|
|
await write_md_to_word(layout, self.output_dir)
|
|
if publish_formats.get("markdown"):
|
|
await write_text_to_md(layout, self.output_dir)
|
|
|
|
async def run(self, research_state: dict):
|
|
task = research_state.get("task")
|
|
publish_formats = task.get("publish_formats")
|
|
if self.websocket and self.stream_output:
|
|
await self.stream_output("logs", "publishing", f"Publishing final research report based on retrieved data...", self.websocket)
|
|
else:
|
|
print_agent_output(output="Publishing final research report based on retrieved data...", agent="PUBLISHER")
|
|
final_research_report = await self.publish_research_report(research_state, publish_formats)
|
|
return {"report": final_research_report}
|