get_legal_moves to get a list of current legal moves. -
make_move to make a move.
A board proxy agent is set up to execute the tools and manage the game.
It is important to use a board proxy as a non-LLM “guard rail” to ensure
the game is played correctly and to prevent agents from making illegal
moves.
Each time a player agent receives a message from the other player agent,
it instantiates a nested chat with the board proxy agent to get the
legal moves and make a move using the tools given. The nested chat
between the player agent and the board agent continues until the a legal
move is made by the tool. Once the nested chat concludes, the player
agent sends a message to the other player agent about the move made.
Installation
First you need to install theautogen and chess packages to use AG2.
Setting up LLMs
Now you can set up the models you want to use.Creating tools
Write functions for getting legal moves and making a move.Creating agents
Let’s create the agents. We have three different agents: -player_white is the agent that plays white. - player_black is the
agent that plays black. - board_proxy is the agent that moves the
pieces on the board.
make_move tool. The
last message in the nested chat is a message from the player agent about
the move made, and this message is then sent to the other player agent.
The following diagram illustrates the nested chat between the player
agent and the board agent.
See nested chats tutorial
chapter
for more information.