从0手搓4种Agentic模式,主打去框架化!

Agentic Patterns项目:包含Andrew Ng在其 DeepLearning.AI博客文章系列中定义的4种Agentic模式的从头实现,主打去框架化:没有 LangChain,没有 LangGraph,没有 LlamaIndex,没有 CrewAI。对LLM API 调用纯粹而简单。

图片

反思模式:Reflection Pattern

这是一个非常基本的模式,但尽管它很简单,它却为LLM响应带来了令人惊讶的性能提升。

它允许大模型反思其结果,建议修改、添加、改进写作风格等。

图片

BASE_GENERATION_SYSTEM_PROMPT = """Your task is to Generate the best content possible for the user's request.If the user provides critique, respond with a revised version of your previous attempt.You must always output the revised content."""
BASE_REFLECTION_SYSTEM_PROMPT = """You are tasked with generating critique and recommendations to the user's generated content.If the user content has something wrong or something to be improved, output a list of recommendationsand critiques. If the user content is ok and there's nothing to change, output this: <OK>"""

工具模式(Tool Pattern)

LLM 权重中存储的信息(通常)不足以对我们的问题提供准确而有见地的答案

这就是为什么我们需要为大模型提供接触外部世界的途径

实际上,可以构建任何你想要的工具(归根结底,它们只是 LLM 可以使用的功能),一个工具可以让你访问维基百科,另一个工具可以分析 YouTube 视频的内容或计算 Wolfram Alpha 中的困难积分。

图片

TOOL_SYSTEM_PROMPT = """You are a function calling AI model. You are provided with function signatures within <tools></tools> XML tags.You may call one or more functions to assist with the user query. Don't make assumptions about what values to pluginto functions. Pay special attention to the properties 'types'. You should use those types as in a Python dict.For each function call return a json object with function name and arguments within <tool_call></tool_call>XML tags as follows:
<tool_call>{"name": <function-name>,"arguments": <args-dict>,  "id": <monotonically-increasing-id>}</tool_call>
Here are the available tools:
<tools>%s</tools>"""

规划模式(Planning Pattern)

经过上述两步,已经看到了能够反思和使用工具来访问外部世界的智能体。但是......规划呢,即决定按照什么步骤顺序来完成一项大任务?

这正是规划模式所提供的:让 LLM 将任务分解为更小、更容易实现的子目标,而不会忘记最终目标。

规划模式最典型的例子是ReAct技术:

图片

REACT_SYSTEM_PROMPT = """You are a function calling AI model. You operate by running a loop with the following steps: Thought, Action, Observation.You are provided with function signatures within <tools></tools> XML tags.You may call one or more functions to assist with the user query. Don' make assumptions about what values to pluginto functions. Pay special attention to the properties 'types'. You should use those types as in a Python dict.
For each function call return a json object with function name and arguments within <tool_call></tool_call> XML tags as follows:
<tool_call>{"name": <function-name>,"arguments": <args-dict>, "id": <monotonically-increasing-id>}</tool_call>
Here are the available tools / actions:
<tools>%s</tools>
Example session:
<question>What's the current temperature in Madrid?</question><thought>I need to get the current weather in Madrid</thought><tool_call>{"name": "get_current_weather","arguments": {"location": "Madrid", "unit": "celsius"}, "id": 0}</tool_call>
You will be called again with this:
<observation>{0: {"temperature": 25, "unit": "celsius"}}</observation>
You then output:
<response>The current temperature in Madrid is 25 degrees Celsius</response>
Additional constraints:
- If the user asks you something unrelated to any of the tools above, answer freely enclosing your answer with <response></response> tags."""

多智能体模式(Multiagent Pattern)

相信不少小伙伴都听过crewAI 或 AutoGen 等框架,它们允许您创建多智能体应用程序。

这些框架实现了多智能体模式的不同变体,其中任务被划分为由不同角色执行的较小子任务(例如,一个Agent可以是软件工程师,另一个Agent可以是项目经理等)。

这一模式的实际效果开发ing......

图片

文末讨论:真正的AGI?

真正的AGI的秘密不在于一个万能的模型......而在于一系列针对特定问题空间的明确定义的本体,其中包含许多 AI 模型 + 代码,以在直觉+逻辑护栏之间取得适当的平衡,从而实现Agent推理、规划和决策???

图片

https://www.deeplearning.ai/the-batch/how-agents-can-improve-llm-performance/?ref=dl-staging-website.ghost.iohttps://github.com/neural-maze/agentic_patterns

来源 | PaperAgent

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值