📒 前言
2025年爆发了很多AI应用,从年初的DeepSeek-R1到后面的Manus,不管是从基础大模型还是Agent工程,都在日新月异的发展。
随着大模型基础能力的提升,尤其是推理能力的提升。AI 业内人士普遍认为今年将是 AI Agent 爆发的元年,跑在最前面的就是 Coding Agent,国外的Cursor到国内的Trae,AI Agent显著提高了软件工程行业的生产效率。随着像 MCP 和 A2A 协议生态进一步的建设,越来越多行业Agent将涌现,Agent应用肯定会成为每个人的生产力助手,甚至是你的数字分身。
Agent这么重要,但是构建一个安全可靠的Agent更关键,这里面就引出了我今天想介绍的一个重点概念:
Human-in-the-loop。相信很多人都已经知道这个概念了。
Human-in-the-loop是一种 AI 系统设计理念,它将人类判断和监督整合到 AI 决策过程中。在 AI Agent 系统中,这一概念尤为重要:
- 安全性保障: 允许人类在关键决策点进行干预和审核,防止 AI 做出潜在有害的决策
- 质量控制: 通过人类专家的反馈来提升 AI 输出的准确性和可靠性
- 持续学习: AI 系统可以从人类反馈中学习和改进,形成良性循环
- 责任明确: 在重要决策上保持人类的最终控制权,明确决策责任
在实际应用中,Human-in-the-loop 可以是多种形式:从简单的决策确认到深度的人机协作对话,确保 AI 系统在自主性和人类监督之间达到最佳平衡,发挥出 AI Agent 系统的最大潜力。
我分析了市面上构建 Agent 工具的平台,像LangGraph、CrewAI等对human-in-the-loop支持都是比较简单,对于越来越复杂的 Agent,需要更安全、更高效的人类反馈控制,所以我最近折腾了一个工具--GoHumanLoop,上线了第一个基础版本,接下来我展开讲讲,欢迎大家交流学习🤝
🚀 GoHumanLoop 介绍
- GitHub地址:github.com/ptonlix/goh… 🌟🌟🌟
GoHumanLoop:是一个Python库,使AI Agent能够在关键阶段动态请求人类输入(批准/反馈/对话)。
核心功能:
- 人类在环控制:让AI代理系统暂停并升级决策,增强安全性和信任。
- 多渠道集成:支持终端、电子邮件、API控制和支持多个LangGraph/CrewAI等框架(即将推出)。
- 灵活的工作流程:结合自动推理和人工监督,确保人工智能操作的可靠性。
通过连接自主代理和人类判断,确保负责任的AI部署。
🎹 快速开始
Installation
GoHumanLoop 目前支持Python
- 安装
pip install gohumanloop
Example
以下基于 LangGraph 官方例子 通过 GoHumanLoop升级 human-in-the-loop
💡 默认采用
Terminal作为langgraph_adapter人机交互方式
import os
from langchain.chat_models import init_chat_model
from typing import Annotated
from langchain_tavily import TavilySearch
from langchain_core.tools import tool
from typing_extensions import TypedDict
from langgraph.checkpoint.memory import MemorySaver
from langgraph.graph import StateGraph, START, END
from langgraph.graph.message import add_messages
from langgraph.prebuilt import ToolNode, tools_condition
# from langgraph.types import Command, interrupt # Don't use langgraph, use gohumanloop instead
from gohumanloop.adapters.langgraph_adapter import interrupt, create_resume_command
# Please replace with your Deepseek API Key from https://platform.deepseek.com/usage
os.environ["DEEPSEEK_API_KEY"] = "sk-xxx"
# Please replace with your Tavily API Key from https://app.tavily.com/home
os.environ["TAVILY_API_KEY"] = "tvly-xxx"
llm = init_chat_model("deepseek:deepseek-chat")
class State(TypedDict):
messages: Annotated[list, add_messages]
graph_builder = StateGraph(State)
@tool
def human_assistance(query: str) -> str:
"""Request assistance from a human."""
human_response = interrupt({"query": query})
return human_response
tool = TavilySearch(max_results=2)
tools = [tool, human_assistance]
llm_with_tools = llm.bind_tools(tools)
def chatbot(state: State):
message = llm_with_tools.invoke(state["messages"])
# Because we will be interrupting during tool execution,
# we disable parallel tool calling to avoid repeating any
# tool invocations when we resume.
assert len(message.tool_calls) <= 1
return {"messages": [message]}
graph_builder.add_node("chatbot", chatbot)
tool_node = ToolNode(tools=tools)
graph_builder.add_node("tools", tool_node)
graph_builder.add_conditional_edges(
"chatbot",
tools_condition,
)
graph_builder.add_edge("tools", "chatbot")
graph_builder.add_edge(START, "chatbot")
memory = MemorySaver()
graph = graph_builder.compile(checkpointer=memory)
user_input = "I need some expert guidance for building an AI agent. Could you request assistance for me?"
config = {"configurable": {"thread_id": "1"}}
events = graph.stream(
{"messages": [{"role": "user", "content": user_input}]},
config,
stream_mode="values",
)
for event in events:
if "messages" in event:
event["messages"][-1].pretty_print()
# LangGraph code:
# human_response = (
# "We, the experts are here to help! We'd recommend you check out LangGraph to build your agent."
# "It's much more reliable and extensible than simple autonomous agents."
# )
# human_command = Command(resume={"data": human_response})
# GoHumanLoop code:
human_command = create_resume_command() # Use this command to resume the execution,instead of using the command above
events = graph.stream(human_command, config, stream_mode="values")
for event in events:
if "messages" in event:
event["messages"][-1].pretty_print()
- 部署测试
运行上述代码
# 1.Initialize environment
uv init gohumanloop-example
cd gohumanloop-example
uv venv .venv --python=3.10
# 2.Copy the above code to main.py
# 3.Deploy and test
uv pip install langchain
uv pip install langchain_tavily
uv pip install langgraph
uv pip install langchain-deepseek
uv pip install gohumanloop
python main.py
- 交互信息
进行 human-in-the-loop 交互, 输入信息
We, the experts are here to help! We'd recommend you check out LangGraph to build your agent.It's much more reliable and extensible than simple autonomous agents.
完成 🚀🚀🚀
➡️ 更多示例请查看项目地址,并期待你的分享~
🎵 Why GoHumanloop?
Human-in-the-loop
Even with state-of-the-art agentic reasoning and prompt routing, LLMs are not sufficiently reliable to be given access to high-stakes functions without human oversight
Human-in-the-loop 是一种 AI 系统设计理念,它将人类判断和监督整合到 AI 决策过程中。在 AI Agent 系统中,这一概念尤为重要:
- 安全性保障: 允许人类在关键决策点进行干预和审核,防止 AI 做出潜在有害的决策
- 质量控制: 通过人类专家的反馈来提升 AI 输出的准确性和可靠性
- 持续学习: AI 系统可以从人类反馈中学习和改进,形成良性循环
- 责任明确: 在重要决策上保持人类的最终控制权,明确决策责任
在实际应用中,Human-in-the-loop 可以是多种形式:从简单的决策确认到深度的人机协作对话,确保 AI 系统在自主性和人类监督之间达到最佳平衡,发挥出 AI Agent 系统的最大潜力。
典型应用场景
A human can review and edit the output from the agent before proceeding. This is particularly critical in applications where the tool calls requested may be sensitive or require human oversight.
- 🛠️ 审核工具调用:在工具执行前,人工可审核、编辑或批准由大语言模型(LLM)发起的工具调用请求。
- ✅ 验证模型输出:人工可审核、编辑或批准大语言模型生成的内容(如文本、决策等)。
- 💡 提供上下文:允许大语言模型主动请求人工输入,以获取澄清、补充细节或支持多轮对话的上下文信息。
安全高效 Go➡Humanloop
GoHumanloop提供了一套工具深度集成在 AI Agent 内部,确保始终存在Human-in-the-loop的监督机制,能够以确定性的方式确保高风险函数调用必须经过人工审核,同时也能够获取人类专家反馈,从而提升 AI 系统的可靠性和安全性,减少 LLM 幻觉导致的风险。
The Outer-Loop and Inversion of Control
通过GoHumanloop的封装可以帮助你在请求工具、Agent 节点、MCP 服务和其它 Agent 时,实现安全高效的Human-in-the-loop。
📚 关键特性
GoHumanLoop Architecture
GoHumanloop 提供了对外提供以下核心能力:
- Approval: 在执行特定工具调用或 Agent 节点时,请求人工审核或批准
- Information: 在执行任务时,获取人类关键信息,减少 LLM 幻觉风险
- Conversation: 通过对话形式与人类进行多轮交互,获取更丰富的上下文信息
- Specific: 针对特定 Agent 框架,提供特定的集成方式,如
LangGraph的interrupt和resume
📅 开发路线图
| Feature | Status |
|---|---|
| Approval | ⚙️ Beta |
| Information | ⚙️ Beta |
| Conversation | ⚙️ Beta |
| Email Provider | ⚙️ Beta |
| Terminal Provider | ⚙️ Beta |
| API Provider | ⚙️ Beta |
| Default Manager | ⚙️ Beta |
| GLH Manager | 🗓️ Planned |
| Langchain Support | ⚙️ Beta |
| CrewAI Support | 🗓️ Planned |
- 💡 GLH Manager - GoHumanLoop Manager 将对接正在打造的集成平台 GoHumanLoop Hub,为用户提供更灵活的管理方式。
🤝 欢迎贡献
GoHumanLoop采用MIT协议开源,欢迎大家贡献力量,一起共建GoHumanLoop。
您可以做
-
报告错误
-
建议改进
-
文档贡献
-
代码贡献
...
👏👏👏
📱 联系交流
🎉 如果你对本项目感兴趣,欢迎评论区交流和联系我~
- GitHub地址:github.com/ptonlix/goh… 🌟🌟🌟
如果感觉对你有帮助,欢迎支持 Star 一下