Automate Your Workflow: Build a Content Analysis AI Agent

In this tutorial, the presenter walks through creating a Python-based AI content‑analysis agent powered by Google Gemini 2.5. The video begins by distinguishing standard AI (a smart calculator) from an AI agent (a digital assistant with a defined job description). It then details the practical steps to obtain a Gemini API key, store it securely as an environment variable, and set up a project folder with a virtual environment. Required libraries (Google GenAI and Pydantic) are installed, and a class‑based architecture is introduced. A Pydantic model defines a strict JSON schema for the agent’s output: summary, sentiment, sentiment score, main topics, takeaways, and suggested tags. The presenter configures the Gemini client, crafts a system instruction that frames the model as an expert content analyst, and sets low temperature (0.2) for high accuracy. Sample code execution demonstrates analyzing a paragraph, producing the structured JSON, and iterating with new text. The tutorial also explains error handling, JSON dumping with proper indentation, and optional image handling. Throughout, the speaker emphasizes the importance of solid OOP fundamentals (constructors, public/protected/private members) for building robust agents, and encourages viewers to experiment and request further projects.
Chapters
Today we are going to make an AI content analysis agent using Python, and we will be also using Gemini API for this project. So this is going to be an AI agent. You can even call it an agentic AI project. So we are basically going to understand the entire AI agent or agentic AI, how exactly these projects has to be created, what all are required, and how you can create it within simple Python code, right? So now see, what is AI agent? What is the type of AI agent that we are creating? You understand the standard AI. What is standard AI? Standard AI is like a smart calculator. You give some input, it processes, it generates the output, it gives you the output. That's it. And this is the AI which you have been using, right? Gemini, Claude, and Antigravity, and there's so many, right? ChatGPT. Now what is AI agent? AI agent is like a digital assistant. When You create an AI agent, you give it a specific task to define a job description. You give it a particular role that, okay, this is what you are going to do for me. Now, within the AI agent, as this is an assistant, obviously assistant has the job roles. So you are going to define the job and what exactly the job this particular AI is going to do for you. One specific thing. It cannot be multiple. It can be multiple, but it has to be very, very specific. Right? I will tell you later how specific it has to be. Next is it will take some input, then it will— there will be an AI agent workflow, like what are the rules, what are the schemas that you have to follow. Just like how we join any company, right? They give them our rules, they give them our, you know, job description that, okay, you have to work on data analysis, you have to work on business analysis project, so you have to work with client dealing. So there is a job role assigned to us. Same way we assign it to the AI agent. We mention strict rules— how low the temperature can be, how strict you have to be, and everything basically within the workflow. Then we also give them how or what is the expected output for this particular role. Then after giving this structured output, we also tell them what is— where to store it and what is the data store for them, right? So it is like creating a complete agent. So for doing this, what all do you need? You simply have to go to Google Gemini API, okay? If you will go to the API key, Google Gemini API, you will get one free API key from this Google AI Studio, okay? This AI Studio will give you free API. You can simply create it by clicking on this Create API button. Once you will click on this Create API button, it will ask you for, you know, what should be the name. So let's say you are creating one AI agent project. So you give it a name and once you will click on create, it will give you the key directly on your screen. So you copy and paste it in the notepad anywhere or even on your WhatsApp as well. But you do not have to commit that API key on your GitHub repo so that— because API is something which is private, right? So you have to make sure you never do that, right? Now after doing that, what you have to do next is you have to open the PowerShell or whatever, like let's say you are using the command prompt or terminal, Mac user or Windows user, you just have to go to this Go to setting the environment variable. You have to create one environment variable which is Gemini API key and then store your API key. Whatever actual API key you have got from Google AI Studio, you will paste it in this quotation and then there will be a user which will be mentioned, right? This particular command you have to enter in your PowerShell command prompt terminal wherever, whichever You have to open it and directly enter this. That's it. If it's not showing anything, it means the environment variable is already created, like successfully created. You do not have to do much things right now. After this, you open a new fresh terminal and enter this command, which is mkdir Gemini agent. This is via terminal, I'm telling you. If you do not want to do it via terminal, you some— simply go to your desktop, and within the desktop, within the desktop, you right-click, create one folder with the same name, and then you give it this Gemini agent as a name. Then go to this folder, open that folder, open that same folder in Visual Studio Code. That is easiest way to do it. So open the same thing in the Visual Studio Code. If you want to do it via commands, you can use these 3 commands and you will enter in the Visual Studio Code. After opening the Visual Studio Code, you have to create a virtual environment. Yes, when you work with different libraries, it is recommended that you create a virtual environment, and using that virtual environment only you work. Now, what all are the libraries that I am going to use for this project is Google Gemini, which is GenAI, and then PyRen. These two libraries I am going to use for creating this project. Now, what is this project about? This project is like human assistant which basically do AI detection work. Okay, I will show you how it works. So this is my agent which I have created. Now it will give me some summary, sentiment, sentiment scores, what is the main topic, key takeaways, and suggested tags. Now let me run this. Now I have already given one paragraph in this, uh, entire script, and that particular paragraph is getting checked. Now it says, please set your Gemini API key. Now, I— let's say I do not have a— let's say I have set up the Gemini API, but it is still showing in the terminal. So what you have to do is you go open the PowerShell. Now, once you will open the PowerShell, you have to directly write down the command to run the file via this PowerShell. You simply go and search for the PowerShell or the terminal wherever you have defined that environment variable. No matter if you have closed it, you have to open the fresh one. Now once you will go there, you have to define the path of the file where your file exists, where is the folder where we are talking about. So I have created this project which is this AI agent. Now you take this path of this, yeah, over here you can see there is a path. So you copy this and paste it over here and then enter. It will jump onto the same path. Yeah, so now we are in the same path which is Gemini agent. Now I have to run this file, right? I have to run this in the same, same file, basically the same virtual environment that I have created. So for doing that, what do we need is we will write down, uh, /env/scripts/activate dot ps1 was one for me, so I have entered in it. And then I will write down simply the python agent.py, and this way it will execute the file for us. Now what is the file saying? What is, what is the paragraph that I have given, the given to the AI agent, is what it will analyze. Now see what we are getting in the output. It is saying initializing the content analyzing agent. It is analyzing the text. Analysis is done. What we are getting is, first is we are getting the summary. So this was a text given to us. If you look at the sentiment, it is neutral. If you look at the sentiment score, it is -0.1. And what are the main topics? You can see I have given about artificial intelligence. So it shows that AI and software engineering, Agentic AI framework, API cost. Then what are the takeaways? Then what are the suggested tags for this text? So it is basically whenever you want to post any blog or something, you can do this, right? Now let's say I'm taking, uh, some text from Google. Let's say AI news June 26th. So let's take this paragraph, and what I will do is I will go to my code. This is where I have added the sample piece. I will paste it, save it, come back, take the previous command and enter. Now it will again analyze the entire text that I have given. It will analyze it. Once it is successful, it will give me the suggested tag, takeaways, main topics, sentiments, and everything. Now you can see I have given Anthropic launched Claude 5 and advanced AI model and so on. It shows that main topics are Anthropic Claude 5, AI model release, government export control, and so on. And then these are the suggested tags. So whenever we work with the blog type of, you know, task, like as a content writer or something, so we can check the sentiments, whether, whether it is for beginners and all. So we can add more, uh, features or for more limitations in this. So now let us understand what we did and what is the code exactly. So I started with the very first library, which is the OS library, then the JSON file because I want the output to be in the JSON, then Pydent where I can take the base model and the fields, and then we are taking the Google, Google GenAI, and then the typing so that I can type it and display. Simple, very basic thing. Now what we did is we created a class. Now starting, I have done is I have created a class. We basically use a tool, Python tool, which is Pydint to create a strict form or a blueprint for us. So we are doing a content analysis result as a model. It is like a human assistant, a blank piece of paper we are providing, and they might write something messy, long review they can write, right? They are assistant, they are AI models, and they can do anything, right? So if you give them printed form with the specific boxes, then it gives, it gives you the specific values in that boxes, right? So that is why what, that is what I am doing. I'm creating summary, sentiment, sentiment score, main topic, takeaways, and suggested tags. So I'm creating a structure, output structure for my model, correct? Output structure is very important. Now next is we are building the model. For building the model, I'm using Content Analysis Agent as a class. Now within this class, obviously I have a constructor. Within the constructor, I'm creating an SDK, basically a client I am creating, and within that client, genai.client. So basically this connects our code to the Google server via API, which we have stored in the environmental variable. And if you are not storing it in the environmental variable, Do not worry, anywhere in this file create a variable and paste it. That's it. Now whatever API key we have saved in our computer, it will basically connect it and it opens the phone line to the AI. Now which one AI I am using? I am using this Gemini 2.5, right? This is the brain, this is the specific model which is perfect because it is incredibly fast, which I feel, and it is highly accurate as well and Obviously it is completely free for the developer to test out. That is why I'm using Gemini. Many of you can even use ChatGPT or Claude if you have the paid version of this. Right now, next is the system instruction and sending the input. So we, whenever we get, you know, analysis, so this is the analysis function that works for us. And what are the system instruction? It is like a prompt given to you. In AI instruction, we need basically We need to give a job title. We need to give a job description, right? So that is what we are doing. We are creating a pep talk, right, before this, right? So you are an expert content analysis agent. Your job is to thoroughly evaluate the provided content, determine its underlying themes, sentiments, and core meaning, and output your findings exactly matching the requested JSON scheme. Now, JSON scheme. Now, whatever you want to write, you can write. Whatever rule, job title, description you want to give. You are an expert analyst, you do this, you do that, you are coder, you are a developer, whatever you want to define, you can define it in the system instruction. Now we are using the try and accept block. Now what is in the try and accept block? Now see, in this few lines I am mentioning about some configuration. I'm mentioning about some configuration. This is where the magic happens. So basically we have mentioned about, uh, how low the temperature has to be, what should be the response data type, and where should be the schema. Low temperature is basically high accuracy, right? So that is why we have kept it 0.2. We cannot keep it 0, but we can keep it 0.2. Now we are saying that please analyze the content which I have, which I'm going to provide you, and then pass it in the JSON format. And if there is any error, do not crash my code, just say error during the agent analysis. And then this is my main code. Now what is the sample execution that I have done is I have created a main function. Now within this, and we have to first ensure that API exists because this is with Python, but entirely everything is done with the AI, but just a job description is given to AI, right? So API has to be there. Suppose what we are doing is we are checking if the API exists. If it doesn't exist, do not crash again, just print set your Gemini API key environmental variable and then exit. Simple. Now after this, if let's say API exist? If it exists, then I'm giving some text and I'm asking it to print, calling the function, analyzing the content, asking it to analyze. If the analysis is done, just dump the JSON file in front of us. What should be the indentation? Indentation has to be 2 so that it looks good, right? Now if there is any image content, then that too can be initialized, right? You just have to save it again in the same format, which is the sample article that's just like this. And then you can even work with the image formatting. So you can create a simple AI agent with few lines of code, but you should have the understanding of how exactly OOPS programming works, how to create constructor, how to create clients within the constructor, what to define within the methods, what to define, how to use public, protected, and even the private member of the classes. So these are the basic knowledge which are required. But those people who say that without basics you can directly create AI agent, I would love to tell you that no, that's not true. If you want to truly understand and create something which is out of the box, which is just unique, which is original, then you should have for sure, you should have the knowledge of fundamentals and even the basics. So I hope this helps. If this helps, hit the like button, drop a comment if you want more projects. If you have the idea, you can drop it in the comments. I will surely, you know, help you create that. So stay tuned, happy learning, and keep growing.










