Research Agent¶
The ResearchAgent
is a built-in utility agent in the AI Refinery SDK for handling complex research queries. It retrieves information from web resources and generates comprehensive responses. For instance, if asked "How do interest rate changes by the Federal Reserve impact the stock market?", the ResearchAgent
will
- search predefined web sources,
- gather the relevant information,
- generate the answer based on the relevant information.
This documentation outlines the workflow and configurations needed to use the ResearchAgent.
Workflow Overview¶
The workflow of ResearchAgent
consists of six components:
-
Source selection: The
ResearchAgent
retrieves information related to a user query from one or more pre-selected sources (e.g., Google, vector database indices). These sources must be specified before project creation. TheResearchAgent
will then utilize all selected sources for its search. Please refer to our Retrievers Gallery for a list of sources currently supported. -
Query transformation: Directly using the user's query to search all selected sources may not be optimal, especially if the query is lengthy or complex. In such cases, the
ResearchAgent
splits the query into multiple, more manageable queries to ensure relevant results. Thus, theResearchAgent
transforms the user's query into one or more queries tailored for each selected source. -
Retrieval: The
ResearchAgent
sends transformed queries to the selected sources and retrieves relevant data, ensuring it aligns with the original user query. -
Reranking: After retrieval, the
ResearchAgent
uses the reranker API to reorder the retrieved documents based on their relevance to the user's query. This ensures that the most pertinent information is prioritized in the response. -
Compression: The
ResearchAgent
then utilizes the prompt compression API to reduce the size of the top-ranked documents while retaining essential information. This step optimizes the prompt length for efficient processing. -
Answer generation: After retrieving, reranking, and compressing data from all sources, the
ResearchAgent
aggregates the information into a coherent and concise response, which is then presented to the user.
Usage¶
As a built-in utility agent in the AI Refinery SDK, ResearchAgent
can be easily integrated into your project by adding the necessary configurations to your project YAML file. Specifically, ensure the following configurations are included:
- Add a utility agent with
agent_class: ResearchAgent
underutility_agents
. - Ensure the
agent_name
you chose for yourResearchAgent
is listed in theagent_list
underorchestrator
.
Quickstart¶
To quickly set up a project with a ResearchAgent
, use the following YAML configuration. This setup includes a single retriever for web search (via Google). You can add more agents and retrievers as needed. Refer to the next section for a detailed overview of configurable options for ResearchAgent.
utility_agents:
- agent_class: ResearchAgent
agent_name: My Research Agent # A name that you choose for your research agent. This needs to be listed under orchestrator.
config:
reranker_top_k: 15 # Optional: Defines the top-k most relevant evidence pieces to retain post-reranking. Set to a negative value to skip reranking.
compression_rate: 0.4 # Optional: Specifies the compression rate for retrieved content. Lower values increase compression, discarding more information (default: 0.6). Set to 1 to retain all content with no compression.
retriever_config_list:
# The list of configurations of the retrievers i.e., sources used by your research agent to search for the relevant information related to a user query.
- retriever_name: "Internet Search" # A name you choose for your retriever
retriever_class: WebSearchRetriever # WebSearchRetriever is the type of retriever that performs web search via Google.
description: "This data source can collect the latest news / information from the open internet to answer any queries." # Optional. A description of the retrievar
orchestrator:
agent_list:
- agent_name: "My Research Agent" # The name you chose for your ResearchAgent above.
Template YAML Configuration for ResearchAgent
¶
In addition to the configurations mentioned for the example above, the ResearchAgent
supports several other configurable options. See the template YAML configuration below for all available settings.
Please note that each retriever supported by the
ResearchAgent
has its own configuration, which is detailed in the Retrievers Gallery.
agent_class: ResearchAgent
agent_name: <your-agent-name> # Unique name for your ResearchAgent
agent_description: <optional-description> # Optional: Describe the purpose of this agent
config:
reranker_top_k: <number of top k> # Optional: Specifies the number of top results you want from the reranked output.
compression_rate: <compression rate> # Optional: Defines the desired level of compression. Set to 1 to retain all content without any compression.
retriever_config_list: # Required: List of retrievers (see Retrievers Gallery for full examples)
- retriever_name: <name>
retriever_class: <RetrieverClass> # e.g., WebSearchRetriever, AzureAISearchRetriever, ElasticSearchRetriever, CustomRetriever,
# ⚠ Depending on the retriever_class, additional configuration fields will differ.
# For detailed retriever-specific parameters, see the Retrievers Gallery.
output_style: <"markdown" or "conversational" or "html"> # Optional field
contexts: # Optional field
- "date"
- "chat_history" # the chat history upto a certain number of rounds
- "env_variable"
- "relevant_chat_history" # the chat history that is relevant to the current query
llm_config:
# Optional. Customized llm config (if you want the research agent to use a different LLM than the on in your base config)
model: <model_name>
self_reflection_config: # Optional. Configuration for self-reflection.
self_reflection: <true or false> # Whether to enable self-reflection for this agent. Default is false.
max_attempts: <number> # Maximum number of times the agent can perform self-reflection. Default is 3.
response_selection_mode: <"best" | "aggregate" | "auto"> # Strategy used to generate the final response after reaching max_attempts. Default is "auto".
return_internal_reflection_msg: <true or false> # Whether to return internal reflection messages. Default is false.