get_legal_moves
to get a list of current
legal moves. - make_move
to make a move.
Two agents will be used to represent the white and black players, each
associated with a different LLM cloud provider and model: - Anthropic’s
Sonnet 3.5 will be Player_White - Mistral’s Mixtral 8x7B (using
Together.AI) will be Player_Black
As this involves function calling, we use larger, more capable, models
from these providers.
The nested chat will be supported be a board proxy agent who is set up
to execute the tools and manage the game.
Tips to improve performance with these non-OpenAI models will be noted
throughout in bold.
Installation
First, you need to install theag2
and chess
packages to use AG2.
We’ll include Anthropic and Together.AI libraries.
Setting up LLMs
We’ll use the Anthropic (api_type
is anthropic
) and Together.AI
(api_type
is together
) client classes, with their respective models,
which both support function calling.
Creating agents
Our main player agents are created next, with a few tweaks to help our models play:- Explicitly telling agents their names (as the name field isn’t sent to the LLM).
- Providing simple instructions on the order of functions (not all models will need it).
- Asking the LLM to include their name in the response so the message content will include their names, helping the LLM understand who has made which moves.
- Ensure no spaces are in the agent names so that their name is distinguishable in the conversation.