Put your AI Agents on a VPS… trust me

Put your AI Agents on a VPS… trust me

How to Self-Host Your AI Agents

Introduction to Self-Hosting

  • David Andre introduces the concept of self-hosting, which involves running applications on a server that you control, contrasting it with cloud-hosted solutions.
  • Key benefits of self-hosting include full data control and privacy, affordability compared to cloud solutions, and ease of migration for your AI agents.

Building an AI Agent in Python

  • David explains what a Virtual Private Server (VPS) is: a remote Linux server with dedicated resources on a shared machine.
  • He emphasizes that building an AI agent can be done without frameworks; even beginners can utilize AI tools for coding assistance.

Project Setup

  • The project involves creating an agent that scrapes the Hacker News front page daily and saves the top 10 posts into a markdown file for later review.
  • David uses Codex to create a project folder structure and generate necessary Python files quickly.

Testing the Project Locally

  • After setting up the environment, he demonstrates how to run the script locally using commands suggested by Codex.
  • The initial version successfully scrapes Hacker News without errors, showcasing the efficiency of modern AI coding assistants.

Enhancing Functionality with LLM

  • To improve insights from scraped data, David plans to integrate a reasoning model instead of just relying on basic outputs from typical models.
  • He discusses using Perplexity for deep research while organizing project documentation effectively within his workspace.

Version Control Setup

  • As part of best practices, he initializes a GitHub repository and creates a .gitignore file to manage sensitive information securely.

Setting Up a Git Repository and Environment Variables

Importance of Ignoring Environment Variables

  • It is crucial to ignore environment variables like the Open Router API key in Git to avoid tracking sensitive information, which is considered a bad practice.

Initializing Git for Project Tracking

  • The speaker stages all files using git add . and commits them with git commit -m "first commit", emphasizing the importance of version control even without using GitHub.

Integrating AI Insights into the Scraper

Updating Project Files

  • After copying necessary data, the speaker updates the project by instructing Codex to read from open router.mmd and append insights from Hacker News stories.

Transforming Data into Actionable Insights

  • The goal is to analyze Hacker News stories for actionable insights related to AI trends, effectively turning a simple scraper into an AI agent that generates unique reports.

Benefits of Automated Reporting

Keeping Up with Trends

  • By collecting reports over time, users can quickly catch up on AI developments, ensuring they remain informed even after breaks from following news.

Building on Existing Knowledge

  • The speaker encourages viewers that by mastering these skills, they will be ahead in building and self-hosting AI agents on their own VPS.

Testing Locally Before Deployment

Preparing for Local Testing

  • Prior to deploying the agent on a VPS, local testing is essential. This includes reinstalling dependencies listed in requirements.txt.

Handling API Keys Securely

  • Users are advised to create an Open Router account and generate an API key while treating it as confidential information akin to passwords.

Debugging Issues During Execution

Identifying Errors in Code Execution

  • When running the script results in errors, troubleshooting involves checking logs and adjusting parameters such as proxy settings or reasoning effort levels for efficiency.

Enhancing Debugging Information

  • Adding print statements during execution helps provide real-time feedback about what the program is doing, aiding debugging efforts significantly.

Analyzing Results from Hacker News

Extracted Insights Overview

  • The analysis yields substantial insights regarding trends like "AI infra consolidation" and "inference moves to the edge," highlighting significant shifts in technology usage patterns.

Potential Applications of Generated Reports

  • Users can leverage generated reports for various purposes including consulting services or social media automation based on trending topics identified through analysis.

Self-hosting Your AI Agent

Choosing a VPS Provider

  • Recommendations are made for selecting Hostinger's KVN2 plan due to its suitability for running long-term projects at an economical rate with added benefits like free domains when opting for longer commitments.

How to Set Up Your VPS for AI Agents

Selecting and Setting Up the Server

  • The process begins with selecting a server location that is closest to you, followed by completing the checkout process.
  • After checkout, users are redirected to their Hostinger panel where they can manage their Virtual Private Server (VPS).
  • SSH (Secure Shell) is introduced as a protocol for securely accessing remote computers through the terminal, crucial for managing AI agents.

Importance of SSH in Managing AI Agents

  • SSH provides remote control over the server from any location, ensuring secure communication through encryption.
  • File transfer capabilities via SSH allow users to upload large files or models generated by AI without issues.

Deploying the AI Agent on Hostinger VPS

  • To deploy an AI agent, necessary details such as VPS specifications and SSH access information must be gathered.
  • Users are advised to keep passwords secure and change them after initial setup to prevent unauthorized access.

Accessing the Server via Terminal

  • Instructions are provided on how to connect to the server using terminal commands after copying root access credentials.
  • Once connected, users can navigate directories and create new folders for organizing projects related to their AI agents.

Installing Prerequisites on Ubuntu

  • Users need essential packages like Python and pip installed; updates are performed using terminal commands.
  • The speaker emphasizes that even those unfamiliar with VPS management can effectively use it with basic knowledge of AI tools.

Copying Local Projects to VPS

  • SCP (Secure Copy Protocol), based on SSH, is highlighted as a method for securely transferring local projects onto the server.
  • The importance of having minimal maintenance due to Hostinger's pre-installed dependencies is noted, making it easier for users.

Setting Up a Virtual Private Server (VPS) for AI Projects

Initial Command Setup

  • The speaker updates the command for connecting to the VPS, emphasizing the speed of Codex in generating commands.
  • After copying the new command, they clarify that it must be run in a new terminal rather than SSH. They proceed to connect to the VPS again through SSH.

File Transfer and Environment Setup

  • The process involves pasting the password again to initiate file transfer to the VPS, which is facilitated by Hostinger's 100 GB storage on their KVM2 plan.
  • Once connected, they navigate into a newly created folder and activate a Python virtual environment using python -m venv.

Running AI Insights

  • The speaker runs a script (python scripts/run_digest) that fetches data from Hacker News and generates AI insights directly on the VPS.
  • They highlight that operations can be performed remotely via SSH, illustrating self-hosting benefits where tasks can run independently of local hardware.

Automating Tasks with Cron Jobs

  • To automate running tasks, they SSH back into the VPS and use crontab -e to open the cron job editor.
  • The speaker advises selecting 'nano' as it's user-friendly for first-time users. They guide viewers on navigating within nano to add commands for scheduled tasks.

Saving and Verifying Cron Jobs

  • After pasting in commands with an API key for daily execution at 9:00 AM, keyboard shortcuts are used (Ctrl O to save and Ctrl X to exit).
  • Finally, they verify that the cron job has been successfully created by executing crontab -l, confirming automation setup.
Video description

Host your AI agents on Hostinger: https://www.hostinger.com/david PS: use code DAVID to save money ;) (Don't miss the black friday deal) Wanna master AI coding? Go here: https://www.skool.com/new-society Video Editors, I'm hiring! Apply here: https://www.vectal.ai/jobs Follow me on Instagram - https://www.instagram.com/davidondrej1/ Follow me on Twitter - https://x.com/DavidOndrej1 Self host AI Agents on a VPS www.vectal.ai