Veja Como eu Criei Um Assistente de Consultas Processuais Com IA no N8n — Transcript
Full transcript
- 0:00In today's video, I'm going to show you
- 0:03how we can build an AI agent that looks
- 0:05up legal cases based on the case number
- 0:08by accessing a public API and helps you
- 0:10analyze them by sending you a summary
- 0:12of the case, okay? And chatting with
- 0:16you about the matters regarding that
- 0:18case. So, if this is a topic that
- 0:21interests you, stay until the end of
- 0:22the video, and I guarantee you'll like
- 0:24it. Today will be a slightly shorter
- 0:27video, but it will be a very useful one
- 0:29. For those in the legal field who have
- 0:31to deal with cases and constantly look
- 0:33up this kind of thing, you'll like the
- 0:35video and find it interesting, because
- 0:38I think it's a flow that's very simple
- 0:40but can also help you a lot in your
- 0:41day-to-day, okay? So, without further
- 0:44ado, let's get to what matters, let's
- 0:46go to the computer screen. So, alright,
- 0:48here on my screen you can see the agent
- 0:50, it's already built, okay? A very
- 0:53small agent, where it's connected to
- 0:56just one tool, but it's interesting
- 0:59because even though it's simple, it can
- 1:02be very useful, okay? Like I mentioned,
- 1:06for those who work with this daily and
- 1:08have to keep looking up cases all the
- 1:11time. And this could be a very
- 1:13interesting flow for you, okay? That
- 1:15will help you save a good amount of
- 1:18time, okay? All right? The flow of this
- 1:21agent is very simple. Basically, we'll
- 1:24start the flow with the chat trigger
- 1:26from n8n itself, okay? We'll connect
- 1:30our agent to an AI model, right? In
- 1:33this case, I'm using GPT itself, I'm
- 1:36using the 4o model, a memory, and a
- 1:39tool, an HTTP request tool, because
- 1:42we're going to query a public API, okay
- 1:45? And to retrieve this case information
- 1:49. Got it? So, before we build this
- 1:52agent step-by-step, let's take a look
- 1:54at this API so you can understand more
- 1:57or less how it works, okay? And we'll
- 2:00also perform some basic tests using
- 2:04Postman, okay? To test these requests
- 2:08to this API. Got it? So here we can
- 2:13search for DataJud, okay? It's possible
- 2:16that some of you already know this API.
- 2:20Alright? Here we can take a look, right
- 2:23, at the public API, have a read here
- 2:26to understand how it works. The DataJud
- 2:29public API is a powerful tool that
- 2:31offers public access to metadata from
- 2:33legal cases throughout Brazil. The data
- 2:36made available through the API comes
- 2:38from the national judiciary database,
- 2:40Datajud. They strictly adhere to the
- 2:43criteria stipulated by ordinance
- 2:45Tananã Tananã, while simultaneously
- 2:47ensuring the protection of confidential
- 2:49cases and the information of the
- 2:51parties involved. So, basically, it
- 2:54will provide us with case data
- 2:55throughout the entire Brazilian
- 2:57territory, right? You were able to
- 2:59understand this part, right? I hope so.
- 3:03We can access this link here, where it
- 3:07will take us directly to the public API
- 3:11documentation, okay? So, we can close
- 3:15that other tab, and here it says I
- 3:17think more or less the same thing we
- 3:19already read, okay? Through this API,
- 3:23developers have access to information
- 3:25on case headers and movements related
- 3:27to judicial proceedings in all
- 3:29instances of the Brazilian judiciary.
- 3:32All good? Here we have some terms of
- 3:35use, which I recommend you read, but if
- 3:37you just want to run some small tests,
- 3:39that's fine, I don't think there's any
- 3:42problem. And access. Here we will
- 3:47understand how we are going to hit the
- 3:48endpoints of this API, okay? How will
- 3:51we be able to access it to successfully
- 3:53return the data we want? The Datajud
- 3:57public API, the tool that provides
- 3:59public access. The same thing we
- 4:01already read. API key here.
- 4:04Authentication for the Datajud public
- 4:06API is performed using a public key,
- 4:08generated and provided by the DPJ CNJ.
- 4:12The current key is always accessible in
- 4:14this section of the Wiki. So, basically
- 4:16, we will use this key here. It is a
- 4:19public key that anyone can come here
- 4:22and grab, okay? So, basically, how are
- 4:25we going to do it, to use this key,
- 4:28okay? We will pass an authorization key
- 4:33in the headers of our request, and the
- 4:35value will be "API Key" followed by the
- 4:38key, okay? So, basically, this is how
- 4:43we will hit our requests. To start, we
- 4:47can already configure these headers in
- 4:49the request we are going to make. I
- 4:52have Postman open here already, and I
- 4:55have two endpoints separated here. No,
- 4:58two endpoints, it's the same place we
- 4:59are going to hit. We are just going to
- 5:00change the method. In one we will send
- 5:02the body and in the other we won't,
- 5:03okay? This first one here, what is this
- 5:07GET for? We are just going to hit the
- 5:10API, okay? In a specific endpoint, and
- 5:13it will return some cases for us. So
- 5:15let's run this test here, okay? But
- 5:18first we need to know the URL, right? I
- 5:22forgot to show you that. We can go here
- 5:26to endpoints, and what we'll use is
- 5:28superior courts and superior court of
- 5:30justice, okay? STJ. But you're not
- 5:35going to click here, okay? We're going
- 5:38to copy this link, all right? We can go
- 5:42back here to Postman and we can paste
- 5:45it here in the URL, okay? And here in
- 5:48headers, we'll pass an authorization
- 5:51and we can go back here to access and
- 5:54copy all of this. Got it? We pass it
- 5:59here in value and we can send this
- 6:01request now. You saw that the status
- 6:04code 200 returned everything correctly.
- 6:06It will return a ton of lines here,
- 6:08okay? About how many? 1,000 lines. I
- 6:12thought more lines would come, but
- 6:14that's fine. If we search by case
- 6:16number, we'll be able to see that we
- 6:19can find 10 cases here, okay? 10
- 6:22different case numbers, and each case
- 6:25has some specific information. Uh, for
- 6:28example, we have the class, we have
- 6:31this class name which, if I'm not
- 6:34mistaken, is the description of the
- 6:36case class, uh, format, the court, the
- 6:39last update date, the movements of this
- 6:42case, okay? So here we can check all of
- 6:45that. Any judge, all right? Here it's
- 6:53basically that, there are movements and
- 6:55also the subjects of the case, okay? So
- 6:57we will have access to all this data.
- 7:00Why am I hitting this endpoint?
- 7:01Basically, I just hit it because I want
- 7:04to get a specific case, a number of a
- 7:06specific case so we can test, okay? So
- 7:08I'll take this case right here, got it?
- 7:11And what we're going to do is hit this
- 7:13endpoint by sending a body, okay? And
- 7:15in this body, we'll pass the case
- 7:17number. By passing the case number, it
- 7:19will return to us only the data for
- 7:21that specific case. And that is what we
- 7:23want. Our chatbot works like this.
- 7:27Basically, we'll have access to a case
- 7:29number and we want to know its
- 7:30information. We want a detailed summary
- 7:34of this case. So we will send the case
- 7:37number to our agent so it can query the
- 7:39API. Then it will return the response.
- 7:43The response will basically have a
- 7:44summary, a small analysis of this case,
- 7:46okay? Got it? So we can copy this URL
- 7:50here, okay? We can go over to the
- 7:52headers here, it will be the same thing
- 7:55. Authorization. And here we can copy
- 7:59this as well, okay? All good? Now here
- 8:03in body we will select raw, okay? This
- 8:05is a JSON. And we can go back here. If
- 8:10we take a look at these examples. we
- 8:12can see here, okay? Uh, it even
- 8:15mentions here, it recommends Postman.
- 8:18Ta-da, we're going to hit it with the
- 8:20post method, right? We are sending a
- 8:23body. And basically here we will use
- 8:27this example body, okay? This body that
- 8:30they left as an example here. So, we
- 8:32can copy this and we can paste it right
- 8:34here, okay? The only difference is that
- 8:37we will have to replace this case
- 8:39number that is already in the example
- 8:41and put the one we just got, okay? So
- 8:44I'm going to grab that. If you have any
- 8:47number, if you have access to any case
- 8:49number there, feel free to test it, put
- 8:51it in and send the request, okay? Got
- 8:54it? It has to be in this format. So
- 8:57here we can hit send and it's OK,
- 8:59everything is just right. Here you will
- 9:02see that it returns many fewer lines,
- 9:04right? about a hundred and something.
- 9:07So it's just the information for this
- 9:09specific case, alright? So, with the
- 9:12API tests done via Postman, we can go
- 9:14to n8n and start to understand how this
- 9:17flow works, and we'll also build it
- 9:19from scratch so you understand it
- 9:21step-by-step, okay? So I'll minimize my
- 9:25Postman here, alright? Here too, if you
- 9:28want, you can take a look at the other
- 9:30examples, okay? There are other ways
- 9:32for you to query the API, there's
- 9:34something else here, a data glossary,
- 9:35okay? So it has the data that will
- 9:38return in the response of the request
- 9:41we sent, okay? So, court, case number,
- 9:44filing date, degree, secrecy level, uh,
- 9:47class, name, oh, the class name I had
- 9:50mentioned to you, description of the
- 9:52procedural class. So, it explains each
- 9:56element here, okay, of the response you
- 9:59might receive. final. There are a few
- 10:03more little things here. Feel free to
- 10:05read through all this documentation
- 10:07here so you can understand how it works
- 10:08, okay? Eh, so, with all that said,
- 10:10with that explained, let's go to n8n,
- 10:12okay? Let's go back there, because
- 10:14that's where the magic really happens.
- 10:16So, very simple. We have a chat trigger
- 10:19, right? And here we have our agent
- 10:23itself, where we will pass a small
- 10:26prompt, okay? Explaining to it what it
- 10:29has to do. We pass the chat input, it
- 10:31will consult the tool, perform the
- 10:34query, and return the answer to us,
- 10:36okay? Basically, if we were to build
- 10:40this from scratch, we would pick a
- 10:43trigger. Where is it? We can't. Let me
- 10:50do the following, let me delete this.
- 10:55And here we will select a chat on chat
- 10:57message, okay? It's no secret, this
- 11:00isn't news to anyone anymore, right? So
- 11:04you can select it, we can connect it to
- 11:06our agent, okay? But in this case, I
- 11:08will pull it down here. Advanced AI. AI
- 11:13agent. Ah, where is it? It pulled it up
- 11:18there, but that's no problem. Here I
- 11:21will copy the prompt, okay? Just to
- 11:24avoid wasting time, but I will read it
- 11:26with you so you understand. I will pass
- 11:29a system message here just explaining
- 11:31that it is a very useful and
- 11:32intelligent legal agent, okay? Basic
- 11:35stuff here. The main prompt we can
- 11:39actually define here as defined below,
- 11:44okay? Expression. We can open this
- 11:48little screen here and copy the prompt.
- 11:50You should talk to the user about cases
- 11:52; when the user asks you to check a
- 11:54case, you must identify the provided
- 11:55number and consult the Tool, which we
- 11:57have named for this Tool. retrieve
- 11:59information about the case in question.
- 12:02If the user asks for a check but didn't
- 12:04provide the number, ask them to do so
- 12:07so you can perform the search correctly
- 12:09. When you find the case, perform an
- 12:12analysis of the content the API returns
- 12:14and synthesize all the content of the
- 12:16case in question. Use a friendly, nice
- 12:19tone, with a touch of humor, okay? You
- 12:21can define whatever you want here. And
- 12:23next, for the user input, you pass a
- 12:25JSON chat input here, got it? So that
- 12:28whatever you type in the previous
- 12:30trigger module, it will send over here.
- 12:34All good? There's no secret here,
- 12:36there's nothing else to do, okay?
- 12:38Basically, it's just the prompt. From
- 12:41here we can pull our model, okay? And
- 12:44here we can pull the OpenAI chat model
- 12:47or whatever you want to use, okay? You
- 12:50can set up your account with your
- 12:54correct credentials. Here I will use
- 13:00the 4o. I'm not sure if this is the new
- 13:07version of N8n, but that's fine. Here
- 13:10it gives a huge list and we can't
- 13:12search, it closes, but that's fine.
- 13:16Configure the model you want to use
- 13:18here, and the memory, okay? Window
- 13:21buffer memory is quite traditional,
- 13:24simple to configure. And our tool,
- 13:28finally, right, so you can see that
- 13:31it's a ridiculously easy agent to
- 13:34configure. It's an HTTP request tool.
- 13:38So here we can provide a description. I
- 13:41have already written the description
- 13:42for this tool. Copy this here, okay?
- 13:47Great. Uh, yeah. Great. I'm just going
- 13:55to quickly copy this URL, okay? So
- 13:58let's configure it here. The method we
- 14:02are going to use will be a POST. Got it
- 14:04? For the URL, we provide the correct
- 14:08URL we used a moment ago in Postman.
- 14:13Here we can select sender, okay? You
- 14:16can activate this here. Uh, it can be
- 14:19in these fields below. We will type
- 14:23authorization, okay? Here we can select
- 14:28using field below. And here we provide
- 14:31the value, okay? Let me go back here to
- 14:34Postman in headers. Let's copy this
- 14:37here. Go back here. Provide the value.
- 14:40Remembering to copy this API that is in
- 14:43front of the key, okay? Send. Here I
- 14:48will, we will use a JSON, okay? So, use
- 14:51JSON below. And here we will use this
- 14:55same body that we used here, okay? With
- 15:01a single difference here in the process
- 15:04number, what are we going to use? If
- 15:08you look here at the top, if I'm not
- 15:11mistaken, it's placeholder. For any
- 15:15part of the request to be filled by the
- 15:17model. So, we can use this syntax here
- 15:21inside braces where we will put a like
- 15:26it's a variable name, okay? Here it's
- 15:30placeholder. So we will put here the
- 15:32process number, okay? Process number.
- 15:39I'll even copy this so there are no
- 15:41mistakes. And down here we will put in
- 15:45placeholder definitions, right? We will
- 15:48set a placeholder. We can put its name,
- 15:50okay? Which is the same one we put here
- 15:52between this pair of braces. And we
- 15:54will provide a description for this
- 15:56placeholder. I will again copy this
- 15:58description that I've already written
- 16:01here. So you provide a little
- 16:06description for this placeholder so we
- 16:08understand what it needs to fill in
- 16:10there, okay? So it's the process number
- 16:13you wish to consult, which you can set
- 16:15as a string, okay? And that's it. Now
- 16:19on to the testing phase. Very simple,
- 16:21right? So let's open a chat here and
- 16:24grab a case with a different number.
- 16:28Let's pick, I don't know, seven. Uh,
- 16:35first let's say hello, right, to test
- 16:38its response. Oh, hello. How can I help
- 16:44you today? If you need any case
- 16:46consultation or have questions about a
- 16:48legal matter, I'm here to help. So, I'd
- 16:51like you to summarize the following
- 16:57case. We passed it a different case.
- 17:02Let's see if it works. Apparently it
- 17:05worked. The API returned a response
- 17:09here. Done. Sure. Let's take a look.
- 17:15This is an ordinary appeal in habeas
- 17:17corpus registered at the STJ. It is
- 17:21completely electronic because we are,
- 17:24right? The action was filed on November
- 17:2711, 2024. Responsible body, office of
- 17:30Minister Sebastião Reis Júnior.
- 17:33Alright. Main case movements.
- 17:36Distribution occurred, it was done by
- 17:38lottery. Conclusion for decision. Right
- 17:41after that, the case was set for
- 17:42decision on the same day. Issuance of
- 17:44documents and petitions. There were
- 17:48several, including merit opinions from
- 17:50the Public Prosecutor's Office and
- 17:52other important petitions. Alright? So
- 17:55it gave the main movements of this case
- 17:57here, right? What was going on?
- 18:01Subjects involved, drug trafficking and
- 18:04related conduct, and provisional
- 18:06release. So here was a very simple
- 18:08little response, right? We are going to
- 18:10check other cases here to test. And
- 18:14there is a judicial journey with many
- 18:16emotions and documents flying
- 18:17everywhere, virtually, of course. If
- 18:19you need any more details or have other
- 18:21questions, I am here. So, as you could
- 18:24see, it responded very well, right?
- 18:25Basically, it synthesized this case
- 18:28that the API returned to it. And let's
- 18:31test two more cases here, okay? Just so
- 18:33we don't have any doubts or anything
- 18:38left. Take this second one here. Copy
- 18:41this number now. This one. Let's see.
- 18:52It hit the tool. We can verify the logs
- 18:55. The API returned the response. I
- 18:59think this one might be a little bigger
- 19:00than the other. or not? Uh,
- 19:04distribution, it was distributed on
- 19:07December 19, 2024. On the same day, it
- 19:11was forwarded for decision. Alright.
- 19:15Alright, done. This case is supervised
- 19:21by the presidency of the STJ and its
- 19:24last update was quite recent, March 10,
- 19:262025. It seems our dear 13th salary is
- 19:30causing quite a stir in the courts. If
- 19:32you need more information and have any
- 19:33questions, I will be happy to help.
- 19:36Alright? Now, finally, let's consult
- 19:38one more case, right, so we can see the
- 19:40response it will return. Let's pick
- 19:42five. Let's wait. Pretty fast, right?
- 19:59His, his answer. Great. And this is an
- 20:06interlocutory appeal of a special
- 20:07appeal. It is entirely electronic,
- 20:09great for saving some trees. Uh, main
- 20:12updates. Distribution, September 10,
- 20:15'24, remittance for redistribution. Ah,
- 20:19receipts were recorded on the 3rd,
- 20:21September 23, 2024. Conclusion for
- 20:25decision. Matters involved. Violation
- 20:27of administrative principles. Burden of
- 20:30proof. Who has the job of proving what?
- 20:33Uh, I don't know much about law, okay?
- 20:35I'm just reading here. So, for those
- 20:37who understand, cool? Ah, obligation to
- 20:40do, or not to do. Someone being ordered
- 20:42to take actions or inaction. Damage to
- 20:46the treasury and illicit enrichment.
- 20:49This touches the government's wallet
- 20:51and perhaps others 'too. Great.
- 20:54Minister Afrânio Vilela. This case is
- 20:59full of discussions about
- 21:01administrative principles,
- 21:03responsibility, and even some complex
- 21:06financial issues. Cool, right? So, as
- 21:10you could see, it, it responds very
- 21:13well, okay? So, if you need to consult
- 21:16cases all the time or you, I don't know
- 21:18, saw a case but don't remember exactly
- 21:20what it's about, if you put it here,
- 21:22you'll get a quick summary of this case
- 21:24. You can ask it to summarize even more
- 21:27or provide even more details. So, all
- 21:30of this you can specify in your prompt,
- 21:32okay? Any specific little detail or
- 21:34some way of responding or let's see
- 21:37some response structure that you want
- 21:40the agent to use, you can send it to us
- 21:43, okay, in the prompt itself and it
- 21:45will know how to answer you in the best
- 21:48possible way for you, okay? So, if you
- 21:51are in the field, if you are a lawyer
- 21:53or whatever it is in the legal area, uh
- 21:55, you understand more about the subject
- 21:57, you can specify all of that in your
- 21:59prompt, okay? The way you want it to
- 22:01respond. You can mix this with perhaps
- 22:04a few more tools. If you want to use
- 22:07some knowledge base for your agent to
- 22:09use, you can also configure that type
- 22:11of flow. We can configure this on
- 22:16Telegram and keep the scenario active
- 22:18so you have an agent always available
- 22:21to you on Telegram, where you can
- 22:23consult cases at any time of the day,
- 22:26from your own cell phone, okay? So
- 22:29there are many use cases, many
- 22:31scenarios, okay? That you can use this
- 22:33in the best way. That's what's
- 22:35important, right? After all, these
- 22:37agents, these flows serve to improve
- 22:39our work, right? Ah, so alright. Yeah,
- 22:43that was what I wanted to show in this
- 22:44video. It's an extremely simple
- 22:46workflow, okay? Anyone can come in and
- 22:49set this up in a little over 5 minutes,
- 22:51I don't know. So that's it, take a look
- 22:54at the documentation, ah, create this
- 22:57flow yourself, put it into practice,
- 22:59right? Especially if you're in the
- 23:01field, put it into practice. Maybe it
- 23:03will help you, maybe not. Eh, it
- 23:05depends on what you do in your work,
- 23:08right? If you work directly with this,
- 23:10it might help you. Otherwise, there are
- 23:12several other workflows we can build
- 23:14focused on the legal field, right? And
- 23:18if you guys really like this type of
- 23:20content or if there are any lawyers out
- 23:22there or people in the legal field who
- 23:24like my videos, leave a comment. I can
- 23:27bring other workflows, okay? Related to
- 23:30this area. Eh, and there is an infinity
- 23:33of possibilities, okay, that we can, eh
- 23:36, build focused on law or any other
- 23:39area, okay? Leave suggestions down
- 23:42below as well, okay? Your opinion is
- 23:44always very welcome, your comment, your
- 23:45feedback, okay? It helps a lot, it
- 23:47gives new ideas. And that's it, this
- 23:50video is coming to an end. Leave your
- 23:52like. If you liked the video, subscribe
- 23:54to the channel, if you're not
- 23:55subscribed, turn on notifications.
- 23:57Every week there's a new video, okay?
- 23:58I'm looking to increase the frequency
- 24:01of videos to, you know, bring more
- 24:02topics to you, right? The channel is a
- 24:05bit slow, but there are some projects
- 24:08underway and good things are coming in
- 24:10the future, okay? So, that was what I
- 24:13had for today's video. Deal? So, I'll
- 24:16see you in the next one.
About this transcript
This page contains the full transcript of Veja Como eu Criei Um Assistente de Consultas Processuais Com IA no N8n by Vitor Pasqualotto, generated from the public captions YouTube serves with the video. The transcript has 3,588 words across 510 segments, with the original timestamps preserved so you can click any line to jump to that moment in the embedded player.
What you can do with it
Use the transcript to take notes, quote the speaker, build a study guide, generate a summary with ChatGPT or Claude via the YouTube Summary tool, or export it as a timed subtitle file with YouTube to SRT. You can also re-open it in the transcriber to translate the transcript into 100+ languages.
Free YouTube transcript tool
YouTube2Text is a free YouTube transcript generator — no signup, no daily limit. Paste any YouTube link and get the full transcript instantly, with timestamps, click-to-jump, translation to 100+ languages, AI prompts for ChatGPT, Claude, and Gemini, and exports to TXT, SRT, VTT, or Markdown.