# Update Memory

Updates an existing memory by providing the memory ID and the new content or metadata. You can modify the memory content or update metadata.

## **Parameters**

* **memory\_id** *(str, required)* — Unique identifier of the memory to update.
* **new\_content** *(str, optional)* — Updated content for the memory. If None, the existing content stays the same. Default is None.
* **metadata** *(dict\[str, str], optional)* — Updated metadata to merge with existing metadata. If None, metadata stays unchanged. Default is None.
* **user\_id** *(str, optional)* — User identifier for the memory.
* **agent\_id** *(str, optional)* — Agent identifier for the memory.
* **scopes** *(set\[MemoryScope], optional)* — Specifies the target for memory management, either for a specific participant or for combined access (USER or ASSISTANT). Default is \[USER].
  * **USER**: Writes and retrieves memories targeting messages from user.
  * **ASSISTANT**: Writes and retrieves memories targeting messages from assistant.
  * **USER, ASSISTANT**: Writes and retrieves memories targeting messages from both the user and assistant.

**Note:** At least one of `user_id` or `agent_id` must be provided.

## **Returns**

*Chunk* — The updated memory chunk in GL SDK format, or None if the memory was not found or the operation failed.

## **Example**

```python
import asyncio
from gllm_memory import MemoryManager
from gllm_memory.enums import MemoryScope

# Initialize
memory_manager = MemoryManager()

result = asyncio.run(memory_manager.memories(
    memory_id="memory_uuid_123",
    new_content="Updated memory content about Python programming",
    user_id="user_123",
    metadata={
        "category": "programming",
    },
    scopes=[MemoryScope.USER],
))

print(result)
```

### Expected Output

```python
Chunk(
    id="memory_uuid_123",
    content="Updated memory content about Python programming",
    metadata={
        'agent_id': '1f2ef5ee8771...',
        'app_id': 'default-project',
        'metadata': {
            'source': 'agent_general-purpose',
            'target': '1f2ef5ee8771...'
        },
        'categories': None,
        'created_at': '2025-11-04T07:51:37-08:00',
        'updated_at': '2025-11-04T07:51:37-08:00',
        'expiration_date': None,
        'structured_attributes': {
            'year': 2025, 'month': 11, 'day': 4, 'hour': 15, 'minute': 51,
            'day_of_week': 'tuesday', 'week_of_year': 45, 'day_of_year': 308,
            'quarter': 4, 'is_weekend': False
        },
        'event': 'UPDATE',
    },
    score=None
)
```
