
关于
自主代理——能够独立分解复杂任务、规划执行路径并自主完成目标的 AI 系统
name: autonomous-agents description: 自主智能体是能够独立分解目标、规划行动、执行工具并自我纠正的 AI 系统,无需持续的人工指导。挑战不在于让它们有能力,而在于让它们可靠。每一个额外的决策都会成倍增加失败概率。 risk: unknown source: vibeship-spawner-skills (Apache 2.0) date_added: 2026-02-27
自主智能体
自主智能体是能够独立分解目标、规划行动、执行工具并自我纠正的 AI 系统,无需持续的人工指导。挑战不在于让它们有能力,而在于让它们可靠。每一个额外的决策都会成倍增加失败概率。
本技能涵盖智能体循环(ReAct、Plan-Execute)、目标分解、反思模式和生产可靠性。关键洞察:复合错误率会杀死自主智能体。每步 95% 的成功率到第 10 步会降至 60%。先构建可靠性,再追求自主性。
2025 年的教训:赢家是有明确边界的、受约束的、领域特定的智能体,而非"万能自主"。将 AI 输出视为提案,而非真理。
原则
- 可靠性优先于自主性——每一步都会复合错误概率
- 约束范围——领域特定优于通用型
- 将输出视为提案,而非真理
- 在扩展能力之前先建立防护栏
- 关键决策中的人机协作不可妥协
- 记录一切——每个操作都必须可审计
- 安全失败并回滚,而非静默损坏
能力
- autonomous-agents
- agent-loops
- goal-decomposition
- self-correction
- reflection-patterns
- react-pattern
- plan-execute
- agent-reliability
- agent-guardrails
范围
- multi-agent-systems → multi-agent-orchestration
- tool-building → agent-tool-builder
- memory-systems → agent-memory-systems
- workflow-orchestration → workflow-automation
工具
框架
- LangGraph - 适用场景:带状态管理的生产智能体 备注:2025 年 10 月发布 1.0,支持检查点、人机协作
- AutoGPT - 适用场景:研究/实验,开放式探索 备注:生产环境需要外部防护栏
- CrewAI - 适用场景:基于角色的智能体团队 备注:适合专业化智能体协作
- Claude Agent SDK - 适用场景:Anthropic 生态系统智能体 备注:计算机使用、工具执行
模式
- ReAct - 适用场景:交替进行推理和行动步骤 备注:大多数现代智能体的基础
- Plan-Execute - 适用场景:将规划与执行分离 备注:更适合复杂的多步骤任务
- Reflection - 适用场景:自我评估和纠正 备注:评估器-优化器循环
模式
ReAct 智能体循环
交替进行推理和行动步骤
适用场景:交互式问题解决、工具使用、探索
ReAct 模式:
""" ReAct 循环:
- 思考:推理下一步该做什么
- 行动:选择并执行工具
- 观察:接收结果
- 重复直到目标达成
关键:显式推理轨迹使调试成为可能 """
基本 ReAct 实现
from langchain.agents import create_react_agent
from langchain_openai import ChatOpenAI
# Define the ReAct prompt template
react_prompt = '''
Answer the question using the following format:
Question: the input question
Thought: reason about what to do
Action: tool_name
Action Input: input to the tool
Observation: result of the action
... (repeat Thought/Action/Observation as needed)
Thought: I now know the final answer
Final Answer: the answer
'''
# Create the agent
agent = create_react_agent(
llm=ChatOpenAI(model="gpt-4o"),
tools=tools,
prompt=react_prompt,
)
# Execute with step limit
result = agent.invoke(
{"input": query},
config={"max_iterations": 10} # Prevent runaway loops
)
LangGraph ReAct(生产环境)
from langgraph.prebuilt import create_react_agent
from langgraph.checkpoint.postgres import PostgresSaver
# Production checkpointer
checkpointer = PostgresSaver.from_conn_string(
os.environ["POSTGRES_URL"]
)
agent = create_react_agent(
model=llm,
tools=tools,
checkpointer=checkpointer, # Durable state
)
# Invoke with thread for state persistence
config = {"configurable": {"thread_id": "user-123"}}
result = agent.invoke({"messages": [query]}, config)
Plan-Execute 模式
将规划阶段与执行分离
适用场景:复杂的多步骤任务,需要完整计划可见性时
Plan-Execute 模式:
""" 两阶段方法:
- 规划:将目标分解为子任务
- 执行:执行子任务,可能重新规划
优势:
- 执行前完整可见计划
- 可与人工验证/修改计划
- 更清晰的关注点分离
劣势:
- 对任务中途发现的适应性较差
- 计划可能变得过时 """
LangGraph Plan-Execute
from langgraph.prebuilt import create_plan_and_execute_agent
# Planner creates the task list
planner_prompt = '''
For the given objective, create a step-by-step plan.
Each
兼容工具
Claude CodeCursor
标签
AI与机器学习