📱

Get Our Mobile App

Take your business learning on the go!

Download on the App StoreGet it on Google Play

Промпт-инжиниринг нового уровня | Создаем AI-агента в n8n, который проводит итеративные дебаты.

ALEKSEI ULIANOV | SPRUT- Ai36:15

Transcription

Hello, friends. Today, a certified physical education instructor, in my person, will speak to you about a scientific approach in prompt engineering. But I ask you to give me a chance to watch the video to the end. And in this video, I will tell you how you can increase the quality of responses by 8% and reduce the cost of API requests by 60% in your automations using prompts. And all this thanks to the research of two Chinese specialists. Uh, based on which I built an AI agent for my assistant Sprut. Uh, here it is, it's called the analyzer. Here is its modest appearance, this is how it looks. And I will definitely share this research and this automation template with you on my Telegram channel, the link to which will be at the bottom. And now, let me briefly tell you about the research and how it works. The essence of this research is that these two Chinese specialists came up with a method that allows creating a debate of several agents directly within the prompt, well, in this case, four, who, uh, each have their own position, their own opinion, and debate among themselves. Well, and in dispute, as we all know, truth is born. That is, after, let's say, playing out this scenario in the prompt, after the LLM's response, a very cool, structured, reasoned answer is obtained, which allows us to save tokens. That is, because all this happens in just one request to our LLM, to our little model. That is, all this happens, all this activity happens in the prompt. This is a cool way that allows you to get truly awesome answers. I've tested this and will definitely show you everything now. Well, first of all, I want to say that I very rarely see information about how people create prompts for their agents, for their automations. And in this video, I will show you how I personally create all instructions for my automations, for my agents. Let me show you using the example of this research. So, look, we all use certain, you know, models, right? Our models are either GPT, as here, and these, you know, models have projects. As well as Perplexity, which I mainly use now. I like it more now. I'll tell you why. It also has the ability to create projects, but here they are called spaces. And here, in this space, you can fill it with information, you know, this space. And based on this information, from this context, we get all the information we need. That is, uh, the model itself will analyze everything that we have loaded into it, and based on, uh, this context, it will give us, uh, cool answers, including prompts. How to fill the context? I call context either some research, or JSON files of automation for which you want to write a prompt. Yes, now the cloud version has the ability to use an agent that independently generates a workflow for you. But, uh, beginners find it quite difficult to understand the logic of work, and these spaces with these workflows can help you, you know, outline the logic of this automation's work and write the agent prompt that you want. That is, you can upload here. So, in this case, what do I have uploaded? Let's see. Two files. This is a PDF with the research and the analyzer, which is the JSON that I assembled based on this research. Here. And then, based on this research and this automation, I can somehow analyze and, you know, ask the model for all the information I need. In Perplexity space, there is an option to choose the model we will communicate with. In GPT, there isn't, there are only, you know, the models from OpenAI, nothing else. So, here I like that I can choose who I want to have a dialogue with. Here. And in this case, Gemini works more than adequately for me. Here. And then you can ask the model your questions based on the loaded information. Well, in this case, I was asking about this research. Give a brief formulation of introspection. That is, it is a process of self-observation when a person or system analyzes their own thoughts, reasoning, and conclusions. That is, in the context of artificial intelligence and most language models, introspection means the system's ability to analyze, critically evaluate its own thought process to improve the final result. That is, how? Well, by creating those very agents within the prompt itself, who argue among themselves, uh, well, and, you know, somehow they come to some decision. Let's make a request to our space, and let it extract the very prompt code from this wonderful research for us. Extract the very prompt code from the research for me. Here. Well, and in this case, as you can see, our space accesses the PDF file that we uploaded with the research and extracts information about the code from it. By the way, the entire logic is very similar to, you know, the work of NTEN automation, where we ask an agent to look somewhere, to see something. It's all the same. And here, it shows us, you know, the logic of reasoning, what this prompt looks like, what is its core, and so on. Well, in this case, we see that, you know, we have two debaters, right, so to speak, two roles. These are agent A and agent B. And they do the initial analysis, some result, right, of this analysis, debates, 10 rounds maximum. That is, well, everything is described here, at which step the model should think as an agent, then, you know. Well, in short, this is the whole essence of this, you know, code, prompt code, it is indicated here. Here. But we will return to the method of how I obtain the prompt for the agent from all this. In this case, I initially always create a prompt for the space, either for Perplexity, or it will be, you know, a project for GPT. That is, I first form everything, uh, precisely there, because testing all this information, how the agent will respond, is better, well, easier, right here, either in the Perplexity model, or in the model from OpenAI, and only then I transfer all this into automation. So, having received this code, right, from the research, how it works, right, I understood that I need to create not two, you know, uh, debater agents, well, those very models that will enter into dialogue and determine, you know, the correctness of each of their judgments. But I need four of them. Here, I thought that I need four. Uh, uh, here are the debate parameters, the rounds are reduced to five. After which, based on this research, I asked, you know, our space to create a prompt for itself, which, upon my request, will automatically write such a prompt code. Here. That is, what I needed to do was to automate the essence of the research. That is, the research was with such an idea, and I needed to implement and automate this idea so that I wouldn't have to manually insert, you know, who among the agents will be, I don't know, a cynologist, and who will be a psychologist, and so on. But I needed the model itself to do it. And for itself, for itself, this space wrote me a prompt. Let me show it to you. Here in the settings, there is an instruction for responses, right, that very prompt. So, what is the essence, that you, right, are an expert in reasoning methodology based on interactive debates. This is the very essence of the research. When I ask you, conduct an interactive analysis of a hypothesis, your task is to take my hypothesis, select three to four relevant experts with different but significant points of view, and generate a complete structured prompt for me using the template provided below. And the template. The template is precisely that, you know, the response from this agent that I want to receive. Here. So, ready prompt? Role, that is, your role is to act as a structured code and so on. Uh, you know, all the necessary phases, how, you know, the models should look, agents, rather, agent A, agent B, agent C, agent D. That is, as I said, I needed four, so that, you know, this prompt code would work as coolly as possible. And three rounds, right, here in this case, three rounds. In the automation that I will share with you, also in the Telegram channel, download it, there are five rounds. So it works even more interestingly. Uh, cycle, phase one, cycle of public-expert discussions. Uh, in this case, in the first round, the agents present their basic positions, that is, the basic positions of agent A, B, C, and D. Each of them, you know, determines some information based on their position. Here. And then comes criticism, right? In-depth criticism. That is, someone, you know, agent B should criticize agent A, agent C should criticize agent B, and so on, right? Because it is in dispute, right, that the very truth is born. That is, essentially, we have obtained that very prompt, within which the debates and discussions are already embedded, and which, in fact, help us get a more accurate answer. Plus, it is also more economical. Here, in general, you know, I can ask it now to execute this prompt in order to get a very cool answer. Let's do that. Execute this prompt. It's written, but not like that, the agent will understand. Here. Then comes the execution of the response of our space to this prompt. That is, uh, what was my task? First, to practically apply this research in my agent. This space helps me write prompts for this agent, which has this research in its context. Uh, well, and then, in fact, I can just take, you know, the prompt of this space and transfer this prompt to my agent on N1, which I did. That is, in your case, right, while, you know, we are searching, while the response is coming, I can, as an example, further clarify. In your case, you can upload to, you know, the sources of this space any information, any, you know, your wishes, right, that is, what tools you plan to connect, how you see the agent working. Perhaps you also have some documents that are necessary for writing a prompt agent. And subsequently, this space will analyze all these documents and create for this agent, knowing those very sources, knowing those very tools. It, uh, this space will create a very cool prompt for you, which you can also copy and paste into your agent on N. That's all. Here. So, based on your request, I have performed a simulation of interactive analysis according to the given methodology. Below are the results of the prompt code generated in accordance with the structure. So, uh, analysis and, well, at the end, it also gives a matrix of social risks and opportunities, right? That is, well, it was a quite complex request here. You can make it much simpler, like, is there life on Mars, right, and so on, and the answer will be more understandable. Here, the answer is what you would not get by writing a regular request to a regular LLM. Here it is powerful, very detailed, and an answer that covers all possible problems, right? That is, if we take, let's try it, take this request and paste it into an LLM, we will get a completely different answer. Even if it's a thinking model. Well, it also brings in philosophy here, right, in this way, it is capable of self-adjustment and gives it full free will. Well, so here this answer to the request will be much drier and sometimes incorrect. Here, I've checked, I've looked, so the prompt code gives a much more interesting and complete answer. Here, uh, so, what I wanted. That is, it's clear that the space works like the same GPT. And if I need something, right, from complex answers, hypotheses, and so on, to get a cool answer, I can turn to this space. But we don't take the easy way, right? That is, I want all this to be in my Telegram. I want all this to work through my assistant Sprut. Thus, I had the idea to create such an automation. And I succeeded, it took me literally 2 hours to create it. That is, my Sprut now has such an agent. I called it the analyzer. Perhaps I could have come up with another name, more logical, but it's easier for me, well, when I communicate with my Sprut, it's easier for me to say: "Ask the analyzer, you know, some question, right, ask him some question, check a certain hypothesis." Here. And this is how the automation itself looks. The automation is quite simple, but effective. There are three heads, that is, three AIs. They are connected sequentially. The first agent has the prompt, that very prompt that is present in the space, right, that we created in the space, based on the research. Here, so all the necessary information is embedded here, from the roles to how, you know, the agents participate in the debates. Here they are visible, there are four of them. And, here is the setting of the debate parameters. Here you can see that there are five rounds. Here. So, everything is described here. Then comes the agent that executes this prompt. That is, it's an agent that conducts these debates according to this prompt. Well, it's also a fairly simple prompt. It's indicated that, you know, how it should do it. Well, and the last agent is the agent that summarizes the previous answer so that it is more concise, understandable, and not so large. Further, what happens with these answers? Well, first of all, right, of course, we, you know, use the subwflow trigger, which is launched upon request from our main assistant Sprut, when I need to check some hypothesis or something else, right, ask some question, I ask him: "Clarify with the analyzer such and such a question." So, it goes here to this node. Well, again, the node launches two. The first is a technical message, that the analyzer is starting work. And the second node adds the phrase "Make a prompt" to the request. This is so that I don't have to additionally tell Sprut that a prompt needs to be made on such and such a topic. I just tell him the topic. Here. Then, as I said, the prompt is made, the agent responds to it, and everything is recorded in the result. And all this information goes into a Google Sheet, which is here, upon request, prompt, debate, and result go into the corresponding columns. Here, it is highlighted in red because there are two ways to create messages. Either I write here, you know, I enter it, or it asks me, you know, Sprut asks it a question. Here, accordingly, there are two options for this message to arrive. Here. And all this goes, as I said, to a Google Sheet. The Google Sheet looks like this. That is, the request column, the prompt column, the debate column, and the result. So, everything goes precisely here. Ah, yes, by the way, it's the same table that I use in all my agents. That is, I just create additional tabs. Here's the analyzer tab. Here it was added recently, as well as this agent. Here. So, all the answers of each agent plus the request are saved here. This is very convenient when you want to read more, so to speak, clearly. Well, sometimes on the phone through Telegram it's not very convenient. So I'll go from the computer here, I'll zoom in a bit and start looking, you know, how this logic was implemented. Well, in this agent, in each of the agents. Here. Well, I guess we can do a test and check how it works. So, let's ask it a question right here, by changing this request, just put a new one. Capable in this way. Is it capable of destroying humanity in the future if its goals diverge from human interests? Here, save. And when we click on test here, launch workflow, this message will go through all these nodes and to the output. If you, you know, well, this automation, again, I'll say, will be in the Telegram channel. The link will be at the bottom in the description. If you want to set up this agent for yourself and it won't work as a sub-agent, you can replace this node with a chat or Telegram node. Here. And communicate with it differently. The only thing you'll probably need to change is something about saving to the table, if the path changes. Here. Let's launch, you know, our test. So, our workflow has launched. Here, a technical message has arrived. The analyzer is preparing a response. Here, accordingly, the request with "Make a prompt" has passed here. Jon Query - this is highlighted in red because it will work when Sprut himself asks questions. Here, the first agent has worked and passed its response, you know, its prompt, already written, for a specific request, it passed, you know, its request to the next agent. Now the next agent is already responding to this specific prompt code, which is written according to the research, and is preparing its response. By the way, while all this is happening, while this automation is being executed, I want to say that initially I added here, you see, there are two threads, so to speak, leading to this node. Initially, there was just a 4.1 model here, and then when I started playing around, looking at the answers, I can confidently say that the 4.1 model with this prompt, which is written based on the research, works very coolly, and the answers are practically no different from the 4A1 model. That is, 4A1 mini, it is, so to speak, a less intelligent model, right? But it works with this prompt as if it were thinking, right? That is, this is what is achieved by this prompt, a cool answer even from quite weak models, which do not give a particularly broad, deep answer. Here, truly cool results are obtained. And I think that with such a prompt, even weaker, cheaper models can be chosen and normal answers can be obtained. Thus, we simply save. We don't just save tokens on multiple requests, because such an answer can only be obtained by communicating with the model, you know, by making multiple requests. First, we make this model smarter, because it reasons directly within this prompt. Plus, we save tokens. First, because the model eats less in terms of money, so to speak, costs less. Well, and the requests, well, I have more requests here, three, because I want to get such answers, and I want to assemble this prompt, and respond to it, plus summarize it. Therefore, as it were, here, for the answer, there is a small saving in tokens, but in terms of the quality of the answer, 100%, right. Here, so, everything has worked out. Here, look, I definitely insert this code node. So, pay attention that the first, you know, our response goes separately, a message goes. And from the subsequent, you know, from the very last one, there is also an additional message. That is, it sends me two messages. And each of these, each branch has this code node. What it does is it removes all the unnecessary things that Telegram doesn't allow, because, as a rule, with such a prompt, the answer is quite large, and Telegram simply cannot, well, Telegram cannot normally accept it. That is, it always complained. This code is cool, I wrote it a long time ago, and it cuts off all the necessary things. Here you see what it does? That is, it escapes everything. Everything, in short, it makes the answer perfectly suitable for Telegram. Here. Plus, what else does it do? It splits a large message. As you can see here, there are three items, you see, passing. That is, it splits a large message, the agent's response, into three items that Telegram allows, because there is a certain, you know, 4,000 characters. Here it splits them, in short. Here. And each of these answers is recorded in, uh, in, so, yes, Google Sheets. Well, let's first look at what. Yes, you see, four messages have arrived, as here in Telegram. The first message, which is the response to the prompt, has been split into three, because it is quite large. Well, here you can observe the iterations by experts, as I already said, there are five iterations here. Here are four and five. And each with its own reasoning, with its own, you know, steps, so to speak, where criticism occurs, where they agree with something, summarize, and so on. That is, and this is how coolly it all goes here. Well, and, accordingly, the last message is a summary. Here. And it is added to the table. Let's refer to it and the last answer. Here is this last answer. Is it capable of destroying humanity in the future if its goals diverge and so on. Yes, let me remove myself from here. Like this. And what do we see here? That is, it wrote the prompt here, right, where it arranged everything necessary, what roles, what agents, and so on. Here it immediately selected agents for us. The first is an artificial intelligence expert. His focus is on technical capabilities and development risks. And the second agent is an ethical philosopher, and his focus is on the ethical aspects of human interaction. The third is a sociologist-analyst, social consequences of AI implementation and a political strategist. His focus is already on political management risks of AI regulation. And then it goes like this, they should formulate their position, then consensus, find contradictions, well, everything, everything, everything according to this research, according to this prompt. And here we see this answer, right, if we do it like this. And here the iterations begin, right, that is, the AI expert indicates that technically it has the potential to lead to catastrophic scenarios. These are its goals will radically diverge from human interests, especially in the absence of reliable control mechanisms and limitations, and so on. Uh, then, look, right, the expert on ethical intelligence critically notes that the position of the ethical philosopher is overly optimistic. That is, in this case, here you can see their interaction, right, and their debates. Well, and subsequently, after going through these iterations, they converge in the final analysis and, you know, further write a matrix of social risks and opportunities. In this case, the matrix of social risks and opportunities, since Telegram does not allow the table that I want, the prompt is set up so that it should respond in text. Well, and thus, everything is clear. That is, here is the stress scenario, stress scenario two, stress scenario three. That is, again, we get all the information. Here. Well, and, accordingly, the next. Well, it didn't turn out to be very short, but a full, complete description, more concentrated, right? Well, and it's written in a more, so to speak, understandable format. That is, the danger that artificial intelligence in the future is capable of destroying humanity if its goals do not coincide with human interests is realistic, and so on. That is, here it, uh, does not highlight its answer in this answer all the agents that participated in the debates, but simply a structured, complete answer. This is how, you know, this automation works. Be sure to get it on Telegram, in my Telegram channel. It works quite reliably. I've already, I don't know, been playing with it for a day. I'm getting cool answers. Well, let's just for the sake of interest, right, if we take the same request, right, like this, we'll take it and send it to our Sprut, right, the agent that works just on GPT 41, right, we'll paste it like this, it's preparing an answer. That is, just to compare, right, the answers that 41 generates with the help of this prompt, and just the answer of GPT 41. Look, the question is whether artificial intelligence in the future is capable of destroying humanity if its goals diverge from human interests is a subject of active discussion among scientists, philosophers, etc. Theoretically, if AI will have high autonomy and power, its goals will conflict with human interests. Blah blah blah blah blah. If you want, I can, in short, here, here's the difference, right, here are two small sentences, right, and here is a whole reasoned conclusion that we get with the help of this automation, this superprompt, so to speak, right, with exactly the same model. And, uh, therefore, yes, take it, use it. If you have any questions, please ask. I'm interested to hear your opinion about this automation. It's very interesting to think, maybe you'll write back with me on Telegram about how this automation can be improved and turned into something. Because there are ideas, but I want to, so to speak, find something very cool, awesome, where it can be applied, that is, maximally, maximally, you know, cool and with a result, right, that's important. Here. Therefore, friends, all the best, cool automations. Learn to write prompts. This is a very promising topic. I hope this video was interesting for you. You can thank me by subscribing to the channel. Be sure to ask questions and give likes if you want. That's all, friends, bye.