使用LlamaIndex工具

CrewAI 与 LlamaIndex 的综合工具包无缝集成,用于 RAG(检索增强生成)和代理管道,支持基于搜索的高级查询等功能。

以下是LlamaIndex提供的可用内置工具。

Code
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 ...

入门步骤

要有效使用LlamaIndexTool,请按照以下步骤操作:

1

包安装

确保在您的Python环境中安装了crewai[tools]包:

2

安装和使用LlamaIndex

按照LlamaIndex文档LlamaIndex Documentation设置RAG/agent管道。

这个页面有帮助吗?