mirror of
https://github.com/hwchase17/langchain.git
synced 2025-06-20 05:43:55 +00:00
Revert "docs: replace deprecated initialize_agent
with create_react_agent
and non-deprecated functions" (#31492)
Reverts langchain-ai/langchain#31361
This commit is contained in:
parent
222578b296
commit
b149cce5f8
@ -22,16 +22,16 @@ You can use it as part of a Self Ask chain:
|
|||||||
|
|
||||||
```python
|
```python
|
||||||
from langchain_community.utilities import GoogleSerperAPIWrapper
|
from langchain_community.utilities import GoogleSerperAPIWrapper
|
||||||
from langchain_core.tools import Tool
|
from langchain_openai import OpenAI
|
||||||
from langchain_openai import ChatOpenAI
|
from langchain.agents import initialize_agent, Tool
|
||||||
from langgraph.prebuilt import create_react_agent
|
from langchain.agents import AgentType
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
|
||||||
os.environ["SERPER_API_KEY"] = ""
|
os.environ["SERPER_API_KEY"] = ""
|
||||||
os.environ['OPENAI_API_KEY'] = ""
|
os.environ['OPENAI_API_KEY'] = ""
|
||||||
|
|
||||||
llm = ChatOpenAI(temperature=0)
|
llm = OpenAI(temperature=0)
|
||||||
search = GoogleSerperAPIWrapper()
|
search = GoogleSerperAPIWrapper()
|
||||||
tools = [
|
tools = [
|
||||||
Tool(
|
Tool(
|
||||||
@ -41,13 +41,8 @@ tools = [
|
|||||||
)
|
)
|
||||||
]
|
]
|
||||||
|
|
||||||
agent = create_react_agent(llm, tools)
|
self_ask_with_search = initialize_agent(tools, llm, agent=AgentType.SELF_ASK_WITH_SEARCH, verbose=True)
|
||||||
|
self_ask_with_search.run("What is the hometown of the reigning men's U.S. Open champion?")
|
||||||
result = agent.invoke({
|
|
||||||
"messages": [("human", "What is the hometown of the reigning men's U.S. Open champion?")]
|
|
||||||
})
|
|
||||||
|
|
||||||
print(result)
|
|
||||||
```
|
```
|
||||||
|
|
||||||
#### Output
|
#### Output
|
||||||
|
@ -22,12 +22,13 @@ You can use it as part of a Self Ask chain:
|
|||||||
```python
|
```python
|
||||||
from langchain_community.utilities import SearchApiAPIWrapper
|
from langchain_community.utilities import SearchApiAPIWrapper
|
||||||
from langchain_openai import OpenAI
|
from langchain_openai import OpenAI
|
||||||
from langchain.agents import Tool, create_openai_functions_agent, AgentExecutor
|
from langchain.agents import initialize_agent, Tool
|
||||||
|
from langchain.agents import AgentType
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
|
||||||
os.environ["SEARCHAPI_API_KEY"] = "<your-searchapi-key>"
|
os.environ["SEARCHAPI_API_KEY"] = ""
|
||||||
os.environ['OPENAI_API_KEY'] = "<your-openai-key>"
|
os.environ['OPENAI_API_KEY'] = ""
|
||||||
|
|
||||||
llm = OpenAI(temperature=0)
|
llm = OpenAI(temperature=0)
|
||||||
search = SearchApiAPIWrapper()
|
search = SearchApiAPIWrapper()
|
||||||
@ -39,13 +40,8 @@ tools = [
|
|||||||
)
|
)
|
||||||
]
|
]
|
||||||
|
|
||||||
# Create agent and executor
|
self_ask_with_search = initialize_agent(tools, llm, agent=AgentType.SELF_ASK_WITH_SEARCH, verbose=True)
|
||||||
agent = create_openai_functions_agent(llm=llm, tools=tools)
|
self_ask_with_search.run("Who lived longer: Plato, Socrates, or Aristotle?")
|
||||||
agent_executor = AgentExecutor(agent=agent, tools=tools, verbose=True)
|
|
||||||
|
|
||||||
# Run the agent
|
|
||||||
response = agent_executor.invoke({"input": "Who lived longer: Plato, Socrates, or Aristotle?"})
|
|
||||||
print(response["output"])
|
|
||||||
```
|
```
|
||||||
|
|
||||||
#### Output
|
#### Output
|
||||||
|
@ -52,18 +52,18 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": null,
|
"execution_count": 1,
|
||||||
"id": "d41405b5",
|
"id": "d41405b5",
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
"from langchain.agents import AgentExecutor, create_react_agent, load_tools\n",
|
"from langchain.agents import AgentType, initialize_agent, load_tools\n",
|
||||||
"from langchain_openai import ChatOpenAI"
|
"from langchain_openai import ChatOpenAI"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": null,
|
"execution_count": 2,
|
||||||
"id": "d9e61df5",
|
"id": "d9e61df5",
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
@ -73,7 +73,7 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": null,
|
"execution_count": 3,
|
||||||
"id": "edc0ea0e",
|
"id": "edc0ea0e",
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"outputs": [
|
"outputs": [
|
||||||
@ -113,15 +113,13 @@
|
|||||||
],
|
],
|
||||||
"source": [
|
"source": [
|
||||||
"llm = ChatOpenAI(temperature=0)\n",
|
"llm = ChatOpenAI(temperature=0)\n",
|
||||||
"\n",
|
|
||||||
"tools = load_tools([\"requests_all\"])\n",
|
"tools = load_tools([\"requests_all\"])\n",
|
||||||
"tools += [tool]\n",
|
"tools += [tool]\n",
|
||||||
"\n",
|
"\n",
|
||||||
"agent = create_react_agent(llm=llm, tools=tools)\n",
|
"agent_chain = initialize_agent(\n",
|
||||||
"\n",
|
" tools, llm, agent=AgentType.ZERO_SHOT_REACT_DESCRIPTION, verbose=True\n",
|
||||||
"agent_executor = AgentExecutor(agent=agent, tools=tools, verbose=True)\n",
|
")\n",
|
||||||
"\n",
|
"agent_chain.run(\"what t shirts are available in klarna?\")"
|
||||||
"agent_executor.invoke({\"input\": \"what t shirts are available in klarna?\"})"
|
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -135,7 +133,7 @@
|
|||||||
],
|
],
|
||||||
"metadata": {
|
"metadata": {
|
||||||
"kernelspec": {
|
"kernelspec": {
|
||||||
"display_name": "AI_env",
|
"display_name": "Python 3 (ipykernel)",
|
||||||
"language": "python",
|
"language": "python",
|
||||||
"name": "python3"
|
"name": "python3"
|
||||||
},
|
},
|
||||||
@ -149,7 +147,7 @@
|
|||||||
"name": "python",
|
"name": "python",
|
||||||
"nbconvert_exporter": "python",
|
"nbconvert_exporter": "python",
|
||||||
"pygments_lexer": "ipython3",
|
"pygments_lexer": "ipython3",
|
||||||
"version": "3.12.2"
|
"version": "3.10.12"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"nbformat": 4,
|
"nbformat": 4,
|
||||||
|
@ -32,19 +32,6 @@
|
|||||||
"%pip install -qU langchain-community"
|
"%pip install -qU langchain-community"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"cell_type": "code",
|
|
||||||
"execution_count": null,
|
|
||||||
"id": "cf0cb2e5",
|
|
||||||
"metadata": {},
|
|
||||||
"outputs": [],
|
|
||||||
"source": [
|
|
||||||
"from langchain_community.agent_toolkits.nasa.toolkit import NasaToolkit\n",
|
|
||||||
"from langchain_community.utilities.nasa import NasaAPIWrapper\n",
|
|
||||||
"from langchain_openai import OpenAI\n",
|
|
||||||
"from langgraph.prebuilt import create_react_agent"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": null,
|
"execution_count": null,
|
||||||
@ -52,12 +39,17 @@
|
|||||||
"metadata": {},
|
"metadata": {},
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
|
"from langchain.agents import AgentType, initialize_agent\n",
|
||||||
|
"from langchain_community.agent_toolkits.nasa.toolkit import NasaToolkit\n",
|
||||||
|
"from langchain_community.utilities.nasa import NasaAPIWrapper\n",
|
||||||
|
"from langchain_openai import OpenAI\n",
|
||||||
|
"\n",
|
||||||
"llm = OpenAI(temperature=0, openai_api_key=\"\")\n",
|
"llm = OpenAI(temperature=0, openai_api_key=\"\")\n",
|
||||||
"nasa = NasaAPIWrapper()\n",
|
"nasa = NasaAPIWrapper()\n",
|
||||||
"toolkit = NasaToolkit.from_nasa_api_wrapper(nasa)\n",
|
"toolkit = NasaToolkit.from_nasa_api_wrapper(nasa)\n",
|
||||||
"tools = toolkit.get_tools()\n",
|
"agent = initialize_agent(\n",
|
||||||
"\n",
|
" toolkit.get_tools(), llm, agent=AgentType.ZERO_SHOT_REACT_DESCRIPTION, verbose=True\n",
|
||||||
"agent = create_react_agent(llm, tools)"
|
")"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -104,7 +96,7 @@
|
|||||||
],
|
],
|
||||||
"metadata": {
|
"metadata": {
|
||||||
"kernelspec": {
|
"kernelspec": {
|
||||||
"display_name": "AI_env",
|
"display_name": "Python 3 (ipykernel)",
|
||||||
"language": "python",
|
"language": "python",
|
||||||
"name": "python3"
|
"name": "python3"
|
||||||
},
|
},
|
||||||
@ -118,7 +110,7 @@
|
|||||||
"name": "python",
|
"name": "python",
|
||||||
"nbconvert_exporter": "python",
|
"nbconvert_exporter": "python",
|
||||||
"pygments_lexer": "ipython3",
|
"pygments_lexer": "ipython3",
|
||||||
"version": "3.12.2"
|
"version": "3.11.5"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"nbformat": 4,
|
"nbformat": 4,
|
||||||
|
Loading…
Reference in New Issue
Block a user