Conversational Chess using non-OpenAI clients
This notebook provides tips for using non-OpenAI models when using functions/tools.
The code is based on this notebook, which provides a detailed look at nested chats for tool use. Please refer to that notebook for more on nested chats as this will be concentrated on tweaks to improve performance with non-OpenAI models.
The notebook represents a chess game between two players with a nested chat to determine the available moves and select a move to make.
This game contains a couple of functions/tools that the LLMs must use
correctly by the LLMs: - 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 the pyautogen
and chess
packages to use
AutoGen. 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.
We’ll setup game variables and the two functions for getting the available moves and then making a move.
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.
Now we create a proxy agent that will be used to move the pieces on the board.
Our functions are then assigned to the agents so they can be passed to the LLM to choose from.
We have tweaked the descriptions to provide more guidance on when to use it.
Almost there, we now create nested chats between players and the board proxy agent to work out the available moves and make the move.
Playing the game
Now the game can begin!
At this stage, it’s hard to tell who’s going to win, but they’re playing well and using the functions correctly.