This marketing agent automates EVERYTHING (free n8n template)

Rory Ridgers builds an autonomous marketing AI agent in n8n that researches topics via web search and Instagram scraping, then generates blog posts or social media content with custom images. The workflow uses multiple LLMs to plan and write, generates images via OpenAI, and logs everything to Google Sheets through a branded web interface.
Chapters
What's up guys, in this video I'm going to be teaching you how you can make a fully autonomous marketing AI agent inside of NAN. This agent is going to be able to automate pretty much all of your social media content creation, and it can do it on request from you, or it can just do it completely on autopilot. You can set up a timer and just have it running sort of every day. Just quickly before we jump into it, if you haven't seen me before, my name is Rory Ridgers and I help business owners to integrate AI agent systems into their businesses. So if that's something you might be interested in, I've left a link to my website in the description and go ahead and book up a free call. We can talk about some ways to implement AI into your business. Also, just before we get into it, I do want to mention that the template for this will be available for completely free. There'll be a link in the description. So something like free templates, you can just go ahead and grab this template for free and get started with it straight away. Yeah, that's enough talking. Let's get into the video and I can show you exactly how it all works. Okay, so this is inside an— and this is how the agent is looking. So it might look a little bit confusing at the moment, but you can see I kind of labeled everything so you can see what's going on. So just give you a quick breakdown of what's going on. To begin with, we scrape Google and then we scrape Instagram to get sort of relevant up-to-date insights on what's going on. In the news and in social media at the moment. And then we just do some manipulating data here. I'll show you what that means in a second. And then if it goes this way, we generate a blog post. You can see it's different from the actual agent. It goes this way, we're generating a blog post and we just plan it out, write it, and then we use this, uh, agent step to do some other bits and bobs, which I'll show you in a sec. But this way means we're generating a full blog post, obviously, for our website. And then if it goes this way, it goes to our agent that's able to generate pretty much any other kind of social media post. So LinkedIn, Instagram, X, anything like that. If we want to create a social media post like that, it'll go this way to this agent and it will be able to do that for us. So to give you a little bit more in-depth breakdown of what's actually going on here, to begin with, we're going to be scraping Google and we're doing this using Tavily. So the first thing, so as we send our input and we're going to say something like, I want to create a LinkedIn post on AI in healthcare, let's say for example, we have a query generation agent that's really, really simple. All we're doing here is taking the input that we got from this step here and then just turning that into a query that we can actually sort of search on Google for, or search on Tavli for. By the way, if you don't know what Tavli is, let me show you really quick. Basically, it's like a Google API for— uh, we use it all the time in NAN and when we're building agents. Really easy to connect to. You can just connect to it and basically just search the web. So that's all that is. You can see we have a Tavli step here. So this step here is just generating an actual search query based on our input for what we can search for to get relevant up-to-date insights on, let's say, AI and healthcare, if we're using that example. So the next step is the Tably steps, the HTTP request, and we're just doing a Tably search. If we come back over to Tably, you can actually see the API endpoints. Go to documentation, API reference, and then it's this one. So Tably search, and this is what we're actually doing here. So first of all, setting it to POST, and then this is our URL. So we just copy that, set this to POST, copy that, paste it into here, and then authorization bearer API key. And then the other header is going to be content-type application/json. And the actual JSON that we're sending over, it's a bit bigger so you can see, this is what we're sending over. So it's literally just this. We just copy this over, paste it into here, and then we've changed out query for obviously the variable that we got here. So whatever, uh, query or prompt was generated here, it's going to be put into this input here. So basically just doing a Google search for that, and we should get a URL for some type of blog or some type of website that's basically going to be relevant to us. So again, if we're searching for AI and healthcare, should come back to us with a website or a blog that's to do with up-to-date insights on AI and healthcare. And then we simply just do a GET request for that URL. So we put in the URL that we get from Tavli, do a GET request, and what this is going to do is just going to return all the HTML from that blog or from that site, that page. It's going to give us all the HTML, and then we convert that into Markdown just to make it easier for our AI agent. And then we pass that to an LLM step, and you can read the prompt here. We've said, you're part of a social media content generation system. Your job is to take the scraped Markdown data of a site relating to the content a user wants to generate. I want you to simply output a summary of the data and what we can actually focus on. Don't mention the content, just give insights. Output just a summary and nothing else. So basically Again, if we found a blog post on AI and healthcare, this step is just going to be summarizing that blog post. It's a little bit easier for us. And then in this next step, we're going to be scraping Instagram. So the way we do this is with Apify. If you haven't used Apify before, it's basically just a really big marketplace of different scraping APIs that are really easy to connect to, and you get some free usage that you can use with it as well. So it's really, really good. So we're over in Apify now, and we're looking at the Instagram post scraper. So if we click on this You can see here basically what I've done already is for this I'm making it all about sort of AI content creation. So like I said, AI and healthcare or AI and education, AI and retail, wherever it might be, I've made it all about AI content creation. So basically what this scraper does is it will scrape specific profiles and get all of their post data. And what I've done is I've pre-filled in some sort of AI news pages that we can scrape to get relevance of up-to-date posts. You can see here I've got the AI field, the daily AI dose, evolving.ai, AI sources, as you can see. And then what we do in NAN to connect to this simple HTTP node, the method is going to be POST, and then the URL. We come back over to Apify, we're on our actor now, so we should go to API, API endpoints, and then we scroll down to this one, run actor and get dataset items. And what this is going to do is it's going to— NAN is going to be able to trigger this actor, and it's actually going to wait. It's just going to sit there and keep running until the scraping is finished and we get all of our dataset items, and it's going to send it back to NAN, and then it's going to carry on with the flow. So all we do, copy that, put that into here, and this contains your API key in here. So you don't actually have to do any headers with your API key or content type application/json. It's all in that URL. So you literally just copy that URL, put it into this URL section here, and then we go JSON using JSON. And the way we get the JSON to use is we switch this from manual to JSON, and it just pre-fills the ones that you put in here. That's why I put them into here. So just pre-fills them in JSON. You just copy that, take that over and paste it into here. You can see I removed one of these when I was testing because it just wasn't so good. So we, um, we put the JSON there and that's going to scrape these 4 pages and we set it to 20. So it's going to scrape the last 20 posts of all 4 of these sort of AI news related pages. And then what we do is we aggregate the data that we get from here. So from here we get a bunch of different data points. So the only ones that we really want is caption, comment count, and first comment. So these are sort of the only relevant data points we could actually use from the data we get from here. So what we do, we're going to get 80 through, obviously, because it's 20 of each. There's 4 pages and we're getting 20 of each, so we're going to get 80 different dataset items through. What we do is we aggregate this to basically just smush all of these different dataset items into one. So all of the captions into just one variable, all the comment counts one variable, first comments into one variable. That's all this aggregate step does. And then we pass all of that over to this LLM step that's going to do the exact same thing as this. It's just going to summarize all of that data. So you can see we've passed over caption, comment count, first comment, and this is from the aggregate step before. So it's just going to be 80 captions, 80 comment counts, and then 80 first comments. And the prompt looks pretty much the same. We're just basically telling it to summarize it and give us some relevant data points that we get from here. So now we should have a summary of a blog post or an article, and then also a summary of some up-to-date Instagram post to do with whatever it was we wanted to create a social media post for. And then we just use another LLM step to basically summarize both of these summarization steps here to just get one summary about sort of up-to-date AI stuff that we search for, to just sort of give us an overview of everything that's in, you know, the internet, on Instagram, everything like that. Just gives us one summary that we can use later on. It makes it much easier. And then we have another LLM step here that just looks really, really simple at this initial query and just determines is it a blog post they want to generate. I found this probably just the best way to do it because your input might look a little bit different every time. So if you say I want to generate a LinkedIn post to do with this, or I want to generate an Instagram post to do this, obviously it's not going to go this way. But if you say I want to generate a blog post, this LLM is going to pick it up. And then we have an if step here that's set to the output from this. If it's equal to blog, we've just got this agent to— if they want to generate a blog post, output blog. If they don't, output not. So it goes through here if the output is blog, then it's obviously a blog that we want to generate at the beginning here. So it sends it up here. If it's not, it sends it this way. So we're going to start with this way just because it's a little bit easier. So we have a planning agent and then we have a writing agent. So if we look at the planning agent, basically we give it the summary that we got from here. So sort of the ultimate summary, we give it that summary. Then we also give it the prompt from the user, and we've just said to it, you're part of a social media marketing system and you're responsible for creating blog posts. And then basically say, I want you to take the summary of the scraped web data as well as the user's prompt and create a plan for a blog post. Lay out the plan with sections with bullet points for each section and also a description at the beginning. So quite simple, but it's just going to basically generate a rough blueprint or an outline for a blog post based on the summary that we got from here and then the user's first prompt here. And then we have a writing agent. We basically just give it this plan and say, flesh this out and turn it into a full blog post. So now we're going to get a full blog post here. And then what we have to do is we have to pass this to our agent here. You can see this agent looks pretty similar to this agent, and we can actually have a look at both these agents right now because I have the same tool. So first one is going to be a Google Sheets tool, the second one is going to be an ImageGen tool. So the Google Sheets tool, it's just going to be because we're going to add all of this data that we get to Google Sheets, which I'll show you now. So you can see I've already got one in here, a blog. The columns are going to be platform, title, caption, image, and date. So I'm just going to mark what platform it's going on. In this case, it's a blog, so we just write blog, but it would be LinkedIn, Instagram, X, whatever it might be. Then we have a title, a caption, an image, and a date. Basically, this agent is going to use this Google Sheets tool to input all the right data it needs to into this table here. And then the other tool it has is the ImageGen tool. So I'm going to show you this tool actually. So this is the image generation tool. You can see it's when executed by another workflow. Because back in the main agent, if I show you again, we have executing another workflow node here. So this is what this node is, it's basically calling upon another workflow. You can see we've selected the ImageGen workflow. So if we go back to that ImageGen, when executed by another workflow, it's going to get an input through with basically a description of the image that we want to generate. And then we just have a prompt generation LLM that's really, really simple, going to take that description that we get from here and just turn it into an actual structured prompt that we can use for our image generation model. And then to actually generate the image— and then to actually generate the image, of course, we're using the new GPT image generation model. I think it came out sort of 1 or 2 weeks ago in the API, but you've probably all used it through the web interface of ChatGPT. So we're just using that, and this is the endpoint we use for it. Really, really simple. If you want to learn how to actually connect to this image generation model, all you have to do is go to the OpenAI platform and it'll show you exactly how to connect to this. Anyway, this is the endpoint, and then this is what we're actually sending over. So we've got a size, the model, and then— and I'm not— we've got the size, we've got the model, and then the prompt. The prompt is just going to be the output from here. So let's again say it was something like AI in healthcare. That's going to come through here. The PromptGen is going to give us an actual structured prompt that we can use to generate a nice image to do with AI in healthcare. That prompt is going to be sent over to here, which is going to generate the image, and then we have to convert that to a file because because from here we'll get a bunch of binary JSON, like loads of it, and we have to convert all that binary into an actual file. So we just have this convert to file node here. We've got the operation set on move base64 string to file, and basically it's just going to convert that binary JSON into an actual file, and then it's going to upload it to our Google Drive so we can get a web view link for it. And then we just have an edit field step here that's just going to set the web view link to web view link. This just basically means because Usually when you call on a workflow like this from an agent, like I showed you before, it's just going to take the output from this last step here and send that back to the agent that called it. But with the Google Drive, I don't know if you've ever used the upload file Google Drive node, you just get loads and loads of different data points back. We don't really want to send all of that back to our agent just because it's too much for it. It might get a little bit confused. So what we do, so we have an edit field step and we just set the web view link. We put in the web view link, uh, variable here, and this basically just means it's only going to send back that WebView link variable back to our agent because that's all it actually needs. So to give you an example, we're going to send over some mock data here. So if I hit set mock data, so if we remove this and do the variable name as description, and then let's just use the exact same, um, example we've been using this whole time. So I want to create an image of AI in healthcare, something like this. So I want to create an image of AI in healthcare. Pin this data, and then if you test this workflow out, we should see this all run through. So the prompt generation, this will get us futuristic scene showing artificial intelligence in healthcare featuring a humanoid robot, yada yada yada. You can read through this whole thing, which gives us a nice prompt that we can send over to our image generation model. Okay, so you can see this finished working here, and look, if we hit show data, you can see this is all the data we got, like an insane amount of data here, which means absolutely nothing to us. We convert this into a file, which you can see here, it's just called data. And then we use a Google Drive node to just download this to— I've just picked a random file. We just download this data into an actual file into Google Drive. You can see this is what I mean by all the different data points we get back. Don't need to send all of this back to our AI agent, so we just have an edit field step that's just going to give us a web view link, and then we can actually have a look at this. Um, okay, so you can see this is what it gave us. Nice little image. You can sort of fine-tune this and adjust it so it makes better prompts or different prompts, but right now I think this looks pretty nice. So if we come out of that, you see this is how the image generation, uh, tool works. We just give it an input and then it's just going to get back a link for an image that it can use. Okay, so back in the main workflow here, if we come back to this agent step that we have here We give it the blog post that is the output from this step here, and then we basically just tell it what it needs to do. So it's part of a social media marketing system, it's responsible for finishing off blog posts. We give it a full blog post, we want it to simply come up with a title and also generate a summary that we can use for a prompt to send to the ImageGen tool. Using this tool will give you back the image URL. I want you to put all of this and the title into the Google Sheet. So it's going to get the blog post through, it's going to create a summary on that, it's also going to create a title for that blog post. It's It's going to send the summary to the ImageGen tool, going to get back a link for an image that it can use. And then in this Google Sheets node here, we have a look. The platform, we've just hardcoded this in to be blog because every time it's using the tool from this step here, it's going to be a blog post. Title, we've left this up to the model because obviously that's one of the tasks that the model has to do. The caption, in this case, the caption is going to be the actual blog post. For the other ones, it would be like the caption of the post. For this one, it's going to be the actual blog post. So we just do the output from this step here. So we put that into there, and then the image, again defined by the model because it's going to be getting back the link that it got from that tool. And then the date, really, really simple. If any of you guys know this on NAMM, you can do this really, really simple JavaScript function that just gets today's date. As you can see, all you do is you do your curly brackets here and then it should pop up. So it's a dollar sign, and then now if you hit that, it's just going to be today's date. Really, really handy. And it's just going to put the exact date this is happening into our table here. So you can see we got the exact date it's happening, which is really, really cool. So that's for that section here if we're generating blog posts. But if we wanted to generate, say, like I said, an X post, a LinkedIn post, an Instagram post, it's going to come this way and come to our AI agent. It's pretty much going to be doing the exact same thing except it's not going to be generating a blog. So again, we give it the summary that we get from here, and then we also give it the user's prompt for the type of, uh, social media post they want to make. And then this is the prompt here. Your social media marketing system, you're responsible for creating social media posts. Your job is to take a summary of current events as well as the user's prompt, which will be the type of post they're looking to generate, and create a post. You'll first use the ImageGen tool to basically create an image and get back a link. Next, I want you to generate a caption, a title for the post we are trying to generate. Make sure to include hashtags in the caption. Once you have this, input it into the Google Sheet as well as the platform that will be posted on. Which will be defined in the user's prompt, and also the image link you got. So basically everything that's got, just put that into the Google Sheet. You can see we've pretty much left this all up to the model apart from the date, which you just set to the JavaScript function for $now. So that was a lot of talking. We're going to get into actually testing this thing out. Now you can see, you might have noticed at the beginning, at the end, we have webhook. So webhook at the beginning, webhook response at the end. And the reason we have this is so we can use my platform that I made here, which just allows you to create custom interfaces for your NAN agents or any other AI agents that you build on any other platform. So we're in the platform now. I did a full video on how this platform works, showing you exactly what you can do with it. But anyway, we're in the interfaces. We're going to hit Add New. We're going to call this something like NAN Marketing Agent. For the description, let's just say does our marketing. Really, really simple. Web interface. And then the integration, we're going to hit Custom Webhook URL. and then we put in this webhook URL that we get here. So at the moment it's a test URL, could do an actual production URL, but just cuz we're testing, we're gonna do the test URL method set to POST. And if we copy this, paste that into here, add webhook. One of the cool things you can do as well, if you're not too sure if it's working, you can just hit listen for test event and then you can just test the webhook like that. And as you can see, it says webhook is working properly. And then we got just some demo data through, which is really, really cool. If we hit save changes, we can actually customize this really quickly. This is how the default one looks. But we're going to customize it a little bit and make it a little bit more personal to us. We've got all these different colors that we can customize the update in real time, as you can see. Pretty cool. But I already have my template preloaded, so autonomously we click this. You can see this is how my one already looks. Let's hit Save Changes. For the branding, I've just got my own logos in there. And then welcome message, we could kind of just leave this the exact same. Pages, we're not going to add any pages in this case. We could add obviously our documents videos pages or analytics page, but in this case we're not going to. So make sure we've hit save. Let's preview this and then let's actually test this out. So if we hit test workflow, you can see now this is listening for events and we can test this out as we usually would. So say something like, I want to create a LinkedIn post on AI in finance. So I've said I want to create a LinkedIn post on AI and finance. If we send this off, and you should see, yeah, it triggers our agent here. And it's just going to sit and wait, obviously, until this is done. It does take a minute, but, um, yeah, it's just going to sit and wait until it's done. So you can see all of this working out. It does take a minute to do this step here. This is definitely the longest step, it's the Apify step. If we come over to Apify, obviously it's done all these, which is really cool. If we come over to Apify, you can see what it's actually doing here. So you can see right now it's scraping Instagram. It's got 25 so far, and this kind of data it's getting— so the text, which is just going to be the caption of the Instagram post, the owner's full name, the author, the post URL, number of comments, first comment, number of likes, posted on, and then the query tag, which is just undefined for pretty much all of these. Um, but right now it's on 43, should get to 80. Okay, it's just jumped up to 66, so we should see this done in a second. Okay, so that's done, and then aggregated, and then went to the Summarize agent. It's gone to the other Summarize agent Is this a blog post? Obviously not. So it goes this way, gets sent to this AI agent, and you can see at the moment it's generating the image. Again, this one does take a second as well, so we're going to leave this for a sec and we're going to come back when it's actually done and I can just show you how it's all worked. Okay, so you can see it's all gone through now. If we check the Google Sheet, let's have a look. LinkedIn for the platform, the title is Harnessing AI to Transform Education, Careers, and Finance. The caption is Explore how AI-driven tools like Computer Vision API are revolutionizing education, career development, and the finance sector. Yada yada, gave us some, uh, hashtags at the bottom here, which is really, really cool. And then the image, let's have a look at this image. So pretty cool. Again, you can kind of fine-tune this so it does more your style, fits with your brand a little bit more. It's kind of just the default at the moment, haven't fine-tuned it too much, but I think it looks pretty cool. And then the date obviously is just going to be today's date and time. So if we look at the actual agent and what happened here, first of all, the query received is I want to create a LinkedIn post on AI and finance. And then it outputs to us AI and finance 2025 trends, use cases, challenges, LinkedIn post examples. And then that is what we searched Tavli for. And then it gave us this little answer here, but also gave us a URL here which we scraped in these two steps, gave it over to our LLM here, and it said the content centers how the transformative impact of AI, particularly computer vision APIs in finance and banking by 2025. Key focus areas include streamlining document processing, yada yada. Greed for all of that. And then we did an HTTP request using Apify to get all of the relevant post data from those AI pages I showed you earlier. And you can see there's 80 items here. If we go to JSON, you can see all of this data that we got. So just 20 different data points, so just 20 different arrays for each Instagram page. Here you can see there's literally loads of it. Send that over to our aggregate to aggregate all of this into just one item. So captions was just one item, and if we scroll down You should see first comment, it's just one item, and then yada yada. Send that over to another OpenAI step, and then it gave us this summary here. So the data reveals strong engagement around innovative use of AI in education and career visualization, highlighting public interest in AI-driven inspiration and creativity. Very cool. Then this agent here summarized it. So the combined insights highlight strong opportunities to create social media content that showcases AI's transformative impact across education, career development, and the finance sector. You see quite a big summary here, which is really, really cool. Is a blog post just outputted not because this isn't a blog post. So that means it went this way, got sent to our AI agent, which generated the image here. Really, really cool. Got this WebView link back, which we just saw. Let's have another look at it. Uh, so go to this, what it gets back, and it's obviously saved in our Drive as well. So we can just look at this whenever we want. And then it updated the Google Sheets with this information. So LinkedIn title, image, date, caption. Really, really cool. Absolutely perfect. And you can see Webhook Response just said, I've created a LinkedIn post titled Harnessing AI to Transform Education, Careers, and Finance with an image showcasing AI-powered tools in these sectors. And then basically just everything it did, and that got sent back to our interface on Communis Agents. So really, really cool. Really great for delivering it to a client as well if you just have this custom branded interface that they can use. If you do want to check out Communis Agents where you can create these completely customizable interfaces to chat with your AI agents through. You can also deliver it to clients. If we go to details here, scroll down, you can add clients, and then it's password protected so only they can access it. And just check out the link in description. I'll leave a link to this platform. You can get started for absolutely free and start creating with no limits for free, which is really, really cool and super, super useful. Again, look at all these colors, looks absolutely amazing. You can customize it so it looks exactly how you want it. So yeah, that is it for the video, guys. Did hope you enjoyed it, and I hope you like watching how we can almost completely automate our social media content creation, because I know that's a big bottleneck for a lot of business owners, especially small business owners, is creating content on all these different platforms and trying to keep up with it, trying not to get behind. I talk to a lot of people that say they want to just automate all of their social media and their content creation. This is an absolutely perfect agent. Again, I didn't show in this video, but like I said at the start of the video, you can just sort of add a timer to this and have it so it triggers like every day, every week, every other day, whatever you like. But in this video, I just wanted to do it so you actually talk to it so you can see it a little bit better. So like I said again at the start of the video, if you do want to work with me so we can implement some AI agent systems into your businesses, then I've left a link to my website in the description. You can go ahead and book up a call and we can talk about some ways to implement AI into your business. And also, again, like I said, if you want to try out Commodus Agents so you can create those customizable interfaces and chat with it for yourself or deliver it to clients. I'll leave the link to that, you can get started for free. Don't forget to download the free template for this so you can get started with it straight away. And if there's any more video suggestions you guys would like to see in the future, then please do just drop in the comments or just drop me an email and I'll try my best to get around to doing them.
More from Rory

Dynamic Workflows are crazy. This is how to actually use them (beginner's guide)










