Skip to content

Zotero Write

This tool is used to save fetched papers to Zotero library after human approval.

ZoteroSaveInput

Bases: BaseModel

Input schema for the Zotero save tool.

Source code in aiagents4pharma/talk2scholars/tools/zotero/zotero_write.py
23
24
25
26
27
28
29
30
class ZoteroSaveInput(BaseModel):
    """Input schema for the Zotero save tool."""

    tool_call_id: Annotated[str, InjectedToolCallId]
    collection_path: str = Field(
        description="The path where the paper should be saved in the Zotero library."
    )
    state: Annotated[dict, InjectedState]

zotero_write(tool_call_id, collection_path, state)

Use this tool to save previously fetched papers from Semantic Scholar to a specified Zotero collection after human approval.

This tool checks if the user has approved the save operation via the zotero_review. If approved, it will save the papers to the approved collection path.

Parameters:

Name Type Description Default
tool_call_id Annotated[str, InjectedToolCallId]

The tool call ID.

required
collection_path str

The Zotero collection path where papers should be saved.

required
state Annotated[dict, InjectedState]

The state containing previously fetched papers.

required
user_confirmation str

User confirmation message when interrupt is

required

Returns:

Type Description
Command[Any]

Command[Any]: The save results and related information.

Source code in aiagents4pharma/talk2scholars/tools/zotero/zotero_write.py
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
80
81
82
83
84
85
86
87
88
89
90
@tool(args_schema=ZoteroSaveInput, parse_docstring=True)
def zotero_write(
    tool_call_id: Annotated[str, InjectedToolCallId],
    collection_path: str,
    state: Annotated[dict, InjectedState],
) -> Command[Any]:
    """
    Use this tool to save previously fetched papers from Semantic Scholar
    to a specified Zotero collection after human approval.

    This tool checks if the user has approved the save operation via the
    zotero_review. If approved, it will save the papers to the
    approved collection path.

    Args:
        tool_call_id (Annotated[str, InjectedToolCallId]): The tool call ID.
        collection_path (str): The Zotero collection path where papers should be saved.
        state (Annotated[dict, InjectedState]): The state containing previously fetched papers.
        user_confirmation (str, optional): User confirmation message when interrupt is
        not available.

    Returns:
        Command[Any]: The save results and related information.
    """
    # Create write data object to organize variables
    write_data = ZoteroWriteData(tool_call_id, collection_path, state)

    try:
        # Process the write operation
        results = write_data.process_write()

        return Command(
            update={
                "messages": [
                    ToolMessage(
                        content=results["content"],
                        tool_call_id=tool_call_id,
                        artifact=results["fetched_papers"],
                    )
                ],
                "zotero_write_approval_status": {},  # Clear approval info
            }
        )
    except ValueError as e:
        # Only handle collection not found errors with a Command
        if "collection path" in str(e).lower():
            return Command(
                update={
                    "messages": [
                        ToolMessage(
                            content=str(e),
                            tool_call_id=tool_call_id,
                        )
                    ],
                }
            )
        # Let other ValueErrors (like no papers) propagate up
        raise