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.
With the emergence of RAG-based AI agents and the accessibility of Pokemon Showdown data through web scraping, 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
What it does
This project is an agent-based chatbot that embodies different Pokemon trainer personalities, focusing on competitive Pokemon battles. The bot handles team building, battles, and strategy discussions using SambaNova Cloud models to generate responses that authentically mimic Pokemon NPCs.
Core Features:
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
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
- Provides competitive analysis based on this information
Battle Mode When a user wants to battle:
- System detects battle intent
- Initiates a generation 9 random battle through Pokemon Showdown
- 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
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)
How we built it
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 Pokemon Showdown simulator is implemented using SockJS, which allows direct connection to the Pokemon Showdown client through a websocket
- Uses the Meta Llama 3.1 70B model directly from the SambaNova Cloud API and LangChain for the agent implementation
- Frontend built with Streamlit to insert settings such as:
- SambaNova API key
- Agent login credentials
- Username of the target user
- Agent personality settings
- Team building uses Smogon's statistical data to select Pokemon based on:
- Usage statistics
- Team synergy
- Current team composition
Challenges we ran into
A couple of challenges include working with the Pokemon Showdown client. I have little experience with using websockets, so understanding the protocol and how to write code to interact with it came with some struggles. Almost all of my struggles arose from difficulty with interacting with the client. It was also difficult to get the agent to perform the correct actions like choosing moves or sending messages to the client. A peculiar case is when the agent is about to lose, it would try to switch to a 7th Pokemon on its team when a team only has 6 Pokemon.
Another challenge I ran into was trying to make this project into a chrome extension. I attempted to host the agent functionality within an AWS EC2 instance, but Pokemon Showdown blocks all IPs that are detected as proxies and VPNs, which gave me websocket connection errors. Therefore, I could not host this project for others try, and I needed to write local running instructions instead.
Accomplishments that we're proud of
The agent is able to play a full battle of Pokemon, can build full teams, and talk strategy with the user! This was my main goal with this iteration of the project
What's next for PokeCompanion
There are a few things I would like to add to this project 1) Add a damage calculator and calculate how much damage each move would do to the current opponent's pokemon 2) Currently, the agent can only engage in random battles - so expanding this to other battle formats would be nice 3) Make the agent better at battling, team building and theory crafting overall. This could include using a more advanced model, better prompt engineering, finetuning, or improve battle context would help the agent perform better 4) Find a way to host the application so that other people can use it without getting blocked by Pokemon Showdown
Built With
- docker
- langchain
- llama
- postgresql
- python
- sambanova
- websockets
Log in or sign up for Devpost to join the conversation.