Skip to main content
Article·georgelarson.me
ai-agentsinfrastructuredeploymentopen-sourceautomationircvps

Show HN: I put an AI agent on a $7/month VPS with IRC as its transport layer

Deploy an AI agent on a $7/month VPS, using IRC as a lightweight communication layer. This enables cost-effective AI agent operation, demonstrating resource-efficient deployment for modern applications.

intermediate1 hour5 steps
The play
  1. Provision a Linux VPS
    Acquire a low-cost Virtual Private Server (VPS) with a Linux distribution (e.g., Ubuntu, Debian). Ensure SSH access is configured for remote management.
  2. Install Python and IRC Library
    Connect to your VPS via SSH. Install Python 3 and the `irc` library using pip: `sudo apt update && sudo apt install -y python3 python3-pip && pip install irc`
  3. Create Your AI Agent Script
    Write or adapt your AI agent's core logic. Use the provided `starter` code as a base, integrating your agent's functionality into the `do_command` method or similar event handlers.
  4. Configure and Run the IRC Agent
    Modify the `server`, `channel`, and `nickname` variables in your Python script (e.g., `ai_irc_bot.py`) to match your desired IRC network. Run the script in the background using `nohup`: `nohup python3 ai_irc_bot.py &`
  5. Interact with Your Agent via IRC
    Join the specified IRC channel using any IRC client. Address your bot by its nickname followed by a command (e.g., `AIBot: ping`) to test its responsiveness and functionality.
Starter code
import irc.bot
import irc.strings
import time

class SimpleBot(irc.bot.SingleServerIRCBot):
    def __init__(self, channel, nickname, server, port=6667):
        irc.bot.SingleServerIRCBot.__init__(self, [(server, port)], nickname, nickname)
        self.channel = channel

    def on_nicknameinuse(self, c, e):
        c.nick(c.get_nickname() + "_")

    def on_welcome(self, c, e):
        c.join(self.channel)
        c.privmsg(self.channel, "Hello, I'm online!")

    def on_privmsg(self, c, e):
        # For private messages directly to the bot
        self.do_command(e, e.arguments[0])

    def on_pubmsg(self, c, e):
        # For messages in a channel, check if bot is addressed
        a = irc.strings.lower(e.arguments[0]).split(":", 1)
        if len(a) > 1 and irc.strings.lower(a[0]) == irc.strings.lower(self.connection.nickname):
            self.do_command(e, a[1].strip())
        return

    def do_command(self, e, cmd):
        nick = e.source.nick
        c = self.connection
        
        # --- Integrate your AI agent's logic here ---
        if cmd == "ping":
            c.privmsg(nick, "pong")
        elif cmd == "help":
            c.privmsg(nick, "Commands: ping, help, echo <message>")
        elif cmd.startswith("echo "):
            message = cmd[len("echo "):]
            c.privmsg(nick, f"You said: {message}")
        else:
            c.privmsg(nick, f"Unknown command: {cmd}")
        # ------------------------------------------

def main():
    # !!! REPLACE THESE WITH YOUR IRC SERVER DETAILS !!!
    server = "irc.libera.chat" # Example: irc.libera.chat
    channel = "#your_channel"   # Example: #mybotchannel
    nickname = "AIBot"          # Your bot's nickname

    bot = SimpleBot(channel, nickname, server)
    bot.start()

if __name__ == "__main__":
    main()
Source
Show HN: I put an AI agent on a $7/month VPS with IRC as its transport layer — Action Pack