Overview
LangChain의 streaming 시스템을 사용하면 agent 실행의 실시간 피드백을 애플리케이션에 전달할 수 있습니다. LangChain streaming으로 가능한 것들:- Stream agent progress — 각 agent 단계 후 상태 업데이트를 받습니다.
- Stream LLM tokens — 생성되는 language model token을 streaming합니다.
- Stream custom updates — 사용자 정의 신호를 전송합니다 (예:
"Fetched 10/100 records"). - Stream multiple modes —
updates(agent progress),messages(LLM tokens + metadata), 또는custom(임의의 사용자 데이터) 중에서 선택합니다.
Agent progress
Agent progress를 streaming하려면stream_mode="updates"와 함께 stream 또는 astream 메서드를 사용하세요. 이는 모든 agent 단계 후에 이벤트를 전송합니다.
예를 들어, tool을 한 번 호출하는 agent가 있다면 다음과 같은 업데이트를 볼 수 있습니다:
- LLM node: tool call 요청이 포함된
AIMessage - Tool node: 실행 결과가 포함된
ToolMessage - LLM node: 최종 AI 응답
Streaming agent progress
Output
LLM tokens
LLM에서 생성되는 token을 streaming하려면stream_mode="messages"를 사용하세요. 아래에서 tool call과 최종 응답을 streaming하는 agent의 출력을 볼 수 있습니다.
Streaming LLM tokens
Output
Custom updates
Tool이 실행될 때 업데이트를 streaming하려면get_stream_writer를 사용할 수 있습니다.
Streaming custom updates
Output
Tool 내부에
get_stream_writer를 추가하면 LangGraph 실행 컨텍스트 외부에서 tool을 호출할 수 없습니다.Stream multiple modes
Stream mode를 list로 전달하여 여러 streaming mode를 지정할 수 있습니다:stream_mode=["updates", "custom"]:
Streaming multiple modes
Output
Disable streaming
일부 애플리케이션에서는 특정 model에 대해 개별 token의 streaming을 비활성화해야 할 수 있습니다. 이는 multi-agent 시스템에서 어떤 agent가 출력을 streaming할지 제어하는 데 유용합니다. Streaming을 비활성화하는 방법을 알아보려면 Models 가이드를 참조하세요.Connect these docs programmatically to Claude, VSCode, and more via MCP for real-time answers.