Skip to content

TinyFishSearchToolkit

autogen.beta.extensions.tools.search.tinyfish.TinyFishSearchToolkit #

TinyFishSearchToolkit(api_key=None, *, base_url=None, timeout=None, max_retries=None, location=None, language=None, format=None, links=None, image_links=None, middleware=())

Bases: Toolkit

Toolkit that exposes TinyFish Search and Fetch APIs as agent tools.

The two tools mirror TinyFish's public APIs: - tinyfish_search: web search with ranked titles, snippets, and URLs - tinyfish_fetch: browser-rendered content extraction for up to 10 URLs

By default, passing the whole toolkit to an agent registers both tools. To use a subset, or to customise per-tool parameters, call the factory methods directly and pass the returned tools to the agent::

toolkit = TinyFishSearchToolkit(api_key=...)

# both tools
agent = Agent("a", config=config, tools=[toolkit])

# only search, with custom defaults
agent = Agent("a", config=config, tools=[toolkit.search(location="US", language="en")])

The constructor reads TINYFISH_API_KEY from the environment when api_key is omitted (handled by the underlying TinyFish SDK).

Source code in autogen/beta/extensions/tools/search/tinyfish.py
def __init__(
    self,
    api_key: str | None = None,
    *,
    base_url: str | None = None,
    timeout: float | None = None,
    max_retries: int | None = None,
    location: str | Variable | None = None,
    language: str | Variable | None = None,
    format: FetchFormat | Variable | None = None,
    links: bool | Variable | None = None,
    image_links: bool | Variable | None = None,
    middleware: Iterable[ToolMiddleware] = (),
) -> None:
    self._api_key = api_key
    self._base_url = base_url
    self._timeout = timeout
    self._max_retries = max_retries

    super().__init__(
        self.search(location=location, language=language),
        self.fetch(format=format, links=links, image_links=image_links),
        name="tinyfish_search_toolkit",
        middleware=middleware,
    )

name instance-attribute #

name = name or __name__

tools property #

tools

search #

search(*, location=None, language=None, name='tinyfish_search', description='Search the web using TinyFish. Returns ranked results with titles, snippets, site names, and URLs.', middleware=())
Source code in autogen/beta/extensions/tools/search/tinyfish.py
def search(
    self,
    *,
    location: str | Variable | None = None,
    language: str | Variable | None = None,
    name: str = "tinyfish_search",
    description: str = (
        "Search the web using TinyFish. Returns ranked results with titles, snippets, site names, and URLs."
    ),
    middleware: Iterable[ToolMiddleware] = (),
) -> FunctionTool:
    client_kwargs = self._client_kwargs()

    @tool(name=name, description=description, middleware=middleware)
    async def tinyfish_search(
        query: Annotated[str, Field(description="The search query string.")],
        ctx: Context,
    ) -> ToolResult:
        """Search the web using TinyFish and return ranked results."""
        params: dict[str, Any] = {
            "location": resolve_variable(location, ctx, param_name="location"),
            "language": resolve_variable(language, ctx, param_name="language"),
        }
        kwargs = {k: v for k, v in params.items() if v is not None}

        client = AsyncTinyFish(**client_kwargs)
        try:
            raw = await client.search.query(query=query, **kwargs)
        finally:
            await client.close()

        return ToolResult(
            TinyFishSearchResponse(
                query=raw.query,
                total_results=raw.total_results,
                results=[
                    TinyFishSearchResult(
                        position=r.position,
                        site_name=r.site_name,
                        title=r.title,
                        snippet=r.snippet,
                        url=r.url,
                    )
                    for r in raw.results
                ],
            )
        )

    return tinyfish_search

fetch #

