LangGraph Platform : Get started : クイックスタート

このガイドは LangGraph アプリケーションをローカルで実行する方法を示します。

LangGraph Platform : Get started : クイックスタート

作成 : クラスキャット・セールスインフォメーション
作成日時 : 06/20/2025

* 本記事は langchain-ai.github.io の以下のページを独自に翻訳した上で、補足説明を加えてまとめ直しています :

* サンプルコードの動作確認はしておりますが、必要な場合には適宜、追加改変しています。
* ご自由にリンクを張って頂いてかまいませんが、sales-info@classcat.com までご一報いただけると嬉しいです。

 

 

LangGraph Platform : Get started : クイックスタート

このガイドは LangGraph アプリケーションをローカルで実行する方法を示します。

 

前提条件

始める前に、次を持っていることを確認してください :

  • LangSmith 用 API キー – サインアップは無料です

 

1. LangGraph CLI のインストール

Python サーバ

# Python >= 3.11 is required.

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

Node サーバ

npx @langchain/langgraph-cli

 

2. LangGraph アプリケーションの作成

new-langgraph-project-python テンプレート または new-langgraph-project-js テンプレート から新しいアプリケーションを作成します。このテンプレートは独自ロジックで拡張可能な単一ノード・アプリケーションを実演します。

Python サーバ

langgraph new path/to/your/app --template new-langgraph-project-python

Node サーバ

langgraph new path/to/your/app --template new-langgraph-project-js

追加のテンプレート : 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. 依存関係のインストール

新しい LangGraph アプリケーションのルートで、edit モードで依存関係をインストールすると、ローカルの変更がサーバにより使用されます :

Python サーバ

cd path/to/your/app
pip install -e .

Node サーバ

cd path/to/your/app
yarn install

 

4. .env ファイルの作成

新しい LangGraph アプリケーションのルートで .env.example が見つかります。新しい LangGraph アプリケーションのルートで .env ファイルを作成して、.env.example ファイルの内容をそれにコピーして、必要な API キーを入力します :

LANGSMITH_API_KEY=lsv2...

 

5. LangGraph サーバの起動

LangGraph API server をローカルで起動します :

Python サーバ

langgraph dev

Node サーバ

npx @langchain/langgraph-cli dev
>    Ready!
>
>    - API: [http://localhost:2024](http://localhost:2024/)
>
>    - Docs: http://localhost:2024/docs
>
>    - LangGraph Studio Web UI: https://smith.langchain.com/studio/?baseUrl=http://127.0.0.1:2024

“langgraph dev” コマンドは in-memory モードで LangGraph サーバを起動します。このモードは開発とテスト目的に適しています。本番環境での利用には、永続化ストレージ・バックエンドへのアクセスを備えた LangGraph Server を配備します。For more information, see Deployment options.

 

6. アプリケーションを LangGraph Studio でテストする

LangGraph Studio は、LangGraph API に接続してローカルでアプリケーションを視覚化、操作、デバッグできる専用の UI です。”langgraph dev” コマンドの出力で提供される URL にアクセスすることで LangGraph Studio でグラフをテストします :

  • LangGraph Studio Web UI: https://smith.langchain.com/studio/?baseUrl=http://127.0.0.1:2024

For a LangGraph Server running on a custom host/port, update the baseURL parameter.

 

7. Test the API

Python SDK (非同期)

  1. LangGraph Python SDK をインストールします :
    pip install langgraph-sdk
    

     

  2. メッセージをアシスタントに送信します (threadless 実行) :
    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())
    

 
Python SDK (同期)

  1. LangGraph Python SDK をインストールします :
    pip install langgraph-sdk
    

     

  2. メッセージをアシスタントに送信します (threadless 実行) :
    from langgraph_sdk import get_sync_client
    
    client = get_sync_client(url="http://localhost:2024")
    
    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?",
            }],
        },
        stream_mode="messages-tuple",
    ):
        print(f"Receiving new event of type: {chunk.event}...")
        print(chunk.data)
        print("\n\n")
    

 

以上