core: add RemoveMessage (#23636)

This change adds a new message type `RemoveMessage`. This will enable
`langgraph` users to manually modify graph state (or have the graph
nodes modify the state) to remove messages by `id`

Examples:

* allow users to delete messages from state by calling

```python
graph.update_state(config, values=[RemoveMessage(id=state.values[-1].id)])
```

* allow nodes to delete messages

```python
graph.add_node("delete_messages", lambda state: [RemoveMessage(id=state[-1].id)])
```
This commit is contained in:
Vadym Barda
2024-06-28 17:40:02 -04:00
committed by GitHub
parent 8fce8c6771
commit e8d77002ea
5 changed files with 39 additions and 0 deletions

View File

@@ -95,6 +95,13 @@ def test_serializable_mapping() -> None:
"structured",
"StructuredPrompt",
),
# This is not exported from langchain, only langchain_core
("langchain", "schema", "messages", "RemoveMessage"): (
"langchain_core",
"messages",
"modifier",
"RemoveMessage",
),
}
serializable_modules = import_all_modules("langchain")