APC 技術ブログ

株式会社エーピーコミュニケーションズの技術ブログです。

株式会社 エーピーコミュニケーションズの技術ブログです。

(settings.json改修)LangChainアプリケーション開発向けのsettings.jsonのその後

はじめに

クラウド事業部の大久保と申します。 以前に、PythonでLangChainやLangGraphのAgentアプリケーションを実装している中でsettings.jsonを添付していたのですが、 当初の内容が雑であったことと、時間が立って使っている中で色々直したので新しいバージョンをシェアするためにブログを書きます。

techblog.ap-com.co.jp

対象読者

  • VSCodeを利用してPythonでLangChainでプログラムを書き始めた皆様。
  • ruffを入れている皆様
  • 前の記事読んでいただいた皆様

現在のsettings.json(こちら使ってください)

    "[python]": {
        "editor.defaultFormatter": "charliermarsh.ruff",
        "editor.formatOnSave": true,
        "editor.tabSize": 4,
        "editor.insertSpaces": true,
        "editor.detectIndentation": false,
        "diffEditor.ignoreTrimWhitespace": false,
        "editor.defaultColorDecorators": "never",
        "gitlens.codeLens.symbolScopes": [
            "!Module"
        ],
        "editor.codeActionsOnSave": {
            "source.fixAll": "explicit",
            "source.organizeImports": "explicit"
        },
        "editor.formatOnType": true,
        "editor.wordBasedSuggestions": "off",
        "editor.suggest.insertMode": "replace",
    },
    "[yaml]": {
        "editor.tabSize": 2,
        "editor.insertSpaces": true,
        "editor.detectIndentation": false
    },
    "[json]": {
        "editor.quickSuggestions": {
            "strings": true
        },
        "editor.suggest.insertMode": "replace",
        "editor.formatOnSave": true,
    },
    // --------------- config for source analysis ---------------
    "python.languageServer": "Pylance",
    "python.envFile": "${workspaceFolder}/.env",
    "python.defaultInterpreterPath": "${workspaceFolder}/.venv/bin/python",
    "python.analysis.extraPaths": [
        "${workspaceFolder}/src",
    ],
    "python.analysis.diagnosticMode": "workspace",
    "python.analysis.indexing": true,
    "python.analysis.autoImportCompletions": true,
    "python.analysis.completeFunctionParens": true,
    "python.analysis.packageIndexDepths": [
        { "name": "langgraph", "depth": 2 },
        { "name": "langgraph_sdk", "depth": 2 },
        { "name": "langchain_core", "depth": 2 },
        { "name": "langchain_community", "depth": 2 }
    ],
    "files.watcherExclude": { "**/.venv/**": true, "**/__pycache__/**": true },
    // --------------- config for ruff extention ---------------
    "ruff.enable": true,
    "ruff.format.preview": true,
    "ruff.lineLength": 100,
    "ruff.interpreter": ["${workspaceFolder}/.venv/bin/python"],
    "ruff.lint.enable": true,
    "ruff.nativeServer": true,
    "pylint.enabled": false,
    "editor.defaultFormatter": "charliermarsh.ruff", // ruff is a only linter

以前のsettings.json

{
  // 仮想環境のパス(.venv を利用)
  "python.defaultInterpreterPath": "${workspaceFolder}/.venv/bin/python",

  // LangChain系モジュールを認識させる
  "python.analysis.extraPaths": ["${workspaceFolder}/.venv/lib/python3.12/site-packages/"],
  "python.analysis.packageIndexDepths": [
    { "name": "langchain_core", "depth": 2 },
    { "name": "langchain", "depth": 2 },
    { "name": "langchain_community", "depth": 2 },
    { "name": "langgraph", "depth": 2 }
  ],
  "python.analysis.autoSearchPaths": true,
  "python.analysis.autoImportCompletions": true,
  "python.autoComplete.extraPaths": [
    "${workspaceFolder}/.venv/lib/python3.12/site-packages/langchain_core"
  ],

  // フォーマッター(Ruffを使用)
  "editor.formatOnSave": true,
  "editor.defaultFormatter": "charliermarsh.ruff",

  // Ruff設定(VSCode拡張必須)
  "ruff.enable": true,
  "ruff.lineLength": 100,
  "ruff.importStrategy": "fromEnvironment",
  "ruff.interpreter": ["${workspaceFolder}/.venv/bin/python"],
  "ruff.path": ["${workspaceFolder}"],

  // pytest設定
  "python.testing.pytestEnabled": true,
  "python.testing.unittestEnabled": false,
  "python.testing.pytestArgs": ["tests"]
}

packageIndexDepth設定後


差分ダイジェスト

差分はGPT-5に書かせましたが意図はその通りなのでそのまま載せます。

  • src-firstextraPathssrc だけにし、site-packages 直指定を撤廃
  • LangGraph 対応強化langgraph_sdkpackageIndexDepths に追加
  • Ruff 一本化nativeServer/preview 有効化、pylint を無効化、保存時アクションは explicit
  • 言語別設定[python], [yaml], [json] を分離して現場標準のフォーマット運用
  • パフォーマンス.venv/__pycache__ をファイル監視から除外、解析の深堀り対象を限定
  • 撤去autoSearchPaths / autoComplete.extraPaths / ruff.path など環境依存ハックを削除
  • テスト設定の分離:pytest 等は pyproject.toml や CI 側に寄せる運用へ(私はpyproject.tomlに寄せてます)

体感で変わった点

  • 軽くなった:元々がSitepackageの中も見ていたのでリポジトリが増える都度重くっていったが、src中心に据えることで軽くはなった。
  • 視覚的なノイズがへった:とりあえずpylintとruffどちらも出していたが、ruffだけで十分なので

反省文

利用当初は良かったのですが、業務が進むにつれて辛くなる都度修正していきました。 pythonに慣れない中探り探りで動けばいいのノリで、公開していたのですがそこそこ見られていたので最初からこのレベルで作りこむべきだったと反省してます。 とはいえ、langchain系のライブラリ触る中で当時この種の情報が無かったので、出したことに後悔はないです、

寧ろ * 次はもっと良くしようという気持ち * Coding Agentが諸々作業する時代にConfigに向き合う機会 があったことが良かったです。

前回の記事のコンテンツが微妙で申し訳なかったところですが、LangChain系のエコシステムもこなれてきている中、またライブラリが肥大化している中で手に取ってもらったり、 レビュー頂けると嬉しいです。

おわりに

私達クラウド事業部はクラウド技術を活用したSI/SESのご支援をしております。

www.ap-com.co.jp

また、一緒に働いていただける仲間も募集中です! ご興味持っていただけましたらぜひお声がけください。

www.ap-com.co.jp