Pubmed Tools
Search PubMed for medical research papers with PubmedTools function toggles.
"""
Pubmed Tools
=============================
Demonstrates pubmed tools.
"""
from agno.agent import Agent
from agno.tools.pubmed import PubmedTools
# ---------------------------------------------------------------------------
# Create Agent
# ---------------------------------------------------------------------------
# Example 1: Enable all PubMed functions
agent_all = Agent(
tools=[
PubmedTools(
all=True, # Enable all PubMed search functions
)
],
markdown=True,
)
# Example 2: Enable specific PubMed functions only
agent_specific = Agent(
tools=[
PubmedTools(
enable_search_pubmed=True, # Only enable the main search function
)
],
markdown=True,
)
# Example 3: Default behavior with search enabled
agent = Agent(
tools=[
PubmedTools(
enable_search_pubmed=True,
)
],
markdown=True,
)
# Example usage with all functions enabled
# ---------------------------------------------------------------------------
# Run Agent
# ---------------------------------------------------------------------------
if __name__ == "__main__":
print("=== Example 1: Using all PubMed functions ===")
agent_all.print_response(
"Tell me about ulcerative colitis and find the latest research."
)
# Example usage with specific functions only
print("\n=== Example 2: Using specific PubMed functions (search only) ===")
agent_specific.print_response("Search for recent studies on diabetes treatment.")
# Example usage with default configuration
print("\n=== Example 3: Default PubMed agent usage ===")
agent.print_response("Tell me about ulcerative colitis.")
agent.print_response("Find research papers on machine learning in healthcare.")Include citation metadata
All three configurations expose the same single search_pubmed function. For titles, publication dates, PubMed URLs, and full abstracts, add email="your_actual_email@example.com" and results_expanded=True to each PubmedTools constructor. The default compact response omits citation URLs and can omit the title and date for short abstracts.
The tool searches PubMed records and returns abstracts and links. It does not retrieve the linked full-text articles. For a date-bounded search, include the date constraint in the PubMed query; the wrapper does not set a newest-first sort simply because the prompt says “latest.”
Run the Example
Set up your virtual environment
uv venv --python 3.12
source .venv/bin/activateInstall dependencies
uv pip install -U agno openaiExport your OpenAI API key
export OPENAI_API_KEY="your_openai_api_key_here"Run the example
Save the code above as pubmed_tools.py, then run:
python pubmed_tools.pyFull source: cookbook/91_tools/pubmed_tools.py