----------------------
The ReAct Agent and OpenAI Agent are both components of LlamaIndex, but they serve different purposes and are used in different contexts.
The ReAct Agent is a part of LlamaIndex's core modules and is designed to reason over a set of tools to achieve an end goal. It can be used with any sufficiently capable Language Model (LLM), including OpenAI models. The ReAct Agent can use tools that are Python functions or LlamaIndex query engines. Here's an example of how to set up a ReAct Agent:
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)
(Source:
LlamaIndex Documentation ())
On the other hand, the OpenAI Agent is a specific implementation of an agent in LlamaIndex that uses OpenAI's models. It's used to set up an agent that can interact with OpenAI's models and perform tasks like automated reasoning over your data. Here's an example of how to set up an OpenAI Agent:
```python
from llama_index.core.agent import AgentRunner, ReActAgent
from llama_index.agent.openai import OpenAIAgentWorker, OpenAIAgent
from llama_index.agent.openai import OpenAIAgentWorker
agent_llm = OpenAI(model="gpt-3.5-turbo")