agentscope.agents.rag_agent module

This example shows how to build an agent with RAG with LlamaIndex.

Notice, this is a Beta version of RAG agent.

class agentscope.agents.rag_agent.LlamaIndexAgent(*args: tuple, **kwargs: dict)[源代码]

基类:AgentBase

A LlamaIndex agent build on LlamaIndex.

__init__(name: str, sys_prompt: str, model_config_name: str, knowledge_list: list[Knowledge] | None = None, knowledge_id_list: list[str] | None = None, similarity_top_k: int | None = None, log_retrieval: bool = True, recent_n_mem_for_retrieve: int = 1, **kwargs: Any) None[源代码]

Initialize the RAG LlamaIndexAgent :param name: the name for the agent :type name: str :param sys_prompt: system prompt for the RAG agent :type sys_prompt: str :param model_config_name: language model for the agent :type model_config_name: str :param knowledge_list: a list of knowledge.

User can choose to pass a list knowledge object directly when initializing the RAG agent. Another choice can be passing a list of knowledge ids and obtain the knowledge with the equip function of a knowledge bank.

参数:
  • knowledge_id_list (list[Knowledge]) – a list of id of the knowledge. This is designed for easy setting up multiple RAG agents with a config file. To obtain the knowledge objects, users can pass this agent to the equip function in a knowledge bank to add corresponding knowledge to agent’s self.knowledge_list.

  • similarity_top_k (int) – the number of most similar data blocks retrieved from each of the knowledge

  • log_retrieval (bool) – whether to print the retrieved content

  • recent_n_mem_for_retrieve (int) – the number of pieces of memory used as part of retrival query

reply(x: Sequence[Msg] | Msg | None = None) Msg[源代码]

Reply function of the RAG agent. Processes the input data, 1) use the input data to retrieve with RAG function; 2) generates a prompt using the current memory and system prompt; 3) invokes the language model to produce a response. The response is then formatted and added to the dialogue memory.

参数:

x (Optional[Union[Msg, Sequence[Msg]]], defaults to None) – The input message(s) to the agent, which also can be omitted if the agent doesn’t need any input.

返回:

The output message generated by the agent.

返回类型:

Msg