Skip to content

Zotero Read

Zotero Read Tool

This LangGraph tool searches a user's Zotero library for items matching a query and optionally downloads their PDF attachments. It returns structured metadata for each found item and makes the results available as an artifact.

ZoteroSearchInput

Bases: BaseModel

Input schema for the Zotero search tool.

Attributes:

Name Type Description
query str

Search string to match against item metadata.

only_articles bool

If True, restrict results to 'journalArticle' and similar types.

limit int

Maximum number of items to fetch from Zotero.

download_pdfs bool

If True, download PDF attachments for each item.

tool_call_id str

Internal identifier for this tool invocation.

Source code in aiagents4pharma/talk2scholars/tools/zotero/zotero_read.py
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
class ZoteroSearchInput(BaseModel):
    """Input schema for the Zotero search tool.

    Attributes:
        query (str): Search string to match against item metadata.
        only_articles (bool): If True, restrict results to 'journalArticle' and similar types.
        limit (int): Maximum number of items to fetch from Zotero.
        download_pdfs (bool): If True, download PDF attachments for each item.
        tool_call_id (str): Internal identifier for this tool invocation.
    """

    query: str = Field(
        description="Search query string to find papers in Zotero library."
    )
    only_articles: bool = Field(
        default=True,
        description="Whether to only search for journal articles/conference papers.",
    )
    limit: int = Field(
        default=2, description="Maximum number of results to return", ge=1, le=100
    )
    download_pdfs: bool = Field(
        default=False,
        description="Whether to download PDF attachments immediately (default True).",
    )
    tool_call_id: Annotated[str, InjectedToolCallId]

zotero_read(query, only_articles, tool_call_id, limit=2, download_pdfs=False)

Execute a search on the Zotero library and return matching items.

Parameters:

Name Type Description Default
query str

Text query to search in titles, abstracts, tags, etc.

required
only_articles bool

When True, only include items of type 'journalArticle'

required
tool_call_id str

Internal ID injected by LangGraph to track this tool call.

required
limit int

Max number of items to return (1–100). Defaults to 2.

2
download_pdfs bool

If True, PDFs for each returned item will be downloaded now. If False, only metadata is fetched. Defaults to False.

False

Returns:

Type Description
Command[Any]

Command[Any]: A LangGraph Command updating the agent state: - 'article_data': dict mapping item keys to metadata (and 'pdf_url' if downloaded). - 'last_displayed_papers': identifier pointing to the articles in state. - 'messages': list containing a ToolMessage with a human-readable summary and an 'artifact' referencing the raw article_data.

Source code in aiagents4pharma/talk2scholars/tools/zotero/zotero_read.py
 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
@tool(args_schema=ZoteroSearchInput, parse_docstring=True)
def zotero_read(
    query: str,
    only_articles: bool,
    tool_call_id: Annotated[str, InjectedToolCallId],
    limit: int = 2,
    download_pdfs: bool = False,
) -> Command[Any]:
    """
    Execute a search on the Zotero library and return matching items.

    Args:
        query (str): Text query to search in titles, abstracts, tags, etc.
        only_articles (bool): When True, only include items of type 'journalArticle'
        or 'conferencePaper'.
        tool_call_id (str): Internal ID injected by LangGraph to track this tool call.
        limit (int, optional): Max number of items to return (1–100). Defaults to 2.
        download_pdfs (bool, optional): If True, PDFs for each returned item will be downloaded now.
                                        If False, only metadata is fetched. Defaults to False.

    Returns:
        Command[Any]: A LangGraph Command updating the agent state:
            - 'article_data': dict mapping item keys to metadata (and 'pdf_url' if downloaded).
            - 'last_displayed_papers': identifier pointing to the articles in state.
            - 'messages': list containing a ToolMessage with a human-readable summary
                           and an 'artifact' referencing the raw article_data.
    """
    # Create search data object to organize variables
    # download_pdfs flag controls whether PDFs are fetched now or deferred
    search_data = ZoteroSearchData(
        query=query,
        only_articles=only_articles,
        limit=limit,
        download_pdfs=download_pdfs,
        tool_call_id=tool_call_id,
    )

    # Process the search
    search_data.process_search()
    results = search_data.get_search_results()

    return Command(
        update={
            "article_data": results["article_data"],
            # Store the latest article_data mapping directly for display
            "last_displayed_papers": results["article_data"],
            "messages": [
                ToolMessage(
                    content=results["content"],
                    tool_call_id=tool_call_id,
                    artifact=results["article_data"],
                )
            ],
        }
    )