fetch(*, format=None, links=None, image_links=None, name='tinyfish_fetch', description='Fetch and extract clean content from URLs using TinyFish. Renders pages in a browser and returns extracted content plus per-URL errors.', middleware=())
Source code in autogen/beta/extensions/tools/search/tinyfish.py
def fetch(
    self,
    *,
    format: FetchFormat | Variable | None = None,
    links: bool | Variable | None = None,
    image_links: bool | Variable | None = None,
    name: str = "tinyfish_fetch",
    description: str = (
        "Fetch and extract clean content from URLs using TinyFish. "
        "Renders pages in a browser and returns extracted content plus per-URL errors."
    ),
    middleware: Iterable[ToolMiddleware] = (),
) -> FunctionTool:
    client_kwargs = self._client_kwargs()

    @tool(name=name, description=description, middleware=middleware)
    async def tinyfish_fetch(
        urls: Annotated[list[str], Field(description="URLs to fetch content for. TinyFish supports 1-10 URLs.")],
        ctx: Context,
    ) -> ToolResult:
        """Fetch web pages using TinyFish and return extracted content."""
        invalid_urls = [url for url in urls if not _safe_url(url)]
        if invalid_urls:
            return ToolResult({"error": f"Only http/https URLs are supported; rejected: {invalid_urls}"})

        params: dict[str, Any] = {
            "format": resolve_variable(format, ctx, param_name="format"),
            "links": resolve_variable(links, ctx, param_name="links"),
            "image_links": resolve_variable(image_links, ctx, param_name="image_links"),
        }
        kwargs = {k: v for k, v in params.items() if v is not None}

        client = AsyncTinyFish(**client_kwargs)
        try:
            with _tinyfish_api_integration():
                raw = await client.fetch.get_contents(urls=urls, **kwargs)
        finally:
            await client.close()

        return ToolResult(
            TinyFishFetchResponse(
                results=[
                    TinyFishFetchResult(
                        url=r.url,
                        final_url=r.final_url,
                        title=r.title,
                        description=r.description,
                        language=r.language,
                        author=r.author,
                        published_date=r.published_date,
                        text=r.text,
                        format=r.format,
                        links=list(r.links or []),
                        image_links=list(r.image_links or []),
                    )
                    for r in raw.results
                ],
                errors=[TinyFishFetchError(url=e.url, error=e.error) for e in raw.errors],
            )
        )

    return tinyfish_fetch

set_provider #

set_provider(provider)
Source code in autogen/beta/tools/final/toolkit.py
def set_provider(self, provider: Provider) -> None:
    for t in self.tools:
        t.set_provider(provider)

schemas async #

schemas(context)
Source code in autogen/beta/tools/final/toolkit.py
async def schemas(self, context: "Context") -> Iterable[ToolSchema]:
    schemas: list[ToolSchema] = []
    for t in self.tools:
        schemas.extend(await t.schemas(context))
    return schemas

register #

register(stack, context, *, middleware=())
Source code in autogen/beta/tools/final/toolkit.py
def register(
    self,
    stack: "ExitStack | AsyncExitStack",
    context: "Context",
    *,
    middleware: Iterable["BaseMiddleware"] = (),
) -> None:
    for t in self.tools:
        t.register(stack, context, middleware=middleware)

tool #

tool(function: Callable[..., Any], *, name: str | None = None, description: str | None = None, schema: FunctionParameters | None = None, sync_to_thread: bool = True, middleware: Iterable[ToolMiddleware] = ()) -> FunctionTool
tool(function: None = None, *, name: str | None = None, description: str | None = None, schema: FunctionParameters | None = None, sync_to_thread: bool = True, middleware: Iterable[ToolMiddleware] = ()) -> Callable[[Callable[..., Any]], FunctionTool]
tool(function=None, *, name=None, description=None, schema=None, sync_to_thread=True, middleware=())
Source code in autogen/beta/tools/final/toolkit.py
def tool(
    self,
    function: Callable[..., Any] | None = None,
    *,
    name: str | None = None,
    description: str | None = None,
    schema: FunctionParameters | None = None,
    sync_to_thread: bool = True,
    middleware: Iterable[ToolMiddleware] = (),
) -> FunctionTool | Callable[[Callable[..., Any]], FunctionTool]:
    def make_tool(f: Callable[..., Any]) -> FunctionTool:
        t = tool(
            f,
            name=name,
            description=description,
            schema=schema,
            sync_to_thread=sync_to_thread,
            middleware=middleware,
        )
        self._add_tool(t)
        return t

    if function:
        return make_tool(function)

    return make_tool