---
title: "Developer Workflow"
description: "This page outlines key aspects of the developer workflow within the project, focusing on code quality enforcement and the implementation of advanced agent capabilities. It covers the use of pre-com..."
last_updated: "2026-05-07T04:45:15.584755+00:00"
canonical_url: "https://www.doc0.dev/docs/faa36707-7c28-4f69-a18f-700ff61c704e/technical/section-8/developer-workflow"
---

<details>
<summary>Relevant source files</summary>

The following files were used as context for generating this wiki page:

- [.pre-commit-config.yaml](https://github.com/blade47/mem0/blob/main/.pre-commit-config.yaml)
- [cookbooks/helper/mem0_teachability.py](https://github.com/blade47/mem0/blob/main/cookbooks/helper/mem0_teachability.py)
- [cookbooks/helper/__init__.py](https://github.com/blade47/mem0/blob/main/cookbooks/helper/__init__.py)
</details>

This page outlines key aspects of the developer workflow within the project, focusing on code quality enforcement and the implementation of advanced agent capabilities. It covers the use of pre-commit hooks to maintain code standards and the `Mem0Teachability` component, which enhances agent intelligence by enabling memory and learning from interactions.

The developer workflow is designed to ensure consistent code style, identify potential issues early in the development cycle, and provide robust, intelligent agent functionalities through memory management.

## Code Quality with Pre-Commit Hooks

The project utilizes `pre-commit` hooks to automate code quality checks and formatting before commits are made. This ensures that all committed code adheres to defined standards, reducing the overhead of manual reviews and maintaining a clean, consistent codebase.

The configuration specifies two primary hooks for Python files: `ruff` for linting and formatting, and `isort` for sorting import statements.

### Pre-Commit Configuration

The `.pre-commit-config.yaml` file defines the hooks.

```yaml
repos:
  - repo: local
    hooks:
      - id: ruff
        name: Ruff
        entry: ruff check
        language: system
        types: [python]
        args: [--fix] 

      - id: isort
        name: isort
        entry: isort
        language: system
        types: [python]
        args: ["--profile", "black"]
```
Sources: [.pre-commit-config.yaml:1-15](https://github.com/blade47/mem0/blob/main/.pre-commit-config.yaml#L1-L15)

<Callout variant="info">
To use these hooks, ensure `pre-commit` is installed (`pip install pre-commit`) and initialized in your repository (`pre-commit install`).
</Callout>

### Pre-Commit Hooks Overview

| Hook ID | Name  | Entry Command | Language | Types   | Arguments | Purpose                                     |
| :------ | :---- | :------------ | :------- | :------ | :-------- | :------------------------------------------ |
| `ruff`  | Ruff  | `ruff check`  | `system` | `python` | `--fix`   | Lints and automatically fixes Python code.  |
| `isort` | isort | `isort`       | `system` | `python` | `--profile black` | Sorts Python imports using the `black` profile. |
Sources: [.pre-commit-config.yaml:1-15](https://github.com/blade47/mem0/blob/main/.pre-commit-config.yaml#L1-L15)

### Pre-Commit Workflow

The following flowchart illustrates the typical developer workflow involving pre-commit hooks.



## Agent Teachability with Mem0

The `Mem0Teachability` class is a crucial component that enhances the capabilities of `autogen` agents by integrating memory management through the `mem0` library. This allows agents to "remember" information, tasks, and advice from past conversations, making them more intelligent and adaptable over time.

### `Mem0Teachability` Class Overview

`Mem0Teachability` is an `AgentCapability` designed to be added to `ConversableAgent` instances. It intercepts messages to store new information (teachings) and retrieve relevant past information to augment current conversations.


Sources: [cookbooks/helper/mem0_teachability.py:12-132](https://github.com/blade47/mem0/blob/main/cookbooks/helper/mem0_teachability.py#L12-L132)

### Initialization Parameters

The `Mem0Teachability` class can be configured with several parameters during instantiation.

| Parameter          | Type                  | Default Value | Description                                                                                             |
| :----------------- | :-------------------- | :------------ | :------------------------------------------------------------------------------------------------------ |
| `verbosity`        | `Optional[int]`       | `0`           | Controls the level of debug output. Higher values (e.g., `1`, `2`) provide more detailed logs.          |
| `reset_db`         | `Optional[bool]`      | `False`       | If `True`, the memory database will be reset upon initialization.                                       |
| `recall_threshold` | `Optional[float]`     | `1.5`         | The similarity threshold for retrieving relevant memories. Lower values mean stricter relevance.        |
| `max_num_retrievals` | `Optional[int]`     | `10`          | Maximum number of relevant memories to retrieve.                                                        |
| `llm_config`       | `Optional[Union[Dict, bool]]` | `None`        | LLM configuration for the internal `TextAnalyzerAgent`. If `None`, it defaults to the agent's `llm_config`. |
| `agent_id`         | `Optional[str]`       | `None`        | An identifier for the agent, used to scope memories.                                                    |
| `memory_client`    | `Optional[Memory]`    | `None`        | An existing `Memory` instance to use. If `None`, a new `Memory` instance is created.                    |
Sources: [cookbooks/helper/mem0_teachability.py:20-30](https://github.com/blade47/mem0/blob/main/cookbooks/helper/mem0_teachability.py#L20-L30)

### Adding Teachability to an Agent

The `add_to_agent` method integrates `Mem0Teachability` with a `ConversableAgent`. It registers a hook to process every last received message and updates the agent's system message to reflect its new memory capabilities.

<Steps>
<Step>
### Registering the Message Hook
The `process_last_received_message` method is registered as a hook for the `process_last_received_message` event on the `ConversableAgent`. This ensures that every incoming message is evaluated for memory storage and retrieval.
</Step>
<Step>
### Initializing the Text Analyzer
An internal `TextAnalyzerAgent` is initialized using the agent's `llm_config`. This analyzer is crucial for interpreting messages to extract tasks, advice, questions, and answers for memory operations.
</Step>
<Step>
### Updating System Message
The agent's `system_message` is augmented with a note indicating its new ability to remember user teachings, informing the LLM of its enhanced capabilities.
</Step>
</Steps>
Sources: [cookbooks/helper/mem0_teachability.py:32-43](https://github.com/blade47/mem0/blob/main/cookbooks/helper/mem0_teachability.py#L32-L43)

### Message Processing and Memory Interaction

When an agent receives a message, the `process_last_received_message` hook is triggered. This method orchestrates the interaction with the `mem0` client, deciding whether to retrieve relevant memories, store new information, or both.


Sources: [cookbooks/helper/mem0_teachability.py:45-132](https://github.com/blade47/mem0/blob/main/cookbooks/helper/mem0_teachability.py#L45-L132)

#### Memory Storage (`_consider_memo_storage`)

This method analyzes the incoming message to identify information suitable for storage. It uses the `TextAnalyzerAgent` to determine if the message contains a task/advice pair or a question/answer pair.

1.  **Task/Advice Storage**: If the message asks the agent to perform a task, the analyzer extracts the specific task and any associated advice. A generalized version of the task is then stored along with the advice in `mem0`.
2.  **Question/Answer Storage**: If the message contains general information that could be committed to memory, the analyzer formulates a question that would elicit this information and extracts the answer. This question-answer pair is then stored in `mem0`.
Sources: [cookbooks/helper/mem0_teachability.py:49-87](https://github.com/blade47/mem0/blob/main/cookbooks/helper/mem0_teachability.py#L49-L87)

#### Memory Retrieval (`_consider_memo_retrieval`)

This method retrieves relevant memories from `mem0` based on the current message.

1.  **Search for Q&A Memos**: It searches `mem0` for question-answer pairs that are relevant to the input message, using the `recall_threshold` and `max_num_retrievals` parameters.
2.  **Search for Task/Advice Memos**: If the message is identified as asking the agent to perform a task, the task is extracted and generalized. This generalized task is then used to search for relevant task-advice pairs in `mem0`.
3.  **Concatenation**: All retrieved memos (both Q&A and Task/Advice) that meet the recall threshold are concatenated and appended to the original message, effectively expanding the context for the agent's next action.
Sources: [cookbooks/helper/mem0_teachability.py:89-114](https://github.com/blade47/mem0/blob/main/cookbooks/helper/mem0_teachability.py#L89-L114)

#### Text Analysis (`_analyze`)

The `_analyze` method is a private helper that uses the `TextAnalyzerAgent` to interpret parts of the conversation. It sends the text to be analyzed along with specific instructions to the `TextAnalyzerAgent` and returns its response. This is critical for extracting structured information (tasks, advice, questions, answers) from natural language.
Sources: [cookbooks/helper/mem0_teachability.py:116-123](https://github.com/blade47/mem0/blob/main/cookbooks/helper/mem0_teachability.py#L116-L123)

## Sitemap

See the full [sitemap](https://www.doc0.dev/docs/faa36707-7c28-4f69-a18f-700ff61c704e/llms.txt) for all pages in this wiki.
