Skip to content

Search Papers

Search for academic papers on Semantic Scholar by title or keywords.

Given a text query, this tool retrieves relevant papers from Semantic Scholar, optionally filtered by publication year.

SearchInput

Bases: BaseModel

Defines the input schema for the paper search tool.

Attributes:

Name Type Description
query str

Full or partial paper title or keywords to search for.

limit int

Maximum number of search results to return (1-100).

year Optional[str]

Optional publication year filter; supports 'YYYY',

'YYYY-', '-YYYY', 'YYYY

YYYY'.

tool_call_id Annotated[str, InjectedToolCallId]

Internal tool call identifier injected by the system.

Source code in aiagents4pharma/talk2scholars/tools/s2/search.py
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
class SearchInput(BaseModel):
    """Defines the input schema for the paper search tool.

    Attributes:
        query: Full or partial paper title or keywords to search for.
        limit: Maximum number of search results to return (1-100).
        year: Optional publication year filter; supports 'YYYY',
        'YYYY-', '-YYYY', 'YYYY:YYYY'.
        tool_call_id: Internal tool call identifier injected by the system.
    """

    query: str = Field(
        description="Full or partial paper title or keywords to search for"
    )
    limit: int = Field(
        default=10,
        description="Maximum number of search results to return (1-100)",
        ge=1,
        le=100,
    )
    year: Optional[str] = Field(
        default=None,
        description="Publication year filter; supports formats:"
        "'YYYY', 'YYYY-', '-YYYY', 'YYYY:YYYY'",
    )
    tool_call_id: Annotated[str, InjectedToolCallId]

search_tool(query, tool_call_id, limit=10, year=None)

Return academic papers from Semantic Scholar matching a title or keyword query.

This tool searches Semantic Scholar for papers whose titles or keywords match the given text, optionally filtered by publication year.

Parameters:

Name Type Description Default
query str

Full or partial paper title or keywords to search for.

required
tool_call_id str

Internal tool call identifier injected by the system.

required
limit int

Maximum number of search results to return. Defaults to 5.

10
year str

Publication year filter; supports 'YYYY',

None
'YYYY-', '-YYYY', 'YYYY

YYYY'. Defaults to None.

required

Returns:

Name Type Description
Command Command[Any]

A Command object containing: - papers: List of matching papers. - last_displayed_papers: Same list for display purposes. - messages: List containing a ToolMessage with search results details.

Source code in aiagents4pharma/talk2scholars/tools/s2/search.py
 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
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
@tool(
    "search_tool",
    args_schema=SearchInput,
    parse_docstring=True,
)
def search_tool(
    query: str,
    tool_call_id: Annotated[str, InjectedToolCallId],
    limit: int = 10,
    year: Optional[str] = None,
) -> Command[Any]:
    """
    Return academic papers from Semantic Scholar matching a title or keyword query.

    This tool searches Semantic Scholar for papers whose titles or keywords
    match the given text, optionally filtered by publication year.

    Args:
        query (str): Full or partial paper title or keywords to search for.
        tool_call_id (str): Internal tool call identifier injected by the system.
        limit (int, optional): Maximum number of search results to return. Defaults to 5.
        year (str, optional): Publication year filter; supports 'YYYY',
        'YYYY-', '-YYYY', 'YYYY:YYYY'. Defaults to None.

    Returns:
        Command: A Command object containing:
            - papers: List of matching papers.
            - last_displayed_papers: Same list for display purposes.
            - messages: List containing a ToolMessage with search results details.
    """
    # Create search data object to organize variables
    search_data = SearchData(query, limit, year, tool_call_id)

    # Process the search
    results = search_data.process_search()

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