Mentals AI是一种工具,旨在创建和操作代理,具有loops , memory和各种tools的特征,并通过直接的markdown文件和.gen扩展名。将代理文件视为可执行文件。您完全专注于代理的逻辑,消除了用Python或任何其他语言编写脚手架代码的必要性。本质上,它重新定义了未来AI应用程序的基本框架?
笔记
由LLM控制的自循环中的单词链游戏: 
NLOP-自然语言操作
或更复杂的用例:
| 任何多代理互动 | ?太空入侵者发电机代理 | ? 2D平台生成器代理 |
|---|---|---|
![]() | ![]() | ![]() |
或帮助内容:
以上所有示例都位于代理文件夹中。
笔记
使用兼容的OpenAI API提供了Llama3支持。
首先通过创建OpenAI帐户来确保OpenAI API密钥。如果您已经有一个API键,请跳过此步骤。
先决条件
在构建项目之前,请确保安装以下依赖关系:
根据操作系统,您可以使用以下命令安装这些命令:
Linux
sudo apt-get update
sudo apt-get install libcurl4-openssl-dev libfmt-dev libpoppler-devmacos
brew update
brew install curl fmt poppler视窗
对于Windows,建议使用VCPKG或类似的软件包管理器:
vcpkg install curl fmt popplerPGVECTOR安装
笔记
在main分支中,您可以跳过此步骤
克隆存储库
git clone https://github.com/turing-machines/mentals-ai
cd mentals-ai配置
将您的API键放入config.toml文件中:
[llm]
# OpenAI
api_key = " "
endpoint = " https://api.openai.com/v1 "
model = " gpt-4o "建立项目
make跑步
./build/mentals agents/loop.gen -dMentals AI以三种重要的方式将自己与其他框架区分开:
Agent Executor ?通过递归循环操作。 LLM确定下一步:选择指令(提示)和基于先前循环管理数据。此递归决策过程对于我们的系统不可或缺,在Mentals_system中概述Markdown创建任何复杂性的代理,从而消除了对传统编程语言的需求。但是,如有必要,可以将Python直接集成到代理的Markdown脚本中。Tree of Thoughts , ReAct , Self-Discovery , Auto-CoT等。一个人还可以将这些框架链接到更复杂的序列中,甚至可以创建各种推理框架的网络。 代理文件是带有.gen扩展名的代理指令的文本描述。
指导是指理学中代理的基本组成部分。代理可以由一个或多个指令组成,可以相互指定。

