"<a href=\"https://colab.research.google.com/github/microsoft/autogen/blob/main/notebook/agentchat_teaching.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"# Auto Generated Agent Chat: Teaching\n",
"\n",
"AutoGen offers conversable agents powered by LLM, tool or human, which can be used to perform tasks collectively via automated chat. This framwork makes it easy to build many advanced applications of LLMs.\n",
"Please find documentation about this feature [here](https://microsoft.github.io/autogen/docs/Use-Cases/agent_chat).\n",
"\n",
"This notebook demonstrates how AutoGen enables a user to teach AI new skills via natural agent interactions, without requiring knowledge of programming language. It is modified based on https://github.com/microsoft/FLAML/blob/evaluation/notebook/research_paper/teaching.ipynb and https://github.com/microsoft/FLAML/blob/evaluation/notebook/research_paper/teaching_recipe_reuse.ipynb.\n",
"\n",
"## Requirements\n",
"\n",
"AutoGen requires `Python>=3.8`. To run this notebook example, please install:\n",
"```bash\n",
"pip install pyautogen\n",
"```"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# %pip install --quiet pyautogen~=0.1.0"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"## Set your API Endpoint\n",
"\n",
"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",
"\n",
"It first looks for environment variable \"OAI_CONFIG_LIST\" which needs to be a valid json string. If that variable is not found, it then looks for a json file named \"OAI_CONFIG_LIST\". It filters the configs by models (you can filter by other keys as well).\n",
"\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",
" \"api_base\": \"<your Azure OpenAI API base here>\",\n",
" \"api_type\": \"azure\",\n",
" \"api_version\": \"2023-06-01-preview\"\n",
" },\n",
" {\n",
" \"model\": \"gpt-4-32k\",\n",
" \"api_key\": \"<your Azure OpenAI API key here>\",\n",
" \"api_base\": \"<your Azure OpenAI API base here>\",\n",
" \"api_type\": \"azure\",\n",
" \"api_version\": \"2023-06-01-preview\"\n",
" }\n",
"]\n",
"```\n",
"\n",
"If you open this notebook in colab, you can upload your files by clicking the file icon on the left panel and then choose \"upload file\" icon.\n"
"We consider a scenario where one needs to find research papers of a certain topic, categorize the application domains, and plot a bar chart of the number of papers in each domain."
"We create an assistant agent to solve tasks with coding and language skills. We create a user proxy agent to describe tasks and execute the code suggested by the assistant agent."
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"# create an AssistantAgent instance named \"assistant\"\n",
"assistant = autogen.AssistantAgent(\n",
" name=\"assistant\",\n",
" llm_config=llm_config,\n",
" is_termination_msg=lambda x: True if \"TERMINATE\" in x.get(\"content\") else False,\n",
")\n",
"# create a UserProxyAgent instance named \"user_proxy\"\n",
"user_proxy = autogen.UserProxyAgent(\n",
" name=\"user_proxy\",\n",
" human_input_mode=\"NEVER\",\n",
" is_termination_msg=lambda x: True if \"TERMINATE\" in x.get(\"content\") else False,\n",
"To find arxiv papers related to trust calibration in AI-based systems, we can use the arxiv API to search for relevant papers. I will write a Python script that queries the arxiv API and prints the titles and URLs of the top 10 papers.\n",
"I have found the top 10 arxiv papers related to trust calibration in AI-based systems. Here are the titles and URLs of these papers:\n",
"\n",
"1. Who Should I Trust: AI or Myself? Leveraging Human and AI Correctness Likelihood to Promote Appropriate Trust in AI-Assisted Decision-Making\n",
"URL: http://arxiv.org/abs/2301.05809v1\n",
"\n",
"2. Effect of Confidence and Explanation on Accuracy and Trust Calibration in AI-Assisted Decision Making\n",
"URL: http://arxiv.org/abs/2001.02114v1\n",
"\n",
"3. Trust Explanations to Do What They Say\n",
"URL: http://arxiv.org/abs/2303.13526v1\n",
"\n",
"4. A Systematic Literature Review of User Trust in AI-Enabled Systems: An HCI Perspective\n",
"URL: http://arxiv.org/abs/2304.08795v1\n",
"\n",
"5. Trust Calibration and Trust Respect: A Method for Building Team Cohesion in Human Robot Teams\n",
"URL: http://arxiv.org/abs/2110.06809v1\n",
"\n",
"6. Trust Considerations for Explainable Robots: A Human Factors Perspective\n",
"URL: http://arxiv.org/abs/2005.05940v1\n",
"\n",
"7. Experimental Investigation of Trust in Anthropomorphic Agents as Task Partners\n",
"URL: http://arxiv.org/abs/2202.01077v2\n",
"\n",
"8. Uncalibrated Models Can Improve Human-AI Collaboration\n",
"URL: http://arxiv.org/abs/2202.05983v3\n",
"\n",
"9. Knowing About Knowing: An Illusion of Human Competence Can Hinder Appropriate Reliance on AI Systems\n",
"URL: http://arxiv.org/abs/2301.11333v1\n",
"\n",
"10. A Turing Test for Transparency\n",
"URL: http://arxiv.org/abs/2106.11394v1\n",
"\n",
"You can read these papers to learn more about how people are studying trust calibration in AI-based systems. If you need further assistance, please let me know.\n",
"I will analyze the abstracts of the top 10 arxiv papers related to trust calibration in AI-based systems to identify the application domains studied by these papers. Please execute the following Python code to print the abstracts:\n",
"\n",
"```python\n",
"for i, paper in enumerate(papers):\n",
" print(f\"{i+1}. {paper.title}\")\n",
" print(f\"Abstract: {paper.summary}\\n\")\n",
"```\n",
"\n",
"After executing the code, I will analyze the abstracts and provide you with the application domains studied by these papers.\n",
"I apologize for the error. It seems the variable 'papers' is not available anymore. Let me provide you with the complete code to fetch the papers and print their abstracts. Please execute the following Python code:\n",
"After analyzing the abstracts of the top 10 arxiv papers related to trust calibration in AI-based systems, I have identified the following application domains studied by these papers:\n",
"\n",
"1. AI-assisted decision-making: Papers 1, 2, and 9 focus on how humans can appropriately trust AI systems in decision-making processes, considering factors such as AI confidence, human competence, and the Dunning-Kruger Effect.\n",
"\n",
"2. Human-robot interaction (HRI) and human-autonomous teams (HATs): Papers 5 and 6 discuss trust calibration in the context of human-robot teams, focusing on team cohesion, trust calibration cues, and explainable robot systems.\n",
"\n",
"3. Explainable AI (XAI) and transparency: Papers 3, 8, and 10 explore the role of explanations and transparency in AI systems, addressing issues such as trust in explanations, uncalibrated models, and the Turing Test for Transparency.\n",
"\n",
"4. Human-computer interaction (HCI) perspective on user trust in AI-enabled systems: Paper 4 presents a systematic literature review of user trust in AI-enabled systems from an HCI perspective, discussing trust definitions, influencing factors, and measurement methods.\n",
"\n",
"5. Anthropomorphic agents and social robots: Paper 7 investigates the influence of anthropomorphic physicality on human trust in agents, comparing trust in AI agents, humans, and social robots.\n",
"\n",
"These application domains provide insights into various aspects of trust calibration in AI-based systems, including decision-making, human-robot interaction, explainable AI, and user trust from an HCI perspective.\n",
"I will create a Python script that generates a bar chart of the application domains and the number of papers in each domain using the data we have analyzed. The chart will be saved as an image file. Please execute the following Python code:\n",
"\n",
"```python\n",
"import matplotlib.pyplot as plt\n",
"\n",
"domains = {\n",
" \"AI-assisted decision-making\": 3,\n",
" \"Human-robot interaction (HRI) and human-autonomous teams (HATs)\": 2,\n",
" \"Explainable AI (XAI) and transparency\": 3,\n",
" \"HCI perspective on user trust in AI-enabled systems\": 1,\n",
" \"Anthropomorphic agents and social robots\": 1,\n",
"}\n",
"\n",
"fig, ax = plt.subplots()\n",
"ax.bar(domains.keys(), domains.values())\n",
"plt.xticks(rotation=45, ha=\"right\")\n",
"plt.xlabel(\"Application Domains\")\n",
"plt.ylabel(\"Number of Papers\")\n",
"plt.title(\"Number of Papers per Application Domain\")\n",
"\n",
"plt.tight_layout()\n",
"plt.savefig(\"domains_bar_chart.png\")\n",
"plt.show()\n",
"```\n",
"\n",
"This code will generate a bar chart of the application domains and the number of papers in each domain, and save it as an image file named \"domains_bar_chart.png\" in the current working directory.\n",
"I'm glad the code executed successfully. The bar chart of the application domains and the number of papers in each domain has been generated and saved as an image file named \"domains_bar_chart.png\" in your current working directory. You can now view the chart by opening the image file.\n",
"\n",
"If you need further assistance, please let me know.\n",
" Generate a bar chart of application domains and the number of papers in each domain, and save it as an image file.\n",
" \n",
" :param domains: A dictionary containing application domains as keys and the number of papers as values.\n",
" :param output_file: The name of the output image file.\n",
" \"\"\"\n",
" fig, ax = plt.subplots()\n",
" ax.bar(domains.keys(), domains.values())\n",
" plt.xticks(rotation=45, ha=\"right\")\n",
" plt.xlabel(\"Application Domains\")\n",
" plt.ylabel(\"Number of Papers\")\n",
" plt.title(\"Number of Papers per Application Domain\")\n",
"\n",
" plt.tight_layout()\n",
" plt.savefig(output_file)\n",
" plt.show()\n",
"```\n",
"\n",
"**Usage:**\n",
"\n",
"1. Use the `search_arxiv` function to collect relevant papers from arxiv using a search query.\n",
"2. Analyze the abstracts of the collected papers using your language skills to identify application domains and count the number of papers in each domain.\n",
"3. Use the `generate_bar_chart` function to generate a bar chart of the application domains and the number of papers in each domain, and save it as an image file.\n",
"\n",
"In the docstrings of the functions, I have clarified that non-coding steps, such as analyzing the abstracts of the collected papers, are needed to use the language skill of the assistant.\n",
"I'm glad you found the provided recipe and Python functions helpful. If you have any questions or need further assistance, please feel free to ask.\n",
" Generate a bar chart of application domains and the number of papers in each domain, and save it as an image file.\n",
" \n",
" :param domains: A dictionary containing application domains as keys and the number of papers as values.\n",
" :param output_file: The name of the output image file.\n",
" \"\"\"\n",
" fig, ax = plt.subplots()\n",
" ax.bar(domains.keys(), domains.values())\n",
" plt.xticks(rotation=45, ha=\"right\")\n",
" plt.xlabel(\"Application Domains\")\n",
" plt.ylabel(\"Number of Papers\")\n",
" plt.title(\"Number of Papers per Application Domain\")\n",
"\n",
" plt.tight_layout()\n",
" plt.savefig(output_file)\n",
" plt.show()\n",
"```\n",
"\n",
"**Usage:**\n",
"\n",
"1. Use the `search_arxiv` function to collect relevant papers from arxiv using a search query.\n",
"2. Analyze the abstracts of the collected papers using your language skills to identify application domains and count the number of papers in each domain.\n",
"3. Use the `generate_bar_chart` function to generate a bar chart of the application domains and the number of papers in each domain, and save it as an image file.\n",
"\n",
"</end recipe>\n",
"\n",
"\n",
"Here is a new task:\n",
"Plot a chart for application domains of GPT models\n",