会話のセットアップ
屋根の長さを計算するためのカスタムツールを用意できたので、エージェントの出力を入力したクエリに応答するように設定できます。print 文を少し工夫すると、クエリとエージェントの応答を直接比較して、正確さを確認できます。tools と query はすでに用意されており、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({
"____": ____,
"____": ____["____"][____].____
})