AI Slack Bots - Juggling Multiple Bot Personas
Tags: openai, slack, development, php
Published: 2023-05-22 21:53:07

I'm thrilled to share a little project I've been working on, something that climbed into my head and refused to leave until I built it. It's called [AI-SlackBot](https://github.com/tony3dmc/ai-slackbot/), and it's designed to inject a dash of AI-fuelled debate and joviality into your Slack workspace.

# Exploring the Potential of Multiple Vantage Points

During early testing of the ChatGPT browser plugin, a few of us were intrigued by the idea of digesting news stories from the web and presenting them back in different styles, like a news reporter with a specific personality. One of our cohort came up with the concept of a virtual newsroom of three reporters with different perspectives. We generating scripted discussions between them on a news story. It was hilarious, but it was also a fun way of cross-verifying a source from multiple vantage points to get a broader perspective.

I've always tinkered with building chatbots in my past, I created my first one in IRC when I was a kid, performing [Markov Chain](https://en.wikipedia.org/wiki/Markov_chain) computations to create funny responses to user messages, based on the same language used by the chatroom participants.

It set me off thinking - chatbots are cool, but what about teams of chatbots with their own personas interacting with each other? Epic.

## The Magic of The Persona

Imagine a Slack workspace with a background cast of bot characters, each with its own unique personality. These bots are not merely responding to our inputs, but also interacting with each other, creating a dynamic and fun environment.

What makes this project particularly exciting is the concept of persona definitions. Think of a persona as the identity or character that the bot adopts when interacting within the workspace. This project allows for multiple personas to exist at once, each with its own distinct characteristics. These personas interact with one another, creating a dynamic, multi-dimensional conversation. 

## The Power of the System Prompt

One of the cool features of the GPT API is the concept of a "system" prompt. This is the first message in the chat completion list, which contains a set of instructions that define the identity and behavioral traits of the assistant.

Each bot persona is defined in a YAML file, which includes the system prompt, a Slack OAuth token, and an App ID. This allows the bot to have its own unique user presence in the workspace

Let's take a closer look at an example:

```yaml
name: 'Natalie'
app_id: '...'
slack_oauth_token: '...'
system_prompt: |
  I want you to act as a Slack chat bot.
  You are Natalie, an enthusiastic community manager for a group of developers at a software development company.
  You respond to messages with an upbeat and friendly attitude.
  You look like Captain Marvel.
  You like to flirt a little in your responses.
  When you provide facts, they are often wrong.
  Your responses are short.
response_rules:
  - rule_type: 'default'
    chance: 0.1
  - rule_type: 'text_contains'
    value: 'help'
    chance: 0.75
  - rule_type: 'text_ends_with'
    value: '?'
    chance: 0.5
```

In this example, we're designing a persona named Natalie. She's envisaged as an enthusiastic community manager for a group of developers at a software development company. Natalie has an upbeat and friendly attitude, and flirts a little in her responses. Interestingly, the facts she provides are often incorrect, adding a layer of humor and unpredictability to her interactions.

Natalie also follows a set of rules that determine how she responds. For example, she has a 10% chance of responding by default, but that increases to 50% if the message ends with a question mark - or 75% if someone mentions "help".

But for every Natalie, there needs to be a Greg :)

```yaml
name: 'Greg'
app_id: '...'
slack_oauth_token: '...'
system_prompt: |
  I want you to act as a Slack chat bot.
  You are Greg, a nerd with an obsession with fact-checking people.
  You are surly and abrasive.
  You look like a grumpy nerd with glasses.
  You love science fiction.
  You despise Natalie.
  Your responses are short.
response_rules:
  - rule_type: 'speaker'
    value: 'Natalie'
```

And when they kick off...

![Natalie and Greg chatting](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/78s31rgrpnuq18zu0ufq.png)

## Setting the Stage

Getting AI-SlackBot up and running requires a few technical steps, such as cloning the repository to a public-facing url that you can give to Slack, installing dependencies, and configuring the bot's settings. You'll also need to set up a Slack App and create a persona file for each bot character you want to introduce into your workspace. The instructions in the README should be pretty comprehensive, but let me know of any shortcuts to streamline setup.

Pull requests always welcome, hit me up if you need help installing :)

## Embracing the Conversation

I hope you'll enjoy experimenting with AI-SlackBot as much as I enjoyed creating it.


![Did you know koalas are pretty athletic?](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/y21emd85ym3w7wykmn7f.png)



How about we turn this comment section into an AI persona brainstorm? Can't wait to see what personalities you come up with!