Objective/Inspiration
I have always been fascinated by game-playing AI like Deep Blue, AlphaZero, and OpenAI Five. However, state of the art game-playing AI typically rely on computationally intensive approaches such as deep reinforcement learning. More reasonable approaches such as minimax search or Monte Carlo Tree Search can be viable, but in many cases has already been done for many games, including Pokemon. Furthermore, with the large search space in Pokemon, search methods often cannot search deep enough without running out of time to make a move.
With the emergence of RAG-based AI agents I saw an opportunity to take a different approach. By leveraging RAG to incorporate competitive Pokemon strategy and game state information, we can create an AI that makes informed decisions without traditional search or learning methods. The interactive nature of LLMs also enables our agent to both play strategically and roleplay as a trainer, creating an immersive battle experience that combines competitive gameplay with personality.
With this in mind, I wanted to accomplish 3 things:
-
Use RAG to help the AI make reasonable battle moves and have informed Pokemon discussions with players
-
Keep response times fast so conversations and battles feel natural, like talking to a real Pokemon NPC/trainer (doable thanks to SambaNova’s “lightning fast” inference times)
-
Let the AI act as different Pokemon trainers with unique personalities and battling styles
I hope that this project provides a proof-of-concept of how game-playing AI and game NPCs can be developed using RAG-based AI (and using SambaNova Cloud API!)
How it works
This project uses Pokemon Showdown, which is a free, web-based Pokemon battle simulator. Pokemon Showdown allows players to battle each other using Pokemon teams without needing actual Pokemon games. The simulator follows competitive Pokemon rules established by Smogon, the largest competitive Pokemon community that creates and maintains the standard ruleset used in competitive Pokemon battles.
Technical Implementation
The simulator is implemented using SockJS, which allows direct connection to the Pokemon Showdown client through a websocket. More details about the technical implementation can be found here.
Core Features
1. User Interaction
-
The system logs into Pokemon Showdown using provided credentials
-
It starts a Direct Message (DM) conversation with a target user
-
Users can interact with the agent through these DMs
2. Pokemon Information Requests
When a user asks about a specific Pokemon:
-
The agent extracts the Pokemon’s name
-
Makes a database call to retrieve:
-
Basic information (ability, type(s), competitive tier)
-
Smogon strategy guides (example: Alomomola Strategy Guide)
-
Provides competitive analysis based on this information
3. Battle Mode
When a user wants to battle:
-
System detects battle intent
-
Initiates a generation 9 random battle battle through Pokemon Showdown (other battle formats not supported yet)
-
Once accepted, enters “battle mode” where it:
-
Monitors battle state updates via websocket
-
Analyzes current situation and strategy information
-
Makes optimal move decisions
-
Explains its reasoning in the battle chat
-
After the battle ends, the agent will provide an analysis of the battle
4. Team Building
To get help building a team, users need to specify:
-
The Pokemon generation (e.g., gen9 for Sword/Shield)
-
The competitive tier (e.g., OU for Overused)
The agent then:
-
Uses Smogon’s statistical data (usage stats and movesets)
-
Selects Pokemon based on:
-
Usage statistics
-
Team synergy
-
Current team composition
-
Outputs a complete team in
src/team.txt
-
This file can be directly imported into Pokemon Showdown’s team builder
5. AI Model Used
The project uses the Meta Llama 3.1 70B model directly from the SambaNova Cloud API. Their models have very fast inference times, which is perfect for a project like this where it improves the immersiveness of the project a ton. To set up and use the model, I used their “enterprise knowledge retriever” example in their AI starter kit which can be found here. This basically got me up and running with model experimentation within a few hours, and was undoubtedly the easiest part of the project to set up!
6. Frontend
The project uses a streamlit frontend to insert settings such as the SambaNova API key, the credentials the agent will use to login, the username of the user the agent interacts with, and the personality of the agent. The default settings must be set in a secrets.toml
file prior to starting the streamlit app. More instructions on this can be found in the project set up section. Press the start button once all settings are set.
Other Notes
Github Repo: GitHub - colinh09/ps-ai-battler: Agentic pokemon showdown battler bot that uses tool calling + RAG
Demo Video: https://www.youtube.com/watch?v=0KZ5oRxJpqI (actual demo happens at 1:30)
Let me know what you think! Thank you to SambaNova for hosting this hackathon.