-
My objective here is to integrate my 'RAGStringQueryEngine' and OpenAIAgentTools (which I developed using Python functions) into an agentic RAG. I was inspired by the article linked here (specifically the Agentic RAG section). Both my RAGString and OpenAIAgents codes work fine individually. However, my vision is to combine them within the agentic RAG framework. Please help!!! My Code which is working fine individually:
The code I am inspired and I like to build like this....
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
To integrate your from llama_index.core.tools import ToolMetadata, QueryEngineTool
from llama_index.core import SimpleDirectoryReader, VectorStoreIndex, Settings
from llama_index.core.agents import OpenAIAgent
from llama_index.agent.llm_compiler import LLMCompilerAgentWorker
from llama_index.core.agent import AgentRunner
from llama_index.llms.openai import OpenAI
# Set up the LLM in global settings
Settings.llm = OpenAI(model="gpt-4", temperature=0)
# Load and index documents for RAGStringQueryEngine
documents = SimpleDirectoryReader("./data").load_data()
index = VectorStoreIndex.from_documents(documents)
rag_query_engine = index.as_query_engine()
# Initialize your OpenAIAgentTools
openai_agent_tools = OpenAIAgentTools(...)
# Create QueryEngineTool instances
query_engine_tools = [
QueryEngineTool(
query_engine=rag_query_engine,
metadata=ToolMetadata(
name="rag_string_query_engine",
description="Provides information using RAGStringQueryEngine."
),
),
QueryEngineTool(
query_engine=openai_agent_tools,
metadata=ToolMetadata(
name="openai_agent_tools",
description="Provides information using OpenAIAgentTools."
),
),
]
# Combine the tools into an LLMCompilerAgentWorker
agent_worker = LLMCompilerAgentWorker.from_tools(
query_engine_tools,
llm=Settings.llm,
verbose=True,
callback_manager=Settings.llm.callback_manager,
)
# Create an AgentRunner
agent = AgentRunner(agent_worker, callback_manager=Settings.llm.callback_manager)
# Use the agent to handle queries
response = agent.chat("Your query here")
print(response) This code sets up the |
Beta Was this translation helpful? Give feedback.
To incorporate your already indexed
RAGStringQueryEngine
into the agentic RAG framework, you can directly use yourquery_engine
in place of therag_query_engine
in the provided code. Here is how you can do it:query_engine
is properly initialized and indexed.rag_query_engine
assignment with yourquery_engine
.query_engine
to create theQueryEngineTool
.Here is the modified code snippet: