Closed brycecf closed 1 week ago
To ensure the SubQuestionQueryEngine
always decomposes a user query into a ReActAgent
, you'll need to use a question generator designed for ReActAgent
. This involves configuring the SubQuestionQueryEngine
with a question_gen
that generates sub-questions tailored for a ReActAgent
. Here's how you can do it:
from my_custom_generators import ReActAgentQuestionGenerator
react_agent_question_gen = ReActAgentQuestionGenerator(...)
sub_question_query_engine = SubQuestionQueryEngine(
question_gen=react_agent_question_gen,
response_synthesizer=my_response_synthesizer,
query_engine_tools=my_query_engine_tools,
verbose=True,
use_async=True
)
This setup requires a ReActAgentQuestionGenerator
, which you need to implement based on the specific needs for decomposing queries for a ReActAgent
. The flexibility of the SubQuestionQueryEngine
allows it to accept any subclass of BaseQuestionGenerator
, enabling customization in query decomposition.
For implementation details, refer to the SubQuestionQueryEngine
source code in the LlamaIndex repository.
To continue the conversation, mention @dosu.
I faced the same question. I founded a medium post with an interesting approch, levering recursive retrieval to the tools (react agents) and a subqueryengine in the top level:
Relevant code to this question:
# # define recursive retriever
recursive_retriever = RecursiveRetriever(
"vector",
retriever_dict={"vector": vector_retriever},
query_engine_dict=agents,
verbose=True,
)
response_synthesizer = get_response_synthesizer(
response_mode="compact",
)
retriever_query_engine = RetrieverQueryEngine.from_args(
recursive_retriever,
response_synthesizer=response_synthesizer,
)
# convert the recursive retriever into a tool
query_engine_tools = [
QueryEngineTool(
query_engine=retriever_query_engine,
metadata=ToolMetadata(
name="index_node_agents",
description="Tool for access the agent for each city"
),
),
]
# setup sub question query engine
top_query_engine = SubQuestionQueryEngine.from_defaults(
query_engine_tools=query_engine_tools,
use_async=True,
)
response = top_query_engine.query(
"Tell me about the sports teams in Boston and the positive aspects of Seattle"
)
Question Validation
Question
How can I use the SubQuestionQueryEngine to always decompose a user query to a ReActAgent?