0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

[1分でわかる]LangGraphってなんだ?

Posted at

結論

「LangChainの弟分、複雑なエージェント向け」

状態管理・ループ・分岐を持つ複雑なAIワークフローを構築するフレームワーク。


LangChainとの違い(3行)

項目 LangChain LangGraph
構造 線形(A→B→C) グラフ(ループ・分岐OK)
状態 手動で受け渡し 自動で管理
用途 シンプルなRAG・Chain 複雑なマルチエージェント

図解

【LangChain】線形パイプライン

  入力 → 処理A → 処理B → 処理C → 出力
  
  ※ 一方通行、戻れない


【LangGraph】グラフ構造

  入力 → 処理A ←──┐
           │      │
           ▼      │ ループ
        判断ノード─┘
           │
     ┌─────┴─────┐
     ▼           ▼ 分岐
   処理B       処理C
     │           │
     └─────┬─────┘
           ▼
         出力

いつLangGraphを使う?

【LangChain向き】
・シンプルなRAG
・1回の入出力で完結
・固定のワークフロー

【LangGraph向き】
・マルチエージェント
・Human-in-the-Loop(人間の承認待ち)
・リトライ・エラーハンドリング
・長時間タスク(状態保存が必要)

コード比較(超簡略)

# LangChain: 線形チェーン
chain = prompt | llm | output_parser
result = chain.invoke({"input": "質問"})

# LangGraph: グラフ構造
graph = StateGraph(State)
graph.add_node("agent", agent_node)
graph.add_node("tool", tool_node)
graph.add_edge("agent", "tool")
graph.add_conditional_edges("tool", should_continue)
app = graph.compile()
result = app.invoke({"input": "質問"})

一言まとめ

LangChain = 直線道路
LangGraph = 交差点・信号・Uターンあり

→ 両方併用が一般的(LangChainで部品、LangGraphで組み立て)

参考

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?