from operator import add from typing import Annotated from langgraph.checkpoint.memory import InMemorySaver from langgraph.graph import START, StateGraph from typing_extensions import NotRequired, TypedDict class ThreadState(TypedDict): events: Annotated[list[str], add] event_count: NotRequired[int] def count_events(state: ThreadState) -> dict[str, int]: return {"event_count": len(state["events"])}