2023-07-23 21:23:09 +08:00
{
"cells": [
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
2023-09-26 05:42:24 +08:00
"<a href=\"https://colab.research.google.com/github/microsoft/autogen/blob/main/notebook/agentchat_two_users.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
2023-07-23 21:23:09 +08:00
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
2023-07-29 12:17:51 +08:00
"# Auto Generated Agent Chat: Collaborative Task Solving with Multiple Agents and Human Users\n",
2023-07-23 21:23:09 +08:00
"\n",
2023-10-22 12:46:07 +08:00
"AutoGen offers conversable agents powered by LLM, tool, or human, which can be used to perform tasks collectively via automated chat. This framework allows tool use and human participation through multi-agent conversation. Please find documentation about this feature [here](https://microsoft.github.io/autogen/docs/Use-Cases/agent_chat).\n",
2023-07-23 21:23:09 +08:00
"\n",
2023-10-22 12:46:07 +08:00
"In this notebook, we demonstrate an application involving multiple agents and human users to work together and accomplish a task. `AssistantAgent` is an LLM-based agent that can write Python code (in a Python coding block) for a user to execute for a given task. `UserProxyAgent` is an agent which serves as a proxy for a user to execute the code written by `AssistantAgent`. We create multiple `UserProxyAgent` instances that can represent different human users.\n",
2023-07-23 21:23:09 +08:00
"\n",
"## Requirements\n",
"\n",
2023-09-26 05:42:24 +08:00
"AutoGen requires `Python>=3.8`. To run this notebook example, please install:\n",
2023-07-23 21:23:09 +08:00
"```bash\n",
2023-09-26 05:42:24 +08:00
"pip install pyautogen\n",
2023-07-23 21:23:09 +08:00
"```"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"execution": {
"iopub.execute_input": "2023-02-13T23:40:52.317406Z",
"iopub.status.busy": "2023-02-13T23:40:52.316561Z",
"iopub.status.idle": "2023-02-13T23:40:52.321193Z",
"shell.execute_reply": "2023-02-13T23:40:52.320628Z"
}
},
"outputs": [],
"source": [
2024-01-07 09:41:33 +08:00
"# %pip install \"pyautogen>=0.2.3\""
2023-07-23 21:23:09 +08:00
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"## Set your API Endpoint\n",
"\n",
2023-09-26 05:42:24 +08:00
"The [`config_list_from_json`](https://microsoft.github.io/autogen/docs/reference/oai/openai_utils#config_list_from_json) function loads a list of configurations from an environment variable or a json file.\n",
2023-07-23 21:23:09 +08:00
"\n",
2023-10-22 12:46:07 +08:00
"It first looks for an environment variable of a specified name (\"OAI_CONFIG_LIST\" in this example), which needs to be a valid json string. If that variable is not found, it looks for a json file with the same name. It filters the configs by models (you can filter by other keys as well).\n",
2023-09-26 05:42:24 +08:00
"\n",
"The json looks like the following:\n",
"```json\n",
"[\n",
" {\n",
" \"model\": \"gpt-4\",\n",
" \"api_key\": \"<your OpenAI API key here>\"\n",
" },\n",
" {\n",
" \"model\": \"gpt-4\",\n",
" \"api_key\": \"<your Azure OpenAI API key here>\",\n",
2023-11-04 12:01:49 +08:00
" \"base_url\": \"<your Azure OpenAI API base here>\",\n",
2023-09-26 05:42:24 +08:00
" \"api_type\": \"azure\",\n",
2024-02-16 02:57:17 +08:00
" \"api_version\": \"2024-02-15-preview\"\n",
2023-09-26 05:42:24 +08:00
" },\n",
" {\n",
" \"model\": \"gpt-4-32k\",\n",
" \"api_key\": \"<your Azure OpenAI API key here>\",\n",
2023-11-04 12:01:49 +08:00
" \"base_url\": \"<your Azure OpenAI API base here>\",\n",
2023-09-26 05:42:24 +08:00
" \"api_type\": \"azure\",\n",
2024-02-16 02:57:17 +08:00
" \"api_version\": \"2024-02-15-preview\"\n",
2023-09-26 05:42:24 +08:00
" }\n",
"]\n",
"```\n",
"\n",
2024-03-05 02:02:26 +08:00
"You can set the value of config_list in any way you prefer. Please refer to this [notebook](https://github.com/microsoft/autogen/blob/main/website/docs/topics/llm_configuration.ipynb) for full code examples of the different methods."
2023-07-23 21:23:09 +08:00
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
2023-09-26 05:42:24 +08:00
"import autogen\n",
2023-07-23 21:23:09 +08:00
"\n",
2023-08-01 10:22:30 +08:00
"config_list = autogen.config_list_from_json(\n",
2023-07-23 21:23:09 +08:00
" \"OAI_CONFIG_LIST\",\n",
" filter_dict={\n",
2023-08-14 15:09:45 +08:00
" \"model\": [\"gpt-4\", \"gpt4\", \"gpt-4-32k\", \"gpt-4-32k-0314\", \"gpt-4-32k-v0314\"],\n",
2023-07-23 21:23:09 +08:00
" },\n",
")"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"## Construct Agents\n",
"\n",
"We define `ask_expert` function to start a conversation between two agents and return a summary of the result. We construct an assistant agent named \"assistant_for_expert\" and a user proxy agent named \"expert\". We specify `human_input_mode` as \"ALWAYS\" in the user proxy agent, which will always ask for feedback from the expert user."
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"def ask_expert(message):\n",
2023-08-01 10:22:30 +08:00
" assistant_for_expert = autogen.AssistantAgent(\n",
2023-07-23 21:23:09 +08:00
" name=\"assistant_for_expert\",\n",
2023-08-01 10:22:30 +08:00
" llm_config={\n",
2023-07-29 12:17:51 +08:00
" \"temperature\": 0,\n",
" \"config_list\": config_list,\n",
" },\n",
2023-07-23 21:23:09 +08:00
" )\n",
2023-08-01 10:22:30 +08:00
" expert = autogen.UserProxyAgent(\n",
2023-07-23 21:23:09 +08:00
" name=\"expert\",\n",
" human_input_mode=\"ALWAYS\",\n",
2024-01-19 01:03:49 +08:00
" code_execution_config={\n",
" \"work_dir\": \"expert\",\n",
" \"use_docker\": False,\n",
" }, # Please set use_docker=True if docker is available to run the generated code. Using docker is safer than running the generated code directly.\n",
2023-07-23 21:23:09 +08:00
" )\n",
"\n",
" expert.initiate_chat(assistant_for_expert, message=message)\n",
2023-08-28 06:16:52 +08:00
" expert.stop_reply_at_receive(assistant_for_expert)\n",
" # expert.human_input_mode, expert.max_consecutive_auto_reply = \"NEVER\", 0\n",
2023-07-29 12:17:51 +08:00
" # final message sent from the expert\n",
2023-08-30 08:54:09 +08:00
" expert.send(\"summarize the solution and explain the answer in an easy-to-understand way\", assistant_for_expert)\n",
2023-07-29 12:17:51 +08:00
" # return the last message the expert received\n",
2024-01-08 11:47:01 +08:00
" return expert.last_message()[\"content\"]"
2023-07-23 21:23:09 +08:00
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"We construct another assistant agent named \"assistant_for_student\" and a user proxy agent named \"student\". We specify `human_input_mode` as \"TERMINATE\" in the user proxy agent, which will ask for feedback when it receives a \"TERMINATE\" signal from the assistant agent. We set the `functions` in `AssistantAgent` and `function_map` in `UserProxyAgent` to use the created `ask_expert` function.\n",
"\n",
"For simplicity, the `ask_expert` function is defined to run locally. For real applications, the function should run remotely to interact with an expert user."
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
2023-08-01 10:22:30 +08:00
"assistant_for_student = autogen.AssistantAgent(\n",
2023-07-23 21:23:09 +08:00
" name=\"assistant_for_student\",\n",
2023-08-30 08:54:09 +08:00
" system_message=\"You are a helpful assistant. Reply TERMINATE when the task is done.\",\n",
2023-08-01 10:22:30 +08:00
" llm_config={\n",
2023-11-04 12:01:49 +08:00
" \"timeout\": 600,\n",
2023-11-09 07:39:02 +08:00
" \"cache_seed\": 42,\n",
2023-11-07 05:14:05 +08:00
" \"config_list\": config_list,\n",
2023-07-26 07:46:11 +08:00
" \"temperature\": 0,\n",
" \"functions\": [\n",
" {\n",
" \"name\": \"ask_expert\",\n",
" \"description\": \"ask expert when you can't solve the problem satisfactorily.\",\n",
" \"parameters\": {\n",
" \"type\": \"object\",\n",
" \"properties\": {\n",
" \"message\": {\n",
" \"type\": \"string\",\n",
2023-10-22 12:46:07 +08:00
" \"description\": \"question to ask expert. Ensure the question includes enough context, such as the code and the execution result. The expert does not know the conversation between you and the user unless you share the conversation with the expert.\",\n",
2023-07-26 07:46:11 +08:00
" },\n",
2023-07-23 21:23:09 +08:00
" },\n",
2023-07-26 07:46:11 +08:00
" \"required\": [\"message\"],\n",
2023-07-23 21:23:09 +08:00
" },\n",
2023-07-26 07:46:11 +08:00
" }\n",
" ],\n",
2024-01-08 11:47:01 +08:00
" },\n",
2023-07-23 21:23:09 +08:00
")\n",
"\n",
2023-08-01 10:22:30 +08:00
"student = autogen.UserProxyAgent(\n",
2023-07-23 21:23:09 +08:00
" name=\"student\",\n",
" human_input_mode=\"TERMINATE\",\n",
" max_consecutive_auto_reply=10,\n",
2024-01-19 01:03:49 +08:00
" code_execution_config={\n",
" \"work_dir\": \"student\",\n",
" \"use_docker\": False,\n",
" }, # Please set use_docker=True if docker is available to run the generated code. Using docker is safer than running the generated code directly.\n",
2023-07-23 21:23:09 +08:00
" function_map={\"ask_expert\": ask_expert},\n",
")"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"## Perform a task\n",
"\n",
2023-10-22 12:46:07 +08:00
"We invoke the `initiate_chat()` method of the student proxy agent to start the conversation. When you run the cell below, you will be prompted to provide feedback after the assistant agent sends a \"TERMINATE\" signal at the end of the message. The conversation will finish if you don't provide any feedback (by pressing Enter directly). Before the \"TERMINATE\" signal, the student proxy agent will try to execute the code suggested by the assistant agent on behalf of the user."
2023-07-23 21:23:09 +08:00
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
2023-08-28 06:16:52 +08:00
"\u001b[33mstudent\u001b[0m (to assistant_for_student):\n",
2023-07-23 21:23:09 +08:00
"\n",
"Find $a + b + c$, given that $x+y \\neq -1$ and \n",
2023-07-29 12:17:51 +08:00
"\\begin{align}\n",
2023-07-23 21:23:09 +08:00
"\tax + by + c & = x + 7,\\\n",
"\ta + bx + cy & = 2x + 6y,\\\n",
"\tay + b + cx & = 4x + y.\n",
2023-07-29 12:17:51 +08:00
"\\end{align}.\n",
2023-07-23 21:23:09 +08:00
"\n",
"\n",
"--------------------------------------------------------------------------------\n",
2023-08-28 06:16:52 +08:00
"\u001b[33massistant_for_student\u001b[0m (to student):\n",
2023-07-23 21:23:09 +08:00
"\n",
2023-08-30 08:54:09 +08:00
"To find the values of $a$, $b$, and $c$, we need to solve the system of equations. However, the system of equations you provided seems to be incomplete or incorrect. The equations are not properly formatted, and it's unclear how $x$ and $y$ are related to $a$, $b$, and $c$. \n",
2023-08-28 06:16:52 +08:00
"\n",
2023-08-30 08:54:09 +08:00
"Could you please provide the correct system of equations?\n",
2023-07-23 21:23:09 +08:00
"\n",
"--------------------------------------------------------------------------------\n",
2023-08-28 06:16:52 +08:00
"\u001b[31m\n",
">>>>>>>> USING AUTO REPLY...\u001b[0m\n",
"\u001b[33mstudent\u001b[0m (to assistant_for_student):\n",
2023-07-23 21:23:09 +08:00
"\n",
"\n",
"\n",
"--------------------------------------------------------------------------------\n",
2023-08-28 06:16:52 +08:00
"\u001b[33massistant_for_student\u001b[0m (to student):\n",
"\n",
2023-08-30 08:54:09 +08:00
"\u001b[32m***** Suggested function Call: ask_expert *****\u001b[0m\n",
"Arguments: \n",
"{\n",
" \"message\": \"The user provided a system of equations and asked to find $a + b + c$, given that $x+y \\\\neq -1$ and \\n\\\\begin{align}\\n\\tax + by + c & = x + 7,\\\\\\n\\ta + bx + cy & = 2x + 6y,\\\\\\n\\tay + b + cx & = 4x + y.\\n\\\\end{align}. However, the system of equations seems to be incomplete or incorrectly formatted. How should I proceed?\"\n",
"}\n",
"\u001b[32m***********************************************\u001b[0m\n",
2023-07-23 21:23:09 +08:00
"\n",
"--------------------------------------------------------------------------------\n",
2023-08-28 06:16:52 +08:00
"\u001b[31m\n",
">>>>>>>> USING AUTO REPLY...\u001b[0m\n",
2023-08-30 08:54:09 +08:00
"\u001b[35m\n",
">>>>>>>> EXECUTING FUNCTION ask_expert...\u001b[0m\n",
"\u001b[33mexpert\u001b[0m (to assistant_for_expert):\n",
2023-07-23 21:23:09 +08:00
"\n",
2023-08-30 08:54:09 +08:00
"The user provided a system of equations and asked to find $a + b + c$, given that $x+y \\neq -1$ and \n",
"\\begin{align}\n",
"\tax + by + c & = x + 7,\\\n",
"\ta + bx + cy & = 2x + 6y,\\\n",
"\tay + b + cx & = 4x + y.\n",
"\\end{align}. However, the system of equations seems to be incomplete or incorrectly formatted. How should I proceed?\n",
2023-07-23 21:23:09 +08:00
"\n",
"--------------------------------------------------------------------------------\n",
2023-08-30 08:54:09 +08:00
"\u001b[33massistant_for_expert\u001b[0m (to expert):\n",
2023-07-23 21:23:09 +08:00
"\n",
2023-08-30 08:54:09 +08:00
"To proceed, we can first try to solve the given system of equations and see if we can find a unique solution for $a$, $b$, and $c$. If we can't find a unique solution, we can then determine if there's any additional information needed or if the system is indeed incomplete or incorrectly formatted.\n",
"\n",
"Let's solve the given system of equations using Python's SymPy library.\n",
2023-07-23 21:23:09 +08:00
"\n",
"--------------------------------------------------------------------------------\n",
2023-08-30 08:54:09 +08:00
"\u001b[33mexpert\u001b[0m (to assistant_for_expert):\n",
2023-07-23 21:23:09 +08:00
"\n",
2023-08-30 08:54:09 +08:00
"make sure you simplify the answer\n",
2023-07-23 21:23:09 +08:00
"\n",
"--------------------------------------------------------------------------------\n",
2023-08-30 08:54:09 +08:00
"\u001b[33massistant_for_expert\u001b[0m (to expert):\n",
2023-07-23 21:23:09 +08:00
"\n",
2023-08-30 08:54:09 +08:00
"Sure, I will simplify the answer. Let's solve the given system of equations using Python's SymPy library and simplify the result.\n",
2023-07-23 21:23:09 +08:00
"\n",
"--------------------------------------------------------------------------------\n",
2023-08-28 06:16:52 +08:00
"\u001b[31m\n",
2023-08-30 08:54:09 +08:00
">>>>>>>> NO HUMAN INPUT RECEIVED.\u001b[0m\n",
"\u001b[31m\n",
2023-08-28 06:16:52 +08:00
">>>>>>>> USING AUTO REPLY...\u001b[0m\n",
"\u001b[33mexpert\u001b[0m (to assistant_for_expert):\n",
2023-07-23 21:23:09 +08:00
"\n",
"\n",
"\n",
"--------------------------------------------------------------------------------\n",
2023-08-28 06:16:52 +08:00
"\u001b[33massistant_for_expert\u001b[0m (to expert):\n",
2023-07-23 21:23:09 +08:00
"\n",
2023-08-30 08:54:09 +08:00
"First, let's install the SymPy library if you haven't already. Execute the following command to install it:\n",
"\n",
"```sh\n",
"pip install sympy\n",
"```\n",
2023-07-23 21:23:09 +08:00
"\n",
2023-08-30 08:54:09 +08:00
"Now, let's solve the given system of equations using Python's SymPy library and simplify the result.\n",
2023-07-23 21:23:09 +08:00
"\n",
2023-08-28 06:16:52 +08:00
"```python\n",
2023-08-30 08:54:09 +08:00
"from sympy import symbols, Eq, solve, simplify\n",
2023-07-23 21:23:09 +08:00
"\n",
2023-08-30 08:54:09 +08:00
"a, b, c, x, y = symbols('a b c x y')\n",
2023-07-23 21:23:09 +08:00
"\n",
2023-08-30 08:54:09 +08:00
"eq1 = Eq(a * x + b * y + c, x + 7)\n",
"eq2 = Eq(a + b * x + c * y, 2 * x + 6 * y)\n",
"eq3 = Eq(a * y + b + c * x, 4 * x + y)\n",
2023-07-23 21:23:09 +08:00
"\n",
2023-08-30 08:54:09 +08:00
"solutions = solve((eq1, eq2, eq3), (a, b, c))\n",
2023-07-23 21:23:09 +08:00
"\n",
2023-08-30 08:54:09 +08:00
"simplified_solutions = {key: simplify(value) for key, value in solutions.items()}\n",
"a_val, b_val, c_val = simplified_solutions[a], simplified_solutions[b], simplified_solutions[c]\n",
"sum_abc = simplify(a_val + b_val + c_val)\n",
"\n",
"print(f\"a: {a_val}\")\n",
"print(f\"b: {b_val}\")\n",
"print(f\"c: {c_val}\")\n",
"print(f\"a + b + c: {sum_abc}\")\n",
2023-07-23 21:23:09 +08:00
"```\n",
"\n",
2023-08-30 08:54:09 +08:00
"Please execute the above Python code to solve the system of equations and simplify the result.\n",
2023-07-23 21:23:09 +08:00
"\n",
"--------------------------------------------------------------------------------\n",
2023-08-28 06:16:52 +08:00
"\u001b[31m\n",
">>>>>>>> NO HUMAN INPUT RECEIVED.\u001b[0m\n",
"\u001b[31m\n",
">>>>>>>> USING AUTO REPLY...\u001b[0m\n",
"\u001b[31m\n",
2023-08-30 08:54:09 +08:00
">>>>>>>> EXECUTING CODE BLOCK 0 (inferred language is sh)...\u001b[0m\n",
"\u001b[31m\n",
">>>>>>>> EXECUTING CODE BLOCK 1 (inferred language is python)...\u001b[0m\n",
2023-08-28 06:16:52 +08:00
"\u001b[33mexpert\u001b[0m (to assistant_for_expert):\n",
2023-07-23 21:23:09 +08:00
"\n",
"exitcode: 0 (execution succeeded)\n",
"Code output: \n",
2023-08-30 08:54:09 +08:00
"Defaulting to user installation because normal site-packages is not writeable\n",
"Requirement already satisfied: sympy in /home/vscode/.local/lib/python3.9/site-packages (1.12)\n",
"Requirement already satisfied: mpmath>=0.19 in /home/vscode/.local/lib/python3.9/site-packages (from sympy) (1.3.0)\n",
2023-07-23 21:23:09 +08:00
"\n",
2023-08-30 08:54:09 +08:00
"a: (x**2 - 3*x*y + 2*x + y**2 - y)/(x**2 - x*y - x + y**2 - y + 1)\n",
"b: (2*x**2 - 3*x + y)/(x**2 - x*y - x + y**2 - y + 1)\n",
"c: (4*x**2 - 4*x*y - 6*x + 6*y**2 - 7*y + 7)/(x**2 - x*y - x + y**2 - y + 1)\n",
"a + b + c: 7\n",
2023-07-23 21:23:09 +08:00
"\n",
"\n",
"--------------------------------------------------------------------------------\n",
2023-08-28 06:16:52 +08:00
"\u001b[33massistant_for_expert\u001b[0m (to expert):\n",
2023-07-23 21:23:09 +08:00
"\n",
2023-08-30 08:54:09 +08:00
"The given system of equations has been solved and simplified. The result is:\n",
2023-07-23 21:23:09 +08:00
"\n",
2023-08-30 08:54:09 +08:00
"$$\n",
"a = \\frac{x^2 - 3xy + 2x + y^2 - y}{x^2 - xy - x + y^2 - y + 1}, \\\\\n",
"b = \\frac{2x^2 - 3x + y}{x^2 - xy - x + y^2 - y + 1}, \\\\\n",
"c = \\frac{4x^2 - 4xy - 6x + 6y^2 - 7y + 7}{x^2 - xy - x + y^2 - y + 1}.\n",
"$$\n",
2023-07-23 21:23:09 +08:00
"\n",
2023-08-30 08:54:09 +08:00
"The sum $a + b + c$ is equal to $7$. Since we were able to find a unique solution for $a$, $b$, and $c$, the system of equations is complete and correctly formatted.\n",
2023-07-23 21:23:09 +08:00
"\n",
2023-08-30 08:54:09 +08:00
"TERMINATE\n",
2023-07-23 21:23:09 +08:00
"\n",
"--------------------------------------------------------------------------------\n",
2023-08-28 06:16:52 +08:00
"\u001b[31m\n",
">>>>>>>> NO HUMAN INPUT RECEIVED.\u001b[0m\n",
"\u001b[31m\n",
">>>>>>>> USING AUTO REPLY...\u001b[0m\n",
"\u001b[33mexpert\u001b[0m (to assistant_for_expert):\n",
2023-07-23 21:23:09 +08:00
"\n",
"\n",
"\n",
"--------------------------------------------------------------------------------\n",
2023-08-28 06:16:52 +08:00
"\u001b[33massistant_for_expert\u001b[0m (to expert):\n",
2023-07-29 12:17:51 +08:00
"\n",
"TERMINATE\n",
2023-07-23 21:23:09 +08:00
"\n",
2023-07-29 12:17:51 +08:00
"--------------------------------------------------------------------------------\n",
2023-08-30 08:54:09 +08:00
"\u001b[31m\n",
">>>>>>>> NO HUMAN INPUT RECEIVED.\u001b[0m\n",
2023-08-28 06:16:52 +08:00
"\u001b[33mexpert\u001b[0m (to assistant_for_expert):\n",
2023-07-23 21:23:09 +08:00
"\n",
2023-08-30 08:54:09 +08:00
"summarize the solution and explain the answer in an easy-to-understand way\n",
2023-07-23 21:23:09 +08:00
"\n",
2023-07-29 12:17:51 +08:00
"--------------------------------------------------------------------------------\n",
2023-08-28 06:16:52 +08:00
"\u001b[33massistant_for_expert\u001b[0m (to expert):\n",
2023-07-23 21:23:09 +08:00
"\n",
2023-08-30 08:54:09 +08:00
"Sure, let me summarize the solution and explain the answer in an easy-to-understand way.\n",
2023-07-23 21:23:09 +08:00
"\n",
2023-08-30 08:54:09 +08:00
"We were given a system of three equations with three unknowns, $a$, $b$, and $c$. The equations were:\n",
2023-07-23 21:23:09 +08:00
"\n",
2023-08-30 08:54:09 +08:00
"1. $ax + by + c = x + 7$\n",
"2. $a + bx + cy = 2x + 6y$\n",
"3. $ay + b + cx = 4x + y$\n",
2023-07-23 21:23:09 +08:00
"\n",
2023-08-30 08:54:09 +08:00
"We were asked to find the sum $a + b + c$ given that $x + y \\neq -1$.\n",
2023-07-23 21:23:09 +08:00
"\n",
2023-08-30 08:54:09 +08:00
"We used Python's SymPy library to solve the system of equations and found the following solutions for $a$, $b$, and $c$:\n",
"\n",
"$$\n",
"a = \\frac{x^2 - 3xy + 2x + y^2 - y}{x^2 - xy - x + y^2 - y + 1}, \\\\\n",
"b = \\frac{2x^2 - 3x + y}{x^2 - xy - x + y^2 - y + 1}, \\\\\n",
"c = \\frac{4x^2 - 4xy - 6x + 6y^2 - 7y + 7}{x^2 - xy - x + y^2 - y + 1}.\n",
"$$\n",
"\n",
"These solutions are expressed in terms of $x$ and $y$. However, we were able to find the sum $a + b + c$ without knowing the values of $x$ and $y$. The sum $a + b + c$ simplifies to $7$.\n",
"\n",
"In conclusion, the sum $a + b + c$ for the given system of equations is equal to $7$.\n",
2023-07-23 21:23:09 +08:00
"\n",
"--------------------------------------------------------------------------------\n",
2023-08-28 06:16:52 +08:00
"\u001b[33mstudent\u001b[0m (to assistant_for_student):\n",
2023-07-23 21:23:09 +08:00
"\n",
2023-08-28 06:16:52 +08:00
"\u001b[32m***** Response from calling function \"ask_expert\" *****\u001b[0m\n",
2023-08-30 08:54:09 +08:00
"Sure, let me summarize the solution and explain the answer in an easy-to-understand way.\n",
2023-07-29 12:17:51 +08:00
"\n",
2023-08-30 08:54:09 +08:00
"We were given a system of three equations with three unknowns, $a$, $b$, and $c$. The equations were:\n",
2023-07-29 12:17:51 +08:00
"\n",
2023-08-30 08:54:09 +08:00
"1. $ax + by + c = x + 7$\n",
"2. $a + bx + cy = 2x + 6y$\n",
"3. $ay + b + cx = 4x + y$\n",
2023-07-23 21:23:09 +08:00
"\n",
2023-08-30 08:54:09 +08:00
"We were asked to find the sum $a + b + c$ given that $x + y \\neq -1$.\n",
2023-07-23 21:23:09 +08:00
"\n",
2023-08-30 08:54:09 +08:00
"We used Python's SymPy library to solve the system of equations and found the following solutions for $a$, $b$, and $c$:\n",
"\n",
"$$\n",
"a = \\frac{x^2 - 3xy + 2x + y^2 - y}{x^2 - xy - x + y^2 - y + 1}, \\\\\n",
"b = \\frac{2x^2 - 3x + y}{x^2 - xy - x + y^2 - y + 1}, \\\\\n",
"c = \\frac{4x^2 - 4xy - 6x + 6y^2 - 7y + 7}{x^2 - xy - x + y^2 - y + 1}.\n",
"$$\n",
"\n",
"These solutions are expressed in terms of $x$ and $y$. However, we were able to find the sum $a + b + c$ without knowing the values of $x$ and $y$. The sum $a + b + c$ simplifies to $7$.\n",
"\n",
"In conclusion, the sum $a + b + c$ for the given system of equations is equal to $7$.\n",
2023-08-28 06:16:52 +08:00
"\u001b[32m*******************************************************\u001b[0m\n",
2023-07-23 21:23:09 +08:00
"\n",
"--------------------------------------------------------------------------------\n",
2023-08-28 06:16:52 +08:00
"\u001b[33massistant_for_student\u001b[0m (to student):\n",
2023-07-23 21:23:09 +08:00
"\n",
2023-08-30 08:54:09 +08:00
"The solution to the system of equations you provided is:\n",
2023-07-23 21:23:09 +08:00
"\n",
2023-08-30 08:54:09 +08:00
"1. $a = \\frac{x^2 - 3xy + 2x + y^2 - y}{x^2 - xy - x + y^2 - y + 1}$\n",
"2. $b = \\frac{2x^2 - 3x + y}{x^2 - xy - x + y^2 - y + 1}$\n",
"3. $c = \\frac{4x^2 - 4xy - 6x + 6y^2 - 7y + 7}{x^2 - xy - x + y^2 - y + 1}$\n",
2023-07-23 21:23:09 +08:00
"\n",
2023-08-30 08:54:09 +08:00
"These solutions are expressed in terms of $x$ and $y$. However, we can find the sum $a + b + c$ without knowing the values of $x$ and $y$. The sum $a + b + c$ simplifies to $7$.\n",
2023-07-23 21:23:09 +08:00
"\n",
2023-08-30 08:54:09 +08:00
"So, the sum $a + b + c$ for the given system of equations is equal to $7$.\n",
2023-07-23 21:23:09 +08:00
"\n",
"--------------------------------------------------------------------------------\n",
2023-08-28 06:16:52 +08:00
"\u001b[31m\n",
">>>>>>>> USING AUTO REPLY...\u001b[0m\n",
"\u001b[33mstudent\u001b[0m (to assistant_for_student):\n",
2023-07-23 21:23:09 +08:00
"\n",
"\n",
"\n",
"--------------------------------------------------------------------------------\n",
2023-08-28 06:16:52 +08:00
"\u001b[33massistant_for_student\u001b[0m (to student):\n",
2023-07-23 21:23:09 +08:00
"\n",
"TERMINATE\n",
"\n",
2023-08-28 06:16:52 +08:00
"--------------------------------------------------------------------------------\n",
"\u001b[31m\n",
">>>>>>>> NO HUMAN INPUT RECEIVED.\u001b[0m\n"
2023-07-23 21:23:09 +08:00
]
}
],
"source": [
"# the assistant receives a message from the student, which contains the task description\n",
"student.initiate_chat(\n",
" assistant_for_student,\n",
2024-01-08 11:47:01 +08:00
" message=\"\"\"Find $a + b + c$, given that $x+y \\\\neq -1$ and\n",
2023-07-29 12:17:51 +08:00
"\\\\begin{align}\n",
2023-07-23 21:23:09 +08:00
"\tax + by + c & = x + 7,\\\\\n",
"\ta + bx + cy & = 2x + 6y,\\\\\n",
"\tay + b + cx & = 4x + y.\n",
2023-07-29 12:17:51 +08:00
"\\\\end{align}.\n",
2023-07-23 21:23:09 +08:00
"\"\"\",\n",
")"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"When the assistant needs to consult the expert, it suggests a function call to `ask_expert`. When this happens, a line like the following will be displayed:\n",
"\n",
"***** Suggested function Call: ask_expert *****\n"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"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.9.17"
},
"vscode": {
"interpreter": {
"hash": "949777d72b0d2535278d3dc13498b2535136f6dfe0678499012e853ee9abcab1"
}
},
"widgets": {
"application/vnd.jupyter.widget-state+json": {
"state": {
"2d910cfd2d2a4fc49fc30fbbdc5576a7": {
"model_module": "@jupyter-widgets/base",
"model_module_version": "2.0.0",
"model_name": "LayoutModel",
"state": {
"_model_module": "@jupyter-widgets/base",
"_model_module_version": "2.0.0",
"_model_name": "LayoutModel",
"_view_count": null,
"_view_module": "@jupyter-widgets/base",
"_view_module_version": "2.0.0",
"_view_name": "LayoutView",
"align_content": null,
"align_items": null,
"align_self": null,
"border_bottom": null,
"border_left": null,
"border_right": null,
"border_top": null,
"bottom": null,
"display": null,
"flex": null,
"flex_flow": null,
"grid_area": null,
"grid_auto_columns": null,
"grid_auto_flow": null,
"grid_auto_rows": null,
"grid_column": null,
"grid_gap": null,
"grid_row": null,
"grid_template_areas": null,
"grid_template_columns": null,
"grid_template_rows": null,
"height": null,
"justify_content": null,
"justify_items": null,
"left": null,
"margin": null,
"max_height": null,
"max_width": null,
"min_height": null,
"min_width": null,
"object_fit": null,
"object_position": null,
"order": null,
"overflow": null,
"padding": null,
"right": null,
"top": null,
"visibility": null,
"width": null
}
},
"454146d0f7224f038689031002906e6f": {
"model_module": "@jupyter-widgets/controls",
"model_module_version": "2.0.0",
"model_name": "HBoxModel",
"state": {
"_dom_classes": [],
"_model_module": "@jupyter-widgets/controls",
"_model_module_version": "2.0.0",
"_model_name": "HBoxModel",
"_view_count": null,
"_view_module": "@jupyter-widgets/controls",
"_view_module_version": "2.0.0",
"_view_name": "HBoxView",
"box_style": "",
"children": [
"IPY_MODEL_e4ae2b6f5a974fd4bafb6abb9d12ff26",
"IPY_MODEL_577e1e3cc4db4942b0883577b3b52755",
"IPY_MODEL_b40bdfb1ac1d4cffb7cefcb870c64d45"
],
"layout": "IPY_MODEL_dc83c7bff2f241309537a8119dfc7555",
"tabbable": null,
"tooltip": null
}
},
"577e1e3cc4db4942b0883577b3b52755": {
"model_module": "@jupyter-widgets/controls",
"model_module_version": "2.0.0",
"model_name": "FloatProgressModel",
"state": {
"_dom_classes": [],
"_model_module": "@jupyter-widgets/controls",
"_model_module_version": "2.0.0",
"_model_name": "FloatProgressModel",
"_view_count": null,
"_view_module": "@jupyter-widgets/controls",
"_view_module_version": "2.0.0",
"_view_name": "ProgressView",
"bar_style": "success",
"description": "",
"description_allow_html": false,
"layout": "IPY_MODEL_2d910cfd2d2a4fc49fc30fbbdc5576a7",
"max": 1,
"min": 0,
"orientation": "horizontal",
"style": "IPY_MODEL_74a6ba0c3cbc4051be0a83e152fe1e62",
"tabbable": null,
"tooltip": null,
"value": 1
}
},
"6086462a12d54bafa59d3c4566f06cb2": {
"model_module": "@jupyter-widgets/base",
"model_module_version": "2.0.0",
"model_name": "LayoutModel",
"state": {
"_model_module": "@jupyter-widgets/base",
"_model_module_version": "2.0.0",
"_model_name": "LayoutModel",
"_view_count": null,
"_view_module": "@jupyter-widgets/base",
"_view_module_version": "2.0.0",
"_view_name": "LayoutView",
"align_content": null,
"align_items": null,
"align_self": null,
"border_bottom": null,
"border_left": null,
"border_right": null,
"border_top": null,
"bottom": null,
"display": null,
"flex": null,
"flex_flow": null,
"grid_area": null,
"grid_auto_columns": null,
"grid_auto_flow": null,
"grid_auto_rows": null,
"grid_column": null,
"grid_gap": null,
"grid_row": null,
"grid_template_areas": null,
"grid_template_columns": null,
"grid_template_rows": null,
"height": null,
"justify_content": null,
"justify_items": null,
"left": null,
"margin": null,
"max_height": null,
"max_width": null,
"min_height": null,
"min_width": null,
"object_fit": null,
"object_position": null,
"order": null,
"overflow": null,
"padding": null,
"right": null,
"top": null,
"visibility": null,
"width": null
}
},
"74a6ba0c3cbc4051be0a83e152fe1e62": {
"model_module": "@jupyter-widgets/controls",
"model_module_version": "2.0.0",
"model_name": "ProgressStyleModel",
"state": {
"_model_module": "@jupyter-widgets/controls",
"_model_module_version": "2.0.0",
"_model_name": "ProgressStyleModel",
"_view_count": null,
"_view_module": "@jupyter-widgets/base",
"_view_module_version": "2.0.0",
"_view_name": "StyleView",
"bar_color": null,
"description_width": ""
}
},
"7d3f3d9e15894d05a4d188ff4f466554": {
"model_module": "@jupyter-widgets/controls",
"model_module_version": "2.0.0",
"model_name": "HTMLStyleModel",
"state": {
"_model_module": "@jupyter-widgets/controls",
"_model_module_version": "2.0.0",
"_model_name": "HTMLStyleModel",
"_view_count": null,
"_view_module": "@jupyter-widgets/base",
"_view_module_version": "2.0.0",
"_view_name": "StyleView",
"background": null,
"description_width": "",
"font_size": null,
"text_color": null
}
},
"b40bdfb1ac1d4cffb7cefcb870c64d45": {
"model_module": "@jupyter-widgets/controls",
"model_module_version": "2.0.0",
"model_name": "HTMLModel",
"state": {
"_dom_classes": [],
"_model_module": "@jupyter-widgets/controls",
"_model_module_version": "2.0.0",
"_model_name": "HTMLModel",
"_view_count": null,
"_view_module": "@jupyter-widgets/controls",
"_view_module_version": "2.0.0",
"_view_name": "HTMLView",
"description": "",
"description_allow_html": false,
"layout": "IPY_MODEL_f1355871cc6f4dd4b50d9df5af20e5c8",
"placeholder": " ",
"style": "IPY_MODEL_ca245376fd9f4354af6b2befe4af4466",
"tabbable": null,
"tooltip": null,
"value": " 1/1 [00:00<00:00, 44.69it/s]"
}
},
"ca245376fd9f4354af6b2befe4af4466": {
"model_module": "@jupyter-widgets/controls",
"model_module_version": "2.0.0",
"model_name": "HTMLStyleModel",
"state": {
"_model_module": "@jupyter-widgets/controls",
"_model_module_version": "2.0.0",
"_model_name": "HTMLStyleModel",
"_view_count": null,
"_view_module": "@jupyter-widgets/base",
"_view_module_version": "2.0.0",
"_view_name": "StyleView",
"background": null,
"description_width": "",
"font_size": null,
"text_color": null
}
},
"dc83c7bff2f241309537a8119dfc7555": {
"model_module": "@jupyter-widgets/base",
"model_module_version": "2.0.0",
"model_name": "LayoutModel",
"state": {
"_model_module": "@jupyter-widgets/base",
"_model_module_version": "2.0.0",
"_model_name": "LayoutModel",
"_view_count": null,
"_view_module": "@jupyter-widgets/base",
"_view_module_version": "2.0.0",
"_view_name": "LayoutView",
"align_content": null,
"align_items": null,
"align_self": null,
"border_bottom": null,
"border_left": null,
"border_right": null,
"border_top": null,
"bottom": null,
"display": null,
"flex": null,
"flex_flow": null,
"grid_area": null,
"grid_auto_columns": null,
"grid_auto_flow": null,
"grid_auto_rows": null,
"grid_column": null,
"grid_gap": null,
"grid_row": null,
"grid_template_areas": null,
"grid_template_columns": null,
"grid_template_rows": null,
"height": null,
"justify_content": null,
"justify_items": null,
"left": null,
"margin": null,
"max_height": null,
"max_width": null,
"min_height": null,
"min_width": null,
"object_fit": null,
"object_position": null,
"order": null,
"overflow": null,
"padding": null,
"right": null,
"top": null,
"visibility": null,
"width": null
}
},
"e4ae2b6f5a974fd4bafb6abb9d12ff26": {
"model_module": "@jupyter-widgets/controls",
"model_module_version": "2.0.0",
"model_name": "HTMLModel",
"state": {
"_dom_classes": [],
"_model_module": "@jupyter-widgets/controls",
"_model_module_version": "2.0.0",
"_model_name": "HTMLModel",
"_view_count": null,
"_view_module": "@jupyter-widgets/controls",
"_view_module_version": "2.0.0",
"_view_name": "HTMLView",
"description": "",
"description_allow_html": false,
"layout": "IPY_MODEL_6086462a12d54bafa59d3c4566f06cb2",
"placeholder": " ",
"style": "IPY_MODEL_7d3f3d9e15894d05a4d188ff4f466554",
"tabbable": null,
"tooltip": null,
"value": "100%"
}
},
"f1355871cc6f4dd4b50d9df5af20e5c8": {
"model_module": "@jupyter-widgets/base",
"model_module_version": "2.0.0",
"model_name": "LayoutModel",
"state": {
"_model_module": "@jupyter-widgets/base",
"_model_module_version": "2.0.0",
"_model_name": "LayoutModel",
"_view_count": null,
"_view_module": "@jupyter-widgets/base",
"_view_module_version": "2.0.0",
"_view_name": "LayoutView",
"align_content": null,
"align_items": null,
"align_self": null,
"border_bottom": null,
"border_left": null,
"border_right": null,
"border_top": null,
"bottom": null,
"display": null,
"flex": null,
"flex_flow": null,
"grid_area": null,
"grid_auto_columns": null,
"grid_auto_flow": null,
"grid_auto_rows": null,
"grid_column": null,
"grid_gap": null,
"grid_row": null,
"grid_template_areas": null,
"grid_template_columns": null,
"grid_template_rows": null,
"height": null,
"justify_content": null,
"justify_items": null,
"left": null,
"margin": null,
"max_height": null,
"max_width": null,
"min_height": null,
"min_width": null,
"object_fit": null,
"object_position": null,
"order": null,
"overflow": null,
"padding": null,
"right": null,
"top": null,
"visibility": null,
"width": null
}
}
},
"version_major": 2,
"version_minor": 0
}
}
},
"nbformat": 4,
"nbformat_minor": 2
}