Custom chatbots made easy: How to build your own ChatGPT agents

Steffen Bewersdorff
Posted by Steffen Bewersdorff

4 minutes read

Ever wanted to create your own chatbot but felt overwhelmed by the complexity? That's why I built SiegfriedAI – a sleek Node.js script that makes it easy to create and load custom GPT-4 chat agents. Learn how to use it and make it your own!

How to build your own GPT-4 agents using SiegfriedAI.

The problem:

Prompts are temporary

ChatGPT can be powerful in helping with very specific tasks like the following:

  • Customer Support: Formulating well written response emails.
  • Development: Helping to answer technical questions.
  • App Support: Helping to find functionalities, like shortcuts.
  • Productivity: Summarising meeting notes and making them actionable.
  • Content Marketing: Creating variations of blog post or video titles.

But to get quality responses, you need to give context to ChatGPT by providing a concise prompt. That’s why I am keeping a list of my day to day prompts in my notes app. Whenever I need a prompt, I open a new conversation in ChatGPT and paste the template. But that’s quite a repetitive process.

There should be a sustainable way to organize, optimize and launch prompt templates as context-aware ChatGPT agents.

Me, Oct. 2023

So I built a tool for that

I developed a lightweight CLI interface for text-based prompt templates. It allows to create, load and interact with custom ChatGPT agents by providing custom GPT prompts in plain text files. Meet SiegfriedAI. 🧔‍♂️👋

To install the CLI tool and learn a few tips, head over to the GitHub repository:

SiegfriedAI - Usage Example

What you’ll get

SiegfriedAI is free and open source. With just 2 kB in size, it’s a compact script that you can easily adapt and extend to your needs. In its simplistic nature, the feature list is small and focused:

Task specific chat agents

Tackle specific, recurring tasks with custom chat agents. Whether it’s customer support, technical assistance or content creation, keep your favorite prompts organized and readily available at your fingertips.

Fast template creation

Simply drop your text files with GPT prompts into the templates folder to create your custom chat agents. The file name will automatically be displayed in the selection prompt. Create as many specialized agents as you like.

A powerful tool belt

Easily build sophisticated AI solutions on top. With just 74 lines, the script is quick to understand and easy to extend. And with langchain, you are prepped with a powerful toolset to load files, crawl websites, generate images and more.

Understanding the tech

While OpenAI provides a wealth of information on their website, I wasn’t sure what I needed to know to get up and running. Here’s what I learned building the tool, hopefully giving you a head start:

The API toolkit

SiegfriedAI is built with langchain, a framework for developing LLM applications. Beyond providing a simple API and great documentation, langchain includes powerful integrations like document loaders, web loaders, vector stores, action agents, output parsers and more to develop sophisticated AI solutions.

Generating chat completions

Sending a message to the OpenAI API and generating a response is simple:

  1. Create an OpenAI API key here.
  2. Set your API key as an environment variable:
    export OPENAI_API_KEY=you_openai_api_key_here
  3. Install the langchain library:
    npm install -S langchain

Create and run your first chat completion:

import { ChatOpenAI } from "langchain/chat_models/openai";

const model = new ChatOpenAI();
const message = "Name something green.";
const aiResponse = await model.predict(message);

console.log(aiResponse); /* Grass */

Providing chat history for context

To get a proper context-aware chat experience, the AI needs to keep track of the chat history. However, OpenAI doesn’t maintain a history of the chat. Instead, you need to send back the full chat history with every new request. While this seems low-level, it makes it simple to work with.

let messages = [
  ["human",  "Name something green."],
  ["ai",  "Grass."],
  ["human",  "What did you say?"]

const aiResponse = await model.predictMessages(messages);

console.log(aiResponse); /* I said "Grass." */

Providing templates as instructions

I’m using Inquirer.js for the template selection and to allow multiline input via editor. It’s easily embeddable and provides a prettier command line interface.

import { select, input } from '@inquirer/prompts';

const template = await select({
  message: 'Select your template:',
  choices: [{
      name: 'ChatGPT',
      value: ''
    }, {
      name: 'Final Cut Pro',
      value: 'Act as a support agent who is an expert in Final Cut Pro for Mac. Only respond with short, precise, helpful messages to my questions.',

The template shall be passed to OpenAI as a system message, which is then followed by user input. The model will then respond with the specified behavior.

let messages = [
  ["system",  template],
  ["human", await input({ message: 'You:' })]

For the full script, please refer to the GitHub repository: steffenbew/siegfried-ai


Developing SiegfriedAI has amazed me – working with AI dev tools is a creator’s dream! Who would’ve guessed chatbot creation could be so simple and fun?

The great developer experience and immense potential that AI developer tools bring to the table are a signal that there’s a big wave of AI advancements coming our way. Witnessing this firsthand, I am buzzing with anticipation for the progress we see in this space.

For anyone looking to get their hands on AI development, I hope to have sparked some curiosity and encouragement! I can’t wait for you to experience it yourself.

PS: I’m still looking for great prompts! Which ones make your life considerably easier? Any that elevate your craft to new heights? Please share your favorite ones by dropping me an email – I’d be excited to hear from you!

PPS: Drop by our YouTube channel for more insights: Siegfried, deploy!

More Posts

We help your WordPress website and business stay ahead of the curve.

Contact Us