Okay, let's break down how this LLM-Colosseum project works, especially regarding the speed and use of models like Pixtral for playing Street Fighter III.
Core Concepts
-
Game Environment: The project uses diambra.arena, a framework that provides an environment for playing fighting games like Street Fighter III. This framework handles the game's graphics, physics, and rules.
-
Agents (Robots): The core of the project involves "Robots" (defined in agent/robot.py). These are the AI players that decide what actions to take in the game. There are two main types of robots:
-
TextRobot: This robot receives a textual description of the game's state. This description includes things like the characters' positions, their health, and the previous actions taken. It uses a language model to decide what moves to perform.
-
VisionRobot: This robot receives an image (a screenshot) of the game. It uses a multimodal language model, which can understand both images and text, to decide its actions.
-
Language Models (LLMs): The "brains" of the robots. These models take in game information (either text or an image) and generate a sequence of actions that the robot will execute in the game. Models like Pixtral, GPT-4, or Claude are used for this.
-
Planning and Acting: The robots work in a loop of planning and acting:
- Plan: The robot calls the LLM to generate a sequence of moves (a "plan") based on the current game situation.
- Act: The robot executes the first action from its plan.
- Observe: After each step, the robot observes the updated game state (position of characters, health, etc.) and updates its memory.
- This loop repeats continuously.
How Pixtral (and other LLMs) Play So Fast
The speed comes from a few clever design choices:
-
Streaming: The call_llm methods in both TextRobot and VisionRobot use the LLM's streaming capability. Instead of waiting for the entire LLM response to be generated at once, the project receives the LLM's output piece-by-piece. This enables the robot to start acting sooner. As soon as it gets a move, the robot will execute that move.
-
Predefined Moves: The robots don't have to generate the game actions themselves. They choose from a predefined list of moves in agent/config.py (e.g., "Fireball", "Medium Punch", "Move Closer"). The LLM simply decides which of these moves to do.
- This simplifies the output of the LLM. Instead of generating the action, the LLM only chooses the action from the list of predefined actions.
-
Action Queue: The LLM doesn't generate one move at a time. The plan method calls the LLM once to get a list of moves and then convert them to a list of actions. Those actions are put in a queue that is consumed step by step by the robot act method.
- The plan method is called in a separate thread, allowing the robot to act in real-time.
-
Multithreading: The PlanAndAct threads (in eval/game.py) allow the robot's planning (calling the LLM) and acting (executing actions in the game) to happen in parallel. The LLM can generate the next action list while the robot is still in the middle of executing the previous one.
-
Optimized Prompts: The prompts sent to the LLMs are concise and formatted to make the LLM respond with a list of moves quickly. The prompts are designed to be precise and short, focusing on what the LLM needs to know to generate the next move.
- Example in the
TextRobot the prompt is:
You are the best and most aggressive Street Fighter III 3rd strike player in the world. Your character is {self.character}. Your goal is to beat the other opponent. You respond with a bullet point list of moves.
{self.context_prompt()}
The moves you can use are:
{move_list}
----
Reply with a bullet point list of moves. The format should be: `- <name of the move>` separated by a new line.
Example if the opponent is close:
- Move closer
- Medium Punch
Example if the opponent is far:
- Fireball
- Move closer
- Example in the
VisionRobot the prompt is:
You are the best and most aggressive Street Fighter III 3rd strike player in the world.
Your character is {self.character}. Your goal is to beat the other opponent. You respond with a bullet point list of moves.
The current state of the game is given in the following image.
The moves you can use are:
{move_list}
----
Reply with a bullet point list of 3 moves. The format should be: `- <name of the move>` separated by a new line.
Example if the opponent is close:
- Move closer
- Medium Punch
Example if the opponent is far:
- Fireball
- Move closer
-
Caching and Fast API: The usage of LLM API is made through Llamaindex library, which support caching. Also the code makes usage of the fastest available API (Groq, Mistral API, etc.)
In Summary
The speed of the robots in this project comes from a combination of:
- Streaming LLM responses: Getting moves from the LLM as soon as they're generated.
- Predefined move set: The LLM chooses from a predefined list of actions, simplifying its task.
- Efficient prompts: The LLM knows the game and has precise instructions on how to respond.
- Multithreading: Planning and acting happen in parallel.
By leveraging these techniques, the project achieves real-time performance even with computationally intensive LLMs.
Let me know if you have any more questions!