Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Task-Centric Memory #5227

Open
wants to merge 140 commits into
base: main
Choose a base branch
from
Open

Task-Centric Memory #5227

wants to merge 140 commits into from

Conversation

rickyloynd-microsoft
Copy link
Contributor

@rickyloynd-microsoft rickyloynd-microsoft commented Jan 28, 2025

(EXPERIMENTAL, RESEARCH IN PROGRESS)

In 2023 AutoGen introduced Teachable Agents that users could teach new facts, preferences and skills. But teachable agents were limited in several ways: They could only be ConversableAgent subclasses, they couldn't learn a new skill unless the user stated (in a single turn) both the task and how to solve it, and they couldn't learn on their own. Task-Centric Memory overcomes these limitations, allowing users to teach arbitrary agents (or teams) more flexibly and reliably, and enabling agents to learn from their own trial-and-error experiences.

This PR is large and complex. All of the files are new, and most of the added components depend on the others to run at all. But the review process can be accelerated if approached in the following order.

  1. Start with the Task-Centric Memory README.
    1. Install the memory extension locally, since it won't be in pypi until it's merged. In the agentic_memory branch, and the python/packages directory:
      • pip install -e autogen-agentchat
      • pip install -e autogen-ext[openai]
      • pip install -e autogen-ext[task-centric-memory]
    2. Run the Quickstart sample code, then immediately open the ./pagelogs/quick/0 Call Tree.html file in a browser to view the work in progress.
    3. Click through the web page links to see the details.
  2. Continue through the rest of the main README to get a high-level overview of the architecture.
  3. Read through the code samples README, running each of the 4 code samples while viewing their page logs.
  4. Skim through the 4 code samples, along with their corresponding yaml config files:
    1. chat_with_teachable_agent.py
    2. eval_retrieval.py
    3. eval_teachability.py
    4. eval_learning_from_demonstration.py
    5. eval_self_teaching.py
  5. Read task_centric_memory_controller.py, referring back to the previously generated page logs as needed. This is the most important and complex file in the PR.
  6. Read the remaining core files.
    1. _task_centric_memory_bank.py
    2. _string_similarity_map.py
    3. _prompter.py
  7. Read the supporting files in the utils dir.
    1. teachability.py
    2. apprentice.py
    3. grader.py
    4. page_logger.py
    5. _functions.py

Make memory optional.
Filter out insights with negative scores.
Refactor memory paths.
Enrich page logging.
Seed messages with random int for variability.
Save sessions as yaml for readability.
Eval simplifications.
self.logger.info(task)

# Get a list of topics from the generalized task.
generalized_task = await self.prompter.generalize_task(task)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as discussed, there is an option to combine these two lines in a single API call, it would sacrifice accuracy potentially, but go from minimum 2 LLM calls to 1 LLM call

)
user_message = [
"Now put yourself in the mind of the students. What misconception led them to their incorrect answer?"
]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there is potential to combine these three LLM calls into a single call, it depends on the LLM, but GPT-4o should be able to do this in a single shot with a COT prompt, other less capable models might need extra reflection

@jackgerrits
Copy link
Member

A good way to convey the development status of this would be to put the module in autogen_ext.experimental.task_centric_memory. This will set clear expectations to users and give us the space to evolve

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use shorter name, e.g., "memory_controller.py"

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use shorter name

model_context: ChatCompletionContext,
) -> UpdateContextResult:
"""
Extracts any advice from the last user turn to be stored in memory,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clarify how advice is extracted in the docs.
[advanced] expose parameters controlling this process in the API of the memory controller or in the teachability obj.

Execute the corresponding commands from this (autogen_ext/task_centric_memory) directory.


### Making AssistantAgent teachable
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
### Making AssistantAgent teachable
### Making AssistantAgent Teachable

Each sample is contained in a separate python script, using data and configs stored in yaml files for easy modification.
Note that since agent behavior is non-deterministic, results will vary between runs.

To watch operations live in a browser and see how task-centric memory works,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How do I turn this on/off? Would prefer if the code didn't make changes outside the cwd.

starting with an empty memory bank.

```bash
rm -r memory_bank
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unclear why this line is there. memory_bank dir was never mentioned before.


class Teachability(Memory):
"""
Gives an AssistantAgent the ability to learn quickly from user teachings, hints, and advice.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Expand the documentation, please.

@@ -0,0 +1,3 @@
from .task_centric_memory_controller import TaskCentricMemoryController

__all__ = ["TaskCentricMemoryController"]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this expose Teachbility?

@gagb gagb self-requested a review February 26, 2025 20:31
@rickyloynd-microsoft
Copy link
Contributor Author

This PR is simply too large. Please propose your changes progressively and iteratively using a separate sequence of PRs. We cannot effectively review these changes as is.

@jackgerrits, I've moved the code under autogen_ext/experimentaltask_centric_memory to convey the status and manage expectations as you suggested. And reviewer feedback has led to many improvements. At this point, do you recommend a series of PRs to review the content in a more iterative fashion?

Copy link
Collaborator

@ekzhu ekzhu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As a next step #5542.

@@ -52,6 +52,8 @@ python/autogen_ext.models.openai
python/autogen_ext.models.replay
python/autogen_ext.models.azure
python/autogen_ext.models.semantic_kernel
python/autogen_ext.experimental.task_centric_memory
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we move this below auth so we are not breaking up the models.

@victordibia
Copy link
Collaborator

The teachability example is pretty cool, shows how the MemoryController can be used with the an AssistantAgent via the Memory interface.

@rickyloynd-microsoft
Copy link
Contributor Author

The teachability example is pretty cool, shows how the MemoryController can be used with the an AssistantAgent via the Memory interface.

And with very little code!
agent = AssistantAgent(model_client=client, memory=[Teachability(MemoryController(False, client))])

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
memory Covering all aspects of fast learning for agents
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants