from typing import Optional, Union, Any, Literal, Callable, TypedDict, Annotated
Optional[int]# = int | NoneUnion[int,str]# = int | strLiteral["a","b"]# 정확히 "a" 또는 "b"Callable[Params,int]# Params가 [int, int]이면 (int, int) -> int 함수Any # 검사 비활성화 (탈출구)
from typing import TypedDict, Annotated
classAgentState(TypedDict): messages:list user_id:str counter:int
from typing import Annotated
from langgraph.graph.message import add_messages
classState(TypedDict): messages: Annotated[list, add_messages]# 두 번째 인자는 reducer
from typing import TypeVar, Generic
T = TypeVar("T")classStack(Generic[T]):def__init__(self): self.items:list[T]=[]defpush(self, x: T)->None: self.items.append(x)defpop(self)-> T:return self.items.pop()s: Stack[int]= Stack()
from typing import Protocol
classEmbeddable(Protocol):defembed(self, text:str)->list[float]:...defindex(model: Embeddable, texts:list[str])->None:...# 명시적 상속 없이도 embed 메서드만 있으면 통과
from langchain_core.tools import tool
@tooldefget_weather(city:str, units: Literal["c","f"]="c")->str:"""도시의 날씨를 반환한다."""...