Skip to content

Commit b149cce

Browse files
authored
Revert "docs: replace deprecated initialize_agent with create_react_agent and non-deprecated functions" (#31492)
Reverts #31361
1 parent 222578b commit b149cce

File tree

4 files changed

+30
-49
lines changed

4 files changed

+30
-49
lines changed

docs/docs/integrations/providers/google_serper.mdx

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,16 @@ You can use it as part of a Self Ask chain:
2222

2323
```python
2424
from langchain_community.utilities import GoogleSerperAPIWrapper
25-
from langchain_core.tools import Tool
26-
from langchain_openai import ChatOpenAI
27-
from langgraph.prebuilt import create_react_agent
25+
from langchain_openai import OpenAI
26+
from langchain.agents import initialize_agent, Tool
27+
from langchain.agents import AgentType
2828

2929
import os
3030

3131
os.environ["SERPER_API_KEY"] = ""
3232
os.environ['OPENAI_API_KEY'] = ""
3333

34-
llm = ChatOpenAI(temperature=0)
34+
llm = OpenAI(temperature=0)
3535
search = GoogleSerperAPIWrapper()
3636
tools = [
3737
Tool(
@@ -41,13 +41,8 @@ tools = [
4141
)
4242
]
4343

44-
agent = create_react_agent(llm, tools)
45-
46-
result = agent.invoke({
47-
"messages": [("human", "What is the hometown of the reigning men's U.S. Open champion?")]
48-
})
49-
50-
print(result)
44+
self_ask_with_search = initialize_agent(tools, llm, agent=AgentType.SELF_ASK_WITH_SEARCH, verbose=True)
45+
self_ask_with_search.run("What is the hometown of the reigning men's U.S. Open champion?")
5146
```
5247

5348
#### Output

docs/docs/integrations/providers/searchapi.mdx

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,13 @@ You can use it as part of a Self Ask chain:
2222
```python
2323
from langchain_community.utilities import SearchApiAPIWrapper
2424
from langchain_openai import OpenAI
25-
from langchain.agents import Tool, create_openai_functions_agent, AgentExecutor
25+
from langchain.agents import initialize_agent, Tool
26+
from langchain.agents import AgentType
2627

2728
import os
2829

29-
os.environ["SEARCHAPI_API_KEY"] = "<your-searchapi-key>"
30-
os.environ['OPENAI_API_KEY'] = "<your-openai-key>"
30+
os.environ["SEARCHAPI_API_KEY"] = ""
31+
os.environ['OPENAI_API_KEY'] = ""
3132

3233
llm = OpenAI(temperature=0)
3334
search = SearchApiAPIWrapper()
@@ -39,13 +40,8 @@ tools = [
3940
)
4041
]
4142

42-
# Create agent and executor
43-
agent = create_openai_functions_agent(llm=llm, tools=tools)
44-
agent_executor = AgentExecutor(agent=agent, tools=tools, verbose=True)
45-
46-
# Run the agent
47-
response = agent_executor.invoke({"input": "Who lived longer: Plato, Socrates, or Aristotle?"})
48-
print(response["output"])
43+
self_ask_with_search = initialize_agent(tools, llm, agent=AgentType.SELF_ASK_WITH_SEARCH, verbose=True)
44+
self_ask_with_search.run("Who lived longer: Plato, Socrates, or Aristotle?")
4945
```
5046

5147
#### Output

docs/docs/integrations/tools/chatgpt_plugins.ipynb

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -52,18 +52,18 @@
5252
},
5353
{
5454
"cell_type": "code",
55-
"execution_count": null,
55+
"execution_count": 1,
5656
"id": "d41405b5",
5757
"metadata": {},
5858
"outputs": [],
5959
"source": [
60-
"from langchain.agents import AgentExecutor, create_react_agent, load_tools\n",
60+
"from langchain.agents import AgentType, initialize_agent, load_tools\n",
6161
"from langchain_openai import ChatOpenAI"
6262
]
6363
},
6464
{
6565
"cell_type": "code",
66-
"execution_count": null,
66+
"execution_count": 2,
6767
"id": "d9e61df5",
6868
"metadata": {},
6969
"outputs": [],
@@ -73,7 +73,7 @@
7373
},
7474
{
7575
"cell_type": "code",
76-
"execution_count": null,
76+
"execution_count": 3,
7777
"id": "edc0ea0e",
7878
"metadata": {},
7979
"outputs": [
@@ -113,15 +113,13 @@
113113
],
114114
"source": [
115115
"llm = ChatOpenAI(temperature=0)\n",
116-
"\n",
117116
"tools = load_tools([\"requests_all\"])\n",
118117
"tools += [tool]\n",
119118
"\n",
120-
"agent = create_react_agent(llm=llm, tools=tools)\n",
121-
"\n",
122-
"agent_executor = AgentExecutor(agent=agent, tools=tools, verbose=True)\n",
123-
"\n",
124-
"agent_executor.invoke({\"input\": \"what t shirts are available in klarna?\"})"
119+
"agent_chain = initialize_agent(\n",
120+
" tools, llm, agent=AgentType.ZERO_SHOT_REACT_DESCRIPTION, verbose=True\n",
121+
")\n",
122+
"agent_chain.run(\"what t shirts are available in klarna?\")"
125123
]
126124
},
127125
{
@@ -135,7 +133,7 @@
135133
],
136134
"metadata": {
137135
"kernelspec": {
138-
"display_name": "AI_env",
136+
"display_name": "Python 3 (ipykernel)",
139137
"language": "python",
140138
"name": "python3"
141139
},
@@ -149,7 +147,7 @@
149147
"name": "python",
150148
"nbconvert_exporter": "python",
151149
"pygments_lexer": "ipython3",
152-
"version": "3.12.2"
150+
"version": "3.10.12"
153151
}
154152
},
155153
"nbformat": 4,

