How to add LlamaHub tools to a LlamaIndex agent

Agent tool lists often need both packaged service integrations and small application-specific functions. LlamaIndex uses the same tool interface for both sources, so a FunctionAgent can receive them as one ordered collection.

A ToolSpec converts a service integration into individual tools through to_tool_list(). The WikipediaToolSpec used here supplies load_data and search_data, while FunctionTool.from_defaults() converts a typed Python function into local_release_note.

The included MockLLM keeps the registration test independent of an API key because the agent does not choose a tool from a prompt. A production agent needs the application's tool-calling LLM before it can select among these registered tools for user requests.

Steps to add LlamaHub tools to a LlamaIndex FunctionAgent:

  1. Install LlamaIndex core and the Wikipedia ToolSpec package in the project environment.
    $ python -m pip install llama-index-core llama-index-tools-wikipedia

    The package name changes to the specific llama-index-tools-* integration for another service. Each integration can add its own credentials and runtime requirements.

  2. Add the imports and local function to a new agent_tools_demo.py file.
    agent_tools_demo.py
    from llama_index.core.agent.workflow import FunctionAgent
    from llama_index.core.llms import MockLLM
    from llama_index.core.tools import FunctionTool
    from llama_index.tools.wikipedia import WikipediaToolSpec
     
     
    def local_release_note(component: str) -> str:
        """Return the release-note owner for a LlamaIndex component."""
        return f"{component} changes are routed to the docs-review queue."

    The type annotation and docstring become part of the schema and description that FunctionTool exposes to the agent.

  3. Append the packaged and local tool construction to agent_tools_demo.py.
    agent_tools_demo.py
    wiki_tools = WikipediaToolSpec().to_tool_list()
    local_tool = FunctionTool.from_defaults(local_release_note)
    tools = [*wiki_tools, local_tool]

    to_tool_list() expands the ToolSpec into separate callable tools before the local tool is added to the same list.

  4. Append the FunctionAgent configuration to agent_tools_demo.py.
    agent_tools_demo.py
    agent = FunctionAgent(
        name="ResearchAgent",
        description="Uses packaged Wikipedia tools and local release-note routing.",
        llm=MockLLM(),
        tools=tools,
        system_prompt="Use tools when a question needs source lookup or routing.",
    )

    MockLLM is suitable for inspecting registration without credentials, but it does not provide production tool selection.

  5. Append the smoke-test block to agent_tools_demo.py.
    agent_tools_demo.py
    tool_by_name = {tool.metadata.name: tool for tool in agent.tools}
    required_names = {"load_data", "search_data", "local_release_note"}
    missing_names = required_names - tool_by_name.keys()
     
    if missing_names:
        raise RuntimeError(f"missing tools: {sorted(missing_names)}")
     
    print("registered tools:")
    for name in tool_by_name:
        print(f"- {name}")
     
    local_result = tool_by_name["local_release_note"].call(component="agent tools")
    print(f"local result: {local_result.raw_output}")

    The missing-name check fails before the output when either the packaged tools or local tool was not registered.

  6. Run agent_tools_demo.py to verify the combined agent tool list.
    $ python agent_tools_demo.py
    registered tools:
    - load_data
    - search_data
    - local_release_note
    local result: agent tools changes are routed to the docs-review queue.

    The two Wikipedia names come from WikipediaToolSpec, and the final line comes from calling the local FunctionTool through the agent's registered tools.