LangChain Reference home pageLangChain ReferenceLangChain Reference
  • GitHub
  • Main Docs
Deep Agents
LangChain
LangGraph
Integrations
LangSmith
  • Overview
    • Overview
    • Graphs
    • Functional API
    • Pregel
    • Checkpointing
    • Storage
    • Caching
    • Types
    • Runtime
    • Config
    • Errors
    • Constants
    • Channels
    • Agents
    LangGraph CLI
    LangGraph SDK
    LangGraph Supervisor
    LangGraph Swarm
    ⌘I

    LangChain Assistant

    Ask a question to get started

    Enter to send•Shift+Enter new line

    Menu

    OverviewGraphsFunctional APIPregelCheckpointingStorageCachingTypesRuntimeConfigErrorsConstantsChannelsAgents
    LangGraph CLI
    LangGraph SDK
    LangGraph Supervisor
    LangGraph Swarm
    Language
    Theme
    Pythonlanggraphfuncentrypointfinal
    Class●Since v0.2

    final

    A primitive that can be returned from an entrypoint.

    This primitive allows to save a value to the checkpointer distinct from the return value from the entrypoint.

    Copy
    final(
        self,
        *,
        value: R,
        save: S,
    )

    Bases

    Generic[R, S]

    Decoupling the return value and the save value:

    from langgraph.checkpoint.memory import InMemorySaver
    from langgraph.func import entrypoint
    
    @entrypoint(checkpointer=InMemorySaver())
    def my_workflow(
        number: int,
        *,
        previous: Any = None,
    ) -> entrypoint.final[int, int]:
        previous = previous or 0
        # This will return the previous value to the caller, saving
        # 2 * number to the checkpoint, which will be used in the next invocation
        # for the `previous` parameter.
        return entrypoint.final(value=previous, save=2 * number)
    
    config = {"configurable": {"thread_id": "1"}}
    
    my_workflow.invoke(3, config)  # 0 (previous was None)
    my_workflow.invoke(1, config)  # 6 (previous was 3 * 2 from the previous invocation)

    Constructors

    constructor
    __init__
    NameType
    valueR
    saveS

    Attributes

    attribute
    value: R

    Value to return. A value will always be returned even if it is None.

    attribute
    save: S

    The value for the state for the next checkpoint.

    A value will always be saved even if it is None.

    View source on GitHub