HumanLayer 开源项目教程

HumanLayer 开源项目教程

humanlayer HumanLayer enables AI agents to communicate with humans in tool-based and async workflows. Guarantee human oversight of high-stakes function calls with approval workflows across slack, email and more. Bring your LLM and Framework of choice and start giving your AI agents safe access to the world. Agentic Workflows, human in the loop, tool calling humanlayer 项目地址: https://gitcode.com/gh_mirrors/hu/humanlayer

1. 项目介绍

HumanLayer 是一个API和SDK,它使AI代理能够联系人类以获取帮助、反馈和批准。通过引入您选择的LLM(如OpenAI、Llama、Claude等)和框架(如LangChain、CrewAI等),您可以开始为您的AI代理提供安全访问外部世界的能力。

HumanLayer 的核心功能是确保高风险功能的调用过程中有人类的监督,从而避免由AI代理独立执行可能产生的风险。

2. 项目快速启动

以下是如何快速启动 HumanLayer 项目的步骤:

首先,您需要安装 HumanLayer。对于Python,可以使用pip命令安装:

pip install humanlayer

对于TypeScript,您可以使用npm来安装:

npm install humanlayer

安装完成后,您可以在Python中创建一个简单的示例来发送电子邮件,并要求人类批准:

from humanlayer import HumanLayer

hl = HumanLayer()

@hl.require_approval()
def send_email(to: str, subject: str, body: str):
    """发送电子邮件给客户"""
    # 这里是发送电子邮件的代码逻辑
    pass

# 使用LLM任务运行器来执行发送电子邮件的操作
run_llm_task(
    prompt="发送一封欢迎邮件给客户,并鼓励他们邀请团队成员。",
    tools=[send_email],
    llm="gpt-4o"
)

在TypeScript中,代码结构类似,但语法会有所不同。

3. 应用案例和最佳实践

HumanLayer 可以用于多种场景,以下是一些应用案例和最佳实践:

  • 审批流程:在执行重要操作前,如发送邮件、发布内容等,使用 HumanLayer 来确保有一个人类在回路中审批。
  • 错误处理:当AI代理遇到不确定的情况时,可以调用 HumanLayer 来获取人类的反馈。
  • 复杂决策:在需要复杂决策的场景中,AI代理可以借助 HumanLayer 来询问人类的意见。

最佳实践

  • 总是在高风险的操作前使用 @hl.require_approval() 装饰器。
  • 在调试阶段,可以使用 hl.human_as_tool() 来手动引入人类干预。

4. 典型生态项目

HumanLayer 的生态中包括了一些典型的项目,这些项目可以与 HumanLayer 集成,以提供更完整的工作流程解决方案:

  • LangChain:一个用于构建复杂AI工作流的框架。
  • CrewAI:一个AI协作平台,可以与 HumanLayer 集成,以实现更高效的团队协作。
  • ControlFlow:一个用于定义和管理工作流的框架。

通过结合这些生态项目,您可以构建出功能丰富且安全的AI应用。

humanlayer HumanLayer enables AI agents to communicate with humans in tool-based and async workflows. Guarantee human oversight of high-stakes function calls with approval workflows across slack, email and more. Bring your LLM and Framework of choice and start giving your AI agents safe access to the world. Agentic Workflows, human in the loop, tool calling humanlayer 项目地址: https://gitcode.com/gh_mirrors/hu/humanlayer

创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

杭律沛Meris

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值