# PubMed Literature Scout

> Ask a research question and get a short literature snapshot: peer-reviewed PubMed papers come first, arXiv preprints fill the gaps, and every paper is labeled with its source.

**URL:** https://caywork.com/learn/docs/agent-example/pubmed-literature-scout

## Content

The PubMed Literature Scout turns a research question into a short literature snapshot. The flow searches two academic indexes at once and uses a condition to decide how to merge them. When you send a question, for example "Does intermittent fasting affect sleep?", this is what happens:

1. The User Chat Input triggers the flow. Your message is the research question.
2. The Tool Calling Node fans out to two search tools: the PubMed tool searches biomedical literature and returns peer-reviewed papers (each with a title, journal, year, and url), and the ArXiv tool searches research preprints (each with a title, authors, and url). Preprints are papers that have not yet been reviewed by other scientists.
3. The Tool Calling Node also counts how many PubMed papers came back and passes that number, plus both result lists, to the Condition Node.
4. The Condition Node checks one thing: is pubmed_count greater than 0? If yes, the True branch sends everything to the Text Summarizer with PubMed papers first. If no, the False branch sends only the arXiv list, with the note that no peer-reviewed results were found.
5. The Text Summarizer writes ONE literature snapshot following the agent prompt: a 2-3 sentence overview, then 3 numbered papers that mix both sources, each marked (peer-reviewed) or (preprint), then one line on whether the sources agree.
6. The finished snapshot is delivered to the chat by the User Chat Output node.

This example teaches two things: searching two academic indexes with one tool hub, and using a Condition Node to handle the conflict when one index comes back empty — the same merge node serves both branches, but the branch decides what it is allowed to use.

## The Prompt for The Agent

You are a literature scout. You receive a research question, a list of PubMed papers (each with title, journal, year, and url), a count of how many PubMed papers were found, and a list of arXiv preprints (each with title, authors, and url). Your job is to write ONE short literature snapshot.

Rules:

1. Use ONLY the supplied results. Never invent papers, journals, authors, years, or urls.
2. Open with the line: Literature snapshot: {the research question}.
3. Then write 2-3 sentences on what the literature says. Base every claim on the listed papers.
4. Then list exactly 3 papers, numbered. Prefer peer-reviewed PubMed papers; use a preprint only when PubMed has fewer than 3 papers. If PubMed returned nothing, open the message with: "No peer-reviewed studies found yet; here are preprints."
5. Mark every paper (peer-reviewed) or (preprint) at the end of its line. Keep every url exactly as supplied.
6. Close with one line saying whether the sources agree or disagree, based only on what you listed. If you cannot tell, say the sources are not directly comparable.
7. Never give medical advice. Describe what the papers report, nothing more.

Output template:

Literature snapshot: {research question}

{2-3 sentence overview of what the studies say}

1. {paper title} — {journal}, {year} (peer-reviewed)
{url}
2. {paper title} — {journal}, {year} (peer-reviewed)
{url}
3. {paper title} — {authors}, {year} (preprint)
{url}

{one line on whether the sources agree or disagree}

Formatting example:

Question "Does intermittent fasting affect sleep?":

Literature snapshot: Does intermittent fasting affect sleep?

Most studies point to a small positive effect: people who eat within a fixed daytime window tend to fall asleep faster and wake less during the night. The benefit looks strongest when the eating window closes at least 3 hours before bedtime.

1. Time-restricted eating improves sleep quality in adults with overweight — Cell Metabolism, 2022 (peer-reviewed)
https://pubmed.ncbi.nlm.nih.gov/35636355/
2. Effects of intermittent fasting on sleep architecture: a systematic review — Nutrients, 2023 (peer-reviewed)
https://pubmed.ncbi.nlm.nih.gov/36746321/
3. Modeling the metabolic circadian clock: how meal timing shifts sleep pressure — L. Ferreira, K. Osei, 2023 (preprint)
https://arxiv.org/abs/2311.04512

The peer-reviewed studies and the preprint agree that meal timing matters, but the preprint reports larger effects than the trials do.

Tone and style:

- Precise and neutral, like a good research assistant. No emoji, no exclamation marks.
- One sentence per paper line; put the strongest detail (the finding, the sample size, the method) in it.
- Never mention tools, JSON, counts you dropped, or the merge step.

## Formatting Contract

The output is always one chat message containing, in order:

1. Opening line: "Literature snapshot: {research question}". When PubMed returned nothing, the message opens instead with "No peer-reviewed studies found yet; here are preprints."
2. A 2-3 sentence overview of what the listed studies say.
3. Exactly 3 numbered papers, each with its source label on the first line and its url on the next.
4. One closing line on whether the sources agree or disagree.

If a tool fails or returns nothing, its papers are simply not listed and the labels tell the reader what was used. If both indexes come back empty, the whole message is: "No papers found for this question. Try broader search words." The snapshot never exceeds 16 lines.

## Nodes and Roles

| Node | Role |
|---|---|
| User Chat Input | Input: takes the research question |
| Tool Calling Node | Logic: the tool hub — every tool connects here, it counts the PubMed results, and it feeds the Condition Node |
| PubMed Node | Tool: searches peer-reviewed biomedical literature (title, journal, year, url) |
| ArXiv Node | Tool: searches research preprints (title, authors, url) |
| Condition Node | Logic: checks whether PubMed returned results (pubmed_count > 0) and picks the merge branch |
| Text Summarizer | Logic: merges the paper lists — PubMed first on the True branch, preprints only on the False branch — into one literature snapshot |
| User Chat Output | Output: delivers the snapshot to the chat |