カスタムツールとエージェントの統合
ツールが手元にそろった今、エージェント型ワークフローをセットアップしましょう! 再びReActエージェントを使います。これは、これから取るべき手順を考え、その文脈とツールの説明に基づいてツールを選択するものです。llmはすでに定義されており、OpenAIのgpt-4o-miniモデルを使っています
この演習はコースの一部です
LangChainを使ったLLMアプリケーション開発
演習の手順
create_react_agent()にllmとあなたのretrieve_customer_infoツールを含むリストを渡して、ReAct エージェントを作成します。agent.invoke()を使って、指定された入力でエージェントを実行します。- 最後のメッセージの内容を出力します。
実践的なインタラクティブ演習
このサンプルコードを完成させて、この演習に挑戦してみましょう。
@tool
def retrieve_customer_info(name: str) -> str:
"""Retrieve customer information based on their name."""
customer_info = customers[customers['name'] == name]
return customer_info.to_string()
# Create a ReAct agent
agent = create_react_agent(____, [____])
# Invoke the agent on the input
messages = agent.____({"messages": [("human", "Create a summary of our customer: Peak Performance Co.")]})
print(messages['messages'][-1].____)