docs/docs/integrations/tools/nasa.ipynb

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -35,29 +35,21 @@
3535
{
3636
"cell_type": "code",
3737
"execution_count": null,
38-
"id": "cf0cb2e5",
38+
"id": "648a2cb2-308e-4b2e-9b73-37109be4e258",
3939
"metadata": {},
4040
"outputs": [],
4141
"source": [
42+
"from langchain.agents import AgentType, initialize_agent\n",
4243
"from langchain_community.agent_toolkits.nasa.toolkit import NasaToolkit\n",
4344
"from langchain_community.utilities.nasa import NasaAPIWrapper\n",
4445
"from langchain_openai import OpenAI\n",
45-
"from langgraph.prebuilt import create_react_agent"
46-
]
47-
},
48-
{
49-
"cell_type": "code",
50-
"execution_count": null,
51-
"id": "648a2cb2-308e-4b2e-9b73-37109be4e258",
52-
"metadata": {},
53-
"outputs": [],
54-
"source": [
46+
"\n",
5547
"llm = OpenAI(temperature=0, openai_api_key=\"\")\n",
5648
"nasa = NasaAPIWrapper()\n",
5749
"toolkit = NasaToolkit.from_nasa_api_wrapper(nasa)\n",
58-
"tools = toolkit.get_tools()\n",
59-
"\n",
60-
"agent = create_react_agent(llm, tools)"
50+
"agent = initialize_agent(\n",
51+
" toolkit.get_tools(), llm, agent=AgentType.ZERO_SHOT_REACT_DESCRIPTION, verbose=True\n",
52+
")"
6153
]
6254
},
6355
{
@@ -104,7 +96,7 @@
10496
],
10597
"metadata": {
10698
"kernelspec": {
107-
"display_name": "AI_env",
99+
"display_name": "Python 3 (ipykernel)",
108100
"language": "python",
109101
"name": "python3"
110102
},
@@ -118,7 +110,7 @@
118110
"name": "python",
119111
"nbconvert_exporter": "python",
120112
"pygments_lexer": "ipython3",
121-
"version": "3.12.2"
113+
"version": "3.11.5"
122114
}
123115
},
124116
"nbformat": 4,

0 commit comments

Comments
 (0)