애플리케이션을 LangSmith에 배포하거나 자체 호스팅하려면 configuration file로 구성되어야 합니다. 이 가이드에서는 requirements.txt를 사용하여 프로젝트 의존성을 지정하고 배포를 위한 애플리케이션을 설정하는 기본 단계를 설명합니다.
이 예제는 LangGraph framework를 사용하는 이 repository를 기반으로 합니다.
최종 repository 구조는 다음과 같습니다:
my-app/
├── my_agent # all project code lies within here
│ ├── utils # utilities for your graph
│ │ ├── __init__.py
│ │ ├── tools.py # tools for your graph
│ │ ├── nodes.py # node functions for your graph
│ │ └── state.py # state definition of your graph
│ ├── requirements.txt # package dependencies
│ ├── __init__.py
│ └── agent.py # code for constructing your graph
├── .env # environment variables
└── langgraph.json # configuration file for LangGraph
LangSmith Deployment는 LangGraph graph 배포를 지원합니다. 그러나 graph의 node 구현에는 임의의 Python 코드가 포함될 수 있습니다. 이는 node 내에서 모든 프레임워크를 구현하고 LangSmith Deployment에 배포할 수 있음을 의미합니다. 이를 통해 핵심 애플리케이션 로직을 LangGraph 외부에 유지하면서도 배포, 확장 및 관찰 가능성을 위해 LangSmith를 계속 사용할 수 있습니다.
다음 방법으로도 설정할 수 있습니다:
pyproject.toml: 의존성 관리를 위해 poetry 사용을 선호하는 경우, LangSmith에서 pyproject.toml을 사용하는 방법에 대한 이 가이드를 확인하세요.
- monorepo: monorepo 내부에 위치한 graph를 배포하는 데 관심이 있다면, 이 repository에서 예제를 확인하세요.
각 단계 후에는 코드를 어떻게 구성할 수 있는지 보여주는 예제 파일 디렉토리가 제공됩니다.
의존성 지정
의존성은 선택적으로 다음 파일 중 하나에 지정할 수 있습니다: pyproject.toml, setup.py, 또는 requirements.txt. 이러한 파일이 생성되지 않은 경우, 나중에 configuration file에서 의존성을 지정할 수 있습니다.
아래 의존성은 이미지에 포함되며, 호환되는 버전 범위로 코드에서 사용할 수 있습니다:
langgraph>=0.6.0
langgraph-sdk>=0.1.66
langgraph-checkpoint>=2.0.23
langchain-core>=0.2.38
langsmith>=0.1.63
orjson>=3.9.7,<3.10.17
httpx>=0.25.0
tenacity>=8.0.0
uvicorn>=0.26.0
sse-starlette>=2.1.0,<2.2.0
uvloop>=0.18.0
httptools>=0.5.0
jsonschema-rs>=0.20.0
structlog>=24.1.0
cloudpickle>=3.0.0
예제 requirements.txt 파일:
langgraph
langchain_anthropic
tavily-python
langchain_community
langchain_openai
예제 파일 디렉토리:
my-app/
├── my_agent # all project code lies within here
│ └── requirements.txt # package dependencies
환경 변수 지정
환경 변수는 선택적으로 파일(예: .env)에 지정할 수 있습니다. 배포를 위한 추가 변수를 구성하려면 Environment Variables reference를 참조하세요.
예제 .env 파일:
MY_ENV_VAR_1=foo
MY_ENV_VAR_2=bar
OPENAI_API_KEY=key
예제 파일 디렉토리:
my-app/
├── my_agent # all project code lies within here
│ └── requirements.txt # package dependencies
└── .env # environment variables
기본적으로 LangSmith는 명시적으로 허용하지 않는 한 prerelease 버전을 설치하지 않는 uv/pip 동작을 따릅니다. prerelease를 사용하려면 다음 옵션을 사용할 수 있습니다:
pyproject.toml 사용 시: [tool.uv] 섹션에 allow-prereleases = true를 추가합니다.
requirements.txt 또는 setup.py 사용 시: 전이 종속성을 포함하여 모든 prerelease 종속성을 명시적으로 지정해야 합니다. 예를 들어, a==0.0.1a1을 선언하고 a가 b==0.0.1a1에 의존하는 경우, 종속성에 b==0.0.1a1도 명시적으로 포함해야 합니다.
Graph 정의
graph를 구현합니다. Graph는 단일 파일 또는 여러 파일에 정의할 수 있습니다. 애플리케이션에 포함될 각 CompiledStateGraph의 변수 이름을 기록해 두세요. 변수 이름은 나중에 LangGraph configuration file을 생성할 때 사용됩니다.
예제 agent.py 파일은 정의한 다른 모듈에서 import하는 방법을 보여줍니다(모듈의 코드는 여기에 표시되지 않으며, 구현을 보려면 이 repository를 참조하세요):
# my_agent/agent.py
from typing import Literal
from typing_extensions import TypedDict
from langgraph.graph import StateGraph, END, START
from my_agent.utils.nodes import call_model, should_continue, tool_node # import nodes
from my_agent.utils.state import AgentState # import state
# Define the runtime context
class GraphContext(TypedDict):
model_name: Literal["anthropic", "openai"]
workflow = StateGraph(AgentState, context_schema=GraphContext)
workflow.add_node("agent", call_model)
workflow.add_node("action", tool_node)
workflow.add_edge(START, "agent")
workflow.add_conditional_edges(
"agent",
should_continue,
{
"continue": "action",
"end": END,
},
)
workflow.add_edge("action", "agent")
graph = workflow.compile()
예제 파일 디렉토리:
my-app/
├── my_agent # all project code lies within here
│ ├── utils # utilities for your graph
│ │ ├── __init__.py
│ │ ├── tools.py # tools for your graph
│ │ ├── nodes.py # node functions for your graph
│ │ └── state.py # state definition of your graph
│ ├── requirements.txt # package dependencies
│ ├── __init__.py
│ └── agent.py # code for constructing your graph
└── .env # environment variables
Configuration file 생성
langgraph.json이라는 configuration file을 생성합니다. configuration file의 JSON 객체에 있는 각 키에 대한 자세한 설명은 configuration file reference를 참조하세요.
예제 langgraph.json 파일:
{
"dependencies": ["./my_agent"],
"graphs": {
"agent": "./my_agent/agent.py:graph"
},
"env": ".env"
}
CompiledGraph의 변수 이름이 최상위 graphs 키의 각 하위 키 값 끝에 나타납니다(즉, :<variable_name>).
Configuration File 위치
Configuration file은 compiled graph와 관련 의존성을 포함하는 Python 파일과 같은 레벨이거나 상위 디렉토리에 배치되어야 합니다.
예제 파일 디렉토리:
my-app/
├── my_agent # all project code lies within here
│ ├── utils # utilities for your graph
│ │ ├── __init__.py
│ │ ├── tools.py # tools for your graph
│ │ ├── nodes.py # node functions for your graph
│ │ └── state.py # state definition of your graph
│ ├── requirements.txt # package dependencies
│ ├── __init__.py
│ └── agent.py # code for constructing your graph
├── .env # environment variables
└── langgraph.json # configuration file for LangGraph
다음 단계
프로젝트를 설정하고 GitHub repository에 배치한 후, 앱을 배포할 차례입니다.