Update naming

This commit is contained in:
Tat Dat Duong
2025-04-03 21:58:16 +02:00
parent e9b5046076
commit 615fc8b4ae
2 changed files with 9 additions and 9 deletions
@@ -80,12 +80,12 @@ CSS and Tailwind 4.x is also supported out of the box, so you can freely use Tai
from langchain_openai import ChatOpenAI
from langgraph.graph import StateGraph
from langgraph.graph.message import add_messages
from langgraph.graph.ui import AnyUIMessage, add_ui_messages, push_ui_message
from langgraph.graph.ui import AnyUIMessage, ui_message_reducer, push_ui_message
class AgentState(TypedDict): # noqa: D101
messages: Annotated[Sequence[BaseMessage], add_messages]
ui: Annotated[Sequence[AnyUIMessage], add_ui_messages]
ui: Annotated[Sequence[AnyUIMessage], ui_message_reducer]
async def weather(state: AgentState):
@@ -342,13 +342,13 @@ Similar to how messages can be removed from the state by appending a RemoveMessa
=== "Python"
```python
from langgraph.graph.ui import push_ui_message, remove_ui_message
from langgraph.graph.ui import push_ui_message, delete_ui_message
# push message
message = push_ui_message("weather", {"city": "London"})
# remove said message
remove_ui_message(message["id"])
delete_ui_message(message["id"])
```
=== "JS"
+5 -5
View File
@@ -115,7 +115,7 @@ def push_ui_message(
return evt
def remove_ui_message(id: str, *, state_key: str = "ui") -> RemoveUIMessage:
def delete_ui_message(id: str, *, state_key: str = "ui") -> RemoveUIMessage:
"""Delete a UI message by ID from the UI state.
This function creates and sends a message to remove a UI component from the current state.
@@ -132,7 +132,7 @@ def remove_ui_message(id: str, *, state_key: str = "ui") -> RemoveUIMessage:
.. code-block:: python
remove_ui_message("message-123")
delete_ui_message("message-123")
"""
writer = get_stream_writer()
@@ -146,14 +146,14 @@ def remove_ui_message(id: str, *, state_key: str = "ui") -> RemoveUIMessage:
return evt
def add_ui_messages(
def ui_message_reducer(
left: Union[list[AnyUIMessage], AnyUIMessage],
right: Union[list[AnyUIMessage], AnyUIMessage],
) -> list[AnyUIMessage]:
"""Merge two lists of UI messages, supporting removing UI messages.
This function combines two lists of UI messages, handling both regular UI messages
and remove-ui messages. When a remove-ui message is encountered, it removes any
and `remove-ui` messages. When a `remove-ui` message is encountered, it removes any
UI message with the matching ID from the current state.
Args:
@@ -167,7 +167,7 @@ def add_ui_messages(
.. code-block:: python
messages = reduce_ui_messages(
messages = ui_message_reducer(
[{"type": "ui", "id": "1", "name": "Chat", "props": {}}],
{"type": "remove-ui", "id": "1"}
)