Discord Agent Builder Gaming Bot
Building a Gaming Community Support Bot with Discord and Elastic Agent Builder A2A
This notebook creates a Discord bot that connects to Elastic Agent Builder's A2A server. Players ask questions like "Who's the best Mage?" or "What's the current meta?" and get real-time answers powered by ES|QL analytics and semantic search.
What you'll build
- ES|QL tools for structured analytics: leaderboards, hero stats, meta reports
- Index Search tools for unstructured knowledge: game mechanics, FAQs (semantic search)
- An agent that automatically selects the right tool based on the user's question
Prerequisites
- Elasticsearch cluster (9.2+, or Serverless)
- Python 3.9+
- Discord bot token and server (for the final integration)
Install dependencies
Configuration
Set your environment variables:
export ELASTICSEARCH_URL="https://your-cluster.es.region.aws.elastic.co:443"
export ELASTIC_API_KEY="your-elasticsearch-api-key"
export KIBANA_URL="https://your-deployment.kb.region.aws.elastic.co"
export KIBANA_API_KEY="your-kibana-api-key"
Create indices
Three indices serve different purposes:
| Index | Purpose | Query Type |
|---|---|---|
player_stats | Player profiles with wins, kills, rank | ES |
hero_meta | Hero pick rates and win rates by tier | ES |
game_knowledge | FAQs and game mechanics | Semantic search |
The game_knowledge index uses semantic_text for meaning-based search. Both title and content are copied into semantic_field for hybrid search.
Index sample data
Sample gaming data includes:
- 5 players with different heroes, ranks, and stats (kills, wins, losses)
- 5 heroes with meta information (pick rate, win rate, tier ranking)
- 3 knowledge articles covering common player questions (mounts, builds, ranking system)
Kibana API connection
The Agent Builder tools and agent are created using the Kibana API. Find your Kibana URL in your Elastic Cloud deployment under Applications > Kibana > Copy endpoint.
Create ES|QL tools
ES|QL tools handle structured analytics queries: aggregations, filtering, sorting on well-defined data.
Three tools cover different query types:
- leaderboard - Top players by kills (no parameters)
- hero_stats - Stats for a specific hero (dynamic
?heroparameter) - meta_report - All heroes sorted by tier (no parameters)
The agent automatically selects the right tool based on the user's question.
Create Index Search tool
Index Search tools handle unstructured knowledge queries using semantic search. Unlike ES|QL which queries structured fields, Index Search understands meaning and context.
A user asking "How do I get the dragon mount?" matches "How to unlock the Dragon Mount" even without exact keyword matches—semantic search understands they mean the same thing.
Create the agent
The agent configuration defines:
- Tool access (leaderboard, hero_stats, meta_report, game_knowledge)
- Instructions on when to use each tool
- Response style (friendly, concise)
The instructions field tells the LLM how to behave and when to use each tool.
Test the agent
Test the agent by sending a message through the /converse API endpoint.
By default, Agent Builder uses the Elastic Managed LLM—no connector configuration required. This makes your code portable across Elasticsearch deployments (Serverless, 9.2+) without connector ID changes.
Note: To use a different LLM provider (OpenAI, Bedrock, Gemini), pass an optional
connector_idparameter. Refer to generative AI connectors for setup.
Additional tests
Test the other tool types to verify the agent selects the appropriate tool:
- Semantic search - Game mechanics questions trigger the
game_knowledgeIndex Search tool - Dynamic parameter - Hero-specific questions trigger
hero_statswith the?heroparameter filled in
Next steps
Now you can connect this agent to Discord using the A2A client:
git clone https://github.com/llermaly/agentbuilder-a2a-discord
cd agentbuilder-a2a-discord
Create a .env file:
DISCORD_BOT_TOKEN=<your_bot_token>
AGENT_BUILDER_URL=https://<kibana_url>/api/agent_builder/a2a/gaming_support_bot
A2A_API_KEY=<your_api_key>
Run the bot:
uv venv && uv sync && uv run main.py
Bidirectional: Giving the agent actions
Beyond answering questions, we can give Agent Builder the ability to trigger Discord actions. With a small modification to the Discord client, we can parse special tags in the agent's response and execute Discord commands.
For example, we added support for a <poll> tag. When the agent includes this in its response, the bot creates a native Discord poll.