Class AlloyDBSummaryTool (0.17.0)

AlloyDBSummaryTool(
    *,
    name: str = "alloydb_summary_tool",
    description: str = "Summarize the given text. Useful for condensing long articles or descriptions into shorter summaries.",
    args_schema: typing.Type[
        pydantic.main.BaseModel
    ] = langchain_google_alloydb_pg.tools.SummaryInput,
    return_direct: bool = False,
    verbose: bool = False,
    callbacks: (
        list[langchain_core.callbacks.base.BaseCallbackHandler]
        | langchain_core.callbacks.base.BaseCallbackManager
        | None
    ) = None,
    tags: list[str] | None = None,
    metadata: dict[str, typing.Any] | None = None,
    handle_tool_error: (
        bool
        | str
        | collections.abc.Callable[
            [langchain_core.tools.base.ToolException],
            str | collections.abc.Sequence[str | dict[str, typing.Any]],
        ]
        | None
    ) = False,
    handle_validation_error: (
        bool
        | str
        | collections.abc.Callable[
            [
                pydantic_core._pydantic_core.ValidationError
                | pydantic.v1.error_wrappers.ValidationError
            ],
            str,
        ]
        | None
    ) = False,
    response_format: typing.Literal["content", "content_and_artifact"] = "content",
    extras: dict[str, typing.Any] | None = None,
    engine: langchain_google_alloydb_pg.engine.AlloyDBEngine,
    model_id: typing.Optional[str] = None,
    additional_instructions: typing.Optional[str] = None
)

Summarizes text with google_ml.summarize.

Requires AlloyDB running PostgreSQL 17 or higher with google_ml_integration. Like any LangChain tool, call it with invoke / ainvoke or give it to an agent:

tool = AlloyDBSummaryTool(engine=engine)
tool.invoke(
    {"content": article, "additional_instructions": "In 3 bullet points"}
)

model_id works as in AlloyDBSentimentTool: it is set on the tool, and None uses the database's default model. additional_instructions can be set on the tool or passed per call; a per-call value replaces the tool's.

Methods

AlloyDBSummaryTool

AlloyDBSummaryTool(
    *,
    name: str = "alloydb_summary_tool",
    description: str = "Summarize the given text. Useful for condensing long articles or descriptions into shorter summaries.",
    args_schema: typing.Type[
        pydantic.main.BaseModel
    ] = langchain_google_alloydb_pg.tools.SummaryInput,
    return_direct: bool = False,
    verbose: bool = False,
    callbacks: (
        list[langchain_core.callbacks.base.BaseCallbackHandler]
        | langchain_core.callbacks.base.BaseCallbackManager
        | None
    ) = None,
    tags: list[str] | None = None,
    metadata: dict[str, typing.Any] | None = None,
    handle_tool_error: (
        bool
        | str
        | collections.abc.Callable[
            [langchain_core.tools.base.ToolException],
            str | collections.abc.Sequence[str | dict[str, typing.Any]],
        ]
        | None
    ) = False,
    handle_validation_error: (
        bool
        | str
        | collections.abc.Callable[
            [
                pydantic_core._pydantic_core.ValidationError
                | pydantic.v1.error_wrappers.ValidationError
            ],
            str,
        ]
        | None
    ) = False,
    response_format: typing.Literal["content", "content_and_artifact"] = "content",
    extras: dict[str, typing.Any] | None = None,
    engine: langchain_google_alloydb_pg.engine.AlloyDBEngine,
    model_id: typing.Optional[str] = None,
    additional_instructions: typing.Optional[str] = None
)

Initialize the tool.

Exceptions
Type Description
TypeError If args_schema is not a subclass of pydantic BaseModel or dict.

_arun

_arun(
    content: str,
    additional_instructions: typing.Optional[str] = None,
    run_manager: typing.Optional[
        langchain_core.callbacks.manager.AsyncCallbackManagerForToolRun
    ] = None,
) -> str

Summarize asynchronously. Called by ainvoke and arun.

_run

_run(
    content: str,
    additional_instructions: typing.Optional[str] = None,
    run_manager: typing.Optional[
        langchain_core.callbacks.manager.CallbackManagerForToolRun
    ] = None,
) -> str

Summarize synchronously. Called by invoke and run.

model_post_init

model_post_init(context: Any, /) -> None

This function is meant to behave like a BaseModel method to initialize private attributes.

It takes context as an argument since that's what pydantic-core passes when calling it.