A memory must be connected to an Agent before historical messages can be written during Agent execution or historical context can be retrieved when answering. Usually, both directions, **write to memory** and **retrieve from memory**, need to be configured.
### Write Agent Messages to Memory
1. Go to the **Agent** page and open the Agent that needs to be configured.
2. Select or add the **Message** component on the Agent canvas.
3. In the **Message** component configuration, find **Save to Memory**.
4. Select the target memory. If historical records need to be distinguished by user, configure the user ID.
5. Save the Agent and run a test. After it runs, return to the memory's **Messages** page to check whether new messages have been generated.