Support Clearing Annotated[list, operator.add] Fields in LangGraph State #387

Closed
opened 2026-02-20 17:39:52 -05:00 by yindo · 1 comment
Owner

Originally created by @funnykeke on GitHub (Jan 7, 2025).

Issue with current documentation:

Context: In LangGraph, the Annotated[list, operator.add] state field is very useful for accumulating results from parallel nodes. This is especially valuable in workflows where multiple nodes run in parallel, and their results need to be combined into a single list.

However, this design comes with a significant limitation: once an Annotated[list, operator.add] field starts accumulating data, there is no way to clear its contents during the workflow. This leads to the following problems:

The list grows indefinitely, which can cause memory issues or exceed LangSmith's state size limit.
Old data from previous nodes can interfere with subsequent steps in the graph.
Use Case: Imagine a workflow with three parallel nodes that aggregate their outputs into a single state["relation_verify_info"] field. After processing this information in a downstream node, it is desirable to clear the field to prevent it from growing indefinitely. However, with the current design, this is not possible.

Additional Context: This issue is particularly relevant for workflows with many parallel branches that feed into a single aggregation point. Without a way to clear the accumulated data, the workflow becomes harder to manage and scale.
Additional Context: This issue is particularly relevant for workflows with many parallel branches that feed into a single aggregation point. Without a way to clear the accumulated data, the workflow becomes harder to manage and scale.

Idea or request for content:

Proposed Solution: Introduce a mechanism to clear Annotated[list, operator.add] fields during the workflow. Some possible approaches:

Allow explicit clearing of the field at a specific node, e.g., state["relation_verify_info"] = [].
Add a new annotation, such as Annotated[list, operator.add_and_clearable], which enables both accumulation and clearing.
Provide a method like state.clear_add_field("relation_verify_info") to programmatically clear the contents.
Impact: This change would make LangGraph more flexible and efficient, especially for long-running workflows or workflows with high concurrency. It would also help prevent state size issues in LangSmith and improve overall usability.
Proposed Solution: Introduce a mechanism to clear Annotated[list, operator.add] fields during the workflow. Some possible approaches:

Allow explicit clearing of the field at a specific node, e.g., state["relation_verify_info"] = [].
Add a new annotation, such as Annotated[list, operator.add_and_clearable], which enables both accumulation and clearing.
Provide a method like state.clear_add_field("relation_verify_info") to programmatically clear the contents.
Impact: This change would make LangGraph more flexible and efficient, especially for long-running workflows or workflows with high concurrency. It would also help prevent state size issues in LangSmith and improve overall usability.

Originally created by @funnykeke on GitHub (Jan 7, 2025). ### Issue with current documentation: Context: In LangGraph, the Annotated[list, operator.add] state field is very useful for accumulating results from parallel nodes. This is especially valuable in workflows where multiple nodes run in parallel, and their results need to be combined into a single list. However, this design comes with a significant limitation: once an Annotated[list, operator.add] field starts accumulating data, there is no way to clear its contents during the workflow. This leads to the following problems: The list grows indefinitely, which can cause memory issues or exceed LangSmith's state size limit. Old data from previous nodes can interfere with subsequent steps in the graph. Use Case: Imagine a workflow with three parallel nodes that aggregate their outputs into a single state["relation_verify_info"] field. After processing this information in a downstream node, it is desirable to clear the field to prevent it from growing indefinitely. However, with the current design, this is not possible. Additional Context: This issue is particularly relevant for workflows with many parallel branches that feed into a single aggregation point. Without a way to clear the accumulated data, the workflow becomes harder to manage and scale. Additional Context: This issue is particularly relevant for workflows with many parallel branches that feed into a single aggregation point. Without a way to clear the accumulated data, the workflow becomes harder to manage and scale. ### Idea or request for content: Proposed Solution: Introduce a mechanism to clear Annotated[list, operator.add] fields during the workflow. Some possible approaches: Allow explicit clearing of the field at a specific node, e.g., state["relation_verify_info"] = []. Add a new annotation, such as Annotated[list, operator.add_and_clearable], which enables both accumulation and clearing. Provide a method like state.clear_add_field("relation_verify_info") to programmatically clear the contents. Impact: This change would make LangGraph more flexible and efficient, especially for long-running workflows or workflows with high concurrency. It would also help prevent state size issues in LangSmith and improve overall usability. Proposed Solution: Introduce a mechanism to clear Annotated[list, operator.add] fields during the workflow. Some possible approaches: Allow explicit clearing of the field at a specific node, e.g., state["relation_verify_info"] = []. Add a new annotation, such as Annotated[list, operator.add_and_clearable], which enables both accumulation and clearing. Provide a method like state.clear_add_field("relation_verify_info") to programmatically clear the contents. Impact: This change would make LangGraph more flexible and efficient, especially for long-running workflows or workflows with high concurrency. It would also help prevent state size issues in LangSmith and improve overall usability.
yindo closed this issue 2026-02-20 17:39:52 -05:00
Author
Owner

@hinthornw commented on GitHub (Jan 7, 2025):

Duplicate of https://github.com/langchain-ai/langgraph/discussions/2944

@hinthornw commented on GitHub (Jan 7, 2025): Duplicate of https://github.com/langchain-ai/langgraph/discussions/2944
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langchain-ai/langgraph#387