AgentLite: 一个轻量级面向任务、多Agent的大模型代理框架


        
          
https://arxiv.org/pdf/2402.15538.pdf  
https://github.com/SalesforceAIResearch/AgentLite  

      

AgentLite是一个专为构建和推进基于LLM,面向任务的Agent系统而设计的框架。它简化了新代理/多代理体系结构的实现,通过管理代理轻松编排多个代理。

Key Features
  • 轻量级代码库:旨在轻松实现新的Agent/多Agent架构。
  • 面向任务的LLM-based代理:专注于为特定任务构建代理,增强其性能和能力。
  • 研究导向设计:是探索LLM-based多Agent系统高级概念的理想工具。
Examples
  1. Define the Action of an Agent

        
          
from agentlite.actions.BaseAction import BaseAction  
from langchain_community.tools import WikipediaQueryRun  
  
class WikipediaSearch(BaseAction):  
    def __init__(self) -> None:  
        action_name = "Wikipedia\_Search"   
        action_desc = "Using this API to search Wiki content." # LLM uses action\_name and action\_desc to understand this action  
        params_doc = {"query": "the search string. be simple."} # LLM uses this params\_doc to understand the parameters in self.\_\_call\_\_() function  
        self.search = WikipediaQueryRun(api_wrapper=WikipediaAPIWrapper())  
        super().__init__(  
            action_name=action_name,  
            action_desc=action_desc,  
            params_doc=params_doc,  
        )  
  
    def __call__(self, query):  
        return self.search.run(query)  

      
  1. Define an Agent with the Search Action

        
          
# get the llm for agent. Should already export OPENAI\_API\_KEY="" in the your terminal if you use OPENAI\_API.  
llm_config_dict = {"llm\_name": "gpt-3.5-turbo", "temperature": 0.9}  
llm_config = LLMConfig(llm_config_dict)  
llm = get_llm_backend(llm_config)  
# define an individual agent  
search_agent_info = {  
    "name": "search\_agent",  
    "role": "you can search wikipedia to get the information."  
}  
search_agent = BaseAgent(name=search_agent_info["name"],   
                         role=search_agent_info["role"],   
                         llm=llm,   
                         actions=[WikipediaSearch()],   
                         logger=agent_logger  
                         )  

      
  1. Calling the Agent with a Task

        
          
# calling the agent with TaskPackage  
from agentlite.commons import TaskPackage  
test_task = "what is the found date of microsoft"  
test_task_pack = TaskPackage(instruction=test_task)  
response = search_agent(test_task_pack)  
print("response:", response)  

      

Building a Multi-Agent System

  1. Define Individual Agents

        
          
# define two different types search agents  
## get llm backend  
from agentlite.llm.agent_llms import get_llm_backend  
from agentlite.llm.LLMConfig import LLMConfig  
llm_config_dict = {  
    "llm\_name": "gpt-3.5-turbo",  
    "temperature": 0.9,  
    "context\_len": 4000,  
}  
llm_config = LLMConfig(llm_config_dict)  
llm = get_llm_backend(llm_config)  
## get individual agents  
from example.SearchAgent import WikiSearchAgent, DuckSearchAgent  
wiki_search_agent = WikiSearchAgent(llm)  
duck_search_agent = DuckSearchAgent(llm)  

      
  1. Define a Manager Agent

        
          
from agentlite.agents import ManagerAgent  
manager_agent_info = {  
    "name": "search\_manager",  
    "role": "you are controlling wiki\_search\_agent and duck\_search\_agent to complete the search task. You should first use wiki\_search\_agent to complete the search task. If didn't answer the task, please try to ask duck\_search\_agent. You should integrate the answer from both agent to finalize the task."  
}  
# simply initializing the manager with info and the TeamAgents.  
search_manager = ManagerAgent(llm, manager_agent_info["name"],   
                              manager_agent_info["role"],  
                              TeamAgents=[wiki_search_agent, duck_search_agent])  

      
  1. Test the Manager Agent with a TaskPackage

        
          
from agentlite.commons import TaskPackage  
test_task = "what is salesforce famous for?"  
test_task_pack = TaskPackage(instruction=test_task, task_creator="User")  
response = search_manager(test_task_pack)  
print(response)  

      

picture.image

0
0
0
0
评论
未登录
暂无评论