Skip to content

Agents#

Putting together an agent in LlamaIndex can be done by defining a set of tools and providing them to our ReActAgent implementation. We're using it here with OpenAI, but it can be used with any sufficiently capable LLM:

from llama_index.core.tools import FunctionTool
from llama_index.llms.openai import OpenAI
from llama_index.core.agent import ReActAgent


# define sample Tool
def multiply(a: int, b: int) -> int:
    """Multiply two integers and returns the result integer"""
    return a * b


multiply_tool = FunctionTool.from_defaults(fn=multiply)

# initialize llm
llm = OpenAI(model="gpt-3.5-turbo-0613")

# initialize ReAct agent
agent = ReActAgent.from_tools([multiply_tool], llm=llm, verbose=True)

These tools can be Python functions as shown above, or they can be LlamaIndex query engines:

from llama_index.core.tools import QueryEngineTool

query_engine_tools = [
    QueryEngineTool(
        query_engine=sql_agent,
        metadata=ToolMetadata(
            name="sql_agent", description="Agent that can execute SQL queries."
        ),
    ),
]

agent = ReActAgent.from_tools(query_engine_tools, llm=llm, verbose=True)

You can learn more in our Agent Module Guide.

Native OpenAIAgent#

We have an OpenAIAgent implementation built on the OpenAI API for function calling that allows you to rapidly build agents:

Agentic Components within LlamaIndex#

LlamaIndex provides core modules capable of automated reasoning for different use cases over your data which makes them essentially Agents. Some of these core modules are shown below along with example tutorials.

SubQuestionQueryEngine for Multi Document Analysis

Query Transformations

Routing

LLM Reranking

Chat Engines

Using LlamaIndex as as Tool within an Agent Framework#

LlamaIndex can be used as as Tool within an agent framework - including LangChain, ChatGPT. These integrations are described below.

LangChain#

We have deep integrations with LangChain. LlamaIndex query engines can be easily packaged as Tools to be used within a LangChain agent, and LlamaIndex can also be used as a memory module / retriever. Check out our guides/tutorials below!

Resources

ChatGPT#

LlamaIndex can be used as a ChatGPT retrieval plugin (we have a TODO to develop a more general plugin as well).

Resources