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的雙重關係。