Skip to content

ykundesu/DisAgent

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

16 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

DisAgent - Discord AI Agent Bot

DisAgent is an AI agent bot that runs on Discord. It can automatically execute complex tasks using various tools (Web Search, HTTP requests, and Discord operations).

Features

  • πŸ€– AI Agent System: Completes tasks via an autonomous loop.
  • πŸ”§ Tool Calling: Web search, HTTP requests, and Discord operations.
  • πŸ“Š Multi-AI Provider Support: OpenRouter, Cerebras, Anthropic, and Google.
  • πŸ’¬ Streaming Responses: Displays thinking process and execution in real-time.
  • πŸ“œ Conversation History: Continue discussions using the /reply command.
  • ⏱️ Rate Limiting: Prevents excessive usage.

Supported AI Providers

  • OpenRouter: Access numerous models including Claude, GPT-4, and Gemini.
  • Cerebras: High-speed Llama models.
  • Anthropic: Claude 3.5 Sonnet, Claude 3 Opus.
  • Google: Gemini 1.5 Pro, Gemini 1.5 Flash.

Setup

1. Prerequisites

  • Node.js 18.x or higher
  • Discord Bot Token
  • API Key(s) for at least one AI provider

2. Creating a Discord Bot

  1. Go to the Discord Developer Portal.
  2. Create a new application.
  3. In the "Bot" section, create a bot and copy the token.
  4. Under "OAuth2" β†’ "URL Generator," select the following scopes:
    • bot
    • applications.commands
  5. Select the following Bot Permissions:
    • Send Messages
    • Embed Links
    • Read Message History
    • Manage Channels
    • Manage Messages
    • Manage Roles
  6. Invite the bot to your server using the generated URL.

3. Project Installation

# Clone the repository (or copy the code)
cd DisAgent

# Install dependency packages
npm install

4. Setting Environment Variables

Create a .env file and set the following values:

# Discord Bot
DISCORD_BOT_TOKEN=your_bot_token_here
CLIENT_ID=your_application_client_id_here
DISCORD_GUILD_ID=your_guild_id_here  # Optional: set for immediate command updates

# AI Providers (At least one required)
OPENROUTER_API_KEY=your_key      # https://openrouter.ai/keys
CEREBRAS_API_KEY=your_key        # https://inference.cerebras.ai/
ANTHROPIC_API_KEY=your_key       # https://console.anthropic.com/settings/keys
GOOGLE_API_KEY=your_key          # https://makersuite.google.com/app/apikey

# Tool API Keys (Optional)
GOOGLE_SEARCH_API_KEY=your_key  # https://developers.google.com/custom-search/v1/overview
GOOGLE_SEARCH_ENGINE_ID=your_id # https://cse.google.com/cse/
BRAVE_SEARCH_API_KEY=your_key   # https://api.search.brave.com/

# Image Related
MAX_IMAGE_BYTES=5242880         # Max image size (bytes)
MAX_IMAGE_COUNT=4               # Max images per request
OPENROUTER_IMAGE_MODEL=your_image_model_id  # Uses openai/dall-e-3 if unset

# GitHub App
GITHUB_APP_ID=your_github_app_id
GITHUB_APP_PRIVATE_KEY=your_private_key_or_base64  # Escape newlines with \\n

# Settings
DEFAULT_PROVIDER=openrouter
DEFAULT_MODEL=gpt-4-turbo
RATE_LIMIT_REQUESTS_PER_MINUTE=10

How to get CLIENT_ID:

  • Found in the "General Information" tab of your application page in the Discord Developer Portal.

5. Launching the Bot

npm start

Usage

Commands

/agent - Execute the Agent

Starts a new agent session.

/agent prompt:"Search for and summarize the latest AI news"
/agent prompt:"Please create a new channel" provider:anthropic
/agent prompt:"Check the weather" model:gpt-4-turbo temperature:0.5

Parameters:

  • prompt (Required): Request for the agent.
  • provider (Optional): AI Provider (OpenRouter, Cerebras, Anthropic, Google).
  • model (Optional): Model to use.
  • temperature (Optional): Temperature parameter (0.0 - 1.0).
  • image1 to image4 (Optional): Image attachments (Up to 4).

/reply - Continue Conversation

Continues from the previous conversation.

/reply prompt:"Tell me more in detail"

/help - Show Help

Displays available commands and features.

/list-models - List Available Models

Lists configured AI models and providers.

/list-models

/history - View Conversation History

Displays the conversation history for the current channel.

/history

Available Tools

The agent can utilize the following tools:

πŸ” Web Search (web_search)

Searches for information on the web.

Example:

/agent prompt:"Search for the latest technology news"

🌐 HTTP Request (fetch)

Sends HTTP requests to any URL. Returns Base64 for image URLs.

Example:

/agent prompt:"Fetch https://api.github.com/repos/octocat/Hello-World"

πŸ’¬ Discord Operations (discord_ops)

