-
Notifications
You must be signed in to change notification settings - Fork 15.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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)]) ```
- Loading branch information
Showing
5 changed files
with
39 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
from typing import Any, List, Literal | ||
|
||
from langchain_core.messages.base import BaseMessage | ||
|
||
|
||
class RemoveMessage(BaseMessage): | ||
"""Message responsible for deleting other messages.""" | ||
|
||
type: Literal["remove"] = "remove" | ||
|
||
def __init__(self, id: str, **kwargs: Any) -> None: | ||
if kwargs.pop("content", None): | ||
raise ValueError("RemoveMessage does not support 'content' field.") | ||
|
||
return super().__init__("", id=id, **kwargs) | ||
|
||
@classmethod | ||
def get_lc_namespace(cls) -> List[str]: | ||
"""Get the namespace of the langchain object.""" | ||
return ["langchain", "schema", "messages"] | ||
|
||
|
||
RemoveMessage.update_forward_refs() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters