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?

[LangGraph] langgraphを触ってみる

Last updated at Posted at 2025-03-25

背景

  • AI World 2025展示会に参加して、ある会社は四つのAIエージェントを提供している
  • ユーザはこの四つのAIエージェントを利用したい場合は、UI画面はどう実装するか

以前のUI画面

メニュー チャット部分
Agent_A
Agent_B
Agent_C
Agent_D

AI時代の画面

チャット部分
ユーザの入力する情報より、自動的にエージェントを選べる

LangGraph基礎

  • Node
    • 状態を受け取り、処理して、新しい情報を状態に返す
  • Edge
    • ノード間の接続を定義し、遷移ルールを決める
  • State
    • Graph全体で共有される状態のオブジェクト

langgraphで上記の問題を解決してみる

ChatGPT Sample - だれの口調で自己紹介するか?(ルフィ/アーニャ)

ワークフロー

スクリーンショット 2025-03-25 20.43.22.png

edgeを定義

def decide_role(
    state: State,
) -> Literal["anya_res", "rufi_res"]:
    if "ルフィ" in state.role:
        return "rufi_res"
    elif "アーニャ" in state.role:
        return "anya_res"
    else:
        print("ロールが正しく入力されていません。もう一度入力してください。")
        return "other"

ソースコード

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?