Allows creating, updating, or deleting Discord channels, messages, and roles. Can also post images (sent as attachments).

Example:

/agent prompt:"Read the information of this channel"
/agent prompt:"Please create a new role"

Note: Discord operations require appropriate permissions.

πŸ–ΌοΈ Image Generation (image_generate)

Generates images via OpenRouter.

Posting generated images (Auto-execution by AI):

  1. Generate with image_generate and get the generatedId.
  2. Pass type: "generated" in the attachments of create_message in discord_ops.
  • External images can be attached via type: "url".

Security: Generated images are saved locally; only images generated within the same channel can be attached.

Example:

/agent prompt:"Paint a sunset at the beach" model:gpt-4o-mini

🧩 GitHub Read (github_read)

Retrieves repository/Issue/PR/Release information using a GitHub App.

Example:

/agent prompt:"Set up GitHub integration installationId=123456 defaultRepo=owner/repo"
/agent prompt:"Show me the latest Issues"

Agent Behavior

  1. Thinking: The agent understands the request and creates a plan.
  2. Tool Execution: Automatically calls necessary tools.
  3. Result Analysis: Analyzes tool output and decides the next action.
  4. Complete or Continue: Loops until the goal is achieved.
  5. Summary: Summarizes and shares the final results.

Configuration

Model Configuration

Available models can be configured in config/models.json:

{
  "providers": {
    "openrouter": {
      "name": "OpenRouter",
      "models": [
        {
          "id": "anthropic/claude-3.5-sonnet",
          "name": "Claude 3.5 Sonnet",
          "supportsTools": true,
          "context": 200000
        }
      ]
    }
  }
}

Rate Limiting

Set rate limits in .env:

RATE_LIMIT_REQUESTS_PER_MINUTE=10

Default is 10 requests per minute.

GitHub App Configuration

  1. Create a GitHub App and install it with necessary (read) permissions.
  2. Set GITHUB_APP_ID and GITHUB_APP_PRIVATE_KEY in .env.
  3. Use set_config within the github_read tool via /agent to save the installationId and defaultRepo for each guild.

Troubleshooting

Bot is not responding

  1. Verify the Discord Bot Token is correct.
  2. Ensure the bot is invited to the server.
  3. Check if the bot has been granted the necessary permissions.

API Error

  1. Verify the API key is correct.
  2. Ensure the API key has the correct permissions.
  3. Check if you have reached API usage limits (rate limits).

Command not found

  1. Check if the bot is running correctly.
  2. Confirm that commands are registered (check the logs at startup).

Project Structure

DisAgent/
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ bot.js                 # Main Discord bot file
β”‚   β”œβ”€β”€ commands/              # Slash commands
β”‚   β”‚   β”œβ”€β”€ agent.js
β”‚   β”‚   β”œβ”€β”€ reply.js
β”‚   β”‚   β”œβ”€β”€ help.js
β”‚   β”‚   β”œβ”€β”€ list-models.js
β”‚   β”‚   └── history.js
β”‚   β”œβ”€β”€ agent/                 # Agent system
β”‚   β”‚   β”œβ”€β”€ agent.js
β”‚   β”‚   └── prompts.js
β”‚   β”œβ”€β”€ providers/             # AI providers
β”‚   β”‚   β”œβ”€β”€ base.js
β”‚   β”‚   β”œβ”€β”€ openrouter.js
β”‚   β”‚   β”œβ”€β”€ cerebras.js
β”‚   β”‚   β”œβ”€β”€ anthropic.js
β”‚   β”‚   β”œβ”€β”€ google.js
β”‚   β”‚   └── index.js
β”‚   β”œβ”€β”€ tools/                 # Tools
β”‚   β”‚   β”œβ”€β”€ base.js
β”‚   β”‚   β”œβ”€β”€ web-search.js
β”‚   β”‚   β”œβ”€β”€ fetch.js
β”‚   β”‚   β”œβ”€β”€ discord-ops.js
β”‚   β”‚   └── index.js
β”‚   β”œβ”€β”€ streaming/             # Streaming handling
β”‚   β”‚   └── stream-handler.js
β”‚   β”œβ”€β”€ utils/                 # Utilities
β”‚   β”‚   β”œβ”€β”€ logger.js
β”‚   β”‚   └── message-formatter.js
β”‚   └── rate-limit.js          # Rate limiting
β”œβ”€β”€ config/
β”‚   └── models.json            # Model settings
β”œβ”€β”€ .env                       # Environment variables (Copy from .env.example)
β”œβ”€β”€ .env.example               # Env variable template
β”œβ”€β”€ package.json
└── README.md

Security

  • Never share your .env file.
  • Do not include the .env file in public repositories like GitHub.
  • It is recommended to add .env to your .gitignore.
  • Keep bot permissions to the minimum necessary.

Contributing

Please open an Issue for bug reports or feature requests.

License

ISC

Support

If you encounter any issues, please open an Issue.


Note: This bot is an experimental project. Use with caution for critical tasks.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published