Skip to main content

Author:

Ricky Loynd

Senior Research Engineer at Microsoft

Teachable Agent Architecture TL;DR:
  • We introduce Teachable Agents so that users can teach their LLM-based assistants new facts, preferences, and skills.
  • We showcase examples of teachable agents learning and later recalling facts, preferences, and skills in subsequent chats.

Introduction

Conversational assistants based on LLMs can remember the current chat with the user, and can also demonstrate in-context learning of user teachings during the conversation. But the assistant’s memories and learnings are lost once the chat is over, or when a single chat grows too long for the LLM to handle effectively. Then in subsequent chats the user is forced to repeat any necessary instructions over and over. Teachability addresses these limitations by persisting user teachings across chat boundaries in long-term memory implemented as a vector database. Instead of copying all of memory into the context window, which would eat up valuable space, individual memories (called memos) are retrieved into context as needed. This allows the user to teach frequently used facts and skills to the teachable agent just once, and have it recall them in later chats. Any instantiated agent that inherits from ConversableAgent can be made teachable by instantiating a Teachability object and calling its add_to_agent(agent) method. In order to make effective decisions about memo storage and retrieval, the Teachability object calls an instance of TextAnalyzerAgent (another AutoGen agent) to identify and reformulate text as needed for remembering facts, preferences, and skills. Note that this adds extra LLM calls involving a relatively small number of tokens, which can add a few seconds to the time a user waits for each response.

Run It Yourself

AutoGen contains four code examples that use Teachability.
  1. Run chat_with_teachable_agent.py to converse with a teachable agent.
  2. Run test_teachable_agent.py for quick unit testing of a teachable agent.
  3. Use the Jupyter notebook agentchat_teachability.ipynb to step through examples discussed below.
  4. Use the Jupyter notebook agentchat_teachable_oai_assistants.ipynb to make arbitrary OpenAI Assistants teachable through GPTAssistantAgent.

Basic Usage of Teachability

  1. Install dependencies
Please install autogen with the [teachable] option before using Teachability.
  1. Import agents
  1. Create llm_config
  1. Create the agents
  1. Chat with the teachable agent

Example 1 - Learning user info

A user can teach the agent facts about themselves. (Note that due to their finetuning, LLMs can be reluctant to admit that they know personal information.)
In a later conversation, the user can check whether the teachable agent remembers their name. (For readability, the user prompts and some logged notices are not repeated below.)

Example 2 - Learning new facts

A user can teach the agent more complex, related facts.
Then in a later chat the teachable agent can answer questions about the facts it has been taught. (Remember to first close the previous chat by typing ‘exit’.)

Example 3 - Learning user preferences

A user can teach the agent how they prefer to have things done. Be aware that a message like the next one cannot be entered as a single message through a command line because it contains a newline character. Such messages can be entered in a Jupyter notebook, or through some UI layer like that of ChatGPT.
Then in later chats the teacher doesn’t need to reiterate their detailed preferences.

Example 4 - Learning new skills

Users can extend the teachable agent’s capabilities by teaching it new skills for accomplishing challenging tasks. It usually works best to first describe the task, then (in the same turn) provide a hint or advice for approaching the task. The Sparks of AGI paper evaluated GPT-4 on math problems like the following, which it could only solve 32% of the time. We first show a failure case, then teach the agent a strategy which lifts GPT-4’s success rate above 95%.
In a later chat the user doesn’t need to repeat the detailed advice.

Planned improvements

  • Understanding user instructions distributed over multiple turns.
  • Learning from the agent’s own experience, to reduce dependence on explicit user teachings.
  • Learning skills built on top of previously learned skills.

Conclusion

Teachability is still under active research and development. For any problems you find or improvements you have in mind, please join our discussions in this repo and on our Discord channel. We look forward to seeing how you and the rest of the community can use and improve teachable agents in AutoGen!