{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Mistral AI\n",
"\n",
"[Mistral AI](https://mistral.ai/) is a cloud based platform serving their own LLMs, like Mistral, Mixtral, and Codestral.\n",
"\n",
"Although AutoGen can be used with Mistral AI's API directly by changing the `base_url` to their url, it does not cater for some differences between messaging and, with their API being more strict than OpenAI's, it is recommended to use the Mistral AI Client class as shown in this notebook.\n",
"\n",
"You will need a Mistral.AI account and create an API key. [See their website for further details](https://mistral.ai/)."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Features\n",
"\n",
"When using this client class, messages are automatically tailored to accommodate the specific requirements of Mistral AI's API (such as role orders), which have become more strict than OpenAI's API.\n",
"\n",
"Additionally, this client class provides support for function/tool calling and will track token usage and cost correctly as per Mistral AI's API costs (as of June 2024).\n",
"\n",
"## Getting started\n",
"\n",
"First you need to install the `pyautogen` package to use AutoGen with the Mistral API library.\n",
"\n",
"``` bash\n",
"pip install pyautogen[mistral]\n",
"```"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Mistral provides a number of models to use, included below. See the list of [models here](https://docs.mistral.ai/platform/endpoints/).\n",
"\n",
"See the sample `OAI_CONFIG_LIST` below showing how the Mistral AI client class is used by specifying the `api_type` as `mistral`.\n",
"\n",
"```python\n",
"[\n",
" {\n",
" \"model\": \"gpt-35-turbo\",\n",
" \"api_key\": \"your OpenAI Key goes here\",\n",
" },\n",
" {\n",
" \"model\": \"gpt-4-vision-preview\",\n",
" \"api_key\": \"your OpenAI Key goes here\",\n",
" },\n",
" {\n",
" \"model\": \"dalle\",\n",
" \"api_key\": \"your OpenAI Key goes here\",\n",
" },\n",
" {\n",
" \"model\": \"open-mistral-7b\",\n",
" \"api_key\": \"your Mistral AI API Key goes here\",\n",
" \"api_type\": \"mistral\"\n",
" },\n",
" {\n",
" \"model\": \"open-mixtral-8x7b\",\n",
" \"api_key\": \"your Mistral AI API Key goes here\",\n",
" \"api_type\": \"mistral\"\n",
" },\n",
" {\n",
" \"model\": \"open-mixtral-8x22b\",\n",
" \"api_key\": \"your Mistral AI API Key goes here\",\n",
" \"api_type\": \"mistral\"\n",
" },\n",
" {\n",
" \"model\": \"mistral-small-latest\",\n",
" \"api_key\": \"your Mistral AI API Key goes here\",\n",
" \"api_type\": \"mistral\"\n",
" },\n",
" {\n",
" \"model\": \"mistral-medium-latest\",\n",
" \"api_key\": \"your Mistral AI API Key goes here\",\n",
" \"api_type\": \"mistral\"\n",
" },\n",
" {\n",
" \"model\": \"mistral-large-latest\",\n",
" \"api_key\": \"your Mistral AI API Key goes here\",\n",
" \"api_type\": \"mistral\"\n",
" },\n",
" {\n",
" \"model\": \"codestral-latest\",\n",
" \"api_key\": \"your Mistral AI API Key goes here\",\n",
" \"api_type\": \"mistral\"\n",
" }\n",
"]\n",
"```"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"As an alternative to the `api_key` key and value in the config, you can set the environment variable `MISTRAL_API_KEY` to your Mistral AI key.\n",
"\n",
"Linux/Mac:\n",
"``` bash\n",
"export MISTRAL_API_KEY=\"your_mistral_ai_api_key_here\"\n",
"```\n",
"\n",
"Windows:\n",
"``` bash\n",
"set MISTRAL_API_KEY=your_mistral_ai_api_key_here\n",
"```\n",
"\n",
"## API parameters\n",
"\n",
"The following parameters can be added to your config for the Mistral.AI API. See [this link](https://docs.mistral.ai/api/#operation/createChatCompletion) for further information on them and their default values.\n",
"\n",
"- temperature (number 0..1)\n",
"- top_p (number 0..1)\n",
"- max_tokens (null, integer >= 0)\n",
"- random_seed (null, integer)\n",
"- safe_prompt (True or False)\n",
"\n",
"Example:\n",
"```python\n",
"[\n",
" {\n",
" \"model\": \"codestral-latest\",\n",
" \"api_key\": \"your Mistral AI API Key goes here\",\n",
" \"api_type\": \"mistral\",\n",
" \"temperature\": 0.5,\n",
" \"top_p\": 0.2, # Note: It is recommended to set temperature or top_p but not both.\n",
" \"max_tokens\": 10000,\n",
" \"safe_prompt\": False,\n",
" \"random_seed\": 42\n",
" }\n",
"]\n",
"```\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Two-Agent Coding Example\n",
"\n",
"In this example, we run a two-agent chat with an AssistantAgent (primarily a coding agent) to generate code to count the number of prime numbers between 1 and 10,000 and then it will be executed.\n",
"\n",
"We'll use Mistral's Mixtral 8x22B model which is suitable for coding."
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [],
"source": [
"import os\n",
"\n",
"config_list = [\n",
" {\n",
" # Let's choose the Mixtral 8x22B model\n",
" \"model\": \"open-mixtral-8x22b\",\n",
" # Provide your Mistral AI API key here or put it into the MISTRAL_API_KEY environment variable.\n",
" \"api_key\": os.environ.get(\"MISTRAL_API_KEY\"),\n",
" # We specify the API Type as 'mistral' so it uses the Mistral AI client class\n",
" \"api_type\": \"mistral\",\n",
" }\n",
"]"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Importantly, we have tweaked the system message so that the model doesn't return the termination keyword, which we've changed to FINISH, with the code block."
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {},
"outputs": [],
"source": [
"from pathlib import Path\n",
"\n",
"from autogen import AssistantAgent, UserProxyAgent\n",
"from autogen.coding import LocalCommandLineCodeExecutor\n",
"\n",
"# Setting up the code executor\n",
"workdir = Path(\"coding\")\n",
"workdir.mkdir(exist_ok=True)\n",
"code_executor = LocalCommandLineCodeExecutor(work_dir=workdir)\n",
"\n",
"# Setting up the agents\n",
"\n",
"# The UserProxyAgent will execute the code that the AssistantAgent provides\n",
"user_proxy_agent = UserProxyAgent(\n",
" name=\"User\",\n",
" code_execution_config={\"executor\": code_executor},\n",
" is_termination_msg=lambda msg: \"FINISH\" in msg.get(\"content\"),\n",
")\n",
"\n",
"system_message = \"\"\"You are a helpful AI assistant who writes code and the user executes it.\n",
"Solve tasks using your coding and language skills.\n",
"In the following cases, suggest python code (in a python coding block) for the user to execute.\n",
"Solve the task step by step if you need to. If a plan is not provided, explain your plan first. Be clear which step uses code, and which step uses your language skill.\n",
"When using code, you must indicate the script type in the code block. The user cannot provide any other feedback or perform any other action beyond executing the code you suggest. The user can't modify your code. So do not suggest incomplete code which requires users to modify. Don't use a code block if it's not intended to be executed by the user.\n",
"Don't include multiple code blocks in one response. Do not ask users to copy and paste the result. Instead, use 'print' function for the output when relevant. Check the execution result returned by the user.\n",
"If the result indicates there is an error, fix the error and output the code again. Suggest the full code instead of partial code or code changes. If the error can't be fixed or if the task is not solved even after the code is executed successfully, analyze the problem, revisit your assumption, collect additional info you need, and think of a different approach to try.\n",
"When you find an answer, verify the answer carefully. Include verifiable evidence in your response if possible.\n",
"IMPORTANT: Wait for the user to execute your code and then you can reply with the word \"FINISH\". DO NOT OUTPUT \"FINISH\" after your code block.\"\"\"\n",
"\n",
"# The AssistantAgent, using Mistral AI's model, will take the coding request and return code\n",
"assistant_agent = AssistantAgent(\n",
" name=\"Mistral Assistant\",\n",
" system_message=system_message,\n",
" llm_config={\"config_list\": config_list},\n",
")"
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\u001b[33mUser\u001b[0m (to Mistral Assistant):\n",
"\n",
"Provide code to count the number of prime numbers from 1 to 10000.\n",
"\n",
"--------------------------------------------------------------------------------\n",
"\u001b[33mMistral Assistant\u001b[0m (to User):\n",
"\n",
"To solve this task, I will write a Python function that checks if a number is prime or not. Then, I will iterate through the numbers from 1 to 10000 and count the prime numbers. Here's the plan:\n",
"\n",
"1. Write a function `is_prime(n)` that checks if a number `n` is prime.\n",
"2. Initialize a variable `prime_count` to 0.\n",
"3. Iterate through numbers from 1 to 10000 using a for loop.\n",
"4. For each number, call the `is_prime(n)` function.\n",
"5. If the function returns True, increment the `prime_count` by 1.\n",
"6. Finally, print the `prime_count`.\n",
"\n",
"Here's the code that implements this plan:\n",
"\n",
"```python\n",
"def is_prime(n):\n",
" if n <= 1:\n",
" return False\n",
" if n <= 3:\n",
" return True\n",
" if n % 2 == 0 or n % 3 == 0:\n",
" return False\n",
" i = 5\n",
" while i * i <= n:\n",
" if n % i == 0 or n % (i + 2) == 0:\n",
" return False\n",
" i += 6\n",
" return True\n",
"\n",
"prime_count = 0\n",
"for num in range(1, 10001):\n",
" if is_prime(num):\n",
" prime_count += 1\n",
"\n",
"print(prime_count)\n",
"```\n",
"\n",
"This code will count the number of prime numbers from 1 to 10000 and print the result. Please execute the code and let me know the output.\n",
"```python\n",
"def is_prime(n):\n",
" if n <= 1:\n",
" return False\n",
" if n <= 3:\n",
" return True\n",
" if n % 2 == 0 or n % 3 == 0:\n",
" return False\n",
" i = 5\n",
" while i * i <= n:\n",
" if n % i == 0 or n % (i + 2) == 0:\n",
" return False\n",
" i += 6\n",
" return True\n",
"\n",
"prime_count = 0\n",
"for num in range(1, 10001):\n",
" if is_prime(num):\n",
" prime_count += 1\n",
"\n",
"prime_count\n",
"```\n",
"\n",
"--------------------------------------------------------------------------------\n",
"\u001b[31m\n",
">>>>>>>> NO HUMAN INPUT RECEIVED.\u001b[0m\n",
"\u001b[31m\n",
">>>>>>>> USING AUTO REPLY...\u001b[0m\n",
"\u001b[31m\n",
">>>>>>>> EXECUTING 2 CODE BLOCKS (inferred languages are [python, python])...\u001b[0m\n",
"\u001b[33mUser\u001b[0m (to Mistral Assistant):\n",
"\n",
"exitcode: 0 (execution succeeded)\n",
"Code output: 1229\n",
"\n",
"\n",
"--------------------------------------------------------------------------------\n",
"\u001b[33mMistral Assistant\u001b[0m (to User):\n",
"\n",
"The code executed successfully and the output is 1229.\n",
"\n",
"This means there are 1229 prime numbers from 1 to 10000.\n",
"\n",
"The code defines a function `is_prime(n)` that checks if a number `n` is prime or not. Then, it initializes a variable `prime_count` to 0. It iterates through numbers from 1 to 10000 using a for loop. For each number, it calls the `is_prime(n)` function. If the function returns True, indicating that the number is prime, it increments the `prime_count` by 1. Finally, it prints the `prime_count`.\n",
"\n",
"This code efficiently checks for prime numbers and accurately counts the number of prime numbers from 1 to 10000.\n",
"\n",
"FINISH\n",
"\n",
"--------------------------------------------------------------------------------\n",
"\u001b[31m\n",
">>>>>>>> NO HUMAN INPUT RECEIVED.\u001b[0m\n"
]
}
],
"source": [
"# Start the chat, with the UserProxyAgent asking the AssistantAgent the message\n",
"chat_result = user_proxy_agent.initiate_chat(\n",
" assistant_agent,\n",
" message=\"Provide code to count the number of prime numbers from 1 to 10000.\",\n",
")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Tool Call Example\n",
"\n",
"In this example, instead of writing code, we will have two agents playing chess against each other using tool calling to make moves.\n",
"\n",
"We'll change models to Mistral AI's large model for this challenging task."
]
},
{
"cell_type": "code",
"execution_count": 15,
"metadata": {},
"outputs": [],
"source": [
"config_list = [\n",
" {\n",
" # Let's choose the Mistral AI's largest model which is better at Chess than the Mixtral model\n",
" \"model\": \"mistral-large-latest\",\n",
" \"api_key\": os.environ.get(\"MISTRAL_API_KEY\"),\n",
" \"api_type\": \"mistral\",\n",
" }\n",
"]"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n",
"First install the `chess` package by running the following command:"
]
},
{
"cell_type": "code",
"execution_count": 16,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Defaulting to user installation because normal site-packages is not writeable\n",
"Requirement already satisfied: chess in /home/autogen/.local/lib/python3.11/site-packages (1.10.0)\n"
]
}
],
"source": [
"! pip install chess"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Write the function for making a move."
]
},
{
"cell_type": "code",
"execution_count": 17,
"metadata": {},
"outputs": [],
"source": [
"import random\n",
"\n",
"import chess\n",
"import chess.svg\n",
"from IPython.display import display\n",
"from typing_extensions import Annotated\n",
"\n",
"board = chess.Board()\n",
"\n",
"\n",
"def make_move() -> Annotated[str, \"A move in UCI format\"]:\n",
" moves = list(board.legal_moves)\n",
" move = random.choice(moves)\n",
" board.push(move)\n",
" # Display the board.\n",
" display(chess.svg.board(board, size=400))\n",
" return str(move)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Let's create the agents. We have three different agents:\n",
"- `player_white` is the agent that plays white.\n",
"- `player_black` is the agent that plays black.\n",
"- `board_proxy` is the agent that moves the pieces on the board."
]
},
{
"cell_type": "code",
"execution_count": 18,
"metadata": {},
"outputs": [],
"source": [
"from autogen import ConversableAgent, register_function\n",
"\n",
"player_white = ConversableAgent(\n",
" name=\"Player White\",\n",
" system_message=\"You are a chess player and you play as white. \" \"Always call make_move() to make a move\",\n",
" llm_config={\"config_list\": config_list, \"cache_seed\": None},\n",
")\n",
"\n",
"player_black = ConversableAgent(\n",
" name=\"Player Black\",\n",
" system_message=\"You are a chess player and you play as black. \" \"Always call make_move() to make a move\",\n",
" llm_config={\"config_list\": config_list, \"cache_seed\": None},\n",
")\n",
"\n",
"board_proxy = ConversableAgent(\n",
" name=\"Board Proxy\",\n",
" llm_config=False,\n",
" # The board proxy will only respond to the make_move function.\n",
" is_termination_msg=lambda msg: \"tool_calls\" not in msg,\n",
")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Register tools for the agents. See the [tutorial chapter on tool use](/docs/tutorial/tool-use) \n",
"for more information."
]
},
{
"cell_type": "code",
"execution_count": 19,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"/home/autogen/autogen/autogen/agentchat/conversable_agent.py:2408: UserWarning: Function 'make_move' is being overridden.\n",
" warnings.warn(f\"Function '{name}' is being overridden.\", UserWarning)\n"
]
}
],
"source": [
"register_function(\n",
" make_move,\n",
" caller=player_white,\n",
" executor=board_proxy,\n",
" name=\"make_move\",\n",
" description=\"Make a move.\",\n",
")\n",
"\n",
"register_function(\n",
" make_move,\n",
" caller=player_black,\n",
" executor=board_proxy,\n",
" name=\"make_move\",\n",
" description=\"Make a move.\",\n",
")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Register nested chats for the player agents.\n",
"Nested chats allows each player agent to chat with the board proxy agent\n",
"to make a move, before communicating with the other player agent.\n",
"See the [nested chats tutorial chapter](/docs/tutorial/conversation-patterns#nested-chats)\n",
"for more information."
]
},
{
"cell_type": "code",
"execution_count": 20,
"metadata": {},
"outputs": [],
"source": [
"player_white.register_nested_chats(\n",
" trigger=player_black,\n",
" chat_queue=[\n",
" {\n",
" \"sender\": board_proxy,\n",
" \"recipient\": player_white,\n",
" }\n",
" ],\n",
")\n",
"\n",
"player_black.register_nested_chats(\n",
" trigger=player_white,\n",
" chat_queue=[\n",
" {\n",
" \"sender\": board_proxy,\n",
" \"recipient\": player_black,\n",
" }\n",
" ],\n",
")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Clear the board and start the chess game."
]
},
{
"cell_type": "code",
"execution_count": 21,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\u001b[33mPlayer White\u001b[0m (to Player Black):\n",
"\n",
"Let's play chess! Your move.\n",
"\n",
"--------------------------------------------------------------------------------\n",
"\u001b[31m\n",
">>>>>>>> USING AUTO REPLY...\u001b[0m\n",
"\u001b[34m\n",
"********************************************************************************\u001b[0m\n",
"\u001b[34mStarting a new chat....\u001b[0m\n",
"\u001b[34m\n",
"********************************************************************************\u001b[0m\n",
"\u001b[33mBoard Proxy\u001b[0m (to Player Black):\n",
"\n",
"Let's play chess! Your move.\n",
"\n",
"--------------------------------------------------------------------------------\n",
"\u001b[31m\n",
">>>>>>>> USING AUTO REPLY...\u001b[0m\n",
"\u001b[33mPlayer Black\u001b[0m (to Board Proxy):\n",
"\n",
"\n",
"\u001b[32m***** Suggested tool call (AcS1aX4Rl): make_move *****\u001b[0m\n",
"Arguments: \n",
"{}\n",
"\u001b[32m******************************************************\u001b[0m\n",
"\n",
"--------------------------------------------------------------------------------\n",
"\u001b[31m\n",
">>>>>>>> USING AUTO REPLY...\u001b[0m\n",
"\u001b[35m\n",
">>>>>>>> EXECUTING FUNCTION make_move...\u001b[0m\n"
]
},
{
"data": {
"image/svg+xml": [
""
],
"text/plain": [
"''"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"[runtime logging] log_function_use: autogen logger is None\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"\u001b[33mBoard Proxy\u001b[0m (to Player Black):\n",
"\n",
"\u001b[33mBoard Proxy\u001b[0m (to Player Black):\n",
"\n",
"\u001b[32m***** Response from calling tool (AcS1aX4Rl) *****\u001b[0m\n",
"g1h3\n",
"\u001b[32m**************************************************\u001b[0m\n",
"\n",
"--------------------------------------------------------------------------------\n",
"\u001b[31m\n",
">>>>>>>> USING AUTO REPLY...\u001b[0m\n",
"\u001b[33mPlayer Black\u001b[0m (to Board Proxy):\n",
"\n",
"I have made my move. It's g1h3. Your turn.\n",
"\n",
"--------------------------------------------------------------------------------\n",
"\u001b[31m\n",
">>>>>>>> NO HUMAN INPUT RECEIVED.\u001b[0m\n",
"\u001b[33mPlayer Black\u001b[0m (to Player White):\n",
"\n",
"I have made my move. It's g1h3. Your turn.\n",
"\n",
"--------------------------------------------------------------------------------\n",
"\u001b[31m\n",
">>>>>>>> USING AUTO REPLY...\u001b[0m\n",
"\u001b[34m\n",
"********************************************************************************\u001b[0m\n",
"\u001b[34mStarting a new chat....\u001b[0m\n",
"\u001b[34m\n",
"********************************************************************************\u001b[0m\n",
"\u001b[33mBoard Proxy\u001b[0m (to Player White):\n",
"\n",
"I have made my move. It's g1h3. Your turn.\n",
"\n",
"--------------------------------------------------------------------------------\n",
"\u001b[31m\n",
">>>>>>>> USING AUTO REPLY...\u001b[0m\n",
"\u001b[33mPlayer White\u001b[0m (to Board Proxy):\n",
"\n",
"\n",
"\u001b[32m***** Suggested tool call (tWVXVAujE): make_move *****\u001b[0m\n",
"Arguments: \n",
"{}\n",
"\u001b[32m******************************************************\u001b[0m\n",
"\n",
"--------------------------------------------------------------------------------\n",
"\u001b[31m\n",
">>>>>>>> USING AUTO REPLY...\u001b[0m\n",
"\u001b[35m\n",
">>>>>>>> EXECUTING FUNCTION make_move...\u001b[0m\n"
]
},
{
"data": {
"image/svg+xml": [
""
],
"text/plain": [
"''"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"[runtime logging] log_function_use: autogen logger is None\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"\u001b[33mBoard Proxy\u001b[0m (to Player White):\n",
"\n",
"\u001b[33mBoard Proxy\u001b[0m (to Player White):\n",
"\n",
"\u001b[32m***** Response from calling tool (tWVXVAujE) *****\u001b[0m\n",
"d7d5\n",
"\u001b[32m**************************************************\u001b[0m\n",
"\n",
"--------------------------------------------------------------------------------\n",
"\u001b[31m\n",
">>>>>>>> USING AUTO REPLY...\u001b[0m\n",
"\u001b[33mPlayer White\u001b[0m (to Board Proxy):\n",
"\n",
"I have made my move. It's d7d5. Your turn.\n",
"\n",
"--------------------------------------------------------------------------------\n",
"\u001b[31m\n",
">>>>>>>> NO HUMAN INPUT RECEIVED.\u001b[0m\n",
"\u001b[33mPlayer White\u001b[0m (to Player Black):\n",
"\n",
"I have made my move. It's d7d5. Your turn.\n",
"\n",
"--------------------------------------------------------------------------------\n",
"\u001b[31m\n",
">>>>>>>> USING AUTO REPLY...\u001b[0m\n",
"\u001b[34m\n",
"********************************************************************************\u001b[0m\n",
"\u001b[34mStarting a new chat....\u001b[0m\n",
"\u001b[34m\n",
"********************************************************************************\u001b[0m\n",
"\u001b[33mBoard Proxy\u001b[0m (to Player Black):\n",
"\n",
"I have made my move. It's d7d5. Your turn.\n",
"\n",
"--------------------------------------------------------------------------------\n",
"\u001b[31m\n",
">>>>>>>> USING AUTO REPLY...\u001b[0m\n",
"\u001b[33mPlayer Black\u001b[0m (to Board Proxy):\n",
"\n",
"\n",
"\u001b[32m***** Suggested tool call (ZOfvRz0B1): make_move *****\u001b[0m\n",
"Arguments: \n",
"{}\n",
"\u001b[32m******************************************************\u001b[0m\n",
"\n",
"--------------------------------------------------------------------------------\n",
"\u001b[31m\n",
">>>>>>>> USING AUTO REPLY...\u001b[0m\n",
"\u001b[35m\n",
">>>>>>>> EXECUTING FUNCTION make_move...\u001b[0m\n"
]
},
{
"data": {
"image/svg+xml": [
""
],
"text/plain": [
"''"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"[runtime logging] log_function_use: autogen logger is None\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"\u001b[33mBoard Proxy\u001b[0m (to Player Black):\n",
"\n",
"\u001b[33mBoard Proxy\u001b[0m (to Player Black):\n",
"\n",
"\u001b[32m***** Response from calling tool (ZOfvRz0B1) *****\u001b[0m\n",
"b1c3\n",
"\u001b[32m**************************************************\u001b[0m\n",
"\n",
"--------------------------------------------------------------------------------\n",
"\u001b[31m\n",
">>>>>>>> USING AUTO REPLY...\u001b[0m\n",
"\u001b[33mPlayer Black\u001b[0m (to Board Proxy):\n",
"\n",
"I have made my move. It's b1c3. Your turn.\n",
"\n",
"--------------------------------------------------------------------------------\n",
"\u001b[31m\n",
">>>>>>>> NO HUMAN INPUT RECEIVED.\u001b[0m\n",
"\u001b[33mPlayer Black\u001b[0m (to Player White):\n",
"\n",
"I have made my move. It's b1c3. Your turn.\n",
"\n",
"--------------------------------------------------------------------------------\n",
"\u001b[31m\n",
">>>>>>>> USING AUTO REPLY...\u001b[0m\n",
"\u001b[34m\n",
"********************************************************************************\u001b[0m\n",
"\u001b[34mStarting a new chat....\u001b[0m\n",
"\u001b[34m\n",
"********************************************************************************\u001b[0m\n",
"\u001b[33mBoard Proxy\u001b[0m (to Player White):\n",
"\n",
"I have made my move. It's b1c3. Your turn.\n",
"\n",
"--------------------------------------------------------------------------------\n",
"\u001b[31m\n",
">>>>>>>> USING AUTO REPLY...\u001b[0m\n",
"\u001b[33mPlayer White\u001b[0m (to Board Proxy):\n",
"\n",
"\n",
"\u001b[32m***** Suggested tool call (LovRpi6Pq): make_move *****\u001b[0m\n",
"Arguments: \n",
"{}\n",
"\u001b[32m******************************************************\u001b[0m\n",
"\n",
"--------------------------------------------------------------------------------\n",
"\u001b[31m\n",
">>>>>>>> USING AUTO REPLY...\u001b[0m\n",
"\u001b[35m\n",
">>>>>>>> EXECUTING FUNCTION make_move...\u001b[0m\n"
]
},
{
"data": {
"image/svg+xml": [
""
],
"text/plain": [
"''"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"[runtime logging] log_function_use: autogen logger is None\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"\u001b[33mBoard Proxy\u001b[0m (to Player White):\n",
"\n",
"\u001b[33mBoard Proxy\u001b[0m (to Player White):\n",
"\n",
"\u001b[32m***** Response from calling tool (LovRpi6Pq) *****\u001b[0m\n",
"c8g4\n",
"\u001b[32m**************************************************\u001b[0m\n",
"\n",
"--------------------------------------------------------------------------------\n",
"\u001b[31m\n",
">>>>>>>> USING AUTO REPLY...\u001b[0m\n",
"\u001b[33mPlayer White\u001b[0m (to Board Proxy):\n",
"\n",
"I have made my move. It's c8g4. Your turn.\n",
"\n",
"--------------------------------------------------------------------------------\n",
"\u001b[33mPlayer White\u001b[0m (to Player Black):\n",
"\n",
"I have made my move. It's c8g4. Your turn.\n",
"\n",
"--------------------------------------------------------------------------------\n",
"\u001b[31m\n",
">>>>>>>> USING AUTO REPLY...\u001b[0m\n",
"\u001b[34m\n",
"********************************************************************************\u001b[0m\n",
"\u001b[34mStarting a new chat....\u001b[0m\n",
"\u001b[34m\n",
"********************************************************************************\u001b[0m\n",
"\u001b[33mBoard Proxy\u001b[0m (to Player Black):\n",
"\n",
"I have made my move. It's c8g4. Your turn.\n",
"\n",
"--------------------------------------------------------------------------------\n",
"\u001b[31m\n",
">>>>>>>> USING AUTO REPLY...\u001b[0m\n",
"\u001b[33mPlayer Black\u001b[0m (to Board Proxy):\n",
"\n",
"\n",
"\u001b[32m***** Suggested tool call (RfhC8brG7): make_move *****\u001b[0m\n",
"Arguments: \n",
"{}\n",
"\u001b[32m******************************************************\u001b[0m\n",
"\n",
"--------------------------------------------------------------------------------\n",
"\u001b[31m\n",
">>>>>>>> USING AUTO REPLY...\u001b[0m\n",
"\u001b[35m\n",
">>>>>>>> EXECUTING FUNCTION make_move...\u001b[0m\n"
]
},
{
"data": {
"image/svg+xml": [
""
],
"text/plain": [
"''"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"[runtime logging] log_function_use: autogen logger is None\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"\u001b[33mBoard Proxy\u001b[0m (to Player Black):\n",
"\n",
"\u001b[33mBoard Proxy\u001b[0m (to Player Black):\n",
"\n",
"\u001b[32m***** Response from calling tool (RfhC8brG7) *****\u001b[0m\n",
"a1b1\n",
"\u001b[32m**************************************************\u001b[0m\n",
"\n",
"--------------------------------------------------------------------------------\n",
"\u001b[31m\n",
">>>>>>>> USING AUTO REPLY...\u001b[0m\n",
"\u001b[33mPlayer Black\u001b[0m (to Board Proxy):\n",
"\n",
"I have made my move. It's a1b1. Your turn.\n",
"\n",
"--------------------------------------------------------------------------------\n",
"\u001b[33mPlayer Black\u001b[0m (to Player White):\n",
"\n",
"I have made my move. It's a1b1. Your turn.\n",
"\n",
"--------------------------------------------------------------------------------\n",
"\u001b[31m\n",
">>>>>>>> USING AUTO REPLY...\u001b[0m\n",
"\u001b[34m\n",
"********************************************************************************\u001b[0m\n",
"\u001b[34mStarting a new chat....\u001b[0m\n",
"\u001b[34m\n",
"********************************************************************************\u001b[0m\n",
"\u001b[33mBoard Proxy\u001b[0m (to Player White):\n",
"\n",
"I have made my move. It's a1b1. Your turn.\n",
"\n",
"--------------------------------------------------------------------------------\n",
"\u001b[31m\n",
">>>>>>>> USING AUTO REPLY...\u001b[0m\n",
"\u001b[33mPlayer White\u001b[0m (to Board Proxy):\n",
"\n",
"\n",
"\u001b[32m***** Suggested tool call (6aVW1t0lm): make_move *****\u001b[0m\n",
"Arguments: \n",
"{}\n",
"\u001b[32m******************************************************\u001b[0m\n",
"\n",
"--------------------------------------------------------------------------------\n",
"\u001b[31m\n",
">>>>>>>> USING AUTO REPLY...\u001b[0m\n",
"\u001b[35m\n",
">>>>>>>> EXECUTING FUNCTION make_move...\u001b[0m\n"
]
},
{
"data": {
"image/svg+xml": [
""
],
"text/plain": [
"''"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"[runtime logging] log_function_use: autogen logger is None\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"\u001b[33mBoard Proxy\u001b[0m (to Player White):\n",
"\n",
"\u001b[33mBoard Proxy\u001b[0m (to Player White):\n",
"\n",
"\u001b[32m***** Response from calling tool (6aVW1t0lm) *****\u001b[0m\n",
"a7a6\n",
"\u001b[32m**************************************************\u001b[0m\n",
"\n",
"--------------------------------------------------------------------------------\n",
"\u001b[31m\n",
">>>>>>>> USING AUTO REPLY...\u001b[0m\n",
"\u001b[33mPlayer White\u001b[0m (to Board Proxy):\n",
"\n",
"I have made my move. It's a7a6. Your turn.\n",
"\n",
"--------------------------------------------------------------------------------\n",
"\u001b[33mPlayer White\u001b[0m (to Player Black):\n",
"\n",
"I have made my move. It's a7a6. Your turn.\n",
"\n",
"--------------------------------------------------------------------------------\n",
"\u001b[31m\n",
">>>>>>>> USING AUTO REPLY...\u001b[0m\n",
"\u001b[34m\n",
"********************************************************************************\u001b[0m\n",
"\u001b[34mStarting a new chat....\u001b[0m\n",
"\u001b[34m\n",
"********************************************************************************\u001b[0m\n",
"\u001b[33mBoard Proxy\u001b[0m (to Player Black):\n",
"\n",
"I have made my move. It's a7a6. Your turn.\n",
"\n",
"--------------------------------------------------------------------------------\n",
"\u001b[31m\n",
">>>>>>>> USING AUTO REPLY...\u001b[0m\n",
"\u001b[33mPlayer Black\u001b[0m (to Board Proxy):\n",
"\n",
"\n",
"\u001b[32m***** Suggested tool call (kPTEInlLR): make_move *****\u001b[0m\n",
"Arguments: \n",
"{}\n",
"\u001b[32m******************************************************\u001b[0m\n",
"\n",
"--------------------------------------------------------------------------------\n",
"\u001b[31m\n",
">>>>>>>> USING AUTO REPLY...\u001b[0m\n",
"\u001b[35m\n",
">>>>>>>> EXECUTING FUNCTION make_move...\u001b[0m\n"
]
},
{
"data": {
"image/svg+xml": [
""
],
"text/plain": [
"''"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"[runtime logging] log_function_use: autogen logger is None\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"\u001b[33mBoard Proxy\u001b[0m (to Player Black):\n",
"\n",
"\u001b[33mBoard Proxy\u001b[0m (to Player Black):\n",
"\n",
"\u001b[32m***** Response from calling tool (kPTEInlLR) *****\u001b[0m\n",
"h3f4\n",
"\u001b[32m**************************************************\u001b[0m\n",
"\n",
"--------------------------------------------------------------------------------\n",
"\u001b[31m\n",
">>>>>>>> USING AUTO REPLY...\u001b[0m\n",
"\u001b[33mPlayer Black\u001b[0m (to Board Proxy):\n",
"\n",
"I have made my move. It's h3f4. Your turn.\n",
"\n",
"--------------------------------------------------------------------------------\n",
"\u001b[33mPlayer Black\u001b[0m (to Player White):\n",
"\n",
"I have made my move. It's h3f4. Your turn.\n",
"\n",
"--------------------------------------------------------------------------------\n"
]
}
],
"source": [
"# Clear the board.\n",
"board = chess.Board()\n",
"\n",
"chat_result = player_white.initiate_chat(\n",
" player_black,\n",
" message=\"Let's play chess! Your move.\",\n",
" max_turns=4,\n",
")"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "autogen",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.9"
}
},
"nbformat": 4,
"nbformat_minor": 2
}