人充当LLM Agent的工具(Human-In-The-Loop ),提升复杂问题解决成功率

42 篇文章 0 订阅
24 篇文章 0 订阅

原文:人充当LLM Agent的工具(Human-In-The-Loop ),提升复杂问题解决成功率

图片

在Agent开发过程中,LLM充当Agent的大脑,对问题进行规划、分解、推理,在执行过程中合理选择利用工具(Tool)解决某些具体领域的子问题。一般来说,大家习惯了选择使用搜索、计算器、code interperter之类的工具,但实际上,人也可以作为LLM的工具之一,被添加到解决问题的循环中,这被称作Human-In-The-Loop。

图片

传统的聊天机器人如 IVR,它会尝试处理呼叫请求,如果无法处理,就会转接给人工完成请求。而在 "Human In loop "下,Agent专注完成为用户请求,而过程中的人工支持对用户是透明的。agent可以通过一次或多次迭代来收集人工协助,而所有这些用户是看不到的。

在具体使用上也比较简单直接,和前面文章一文探秘LLM应用开发(24)-Prompt(架构模式Agent)提到的写法也没有什么区别。

举例,让agent回答:科布斯-葛瑞林的生日是几月几号?

完整代码:

pip install langchainpip install google-search-resultspip install openai
import osos.environ['OPENAI_API_KEY'] = str("xxxxxxxxxx")os.environ["SERPAPI_API_KEY"] = str("xxxxxxxxxx")llm = OpenAI(temperature=0,model_name='gpt-4-0314')
import sysfrom langchain.chat_models import ChatOpenAIfrom langchain.llms import OpenAIfrom langchain.agents import load_tools, initialize_agentfrom langchain.agents import AgentType
llm = ChatOpenAI(temperature=0.0)math_llm = OpenAI(temperature=0.0)tools = load_tools(    ["human", "llm-math"],     llm=math_llm,)
agent_chain = initialize_agent(    tools,    llm,    agent=AgentType.ZERO_SHOT_REACT_DESCRIPTION,    verbose=True,)
agent_chain.run("In what month is Cobus Greyling's birthday?")

从下面代码可以看到,我们将human作为tool添加到agent可用的工具箱中。那么,什么情况可以使用human这个工具呢?这段源码可以看到答案。

class HumanInputRun(BaseTool):    """Tool that adds the capability to ask user for input."""
    name = "Human"    description = (        "You can ask a human for guidance when you think you "        "got stuck or you are not sure what to do next. "        "The input should be a question for the human."    )    prompt_func: Callable[[str], None] = Field(default_factory=lambda: _print_func)    input_func: Callable = Field(default_factory=lambda: input)

执行查看运行结果:

图片

总之,这一思路非常新颖,可以很好解决那种开放环境下,与用户交互的复杂场景任务,通过寻求人工的帮助能够有效降低任务的失败。这在智能客服情境下有很大的应用前景,比如可以定义哪些问题,哪些时间点应该寻求人工支持。基于这个思路,还可以进一步扩展,比如完成专业角色问题的分发,多人协同,形成一个人+AI的Agent网络,这对于解决当前阶段Agent现实挑战(详见:一文探秘LLM应用开发(25)-Prompt(架构模式之Agent的现实挑战))有了一个过渡性方案。

  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
Human-in-the-Loop Machine Learning lays out methods for humans and machines to work together effectively. Summary Most machine learning systems that are deployed in the world today learn from human feedback. However, most machine learning courses focus almost exclusively on the algorithms, not the human-computer interaction part of the systems. This can leave a big knowledge gap for data scientists working in real-world machine learning, where data scientists spend more time on data management than on building algorithms. Human-in-the-Loop Machine Learning is a practical guide to optimizing the entire machine learning process, including techniques for annotation, active learning, transfer learning, and using machine learning to optimize every step of the process. Purchase of the print book includes a free eBook in PDF, Kindle, and ePub formats from Manning Publications. About the technology Machine learning applications perform better with human feedback. Keeping the right people in the loop improves the accuracy of models, reduces errors in data, lowers costs, and helps you ship models faster. About the book Human-in-the-Loop Machine Learning lays out methods for humans and machines to work together effectively. You'll find best practices on selecting sample data for human feedback, quality control for human annotations, and designing annotation interfaces. You'll learn to create training data for labeling, object detection, and semantic segmentation, sequence labeling, and more. The book starts with the basics and progresses to advanced techniques like transfer learning and self-supervision within annotation workflows. What's inside Identifying the right training and evaluation data Finding and managing people to annotate data Selecting annotation quality control strategies Designing interfaces to improve accuracy and efficiency About the author Robert (Munro) Monarch is a data scientist and engineer who has built machine learning data for companies such as
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值