Implementation:CrewAIInc CrewAI LlamaIndex Tool
| Knowledge Sources | |
|---|---|
| Domains | Tools, LlamaIndex, Integration |
| Last Updated | 2026-02-11 00:00 GMT |
Overview
LlamaIndexTool wraps LlamaIndex tools and query engines to make them compatible with CrewAI agents.
Description
The LlamaIndexTool extends BaseTool and serves as a critical bridge between the CrewAI and LlamaIndex ecosystems. It stores a reference to a LlamaIndex tool instance via the llama_index_tool attribute. The _run method executes the wrapped tool, optionally extracting just the content from responses when result_as_answer is enabled. Two class factory methods provide flexible construction: from_tool() validates and wraps a LlamaIndex BaseTool instance by extracting its metadata (name, description) and fn_schema for argument validation; from_query_engine() wraps a BaseQueryEngine with a custom QueryToolSchema that remaps the default input parameter to query (to avoid confusion within CrewAI), and sets resolve_input_errors=True to handle the schema mismatch gracefully.
Usage
Use this tool when you need to leverage LlamaIndex's extensive ecosystem of tools, query engines, and data connectors within a CrewAI agent workflow.
Code Reference
Source Location
- Repository: CrewAI
- File: lib/crewai-tools/src/crewai_tools/tools/llamaindex_tool/llamaindex_tool.py
- Lines: 1-92
Signature
class LlamaIndexTool(BaseTool):
llama_index_tool: Any
def _run(self, *args: Any, **kwargs: Any) -> Any: ...
@classmethod
def from_tool(cls, tool: Any, **kwargs: Any) -> LlamaIndexTool: ...
@classmethod
def from_query_engine(
cls,
query_engine: Any,
name: str | None = None,
description: str | None = None,
return_direct: bool = False,
**kwargs: Any,
) -> LlamaIndexTool: ...
Import
from crewai_tools import LlamaIndexTool
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| llama_index_tool | Any | Yes | A LlamaIndex BaseTool instance to wrap |
| query_engine | Any | Yes (for from_query_engine) | A LlamaIndex BaseQueryEngine instance |
| name | str or None | No | Tool name override (for from_query_engine) |
| description | str or None | No | Tool description override (for from_query_engine) |
| return_direct | bool | No | Whether to return the query engine result directly; defaults to False |
Outputs
| Name | Type | Description |
|---|---|---|
| _run() returns | Any | The result from the wrapped LlamaIndex tool; returns content string if result_as_answer is True |
Usage Examples
From LlamaIndex Tool
from crewai_tools import LlamaIndexTool
from llama_index.core.tools import FunctionTool
llama_tool = FunctionTool.from_defaults(fn=my_function)
tool = LlamaIndexTool.from_tool(llama_tool)
From Query Engine
from crewai_tools import LlamaIndexTool
from llama_index.core import VectorStoreIndex
index = VectorStoreIndex.from_documents(documents)
query_engine = index.as_query_engine()
tool = LlamaIndexTool.from_query_engine(
query_engine,
name="Document Search",
description="Search through indexed documents",
)