Skip to content

LLM Agent 框架设计模式

LLM Agent 框架定义了智能体的决策循环和执行策略。不同框架在自主性、可靠性和效率之间做出不同权衡。

Agent 框架

主流框架模式

python
# ReAct 模式
def react_loop(task, model, tools):
    for _ in range(MAX_STEPS):
        thought = model.think(task, history)
        action = model.select_action(thought, tools)
        observation = execute(action)
        history.append((thought, action, observation))
        if is_complete(observation):
            return observation

# Plan-and-Execute 模式
def plan_and_execute(task, model, tools):
    plan = model.plan(task)
    for step in plan:
        result = model.execute(step, tools)
        if result.needs_replan:
            plan = model.replan(task, result)
框架自主性可靠性适用场景
ReAct探索性任务
Plan-Execute结构化任务
Reflexion需要迭代的任务

框架选择

简单任务用 ReAct,复杂项目用 Plan-Execute,需要自我修正的用 Reflexion。

相关资源

最近更新