Skip to main content
本快速入门教程向您展示如何在本地上设置LangGraph应用程序进行测试和开发。

前提条件

在开始之前,请确保您已注册LangSmith(免费注册)并获取了API密钥。

1. 安装 LangGraph CLI

# Python >= 3.11 is required.

pip install -U "langgraph-cli[inmem]"

2. Create a LangGraph app 🌱

Create a new app from the new-langgraph-project-python template or new-langgraph-project-js template. This template demonstrates a single-node application you can extend with your own logic.
langgraph new path/to/your/app --template new-langgraph-project-python
Additional templates
If you use langgraph new without specifying a template, you will be presented with an interactive menu that will allow you to choose from a list of available templates.

3. Install dependencies

In the root of your new LangGraph app, install the dependencies in edit mode so your local changes are used by the server:
cd path/to/your/app
pip install -e .

4. Create a .env file

You will find a .env.example in the root of your new LangGraph app. Create a .env file in the root of your new LangGraph app and copy the contents of the .env.example file into it, filling in the necessary API keys:
LANGSMITH_API_KEY=lsv2...

5. Launch LangGraph Server 🚀

Start the LangGraph API server locally:
langgraph dev
Sample output:
>    Ready!
>
>    - API: [http://localhost:2024](http://localhost:2024/)
>
>    - Docs: http://localhost:2024/docs
>
>    - Studio Web UI: https://smith.langchain.com/studio/?baseUrl=http://127.0.0.1:2024
The langgraph dev command starts LangGraph Server in an in-memory mode. This mode is suitable for development and testing purposes.
For production use, deploy LangGraph Server with a persistent storage backend. For more information, refer to the LangSmith hosting options.

6. Test the API

  1. Install the LangGraph Python SDK:
pip install langgraph-sdk
  1. Send a message to the assistant (threadless run):
from langgraph_sdk import get_client
import asyncio

client = get_client(url="http://localhost:2024")

async def main():
    async for chunk in client.runs.stream(
        None,  # Threadless run
        "agent", # Name of assistant. Defined in 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())

下一步

现在您已经在本地上运行了 LangGraph 应用程序,您就可以准备部署它了: 为LangSmith选择一个托管选项:
  • :快速设置,全面管理(推荐)。
  • 混合:在您的云中运行时环境,您的LangGraph服务器和智能体执行的地方。,由LangChain管理的
  • 自托管:在您的基础设施中拥有完全控制权。
有关更多详细信息,请参阅托管比较 然后部署您的应用: 探索功能: