로컬 서버 실행하기
로컬 서버 실행하기
이 가이드는 LangGraph 애플리케이션을 로컬에서 실행하는 방법을 보여줘요.
사전 요구사항
시작 전에 다음이 있어야 해요:
- LangSmith용 API 키 — 가입 무료
출처: 로컬 서버 실행 - 공식 문서
1. LangGraph CLI 설치
# Python >= 3.11 필요.
uv add "langgraph-cli[inmem]"
2. LangGraph 앱 만들기
new-langgraph-project-python 템플릿에서 새 앱을 만들어요. 이 템플릿은 여러분의 로직으로 확장할 수 있는 단일 노드 애플리케이션을 보여줘요.
langgraph new path/to/your/app --template new-langgraph-project-python
3. 의존성 설치
새 LangGraph 앱의 루트에서 의존성을 edit 모드로 설치해서 로컬 변경 사항이 서버에 반영되게 해요:
cd path/to/your/app
uv sync
4. .env 파일 만들기
새 LangGraph 앱의 루트에 .env.example이 있을 거예요. 새 앱 루트에 .env 파일을 만들고 .env.example 내용을 복사한 다음 필요한 API 키를 채워요:
LANGSMITH_API_KEY=lsv2...
5. Agent server 실행
LangGraph API 서버를 로컬에서 시작해요:
langgraph dev
샘플 출력:
INFO:langgraph_api.cli:
Welcome to
╦ ┌─┐┌┐┌┌─┐╔═╗┬─┐┌─┐┌─┐┬ ┬
║ ├─┤││││ ┬║ ╦├┬┘├─┤├─┘├─┤
╩═╝┴ ┴┘└┘└─┘╚═╝┴└─┴ ┴┴ ┴ ┴
- 🚀 API: http://127.0.0.1:2024
- 🎨 Studio UI: https://smith.langchain.com/studio/?baseUrl=http://127.0.0.1:2024
- 📚 API Docs: http://127.0.0.1:2024/docs
This in-memory server is designed for development and testing.
For production use, please use LangSmith Deployment.
langgraph dev 명령은 Agent Server를 인메모리 모드로 시작해요. 이 모드는 개발·테스트 용도에 적합해요. 프로덕션에서는 영속 스토리지 백엔드에 접근 가능한 Agent Server를 배포하세요. 자세한 내용은 Platform 설정 개요를 보세요.
6. Studio에서 애플리케이션 테스트
Studio는 LangGraph API 서버에 연결해서 애플리케이션을 로컬에서 시각화·상호작용·디버그할 수 있는 특화된 UI예요. langgraph dev 명령 출력에 주어진 URL을 방문해 Studio에서 그래프를 테스트해요:
> - LangGraph Studio Web UI: https://smith.langchain.com/studio/?baseUrl=http://127.0.0.1:2024
커스텀 호스트/포트에서 실행되는 Agent Server의 경우 URL의 baseUrl 쿼리 파라미터를 갱신해요. 예를 들어 서버가 http://myhost:3000에서 실행 중이라면:
https://smith.langchain.com/studio/?baseUrl=http://myhost:3000
langgraph dev --tunnel
7. API 테스트
client = get_client(url="http://localhost:2024")
async def main():
async for chunk in client.runs.stream(
None, # Threadless run
"agent", # Assistant name. langgraph.json에 정의.
input={
"messages": [{
"role": "human",
"content": "What is LangGraph?",
}],
},
):
print(f"Receiving new event of type: {chunk.event}...")
print(chunk.data)
print("\n\n")
asyncio.run(main())
```
client = get_sync_client(url="http://localhost:2024")
for chunk in client.runs.stream(
None, # Threadless run
"agent", # Assistant name. langgraph.json에 정의.
input={
"messages": [{
"role": "human",
"content": "What is LangGraph?",
}],
},
stream_mode="messages-tuple",
):
print(f"Receiving new event of type: {chunk.event}...")
print(chunk.data)
print("\n\n")
```
다음 단계
이제 LangGraph 앱이 로컬에서 실행 중이니, 배포와 고급 기능을 탐구해 여정을 이어가세요:
- Deployment quickstart: LangSmith로 LangGraph 앱을 배포해요.
- LangSmith: LangSmith의 기초 개념에 대해 배워요.
- SDK Reference: SDK API 레퍼런스를 살펴봐요.