はじめに
LangChainが便利そうなので試してみました。
クイックスタートで試す
以下でクイックスタートが公開されています。
Quickstart Guide
python.langchain.com

Page Not Found | 🦜️🔗 LangChain
日本語で下記が詳しいので参考にしています。
以下のようなコードで実行。都道府県の大きさを確認しています。
SerpAPIを利用しています。
export OPENAI_API_KEY=sk-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
from langchain.agents import load_tools
from langchain.agents import initialize_agent
from langchain.llms import OpenAI
# LLM ラッパーを導入します。これは、エージェントをコントロールするために使われます。
llm = OpenAI(temperature=0)
# ツールを導入します。 `llm-math` ツールを使うのに LLM を指定する必要があることに注意してください
tools = load_tools(["serpapi", "llm-math"], llm=llm)
# エージェントを初期化します
# 初期化時には、使用するツールの一覧と、使用する LLM, エージェントの種類を指定します
# ここで指定している "zero-shot-react-description" というエージェントは、ツールの説明のみに基づいて、どのツールを使用するかを決定してくれます
agent = initialize_agent(tools, llm, agent="zero-shot-react-description", verbose=True)
#エージェントにタスクを実行してもらいます
agent.run("日本の都道府県で面積の大きな順に上位10位までを日本語で箇条書きで出力してください。")
> Entering new AgentExecutor chain... I need to find the top 10 prefectures in Japan by area. Action: Search Action Input: "Japan prefectures by area" Observation: No good search result found Thought: I should try a different search query Action: Search Action Input: "Japan prefectures area ranking" Observation: No good search result found Thought: I should try a different search query Action: Search Action Input: "Japan prefectures area list" Observation: Japan is divided into 47 prefectures which rank immediately below the national government and form the country's first level of jurisdiction and ... Thought: This looks like a good search result Final Answer: 1. 北海道 2. 青森県 3. 岩手県 4. 宮城県 5. 秋田県 6. 山形県 7. 福島県 8. 茨城県 9. 栃木県 10. 群馬県 > Finished chain.
ちなみにOpenAIのChatGPT4に聞くとどうでしょう。

正解はこちら
どっちも違うやんw
まとめ
LangChainを試してみました。正誤はまた別の話なので良しとしましょう。
