Skip to content

TinyFishFetchTool

autogen.tools.experimental.TinyFishFetchTool #

TinyFishFetchTool(*, llm_config=None, tinyfish_api_key=None)

Bases: Tool

TinyFishFetchTool uses the TinyFish Fetch API to extract content from URLs.

TinyFish Fetch renders pages in a browser and returns clean extracted content, metadata, and per-URL errors. This tool requires a TinyFish API key, which can be provided during initialization or set as an environment variable TINYFISH_API_KEY.

ATTRIBUTE DESCRIPTION
tinyfish_api_key

The API key used for authenticating with the TinyFish API.

TYPE: str

Initializes the TinyFishFetchTool.

PARAMETER DESCRIPTION
llm_config

LLM configuration. (Currently unused but kept for potential future integration).

TYPE: Optional[Union[LLMConfig, dict[str, Any]]] DEFAULT: None

tinyfish_api_key

The API key for the TinyFish API. If not provided, it attempts to read from the TINYFISH_API_KEY environment variable.

TYPE: Optional[str] DEFAULT: None

RAISES DESCRIPTION
ValueError

If tinyfish_api_key is not provided either directly or via the environment variable.

Source code in autogen/tools/experimental/tinyfish/tinyfish_tool.py
def __init__(
    self,
    *,
    llm_config: LLMConfig | dict[str, Any] | None = None,
    tinyfish_api_key: str | None = None,
):
    """Initializes the TinyFishFetchTool.

    Args:
        llm_config (Optional[Union[LLMConfig, dict[str, Any]]]): LLM configuration.
            (Currently unused but kept for potential future integration).
        tinyfish_api_key (Optional[str]): The API key for the TinyFish API. If not provided,
            it attempts to read from the ``TINYFISH_API_KEY`` environment variable.

    Raises:
        ValueError: If ``tinyfish_api_key`` is not provided either directly or via the environment variable.
    """
    self.tinyfish_api_key = tinyfish_api_key or os.getenv("TINYFISH_API_KEY")

    if self.tinyfish_api_key is None:
        raise ValueError("tinyfish_api_key must be provided either as an argument or via TINYFISH_API_KEY env var")

    def tinyfish_fetch(
        urls: Annotated[list[str], "URLs to fetch and extract. TinyFish supports 1-10 URLs."],
        tinyfish_api_key: Annotated[str | None, Depends(on(self.tinyfish_api_key))],
        format: Annotated[str | None, "Output format: 'markdown', 'html', or 'json'."] = None,
        links: Annotated[bool | None, "Whether to include page links in results."] = None,
        image_links: Annotated[bool | None, "Whether to include image links in results."] = None,
    ) -> dict[str, Any]:
        """Fetch and extract content from URLs using TinyFish Fetch.

        Args:
            urls: URLs to fetch and extract.
            tinyfish_api_key: The API key for TinyFish (injected dependency).
            format: Output format: "markdown", "html", or "json".
            links: Whether to include page links in results.
            image_links: Whether to include image links in results.

        Returns:
            A dictionary containing successful fetch results and per-URL errors.

        Raises:
            ValueError: If the TinyFish API key is not available.
        """
        if tinyfish_api_key is None:
            raise ValueError("TinyFish API key is missing.")
        return _tinyfish_fetch(
            urls=urls,
            tinyfish_api_key=tinyfish_api_key,
            format=format,
            links=links,
            image_links=image_links,
        )

    super().__init__(
        name="tinyfish_fetch",
        description="Fetch and extract clean content from URLs using TinyFish. Returns extracted content and per-URL errors.",
        func_or_tool=tinyfish_fetch,
    )

name property #

name

description property #

description

func property #

func

tool_schema property #

tool_schema

Get the schema for the tool.

This is the preferred way of handling function calls with OpeaAI and compatible frameworks.

function_schema property #

function_schema

Get the schema for the function.

This is the old way of handling function calls with OpenAI and compatible frameworks. It is provided for backward compatibility.

realtime_tool_schema property #

realtime_tool_schema

Get the schema for the tool.

This is the preferred way of handling function calls with OpeaAI and compatible frameworks.

tinyfish_api_key instance-attribute #

tinyfish_api_key = tinyfish_api_key or getenv('TINYFISH_API_KEY')

register_for_llm #

register_for_llm(agent)

Registers the tool for use with a ConversableAgent's language model (LLM).

This method registers the tool so that it can be invoked by the agent during interactions with the language model.

PARAMETER DESCRIPTION
agent

The agent to which the tool will be registered.

TYPE: ConversableAgent

Source code in autogen/tools/tool.py
def register_for_llm(self, agent: "ConversableAgent") -> None:
    """Registers the tool for use with a ConversableAgent's language model (LLM).

    This method registers the tool so that it can be invoked by the agent during
    interactions with the language model.

    Args:
        agent (ConversableAgent): The agent to which the tool will be registered.
    """
    if self._func_schema:
        agent.update_tool_signature(self._func_schema, is_remove=False)
    else:
        agent.register_for_llm()(self)

register_for_execution #

register_for_execution(agent)

Registers the tool for direct execution by a ConversableAgent.

This method registers the tool so that it can be executed by the agent, typically outside of the context of an LLM interaction.

PARAMETER DESCRIPTION
agent

The agent to which the tool will be registered.

TYPE: ConversableAgent

Source code in autogen/tools/tool.py
def register_for_execution(self, agent: "ConversableAgent") -> None:
    """Registers the tool for direct execution by a ConversableAgent.

    This method registers the tool so that it can be executed by the agent,
    typically outside of the context of an LLM interaction.

    Args:
        agent (ConversableAgent): The agent to which the tool will be registered.
    """
    agent.register_for_execution()(self)

register_tool #

register_tool(agent)

Register a tool to be both proposed and executed by an agent.

Equivalent to calling both register_for_llm and register_for_execution with the same agent.

Note: This will not make the agent recommend and execute the call in the one step. If the agent recommends the tool, it will need to be the next agent to speak in order to execute the tool.

PARAMETER DESCRIPTION
agent

The agent to which the tool will be registered.

TYPE: ConversableAgent

Source code in autogen/tools/tool.py
def register_tool(self, agent: "ConversableAgent") -> None:
    """Register a tool to be both proposed and executed by an agent.

    Equivalent to calling both `register_for_llm` and `register_for_execution` with the same agent.

    Note: This will not make the agent recommend and execute the call in the one step. If the agent
    recommends the tool, it will need to be the next agent to speak in order to execute the tool.

    Args:
        agent (ConversableAgent): The agent to which the tool will be registered.
    """
    self.register_for_llm(agent)
    self.register_for_execution(agent)