说明可以以自由形式写入,但是它们总是以#符号开头的名称。 ## use:指令用于指定对其他说明的引用。多个参考文献列出了逗号分隔。
以下是两个指令root and meme_explain的示例,并带有参考:
# root
## use: meme_explain
1. Create 3 memes about AGI;
2. Then do meme explain with meme per call;
3. Output memes and their explanations in a list.
# meme_explain
Explain the gist of the meme in 20 words in medieval style.
Return explanation.
在此示例中, root指令调用meme_explain指令。然后,MEME_EXPLAIN的响应将返回到所谓的指令,即根。
指令可以采用input参数,该参数将根据调用指令的上下文自动生成。要更精确地指定输入数据,您可以在##输入中使用自由形式的提示## input:指令,例如JSON对象或null 。
使用文档进行输入:
# some_instruction
## input: design document only
使用JSON对象作为输入:
# duckduckgo
## input: { search_query: search query, search_limit: search limit }
Write a Python script to search in DuckDuckGo.
Simulate request headers correctly e.g. user-agent as Mozilla and Linux.
笔记
指令调用是独立于OpenAI的功能或工具调用来实现的,从而使代理商使用Llama3之类的模型进行操作。指令调用的实现是透明的,并包含在mentals_system.prompt文件中。
工具是一种指令。 Mentals拥有一组本机工具,可以处理消息输出,用户输入,文件处理,Python解释器,bash命令和短期内存。
询问用户示例:
# root
## use: user_input
Ask user name.
Then output: `Welcome, user_name!`
文件处理示例:
# root
## use: write_file, read_file
Write 'Hello world' to a file.
Then read and output file content.
本机工具的完整列表在文件native_tools.toml中列出。
每个指令都有自己的工作记忆 - 上下文。当退出指令并重新输入该指令时,默认情况下将保留上下文。要在退出指令时清除上下文,您可以使用## keep_context: false指令:
# meme_explain
## keep_context: false
Explain the gist of the meme in 20 words in medieval style.
Return explanation.
默认情况下,指令上下文的大小不受限制。为了限制上下文,有一个指令## max_context: number指定仅应存储最新消息的number 。旧消息将被推出上下文。当您想将最新数据保留在上下文中,以使旧数据不会影响推理链时,此功能很有用。
# python_code_generation
## input: development tasks in a list
## use: write_file
## max_context: 5
Do all development tasks in a loop: task by task.
Save the Python code you implement in the main.py file.
短期内存允许从代理活动的活动中存储中间结果,然后可以将其用于进一步的推理。在所有指令上下文中都可以访问此内存的内容。
memory工具用于存储数据。存储数据后,生成了关键字和内容的描述。在下面的示例中, meme_recall指令意识到模因,因为它以前存储在内存中。
# root
## use: memory, meme_recall
Come up with and memorize a meme.
Call meme recall.
# meme_recall
## input: nothing
What the meme was about?
控制流程包括条件,指令呼叫和循环(例如ReAct , Auto-CoT等),以自然语言充分表达。此方法可以创建直接数据流分支的semantic conditions 。例如,您可以请求代理在循环中自主玩单词链游戏或建立模棱两可的退出条件: exit the loop if you are satisfied with the result 。在这里,语言模型及其上下文决定了是继续还是停止。所有这些都是实现的,而无需在Python或任何其他编程语言中定义流逻辑。
## use: execute_bash_command, software_development, quality_assurance
...
You run in a loop of "Thought", "Action", "Observation".
At the end of the loop return with the final answer.
Use "Thought" to describe your thoughts about the task
you have been asked. Use "Action" to run one of the actions
available to you. Output action as: "Action: action name to call".
"Observation" will be the result of running those actions.
Your available actions:
- `execute_bash_command` for util purposes e.g. make directory, install packages, etc.;
- `software_development` for software development and bug fixing purposes;
- `quality_assurance` for QA testing purposes.
...
TOT背后的想法是生成多个想法来解决问题,然后评估其价值。保留和开发有价值的想法,其他想法被丢弃。
让我们以24场比赛为例。 24个拼图是一个算术难题,在该难题中,目标是找到一种操纵四个整数的方法,以使最终结果为24。首先,我们定义了创建和操纵树数据结构的指令。该模型知道树是什么,并且可以以任何格式表示,从纯文本到XML/JSON或任何自定义格式。
在此示例中,我们将使用纯文本格式:
# tree
## input: e.g. "add to node `A` child nodes `B` and `C`", "remove node `D` with all branches", etc.
## use: memory
## keep_context: false
Build/update tree structure in formatted text.
Update the tree structure within the specified action;
Memorize final tree structure.
接下来,我们需要用初始数据初始化树,让我们从根指令开始:
# root
## use: tree
Input: 4 5 8 2
Generate 8 possible next steps.
Store all steps in the tree as nodes e.g.
Node value 1: "2 + 8 = 10 (left: 8 10 14)"
Node value 2: "8 / 2 = 4 (left: 4 8 14)"
etc.
调用根指令将建议使用前两个数字计算的8个可能的下一步,并将这些步骤存储为树节点。代理商的进一步工作会导致建造一棵树,该树方便该模型可以理解和推断最终答案。
4 5 8 2
├── 4 + 5 = 9 (left: 9, 8, 2)
│ └── discard
├── 4 + 8 = 12 (left: 12, 5, 2)
│ └── discard
├── 4 + 2 = 6 (left: 6, 5, 8)
│ └── discard
├── 5 + 8 = 13 (left: 13, 4, 2)
│ └── discard
├── 5 + 2 = 7 (left: 7, 4, 8)
│ └── (7 - 4) * 8 = 24
├── 8 + 2 = 10 (left: 10, 4, 5)
│ └── discard
├── 4 * 5 = 20 (left: 20, 8, 2)
│ └── (20 - 8) * 2 = 24
└── 4 * 8 = 32 (left: 32, 5, 2)
└── discard
Based on the evaluations, we have found two successful paths to reach 24:
1. From the node "5 + 2 = 7 (left: 7, 4, 8)", we have the equation: (7 - 4) * 8 = 24.
2. From the node "4 * 5 = 20 (left: 20, 8, 2)", we have the equation: (20 - 8) * 2 = 24.
Thus, the final equations using all given numbers from the input are:
1. (5 + 2 - 4) * 8 = 24
2. (4 * 5 - 8) * 2 = 24
一个完整的示例包含在agents/tree_structure.gen中
该概念源自关于精神分析执行功能的研究,探索了中央执行官,艾伦·巴德利(Alan Baddeley),1996年。他描述了一种系统,该系统策划了认知过程和工作记忆,从而促进了从长期记忆中的检索。 LLM用作System 1 ,处理查询并执行指令,而无需固有的动机或目标设定。那么, System 2是什么?从历史见解中汲取灵感,现在通过科学镜头重新考虑:
中央主管或执行职能对于工作记忆中的控制处理至关重要。它管理任务,包括指导注意力,维护任务目标,决策和内存检索。
这引发了一种有趣的可能性:通过集成System 1和System 2来构建更复杂的代理。作为认知执行器System 1 ,LLM与中央执行System 2一起工作,该系统管理和控制LLM。这种伙伴关系构成了对AI的双重关系。