Skip to content

Tool

WebSearch

Bases: BaseTool

Source code in griptape/tools/web_search/tool.py
@define
class WebSearch(BaseTool):
    web_search_driver: BaseWebSearchDriver = field(default=None, kw_only=True)

    @activity(
        config={
            "description": "Can be used for searching the web",
            "schema": Schema(
                {
                    Literal(
                        "query",
                        description="Search engine request that returns a list of pages with titles, descriptions, and URLs",
                    ): str
                }
            ),
        }
    )
    def search(self, props: dict) -> ListArtifact | ErrorArtifact:
        query = props["values"]["query"]

        try:
            return self.web_search_driver.search(query)
        except Exception as e:
            return ErrorArtifact(f"Error searching '{query}' with {self.web_search_driver.__class__.__name__}: {e}")

web_search_driver: BaseWebSearchDriver = field(default=None, kw_only=True) class-attribute instance-attribute

search(props)

Source code in griptape/tools/web_search/tool.py
@activity(
    config={
        "description": "Can be used for searching the web",
        "schema": Schema(
            {
                Literal(
                    "query",
                    description="Search engine request that returns a list of pages with titles, descriptions, and URLs",
                ): str
            }
        ),
    }
)
def search(self, props: dict) -> ListArtifact | ErrorArtifact:
    query = props["values"]["query"]

    try:
        return self.web_search_driver.search(query)
    except Exception as e:
        return ErrorArtifact(f"Error searching '{query}' with {self.web_search_driver.__class__.__name__}: {e}")