Learn how to build an AI agent with cursor and nex.js. You'll basically build your own version of open claw. This course covers the entire development process utilizing the AI SDK, super memory, and composio to create an intelligent system capable of executing complex actions. Sean Eskeel developed this course and Composio provided a grant to make this course possible. Welcome to the course, Build Your Own Open Claw from Scratch. In this video, we're going to build an AI agent that we can chat with through Telegram that has persistent memory, so it actually learns from every single conversation. This agent will be able to actually do things for you, and we're going to take major inspiration from the popular open-source project, OpenClaw. OpenClaw is an AI agent that runs on your local machine. It has 371,000 stars on GitHub and it's one of the fastest growing open source projects of all time. It can connect to tools that you already use like Gmail, Slack, Linear, learn from your style over time, and everything runs on your own machine. All right, so first I'll show you a quick demo of what we're going to be building. I'm here on my deployed Versell app, which is what we're actually going to use to deploy our finished AI agent. And here we have a UI that kind of looks similar to chat GBT. We have a sidebar where we can toggle our past chats and we have our user account here on the bottom left. We can toggle dark mode, sign out, and even check out some of our settings. Over here, we can click to see some of the available models from Versel AI Gateway Router. At the time of filming this, you get $5 of free Versel AI gateway credits every month, I believe. But I'm just actually going to choose Claude Sonnet 4.6. And I'm going to test out one of these prompts. If we ask it to write an essay about Silicon Valley, it'll create this nice sidebar where it'll create a markdown document that we can actually interact with. If we ask it about the weather, it'll put the weather into these dynamic weather UIs where it puts all the weather into these hourly forecasts with these nice icons. If we ask about code, it'll put into these code blocks. And in this other chat, I've asked it to use Composeio, one of the tools we're going to use in this project to fetch my latest emails on Gmail and then send a draft to reply to any of the customer complaints. The agent uses the search tools function and then it checks our connections and gives us a link to add my Gmail. If I open this link, I can then connect my Gmail. It's going to look through my emails and actually draft a message for me in the thread. Then if I go back to my emails, check out my drafts, you can see that my AI agent was able to draft this email for us. The last thing I'd like to highlight is that it's actually speaking a little bit of Japanese to me, and that's because I told it to in one of my previous chat. By the end of this course, my hope is that you'll have a better understanding about how AI agents work. You'll have a fully working version that you can deploy and start serving to users today. And this will serve as a valuable starting point for any other AI agent that you want to build in the future. With the Versell AI SDK, we have a beautiful chatbot template as well as all of the latest AI models available to our users. Then with Composeio, we can connect to any of the apps that we use. So we can do cross app automations like going from Slack to notion to email. And we'll use super memory so our agent learns from our conversations over time. And just a quick note on me, your instructor. So I'm a developer relations engineer at Composeio and I'm also a cursor ambassador. I've taught thousands of people now how to use AI tools like Cursor, Composio, and Langchain. And I'm constantly using these products myself as a full sec developer and someone who just likes to build AI apps in their free time. I think in 2026, it's also really important to know how to use AI tools in your workflow. Throughout the course, I'll be dropping some helpful tips about using AI for coding. But you can use these same principles for Codeex, Claude Code, or whatever AI agent you happen to be using. By now, you're probably also thinking, "Do I need to know how to code to follow along in this course?" And no, we're not. We're going to be using a lot of AI to write the code. Your job is just to understand it, to review some of the changes, and we're going to be basing most of the code off of Versel's AI chatbot template. So, that's going to do about 80% of the work in setting up the UI and even setting up the database for us. As I mentioned, this course will be using cursor, which is an agentic AI code editor. So, I'll also be dropping tools on how you can troubleshoot bugs and also build new features securely. So, in this tutorial, we will be using cursor. It has a free hobby plan with limited agent requests that has no credit card required. And it's agent agnostic, which means that you can use their composer 2 model, the latest cloud models, the latest GPT models, all from the same UI. And everything that I mentioned in this tutorial will be in the description. So, just check that out if there's a link you're looking for. Or you can just clone the final repo by grabbing the SSH key here in the Composio repo. I also want to be transparent here about costs so that this can be as accessible for everyone as much as possible. Um, you're going to need a credit card to sign up for any sort of pro plans on Cursor if you want to use the premier AI models. But luckily, if you're a student, you can get Cursor Pro for free if you go to cursor.com/uds. And OpenAI also has a similar program, and I'll leave the links for these programs in the description. Just another quick note on the cursor paid plans. So, if you click the link in the description, you can get 50% off any of the cursor plans. So, if you want this $20 a month plan, you can get $10 off that. So, check out that link in the description. All right. And before we go any further, I think it's really important that we answer this question. What is an AI agent? To explain this, I think it's really helpful to use this analogy of a human agent. So an AI agent is pretty similar in that it can perceive its own environment. So the chat itself, how the user structures its prompt and then from this it can then reason, plan and autonomously execute multiple steps in order to achieve a specific goal. And it can use tools to do this. It can look at your files to do this and it can use all of that to achieve a specific goal. Whether it's something simple like getting the weather or something more complicated like doing a workflow that stretches across multiple apps. The first thing that we're going to do is build the UI. And you can think of this like the body or the first thing that the user sees on the outside. And this is how they communicate with your AI agent. And we're going to be doing this through the Verscell AI SDK. Next, we have the brain. And these are going to be the AI models. Whether that's the latest Claude or GPT model or maybe an open-source model like Kimmy 2.5. You can think of these AI models as the brain living inside of your agent. And this is going to shape the way that it executes tools, comes up with plans, and it's going to improve the overall accuracy if you use a model with higher levels of intelligence. You can think of the hands as being the tools that your AI agent has access to. The tools in this case could be any app that you already use in your personal life or business. This could be communication tools like Slack or Gmail or maybe productivity tools like Linear and Notion or even developer tools like GitHub or other coding agents. So our AI agent from Verscell already has a list of tools it can use. So it can get the weather. It can use tools that put code into code blocks. But we're also going to give it a bunch of other tools, tools from our actual apps using Composeio. With Composeio, we'll give our agent access to a thousand plus toolkits that let us run various commands. For example, in Gmail, there are many many tools within Gmail like drafting emails, reading emails, etc. And by just integrating Composeio, we can get access to all of these toolkits and give them to our AI agent. So, our agent will have its brain, the AI models. It'll be able to read the user prompt to come up with a plan of what it needs to do and it'll use the user prompts. It'll use the files and then it'll use any of the tools that it has available. So if the user asks for its latest emails and it doesn't have that in the chat context, then it might use one of the tools it has available to it like Gmail or Outlook to actually fetch those emails and get it into its context window. In the later sections, we'll add super memory so that our agent can learn from all of our chats continuously. We'll add a soul so that it has more of a personality. And then we'll also add Telegram so that we can message our agent through our phone. And finally, we'll add cron jobs so that our agent can run repeated workflows the same way every time at specified time periods. All right. So, in this section, we're going to start building the UI using the VersellAI SDK using the chatbot template. So, in the description, go to the github.com/verell/hatbot link. Scroll down all the way here and just click on this deploy. You can look at this for a quick overview of the features that's included, which I've already gone over. So, we'll just click deploy here. If you haven't already, you'll be prompted to create your Versell account, which is 100% free on the hobby plan, which is what I'm currently on. Then you can add your GitHub account over here by clicking add GitHub account. And we'll just use the default private repository name, chatbot. Looks like I already have that deployed, so I'll call it chatbot 2, and I'll create it. All right, so really quickly, these are all the products that come out of the box and ready to go with a chatbot template. These are optional but they make setup a lot faster. So the first one here is Neon and this is a serverless Postgress so it's hosted by Neon. We'll click add. Select a region and this won't really matter but we'll choose the one closest to our users. We'll enable O so that people can actually sign up and you can see the free tier that it comes with. We'll just accept all of these defaults and click create and it'll quickly provision this database for us and then it's already available for us to use. We'll also accept the default environments. So the production and the preview environment. And this is also going to create this prefix storage URL. And this is a sensitive URL that Versell is going to add to our project. When we click connect, it's going to add all our environment variables for Neon to our Versell chatbot template that we cloned. So that was super easy and we'll just go through the rest. We'll add up stash for Reddus. Use the same default region. Toggle the free tier. Accept all these defaults. And you can see we have 500,000 monthly commands, which is plenty for while we're testing this out. And then it'll provision it for us in a couple of seconds. All right. Same thing here. Accept all the defaults and connect Reddus to our resell project. Reddus is going to be useful for rate limiting people so they don't abuse our AI features and it'll also enable us to have reusable chat streams. And finally, we have blob store by Verscell. This is going to enable us to have file uploads so that the user can upload CSV files, markdown files, whatever into the chat for context. We'll just accept the default store name, default region, and make this private. and create this. So when I scroll down here to the add environment variables section, we're going to see all of the environment variables that Verscell's already configured for us. And these are going to be the deployed environment variables that we're going to need to link to our local session so that we can actually use these services from local host. We have this O secret. We can refresh this O secret in case it ever gets leaked and then click deploy here when you're ready. All right. So once we click deploy, it's going to start provisioning the integrations, giving us our build logs, and we'll just wait for all of this to finish as it creates our initial commit and deploys everything for us. All right, so now that it's done, we can click on the preview and it's going to show us the deployed chatbot template. All right. And so you can see we're on the guest account and it allowed us to run this prompt and it uses the versel AI SDK to have this thinking UI, this code block UI and it gives us the full response using Kimmy K 2.5 and it has all these other models here by default that we can use. All right, next we can just continue on to our dashboard. The only important things for us to see here are the domains. So this is the default one that it gives us. And we can also go to Verscell AI Gateway for chatbot 2. And we can see that with that first response, we used about 1 cent of our $5 credits. We can see the full list of available models. So we can have sonnet 4.6, 4.5, and 4. We also have the GPT models. So, why would you use AI gateway router over just using the anthropic API key natively? Well, this is an easy way to give your users access to hundreds of different models. There's also built-in failures, so like fallbacks to make sure that if Anthropic is not working, the model can change to GPT. If GPT is not working, it can change to DeepSeek. And this is super easy to include rather than creating all of that logic in your app. There's also no platform markup. So, Versell is not charging you extra to use this feature. And you can use this for text, image, and video models. As mentioned here, you get $5 of free credits every month, and they don't restrict your access to the premium models. All right. So now let's set this up locally. And we'll do that by going back to the project overview, clicking the GitHub repo that was created for us. And this should be in our account with the initial commit that we just made. Next up, I'm going to open this up with GitHub desktop. Clone the repo. And then I already have Cursor downloaded. So I'm just going to open this up in Cursor. So quick overview. If you're a new cursor user, we have the file tree on the left hand side. We have some quick commands so that we can open up new agents, the terminal, the browser, or just start talking to our agent right here by clicking control shift tilda. And then I'm going to install the global Versel CLI. Make sure you're in the correct repo. And then I'm going to run Versell link. I'll hit Y, enter, and it's going to ask if I want to link to chatbot 2. So, this is the deployed version. I'm just going to press enter to accept the default. Yes. And then it's going to ask me if I want to pull the environment variables now. And so, this is going to run the Verscell link command and it's going to pull down the deployed environment variables so that we can have the exact same setup that we have in production. Hit enter and it creates thev.local file and then with the versel plugin for cloud code. You can install it if you're using cloud code right now, but I'm not. So I'm just going to click no. If you install the CLI, use the link command and the env pull command. You should have av.local that looks something like this. It'll have your O secret, your blob write token, and your Versell OIDC token. Make sure to keep this secret and never expose it to anyone. Then we can run the pnmp install command and this is going to install everything from our package.json which are all the dependencies that we need and we can ignore this warning. Then we'll run pnpm db migrate to make sure that we have the latest database changes. But you can see here that we're missing the postgress URL. And this is because it's a sensitive environment variable that we'll need to populate manually. So we'll go back to the Versell dashboard. We'll go back to versell.com. Go to our chatbot project. And then we'll go to the integrations tab. And we set up neon and upstach for this. So let's first grab the neon environment variables and grab the neon champagne pebble. So, I've set this up multiple times now, but this is the one for chatbot 2. And then I'll copy the snippet and paste it into myv.local. The second integration we set up was upstash. So, let's go there, manage, click it, and then copy this snippet and also paste that into our NV.local and give it a save. So, now we can run the pnpmdv migrate command again. And this should run the migrations. And all of our migrations completed in about 5 seconds. All right. And the final command is pnpmdev. Copy that, paste it, and this is going to start our local server. And we can open it up. And by default, it creates this guest account for us using o.js. And then we can test out this is working. And it looks like everything's working properly. So we have the deployed template as well as the local template that we can now start editing. Just quickly going over the template itself. We could ignore the next versel folders and most of the important stuff is going to live in this app folder. The app folder contains our next.js layouts. So every page that you see on localhost 3000 is a file inside of the app folder. So every time you create a new chat, this is going to be rendered through this folder. And we can see some of the components it's using. So it has the app sidebar and then it has all the functionality and then the JSX which has all the layouts that you actually see including the sidebar any alerts and this is all written in React and we don't really need to touch this as AI is going to edit most of the files for us. The only other thing I'll show you is rate liimiting.ts in our library folder. And so this is going to let your guest users only send up to 10 messages, but you can bump this up to 100. All right. So now that we have this working chatbot from Verscell, we're going to start adding the hands. So going back to our body analogy, we have the body, which is the Verscell Nex.js chatbot. And now we need to adapt this chatbot to make it more useful by extending the tools that it has available to it. The chatbot can already call tools that get the weather, create nice formatting for the code blocks as well as markdown documents. And what it's doing under the hood is exposing this tool list to the agent. And throughout each message, this agent is going to decide if it should call one of the tools. And if it's relevant, like if the user mentioned weather and the message has weather, it's definitely going to call the get weather tool so that it can actually display it in a nice UI. And so now we're on this step where we give our agent a thousand plus toolkits and thousands more tools available through MCP or the model context protocol. And more on that later. So now we're going to add Compose which gives us a thousand plus toolkits through some of the most popular apps you're probably already using in your day-to-day. And it gives it to them in a really smart way that I'm really excited to show you. But before we talk about that, it's important that we talk about context windows, which is one of the most important concepts when you're building reliable AI agent. A context window is defined as the maximum amount of information measured in tokens that a large language model or an LLM can remember at one time. You can think of it like the AI's working memory or its short-term memory. And anything outside of this window will affect the response. and anything outside of it can get forgotten. So when you use a tool like cursor or chat GBT or claude and you notice that your chat is getting really long, you might have noticed that the AI gets worse. The accuracy goes down. It starts forgetting details and eventually it becomes unusable and you have to start a new chat. And you can blame the context window for this. Here are some famous context windows with GPT40 from 2 years ago hovering around 128,000 tokens. Whereas two years later, we have premier models GBT 5.5 and Opus, both around 1 million tokens, and you have other models like Kim K 2.6 with a 256,000 token limit. And since we're building AI agents, we can't help but talk about context engineering. And at its simplest definition, each tool is going to require more tokens, and each token costs more money and reduces the overall accuracy. So, when you're on a fresh chat and you're well below this 1 million token limit, you're going to find that your LLM performs great. But once you start adding more and more messages to your conversation, you're going to find that the accuracy eventually hits a point where it's unusable and you need to start a new chat. If you're creating an AI agent, you definitely want it to stay accurate and you definitely don't want it to cost more money than it needs to. We have the full technical definition here which is that context engineering is a strategic curation, management and optimization of the tokens that we feed into LLMs to make sure that outputs are high quality and relevant. It goes beyond prompt engineering by designing dynamic systems that deliver the right info, tools, and context to agents at the right time. And that's where Composio comes in. It acts as a dynamic system layer that gives your agent access to a huge toolkit catalog without ever overwhelming the context window at one given time. You can go to composio.dev/toolkits to see the 1,000 plus toolkits that we support here, ranging from Slack, Notion, GitHub, Gmail, and more. And if we peek into the Gmail toolkit, we can see that this alone adds 61 tools to the context window. So, if you were just to give your agent access to Gmail, you'd be adding all of these tool definitions into your context window on every single prompt. Now, for one connected app, that might be feasible. But if you have one, two, five, or maybe 10 apps connected to your AI agent, this is going to reduce the systems efficacy because your agent is going to have to read all of those toolkit cataloges on every single turn, even when they're not relevant. Basically, the agent only ever sees the higher level toolkit that it has available. And so, the agent's context stays small and not bloated with over a thousand plus tools that aren't relevant to it. So, in the demo, you'll see that I use Composio to fetch my latest emails. And so, it searches through the available tools, which is just JSON. It checks to see if we have Gmail authenticated, and then it gives me a link to connect my Gmail directly. Once it's connected, you'll see these tool cards rendering as the agent searches Composio for the right tool to use within Gmail. And then it's able to draft or reply using this same multi-execute tool. And this is exactly why context engineering is important. With Composeio, we only deliver the right tools and context to our agent so that it can just fetch our Gmails and just create drafts when it needs to and it doesn't have to have any information about any of the other connected apps. So to get started with Composio, we'll go to Composeio.dev. Get started. We'll go through the onboarding flow to build with Composeio and we'll just go through this. All right. So next here on the left, we'll make sure that we're on the platform. Next, we'll go to settings, API keys, and we'll create a new API key here, free code camp. And we'll grab this key. Go back to cursor and create a composio API key. We also need to go back to versell.com. Go into that same chatbot pro project. Go to environment variables and we'll add the same environment variable here. Mark it as sensitive and save. and we'll go back to cursor to start testing this out. All right. So, if you go back to the agent ready prompts section in the readme file, we can copy this part two prompt for adding composio tools and we'll copy and paste this entire thing here. We'll create a new agent and we'll paste that in. I'm going to use opus 4.7 just so this probably will get it right on the first try, but you can still use this with the auto model. So, let's talk about what this prompt contains. We're basically going to add Composeio tools to the Verscell AI SDK with a per user identity from the start. We'll keep the existing chat UI. We'll mention the context that's already there. So, we have O.js. We don't want to hardcode any user IDs. We'll make sure that guest users do not get access to any of these tools. And we'll and we'll just mention that.env.local already has a Composio API key. This second section is not necessary, but it definitely helps for when you're testing out new features. We're going to ask our agent to create a new admin page that shows us the current users integration state with the user ID, the user type, and the available toolkits that are connected. And in this final step, I'll ask it to verify some of these things, but some of these will be up to us to verify in the chat. All right, it took quite a while for all those changes to get implemented. So let's see how our agent did. We can see here that it went through a couple of steps. First, it explored the codebase by gathering enough context to answer the prompt and it looked at some of the relevant files as per the original prompt. First, we can see that it explored the codebase to gather enough context to answer the question. It looks through files, goes through Composio's documentation, and then it creates a to-do list for how it's going to implement this feature. Then it just goes step by step creating new files, wiring them into our next.js routes, and then updating our system prompt. Then the cursor agent runs a really important step. It runs the npxtsc command, which basically checks for any TypeScript errors. As you can see here, it generated a bunch of TypeScript errors, thought about how it could fix them, and then it goes one by one fixing those. Then it runs that same linting command again, sees that there's no TypeScript errors, and finishes up its to-do list. Next, I'll go through each of these files one by one. All right, so I'm doing two things when I review here. I'm reviewing the actual code to make sure that everything looks okay, but I'm also constantly cross- refferencing to the what changed file to understand the reasoning behind some of those changes. Especially when there's a large prompt, it's important to make sure that all of the steps were followed and that the AI didn't deviate too much from the original prompt. Then I'll look at this verify step here at the very end and look at the major test cases that I need to verify for myself. So first, as a regular user, we have these two test cases to make sure are working. We have the admin page we need to test and we have the guest page that we need to test. I'll go back to localhost 3000 logged in as a guest and I'll try to ask for my Gmails. As expected, our agent doesn't know that it has Composio tools because we're currently logged in as a guest user. So, it looks like this is working properly. Next, I'm going to actually log into my account. So, I'll sign up and I'll ask it the exact same prompt. use Composio to fetch my latest emails. All right, so I just tested this out on my new user asking it to use Composio to fetch my latest emails. We can see that it uses the Composio search tools and this is actually going to look up what tool it should use for fetching emails from the inbox. This contains really important things to make sure that your AI agent is going to execute the tool properly. This includes execution guidance, recommended plan steps, known pitfalls for Gmail and Outlook, how it should test for active connections to Gmail and Outlook, as well as the exact schemas that it needs to use to call certain tools from the toolkits. For example, if it were to fetch emails from your Gmail, the LLM needs to generate this exact input schema. It even contains examples, descriptions for each property like query and user ID. It also contains the type examples and a description of what that property is there for. This way when it calls the composio manage connections command, it gets it right on the first go. Then we'll click the link to connect our email to our current composio chat. After we go through this oath flow, I'll ask it again. And now the agent still maintains the context of how it should fetch emails which can then use the composial multi-execute tool using the correct tool slug which is Gmail fetch emails and then it passes the exact arguments that it needs to call this tool properly. From that the agent is going to get this JSON of results. This is going to contain all the data from this MCP tool call and it's going to give it in an easy to read format for LLMs which is going to contain all of their emails in this nice easy to read form. And for the final check, I'll go to localhost 3000/admin. And this is just going to verify my current user ID, the user type, and that I currently have a Gmail account connected. Also want to mention that if you're thinking of trying out the starter plan because you're anticipating a lot of usage, you can check out billing to check out the starter plan which gives you 10 times more usage with 200,000 tool calls per month. So you can use the code free code camp at checkout and get 1 month completely free. So what is OOTH and why do we use it with Compose? You've already seen us use OOTH throughout this app. And this happens when we click the connect Gmail link. It takes us to Google to authenticate. Google gives us the OOTH screen. And then Compose is actually storing a token for us and telling our agent that it's able to use certain tools like Gmail. This works great because there's no passwords shared with AI. It has limited scope and permissions, and you can always revoke these permissions later. So, you might be wondering, why don't I just do this myself? like I could just vibe code it. Well, the reason is that creating this from scratch is kind of annoying. Every app that you see available in Composeio already has a list of toolkits here with Gmail alone having 61 different tools. Each tool has a different format, a different description, and certain failure points that AI agents commonly run into. By using Composeio, it abstracts all of this away for us, including the token storage, refresh logic, and tool definitions. That means the user token is stored safely. The user stays authenticated so they can quickly access the tools that they've given permissions for. And all of the tools within Gmail and all the other apps that we gave permission to are defined in a clear way for the AI agent to understand. By abstracting this away to Composio, we can just focus on making our AI agent better instead of building each of these integrations one by one. Next, in the readme, we'll grab this expand the model list prompt. We'll go back to our cursor agent and paste it in. And this is basically going to add more models to our list from AI gateway as they're constantly adding new models. And so this is going to be a really simple UI fix. Here we can see that cursor actually creates a sub agent and opens up the browser. So now it's actually viewing the web page live looking at the versel AI gateway models. It's actually scrolling down manually on the web page and it's going to start grabbing individual model IDs so that it can add them to our app. All right. And so it looks like it updates our model.ts file with some GPT5, Gemini, and Claude Opus models. Looks like that's all pretty straightforward. And we can see that those are now available in our chat. And so we've actually told the cursor agent in this very specific prompt to add new models. And then cursor actually uses this really powerful tool that verifies that the model list was actually created and it creates this sub agent for us which we can check out. Basically it creates this subprompt that tells it to navigate to the local host 3000 verify the new models that it just added. It then tells it to use an inexpensive model, send a short prompt to report on what happened. So we can see here that it navigated, clicked, clicked, clicked, typed into the prompt box, and then clicked the submit button. And on any of these, we can click on them to see exactly what the UI, the cursor agent was looking at at the exact time. So we can see it waited. Then over here we can see it captured a snapshot. So we did not test this ourselves. This was purely the cursor agent typing in these things clicking into the UI for us and then verifying using screenshots that everything was working properly. I think this is absolutely crazy and this is one of my favorite features in cursor because it saves me so much time in having to click around in my web app to test that things are working. And so by telling the agent to actually verify in the UI that things are happening as they should, you're going to allow your cursor agent to create these sub agents, test changes itself, and actually verify things for you. All right. Now, we're going to just quickly inspect how the database is working. I'll ask my cursor agent to open up the database studio. I think we're using Drizzle. start it up and tell me how to open it. So, it actually starts the studio up for me. And you can see that it creates this background terminal that's now running. I'll click it to open it up over here on the left. And we can see that it's up and running right here. So, I'll follow it. So every new chat is going to get created as a row in this table. Every message for each of those chats is going to get listed in this table. And they're separated by the user and the AI assistant. And then we also have the user table. We have a different row for every time a different guest logs in. We have me over here where I actually signed up. And we have our password encrypted here on the right. All right. So, quick recap of what we've built so far. Going back to our body analogy for the agent. First, we built the body and that's the Verscell chat UI. So, this is what users can see and interact with. Then, we gave the agent hands to extend its capabilities so that it could connect to tools like Gmail, notion, and GitHub. Then we added a brain for our agent, giving it AI gateways so that it could connect to the latest AI models for the best intelligence to improve its ability to call those tools. But right now, the agent is still missing a big piece that improves the usability of the chatbot in the long term. And so this is where we introduce a tool called super memory. Supermemory is a managed memory layer for AI apps that lets the agent store, search, and recall important facts about the user across multiple conversations. Like everything else in this project, you could build this by yourself by creating a database, embeddings, search, and ranking tool. But Super Memory abstracts all of this away so that we can treat memory as another optional tool within our agent. You can check out their pricing to see how it works, but basically you get $5 of monthly usage built in, and they also have a startup and research program where you can get $1,000 of free credits. So, it's worth applying to if you want to keep building with super memory. The context window is the short-term memory, which is in a single chat. And we can think of super memory as the long-term memory of our agent. So in this section, we'll add these super memory tools, add memory, search memory, and get profile so that the agent can store and retrieve important facts for later. With super memory, your agent can store important facts like your name, preferences, projects you're working on, and other important nuances that might be important. Without this tool, memory would only live across single chats. So this is basically a memory layer that helps important information live across multiple conversations. So with super memory, we can create persistent data that lives across multiple conversations. The way that this works is pretty simple. We're going to use super memory as another tool just like we did with Composio. The model will see new tools like add memory, search memories, and get profile. And when the user says something that's worth remembering, like my name is Shawn, the model can then say, "Hey, maybe I should remember this fact for later." And add a memory into Super Memories container. Then later, if the user says something like, "Fill in this form for me," and there's a name field in that form, the chatbot should remember that the user's name is Sean and fill that in appropriately. The key thing here is that we're not storing these memories in the system message because that would be slow, expensive, and it would just ruin the overall accuracy of the agent because it would pull in these memories when they're not even relevant. Just like we talked about earlier with context engineering, this is going to give our system that dynamic ability to pull in the right information and deliver that context to our AI agent at the right time. Okay, so we can head over to our readme in the part 3 super memory section. The first thing that we need to do is go to super memory, create a new account, and grab our API key. We'll go to super memory. And we can see here an overview of the documents and memories that I've already created in my app. But we're just going to grab the API key. Create a new key. And I'll create this API key. Then we'll go to ourv.local and create a super memory API key and paste it like that. Then I'll copy this whole thing and I'll go to my Verscell dashboard. Open up my chatbot project. Go to environment variables and I'll add an environment variable and I'll paste the whole thing here and it'll autofill the API key for me and I'll save it. Okay, after that all I need to do is install the super memory tools. So I'll copy this. I'll make a new terminal and I'll paste that in. Okay, now we just need to paste the prompt three from below. I'll copy this and I'll give it to my cursor agent. The key implementation detail here is that container tags should include session user ID. And this means that our users memories should only go into their own memory bucket. And later on when we add Telegram, the Telegram bot is going to use that same user ID to make sure that memories are shared across the web app and the Telegram interface. This prompt is basically going to ask the agent to do three things. First, it's going to add super memory to the list of tool definitions. And this is where we already have tools like the Composio ones and the weather tool defined for our AI agent. Secondly, we're going to make sure that memory is only enabled for signed in users so that guests don't get long-term memory. Then, we're going to modify this system prompt rule so the model knows exactly when to store and recall memories. Okay, so now that we have the API key set up and super memory installed, we're going to grab this prompt and go back into cursor. This is basically asking the agent to do three things. First, it adds super memory to the list of tool definitions where we already have local tools like weather tool and composio tools. Then, we'll make sure that memory only gets enabled for signed in users, making sure that guest users don't get long-term memory. And then, we'll add some system prompt rule changes so the model knows when to store and recall memories. So, I'll run this and check back in with you. Now that our cursor agent is done, let's check out what it did. So, it updated our route.ts ts file to add some supermemory tools from their software development kit. And then it updated our system prompt to have some information about super memory. And then it ran some TypeScript checks and fixed its own TypeScript errors. And everything looks good to me. So I'm going to accept all of the changes. So here I've just tested out to make sure that everything's working properly. First, I asked my agent what my name was, and it called the supermemory get profile tool, and it looks like nothing showed up. Then, I gave it my name, and it added a memory for Shawn. And then I opened up a new chat, asked it that same question, what my name was. It used the super memory search memories tool, and we can open up the queries it used. So, it asked for the user's name, and then here was the result it got back. And you can see right here that I got the content and finally we get that assistant answer which is that my name is Sean. Now our agent can call durable facts across multiple conversations which can help it to feel a lot more personal. Our agent already has a lot of working pieces which has really extended its capability from where we first started. The next thing we're going to add to give it a little bit of pop, a little bit of personality is a soul. So stay tuned and I'll see you in the next section. In this section, we're going to create the soul of our AI agent. If memory is about the user and things that the chatbot learns about the user over time, this soul is the definition of our agent's personality. And soul is just a fancy word for system prompt, and it basically decides how we want our agent to act. Basically, if we say a fact about ourselves, like my name is Shawn, that should go into Super Memories memory store. But the agents name, how it likes to talk, the length of its replies, all of that should live in the soul. For this, we'll take a lot of inspiration from the soul.md file from OpenClaw. But instead of storing MD files, we're going to store the soul as a column in our database. In the final working demo, you can see that I've asked my AI agent what its name is, and it already knows that it's key, my personal agent. For this, we're going to add a new feature. if the soul hasn't been defined yet for the user, the agent should run onboarding as a conversation instead of putting some long form on the screen. So when a user has signed in and their agent has no soul yet, we're going to inject an onboarding prompt into the system prompt. The agent will then ask a couple of questions and store any user facts with ad memory and then it'll use set soul to commit the agents identity to the database. From that, we shouldn't see the onboarding prompt anymore. And the saved soul should get prepended to the system prompt on all future messages. So our system prompt is going to look a little bit different now. First we'll have the onboarding prompt and this is only going to appear if the user.soul is null. We'll have the agents identity as the first part of the prompt. Then we'll have the regular prompt and the memory rules. Then we'll have the latest chat messages. And then we'll have any of the tool definitions like the weather tools, Composio tools, and memory tools. All right. To get started here, we'll go to part 4 and all we need to do is grab the prompt over here and paste it into cursor. This prompt is a little bit bigger because it touches the UI database and it also creates a new admin page so that we can debug that everything is working. First, we're going to add some parts to the database and then we're going to generate the migration files which are basically the changes that we made to the database and then we're going to apply those migrations. Then we'll add these queries in the queries.ts ts file so that we can actually get the user soul prompt for the chatbot and we can also update it. In this section, we're just going to change how the prompt is assembled. So if the user dossole is null, we want to inject the onboarding prompt and if it's already defined, we're just going to use the saved soul as it is. We're going to create a new tool definition here which takes in the description of the soul. We're going to wire this into our chatbot so that it can then call this information. Then we'll ask the agent to create this admin page that's going to let us debug the soil on the screen and that's going to need an associated API route so that it can actually fetch that data. All right, I've already copied and pasted this into cursor and let it run for a couple minutes. It basically went ahead created a to-do list and went one by one creating the schema queries and updating the prompt. And I'm just going to review all of the files to make sure that everything makes sense here. All right, so I've started a new chat and I've just said hi. And we can see here that the agent has noticed that it's the first interaction in the conversation. So it needs to run the onboarding prompt and ask about the name, the style, and the principles. I'll go ahead and answer these. All right. So I give it a name, told it to be friendly, told it I also wanted to learn new Japanese words, and then I told it to explain if it ever makes any deviations from the original instructions. We can see that it calls the new set soul tool. So it includes all of this information that I just gave it. And then it also adds a memory to super memory so that it can remember this in the future. I'll just ask to make sure that my email functionality is still working with Composeio. And let's see how it changes with the new system prompt. It's still able to use Composeio tools to fetch my emails. It summarizes them simply and then it ends off the message with a new Japanese word. We can then verify in /admin/ aent to check out the agent's personality definition. And we can see all of this is working right here. Then I'll actually inspect how this looks like in the database. So I'll ask cursor to start the drizzle studio since I forgot what the command was. It starts it up with pnpmdb studio and I can go check it out by going to this link. All right. So we should see a new soul column if we scroll horizontally and we see right here that there's a new user soul property. So for this latest user I've have my soul defined but for all these other guest users they don't have any soul defined for their AI agent. Great. So now our agent has a soul and it can now remember facts and it also has a stable identity to use for the rest of the prompts. So user facts like memories live in super memory and the agent's personality is going to live in the user.soul column. Great. So we've built up our agent from a chatbot to an agent with tools to an agent with memory and now an agent with a personality. You might have seen popular AI tools living inside your messaging apps like iMessage. We have poke here on the left and then get Victor here on the right that lives in your Slack. And from a product standpoint, this makes sense. It's basically a distribution problem where you have to make sure that you meet your users where they already are. There are way more active smartphones in the world than laptops and desktop computers. So, if your AI agent only lives inside of a browser tab, you're making users come to you instead of putting the agent where they already spend most of their time. Since Chat GBT came out, most people have interacted with AI through a laptop. But what do you always have on you? Your phone. So in this section, we're going to make our AI agent more accessible by linking it through in the Telegram mobile app. The key idea here is that Telegram is not a separate agent. It's just another front door into the same app. It'll have that same user information, tools, and memory just living inside of Telegram. Our web app and Telegram are both going to point to the same agent runtime. And once the telegram chat is linked to our web user, both channels are going to use that same user ID to identify the user. And that's what makes this whole thing work. If I connect Gmail on the web app, Telegram can use that same Gmail connection. And if the agent remembers something, it can always call that same super memory service for the relevant context. To set this up, we're going to use the exact same workflow that other apps like OpenClaw use to connect users to messaging apps like Telegram. First, we'll use botfather, which is the official Telegram bot that gives us our bot token. Second, we're going to create a web hook secret. This is basically like a password that Telegram sends with each request so that our app can verify that the request really came from Telegram. Then, because we're running this all locally, we'll use Enro. More on that later. But after we register the web hook and link our Telegram account, we should be able to send messages to our AI agent from the app. All right. So, following the instructions on the screen here, first I'm going to open up Telegram on my iPhone. Once I have this opened up, I'm going to follow this step and search up botfather. Bot father and open up a chat. In the list of the starter commands, you can see that we can click create new bot here. So, I'll click that and I'm going to add a name for my bot. Okay. And I'll make it. So, this has to be a unique name. One, two, three. Bot. Great. Right. So, it's going to create a new bot. We can tap this to go to it. And we can also look at this token on the bottom. And we need to secure this and store this for later. I'll copy the whole message. And I'll put this on my Apple Notes so that I can open it up on my Mac. All right. So, I'll open this on my Mac. First, I'll grab this code snippet and populate it in myv.local file. The bot token is this goes up top here. The Telegram bot name is right here. And for the Telegram web hook secret, we're going to generate this in a terminal window. Open one up. And I'll copy this command. Open SSL randex 16. And I'll grab that key. and we're going to use this as our web hook secret. Okay, the next public app URL can stay like this. And then I'll go back to the terminal with my dev server running. I'll hit control C to close it. And I'll type in pnpmdev to restart the server. Great. And that should make it pick up all these new tokens. Next, we're going to set up enro. And if you already have it installed, the command is simply rue install. Then create a free account on Enro and go to dashboard.enrock.com. Then over here on our account settings, we can just grab our O token and you should treat this like a password and we're going to copy this line. go to our terminal again and we'll replace this line up until the dollar sign with our enro token and hit enter. I'm going to start a new terminal window and I'll run enro http 3000. That's going to forward all the requests to this URL to our localhost 3000. So now we'll go back into ourv.local and we'll replace the public app URL with the enro URL. Then once again we can see our dev server has reloaded the env file since we made some changes. And so if you ever find this stops working it might be because you restarted your enro server. So every single time this forwarding address is going to change and you'll have to update your ENV file. Here's a quick explanation of how the web hook is now working and why it's necessary for it for Telegram to call our app. This is the basic workflow which is that a user is going to send a message through the Telegram app. Telegram is going to send a request to the web hook URL that's points to our app and then it's going to run the agent workflow that we know and love. The reason this is important is because instead of our app constantly asking Telegram if there are new messages, we can get this one-way tunnel between Telegram and our app through the web hook URL. And remember, the reason we're using Enro here is because we need HTTPS, which is the secure version. And when we're in local development, we only have HTTP available. So that's why we use Enro. Now that Enro is set up, let's grab the agent ready prompt for this section. There are three main pieces in this prompt. First is the Telegram bot API wrapper. These are going to be some helper functions that help us to send messages, register the web hook, and check for bot info. The second is going to be the second is the actual web hook route. This is the listener where Telegram actually sends incoming messages. And the third is the linking system and this maps a Telegram chat ID to one of our app users. Once again, we have this telegram page that we have available so that we can link our telegram to the user and then we have some verification instruction. Looking over here, we have some changes to our schema.ts file. Remember, this is going to affect our database. In this part, we're going to make sure that the cursor agent runs the generate and migrate commands and this is going to create migration files and apply them so that our database sees the changes that we're making to include all these Telegram columns. Okay, so it looks like it finished its seven to-dos. It added the new Telegram database fields, ran the migrations on the database, and even added some debugging pages that we can check out. And finally, it gives a step for us that we need to verify live with the actual Enro web hook delivery, Telegram token, and do a test case to make sure everything's wired up properly. All right, so next we need to tell Telegram where our app actually lives. But Telegram still doesn't know where to send messages to connect to our bot. So let's go back to localhost 3000 and we'll open up the Telegram debug page. This is just a developer page that we're using to make sure that we've set the bot and the web hook. And it looks like we don't have the web hook set up yet. Next, let's just register the web hook. And it looks like it's not working because the HTTPS URL must be set. This actually failed for some reason. So, I passed all this information back to the cursor agent. And it looks like there was a fallback URL error. So, it goes ahead and fixes it for me. I'm going to restart my dev server. And I'll click register. I'll refresh the localhost/telegram page. And I'll try to refresh. And then I'll try registering the web hook again. All right. Looks like it's registered now. And we'll go back to cursor. So, the most important stuff is in this telegram.ts ts file where you can see that we're grabbing the web hook secret and that's this secret that we generated over here. We're also hitting this URL which is telegram web hook and it's basically this next.js route that we've defined to process it. This can be a tricky section to get right just because there's a little bit of wiring and integration going on. So, if something goes wrong at this step, make sure you have your Enro terminal running and you've copied the full URL and put it into yourv.local file. Make sure that your Telegram web hook secret is set, your bot username is set, and your bot token was set up by the botfather. And you can reset any of these steps if you think there was an error there. Another page we created was the /admin/telegram page. This is going to show us the current loggedin user and it has this button so that they can link their Telegram account. This is going to generate a one-time code for our user. So now we can link this manually on our phone now that we have this code. So I'm going to open up Telegram one more time. Go to my free code camp startbot. All right. So we'll hop back into the free code camp bot. Type in /start with the code. And then you should get a message that it was linked. Now, if I say hi, you'll see that I get messages back from my Telegram bot talking to me in Japanese like we said in the soul.md earlier. We'll let it run for a couple of seconds and then it grabs all of my emails. This is a huge product upgrade because instead of only being able to talk through the web app, people can now talk to their AI agent through the messaging app that they already use every day. In the next section, we'll add one of the most powerful OpenClaw features, scheduled jobs. I'll see you in the next one. Up until now, we've had to message our agent in a manual turn-based way. This means that unless you're constantly chatting with your agent, it isn't doing anything for you. Like most people who message chat GPT or Claude, the AI is only going to respond whenever you send a message. But to make our AI agent truly usable, our agent should act more like an employee. Once we've discussed the way that we like to do things, it should be able to go and do those things by itself on a predetermined schedule. And that's exactly what we're going to build in this section. Instead of an agent that only works when you message it, we're going to create a heartbeat for our agent. The ability for it to wake up on its own and run predefined workflows. Going back to our body analogy, we're just going to add another tool to our agent, and this is going to be the schedule task tool. These are commonly referred to as cron jobs. And to use crons, we're going to use a service called versel cron. So you can read more about versel cron jobs here. But basically this is going to call a URL on our app that runs predetermined agent workflows. The flow is the user is going to ask the agent in chat to run a workflow every single day at a specified time. The agent is going to call its schedule task tool which writes a new row in the database. And every day when Verscell Chron runs, it's going to call our AI agent. It's going to check if there's any tasks ready to be run. And then it's going to run that task and update the row in the database so that we know that it was already run. So when the user has a prompt like run this workflow daily, the model is going to see that user message, check its system prompt to see all of its tool definitions, and then it's going to call the schedule task tool so that it can add that new task to our cron jobs table. All right, so now let's go to the heartbeat section and follow all of these instructions. One important thing to mention is that on Verscell's free hobby plan, we can only run this schedule once a day. So, if you want to get per minute scheduling, we'll have to upgrade to one of their paid plans. All right, first thing we're going to do is run this command and create a new cron secret. So, I'll open a new terminal window. Paste this in. And I'll grab this code and I'll write cron secret equals that code. Then I'll also go to my versel environment variables and add this cron secret there as well. Go to our project environment variables, add environment variable, and I'll just paste this whole thing in there. Next, we'll run this command in the terminal to add the cron parser. And then we'll copy the agent ready prompt from here. And I'll open a new chat and run this. Okay, so there are three main components to this prompt. First, we're going to add this cron job table to our database. This table is going to have the ID of the task, the user that created that task, the cron expression, which defines how often they want it run, the prompt the agent is going to use when it's called, and when we want this to run at. And then, as with every change to our database, we're going to make sure we run the appropriate migrations. Then we're going to create some queries so that we can create, fetch, and update these jobs. And then we'll create three new tools for the agent to call. This way, the agent can schedule new tasks based on the user's preferences, list all of the schedules, as well as cancel schedules, all in natural language. Then we'll create the route that Versell is going to hit every single day. And finally, we'll add some simple debugging UI so we can see all the schedules and make sure that everything is working properly. So, we'll run this and I'll check in when this is done. So, it added the chat route, updated our database layer, and then it ran the database migrations, created new tools for our agent, and then it just wired everything together for us. Looks like everything's good. And then I just added one more follow-up prompt, and I asked it to wire the admin schedules into the user settings tab. Let's go check out the changes. If we go to the settings, it added this new schedules tab. And we can see that for the user, they have no scheduled tasks yet. And I'll say, "Every day at 9:00 a.m., look at my last five emails and create a summary." Great. So, it looks like it calls the new schedule task tool. It creates the chron expression, and this just means every day at 9:00 a.m. We can see the full prompt that it used with the right level of details. We can see that it was successfully created and then the agent gives us a summary. Let's hop back into our schedules and we can see the new scheduled task appear there. If we look at our last output, there's nothing there yet. And then if we hop into our database, we can see that this new scheduled task with all the right information has shown up in the database. All right. So, I'll go back to the admin tab and I'll just run this manually so that we don't have to wait for 9:00 a.m. to see how this looks. And we'll give this a couple of seconds as this is running in the background. And we get a summary of our last five emails. And it still has our agent personality there giving us a Japanese word. Over in the database, if we give it a refresh, we're going to see that the last output column is going to update. And this also has the exact same information there. All right. And let's do one final test. Let's make sure that we can delete the schedule. I'll go back to my agent and say delete all my scheduled tasks. All right. First, it lists the schedules so it can grab this ID. And then it cancels the schedule with the same ID and confirms that they're gone. Let's go check out and confirm that. And there's no more scheduled tasks here. And in the database, there's no more scheduled tasks. All right. So, all we need to do to get this production ready is to update our Telegram web hook to our actual domain. To grab your domain, go back to Verscell, find your project, and then grab this URL, copy it, and I'll go back to my next public app URL and put it there without the backslash. Same thing on the production environment variables. You can copy this, paste it here. And so this is going to point to your actual domain. And give it a save. In this last section, I put together a quick checklist for making sure you have all the right API keys, how to generate your web hook secrets and cron secrets. And so if any of your services fail, it's usually an environment variable issue. So just go and double check and regenerate those if needed. Then we'll go back into the chatbot. There's a bunch of changes here. So we're going to commit all of these to GitHub. Now I'm just going to commit I'm just going to stage all of these changes to GitHub. I'll call it initial commit and give it a commit and push. If we hop back into the project on RCL and we go to the deployments tab, we should see that it's building that new deployment. And this should take a couple of minutes to fully deploy. Another thing you should be aware of is that every single time you change your environment variables, your app will not redeploy. So, just make sure that when you do that, you go back to your deployments and you can click here and you can always redeploy to get your latest environment variables. All right, I hope you enjoyed the tutorial. If something breaks, feel free to open up an issue on GitHub or send me a DM on Twitter and I'll help you debug it. The point of this tutorial wasn't to build openclaw feature for feature. It was to teach you about the fundamentals around how AI agents work under the hood. At Composio, we also released another productionready version of this same chatbot and it's called trustclaw.app and you can view the source code for it on GitHub and actually deploy this for yourself on Verscell. It's built on the exact same tech stack he used in this video, Composio, Verscell AI, Postgress, Telegram, and cron. Anyway, that's it for this tutorial. Thanks so much for staying until the very end. And as mentioned, all the links and resources will be in the description for you to check out and clone the templates.
Generated algorithmically for Search Engine
Indexing.