How to use LlamaIndex tools with CrewAI?

Hi,

Just by curiosity - is anybody in the crewai core team considering (or already considered) integrating Llamaindex as crewai did with LangChain/tools?

Is it feasible/possible (or advised) to do this by implementing a BaseTool / “wrapper” to a given llamaindex tool?

kthx

@include See the CrewAI docs.

Steps to get started:

  1. Make sure that crewai[tools] package is installed in your Python environment: pip install 'crewai[tools]'
  2. Follow the LlamaIndex docs on how to set up a RAG/agent pipeline.

Here’s an example from the docs:

from crewai import Agent
from crewai_tools import LlamaIndexTool

# Example 1: Initialize from FunctionTool
from llama_index.core.tools import FunctionTool

your_python_function = lambda ...: ...
og_tool = FunctionTool.from_defaults(
    your_python_function, 
    name="<name>", 
    description='<description>'
)
tool = LlamaIndexTool.from_tool(og_tool)

# Example 2: Initialize from LlamaHub Tools
from llama_index.tools.wolfram_alpha import WolframAlphaToolSpec
wolfram_spec = WolframAlphaToolSpec(app_id="<app_id>")
wolfram_tools = wolfram_spec.to_tool_list()
tools = [LlamaIndexTool.from_tool(t) for t in wolfram_tools]

# Example 3: Initialize Tool from a LlamaIndex Query Engine
query_engine = index.as_query_engine()
query_tool = LlamaIndexTool.from_query_engine(
    query_engine,
    name="Uber 2019 10K Query Tool",
    description="Use this tool to lookup the 2019 Uber 10K Annual Report"
)

# Create and assign the tools to an agent
agent = Agent(
    role='Research Analyst',
    goal='Provide up-to-date market analysis',
    backstory='An expert analyst with a keen eye for market trends.',
    tools=[tool, *tools, query_tool]
)

# rest of the code ...
1 Like

I must be blind… thank you for pointing.

@include Happens to the best of us. Glad we solved the issue! :slight_smile:

Really shame :sweat_smile: … I was so excited following the Multi AI Agent Systems with crewAI - DeepLearning.AI that I jumped into this forum before checking the docs carefully… :slight_smile:

Awesome. I think I need something very similar to example 3. I am assembling a set of agents each one specialized in analyzing (and do some computation) in some specific PDF sections - in a way AgentSection1 can be focused on just that Section1, AgentSection2, Section2, etc.
Again, thank you :slight_smile:

PS: CrewAI was the missing tool. I was playing with LangChain and LlamaIndex but glueing everything in a nasty way… Now it will be very clean and integrated.

@include You’re welcome! :slight_smile: If you’ll face any issues, feel free to create a new topic/question.

1 Like