始める無料で始める

会話のセットアップ

屋根の長さを計算するためのカスタムツールを用意できたので、エージェントの出力を入力したクエリに応答するように設定できます。print 文を少し工夫すると、クエリとエージェントの応答を直接比較して、正確さを確認できます。toolsquery はすでに用意されており、model も使用可能です。

この演習はコースの一部です

LangChainで設計するエージェント型システム

コースを見る

演習の手順

  • 必要な引数を渡して create_react_agent 関数を初期化し、app というオブジェクトを作成します。
  • エージェント app を呼び出し、query を渡してエージェントの response を保存・出力します。
  • response"messages" から抽出した最後の要素を "agent_output"query"user_input" として定義し、両方を出力します。

実践的なインタラクティブ演習

このサンプルコードを完成させて、この演習に挑戦してみましょう。

tools = [hypotenuse_length]
query = "What is the value of the hypotenuse for a triangle with sides 3 and 5?"

# Create the ReAct agent
app = ____(____, ____)

# Invoke the agent with a query and store the messages
response = ____.____({"messages": [("human", ____)]})

# Define and print the input and output messages
print({
    "____": ____,
    "____": ____["____"][____].____
})
コードを編集して実行