Documentation

Integrating kagent with Discord

Kagent enables you to create AI agents that run inside your Kubernetes cluster. They can access a variety of built-in tools, fetch data from your memory, and use other external tools via MCP.

This guide shows how to connect a Discord bot to one of your agents using the A2A protocol, enabling natural conversations and command execution inside Discord.

GitHub Repository: lekkerelou/kagent-a2a-discord

We’ll walk through:

  1. Setting up a Discord bot.
  2. Connecting it to a kagent agent via A2A.
  3. Running and testing the integration locally or in Docker.

Creating a Discord Bot

  1. Visit the Discord Developer Portal
  2. Click New Application, give it a name, and save.
  3. Go to the Bot tab → Reset Token and save the Discord Bot Token
  4. Under Privileged Gateway Intents, enable Message Content Intent. This allows the bot to receive Discord message content.
  5. Copy your bot token, you'll need it for your .env file.

Under the OAuth2 → OAuth2 URL Generator, check:

  • bot under scopes
  • Send Messages, Read Message History under bot permissions

Make sure the "Integration Type" is set to Guild Install.

Use the generated URL to invite your bot to your server.


Setting up the bot code

  1. Clone the repository:
git clone https://github.com/lekkerelou/kagent-a2a-discord.git
cd kagent-a2a-discord
  1. Copy the example environment file and fill in your values:
cp .env.example .env

Edit .env:

DISCORD_BOT_TOKEN=your_token
KAGENT_A2A_URL=http://127.0.0.1:8083/api/a2a/kagent/my-k8s-agent
  1. Create and activate a virtual environment:
uv venv
  1. Install dependencies:
uv sync
  1. Run the bot:
uv run main.py
# or
python main.py

You should see logs indicating the bot is online.


Running with Docker

If you prefer Docker, you can use the pre-built image:

docker pull ghcr.io/lekkerelou/kagent-a2a-discord:latest
docker run --env-file .env ghcr.io/lekkerelou/kagent-a2a-discord:latest

You can also build the image locally if needed:

docker build -t a2a-discord-bot .
docker run --env-file .env a2a-discord-bot

Bot Behavior

The bot listens to messages in all channels unless restricted by environment variables.

Optional .env keys

You can customize the bot's behavior with the following optional environment variables:

  • DISCORD_MENTION_ONLY: Set to true to make the bot respond only when mentioned.
  • DISCORD_CHANNEL_ONLY: A comma-separated list of channel IDs where the bot is allowed to respond.

When a message is received, it’s sent to the A2A endpoint (KAGENT_A2A_URL), and the agent’s response is posted back in Discord.


Agent Setup

If you haven’t deployed your agent yet, follow the instructions in Deploying an Agent. You can reuse the same agent across Slack and Discord integrations.

Be sure to port-forward your agent if running locally:

kubectl port-forward -n kagent svc/kagent-service 8083:8083

Set KAGENT_A2A_URL accordingly in your .env:

http://127.0.0.1:8083/api/a2a/kagent/my-k8s-agent

Conclusion

You now have a working Discord bot connected to your kagent agent via A2A. From here, you can:

  • Customize the bot behavior
  • Extend the agent with new tools
  • Deploy in production

For questions or support, join our Discord community, or open an issue on GitHub.