Skip to content

Retrieve ID

This tool is used to search for academic papers on Semantic Scholar.

retrieve_semantic_scholar_paper_id(tool_call_id, paper_title=Field(description='The title of the paper to search for on Semantic Scholar.'))

This tool can be used to search for a paper on Semantic Scholar and retrieve the paper Semantic Scholar ID.

This is useful for when an article is retrieved from users Zotero library and the Semantic Scholar ID is needed to retrieve more information about the paper.

Parameters:

Name Type Description Default
tool_call_id Annotated[str, InjectedToolCallId]

The tool call ID.

required
paper_title str

The title of the paper to search for on Semantic Scholar.

Field(description='The title of the paper to search for on Semantic Scholar.')

Returns:

Name Type Description
ToolMessage Command[Any]

A message containing the paper ID.

Source code in aiagents4pharma/talk2scholars/tools/s2/retrieve_semantic_scholar_paper_id.py
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
@tool("retrieve_semantic_scholar_paper_id", parse_docstring=True)
def retrieve_semantic_scholar_paper_id(
    tool_call_id: Annotated[str, InjectedToolCallId],
    paper_title: str = Field(
        description="The title of the paper to search for on Semantic Scholar."
    ),
) -> Command[Any]:
    """
    This tool can be used to search for a paper on Semantic Scholar
    and retrieve the paper Semantic Scholar ID.

    This is useful for when an article is retrieved from users Zotero library
    and the Semantic Scholar ID is needed to retrieve more information about the paper.

    Args:
        tool_call_id (Annotated[str, InjectedToolCallId]): The tool call ID.
        paper_title (str): The title of the paper to search for on Semantic Scholar.

    Returns:
        ToolMessage: A message containing the paper ID.
    """
    logger.info("Retrieving ID of paper with title: %s", paper_title)
    endpoint = cfg.api_endpoint
    params = {
        "query": paper_title,
        "limit": 1,
        "fields": ",".join(cfg.api_fields),
    }

    response = requests.get(endpoint, params=params, timeout=10)
    data = response.json()
    papers = data.get("data", [])
    logger.info("Received %d papers", len(papers))
    if not papers:
        logger.error("No papers found for query: %s", paper_title)
        raise ValueError(f"No papers found for query: {paper_title}. Try again.")
    # Get the paper ID
    paper_id = papers[0]["paperId"]

    return Command(
        update={
            "messages": [
                ToolMessage(
                    content=f"Paper ID for '{paper_title}' is: {paper_id}",
                    tool_call_id=tool_call_id,
                )
            ],
        }
    )